Refactor infra tests, clean E2E step suites, and fix TS in tests

This commit is contained in:
2025-11-30 10:58:49 +01:00
parent af14526ae2
commit f8a1fbeb50
43 changed files with 883 additions and 2159 deletions

View File

@@ -1,57 +0,0 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { PlaywrightAutomationAdapter } from '../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter';
import { StepId } from '../../packages/domain/value-objects/StepId';
import { NoOpLogAdapter } from '../../packages/infrastructure/adapters/logging/NoOpLogAdapter';
/**
* RED Phase Test: Step 6 Missing Case
*
* This test exercises step 6 (SET_ADMINS) and MUST fail with "Unknown step: 6" error
* because case 6 is missing from the executeStep() switch statement.
*
* Given: A mock automation adapter configured for step execution
* When: Step 6 is executed
* Then: The adapter should throw "Unknown step: 6" error
*/
describe('E2E: Step 6 Missing Case (RED Phase)', () => {
let adapter: PlaywrightAutomationAdapter;
beforeEach(async () => {
const logger = new NoOpLogAdapter();
adapter = new PlaywrightAutomationAdapter({
headless: true,
timeout: 5000,
mode: 'mock',
baseUrl: 'file://' + process.cwd() + '/html-dumps',
}, logger);
await adapter.connect();
});
afterEach(async () => {
if (adapter) {
await adapter.disconnect();
}
});
it('should successfully execute step 6 (SET_ADMINS)', async () => {
// Given: Navigate to step 6 fixture (Set Admins page)
const navResult = await adapter.navigateToPage(`file://${process.cwd()}/html-dumps/step-06-set-admins.html`);
expect(navResult.success).toBe(true);
// When: Execute step 6 (should navigate to Time Limits)
const step6Result = await adapter.executeStep(StepId.create(6), {});
// Then: Should succeed (RED phase - this WILL FAIL because case 6 is missing)
expect(step6Result.success).toBe(true);
expect(step6Result.error).toBeUndefined();
});
it('should verify step 6 is recognized as valid by StepId', () => {
// Step 6 should be within valid range (1-17)
expect(() => StepId.create(6)).not.toThrow();
const step6 = StepId.create(6);
expect(step6.value).toBe(6);
});
});

View File

@@ -1,144 +0,0 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { PlaywrightAutomationAdapter } from '../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter';
import { StepId } from '../../packages/domain/value-objects/StepId';
import path from 'path';
/**
* E2E tests for Steps 7-9 alignment fix.
*
* Tests verify that:
* - Step 7 correctly handles Time Limits wizard step (#set-time-limit)
* - Step 8 correctly handles Set Cars wizard step (#set-cars)
* - Step 9 correctly handles Add Car modal (not a wizard step)
*
* These tests MUST FAIL initially to demonstrate the off-by-one error.
*/
describe('Steps 7-9 Alignment Fix (E2E)', () => {
let adapter: PlaywrightAutomationAdapter;
const fixtureBaseUrl = `file://${path.resolve(process.cwd(), 'html-dumps')}`;
beforeAll(async () => {
adapter = new PlaywrightAutomationAdapter({
headless: true,
timeout: 5000,
baseUrl: fixtureBaseUrl,
mode: 'mock',
});
await adapter.connect();
});
afterAll(async () => {
await adapter.disconnect();
});
describe('RED Phase - These tests MUST fail initially', () => {
it('Step 7 should wait for #set-time-limit wizard step', async () => {
// Navigate to Step 7 fixture
await adapter.navigateToPage(`${fixtureBaseUrl}/step-07-time-limits.html`);
const page = adapter.getPage();
expect(page).not.toBeNull();
// Verify we're on the correct page BEFORE execution
const stepIndicatorBefore = await page!.textContent('[data-indicator]');
expect(stepIndicatorBefore).toContain('Time Limits');
// Execute Step 7 with time limit config
const result = await adapter.executeStep(
StepId.create(7),
{
practice: 10,
qualify: 10,
race: 20,
}
);
// Should succeed
expect(result.success).toBe(true);
expect(result.error).toBeUndefined();
// After execution, we should have navigated to Step 8 (Set Cars)
// This is the expected behavior - executeStep() clicks "Next" at the end
const stepIndicatorAfter = await page!.textContent('[data-indicator]');
expect(stepIndicatorAfter).toContain('Set Cars');
});
it('Step 8 should wait for #set-cars wizard step', async () => {
// Navigate to Step 8 fixture (Set Cars)
await adapter.navigateToPage(`${fixtureBaseUrl}/step-08-set-cars.html`);
const page = adapter.getPage();
expect(page).not.toBeNull();
// Verify we're on the correct page BEFORE execution
const stepIndicatorBefore = await page!.textContent('[data-indicator]');
expect(stepIndicatorBefore).toContain('Set Cars');
// Execute Step 8 - should just wait for #set-cars and click next
const result = await adapter.executeStep(
StepId.create(8),
{}
);
// Should succeed
expect(result.success).toBe(true);
expect(result.error).toBeUndefined();
// Note: After Step 8, we'd normally navigate to Track, but that fixture doesn't exist yet
// So we just verify Step 8 executed successfully
});
it('Step 9 should handle Add Car modal correctly', async () => {
// Navigate to Step 9 fixture (Add Car modal)
await adapter.navigateToPage(`${fixtureBaseUrl}/step-09-add-car.html`);
const page = adapter.getPage();
expect(page).not.toBeNull();
// Verify we're on the Add Car modal page
const modalTitleBefore = await page!.textContent('[data-indicator="add-car"]');
expect(modalTitleBefore).toContain('Add a Car');
// Execute Step 9 with car search
const result = await adapter.executeStep(
StepId.create(9),
{
carSearch: 'Porsche 911 GT3 R',
}
);
// Should succeed
expect(result.success).toBe(true);
expect(result.error).toBeUndefined();
// Step 9 is a modal-only step - it doesn't navigate to another page
// It just handles the car addition modal, so we verify it completed successfully
});
});
describe('Integration - Full Steps 7-9 flow', () => {
it('should execute Steps 7-9 in correct sequence', async () => {
// Step 7: Time Limits
await adapter.navigateToPage(`${fixtureBaseUrl}/step-07-time-limits.html`);
const step7Result = await adapter.executeStep(StepId.create(7), {
practice: 10,
qualify: 10,
race: 20,
});
expect(step7Result.success).toBe(true);
// Step 8: Set Cars
await adapter.navigateToPage(`${fixtureBaseUrl}/step-08-set-cars.html`);
const step8Result = await adapter.executeStep(StepId.create(8), {});
expect(step8Result.success).toBe(true);
// Step 9: Add Car modal
await adapter.navigateToPage(`${fixtureBaseUrl}/step-09-add-car.html`);
const step9Result = await adapter.executeStep(StepId.create(9), {
carSearch: 'Porsche 911 GT3 R',
});
expect(step9Result.success).toBe(true);
});
});
});

View File

@@ -1,75 +0,0 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import path from 'path';
import { PlaywrightAutomationAdapter } from 'packages/infrastructure/adapters/automation';
import { NoOpLogAdapter } from '../../packages/infrastructure/adapters/logging/NoOpLogAdapter';
import { StepId } from '../../packages/domain/value-objects/StepId';
/**
* E2E Test: Step 8→9→11 State Synchronization Bug
*
* This test reproduces the bug where:
* 1. Step 8 prematurely navigates to Step 11 (Track page)
* 2. Step 9 fails because it expects to be on Step 8 (Cars page)
*
* Expected Behavior:
* - Step 8 should NOT navigate (only view cars)
* - Step 9 should navigate from Cars → Track after adding car
* - Step 11 should find itself already on Track page
*
* This test MUST fail initially to prove the bug exists.
*/
describe('E2E: Step 8→9→11 State Synchronization', () => {
let adapter: PlaywrightAutomationAdapter;
const fixtureBaseUrl = `file://${path.resolve(process.cwd(), 'html-dumps')}`;
beforeAll(async () => {
const logger = new NoOpLogAdapter();
adapter = new PlaywrightAutomationAdapter(
{ headless: true, mode: 'mock', baseUrl: fixtureBaseUrl, timeout: 5000 },
logger
);
await adapter.connect();
}, 30000);
afterAll(async () => {
await adapter?.disconnect();
});
it('should expose the bug: Step 8 navigates prematurely causing Step 9 to fail', async () => {
// Navigate to Step 8 (Cars page)
await adapter.navigateToPage(`${fixtureBaseUrl}/step-08-set-cars.html`);
const page = adapter.getPage();
expect(page).not.toBeNull();
// Verify we start on Cars page
const initialStepTitle = await page!.textContent('[data-indicator]');
expect(initialStepTitle).toContain('Set Cars');
// Execute Step 8 - it will navigate to Track (bug!)
const step8Result = await adapter.executeStep(StepId.create(8), {});
expect(step8Result.success).toBe(true);
// After Step 8, check where we are
const pageAfterStep8 = await page!.textContent('[data-indicator]');
// BUG ASSERTION: This WILL pass because Step 8 navigates (incorrectly)
// After fix, Step 8 should NOT navigate, so this will fail
expect(pageAfterStep8).toContain('Set Track');
}, 30000);
it.skip('should demonstrate correct behavior after fix', async () => {
// This test will be unskipped after the fix
await adapter.navigateToPage(`${fixtureBaseUrl}/step-08-set-cars.html`);
const page = adapter.getPage();
expect(page).not.toBeNull();
// Step 8: View cars only (NO navigation)
await adapter.executeStep(StepId.create(8), {});
// After Step 8, we should STILL be on Cars page
const pageAfterStep8 = await page!.textContent('[data-indicator]');
expect(pageAfterStep8).toContain('Set Cars');
}, 30000);
});

View File

@@ -1,292 +0,0 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { PlaywrightAutomationAdapter } from '../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter';
import { FixtureServer } from '../../packages/infrastructure/adapters/automation/FixtureServer';
import { StepId } from '../../packages/domain/value-objects/StepId';
import { PinoLogAdapter } from '../../packages/infrastructure/adapters/logging/PinoLogAdapter';
/**
* Regression Test: Step 9 State Synchronization
*
* This test prevents regression of the critical bug where Step 9 (ADD_CAR)
* executes while the browser is already on Step 11 (SET_TRACK).
*
* **Root Cause**: Validation was checking `validation.isErr()` instead of
* `validationResult.isValid`, causing validation failures to be silently ignored.
*
* **Evidence**: Debug dump showed:
* - Wizard Footer: "← Cars | Track Options →"
* - Actual Page: Step 11 (SET_TRACK)
* - Expected Page: Step 8/9 (SET_CARS)
* - Discrepancy: 3 steps ahead
*/
describe('Step 9 State Validation Regression Test', () => {
let server: FixtureServer;
let adapter: PlaywrightAutomationAdapter;
let logger: PinoLogAdapter;
beforeEach(async () => {
// Setup fixture server
server = new FixtureServer();
const serverInfo = await server.start();
// Setup logger
logger = new PinoLogAdapter();
// Setup adapter in mock mode
adapter = new PlaywrightAutomationAdapter(
{
headless: true,
timeout: 5000,
mode: 'mock',
baseUrl: serverInfo.url,
},
logger
);
await adapter.connect();
});
afterEach(async () => {
await adapter.disconnect();
await server.stop();
});
it('should throw error if Step 9 executes on Track page instead of Cars page', async () => {
// Arrange: Navigate directly to Track page (Step 11)
await adapter.navigateToPage(server.getFixtureUrl(11));
// Wait for page to load
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act & Assert: Attempt to execute Step 9 (should fail immediately)
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
carSearch: 'Mazda MX-5'
});
}).rejects.toThrow(/Step 9 FAILED validation/i);
});
it('should detect state mismatch when Cars button is missing', async () => {
// Arrange: Navigate to Track page
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act & Assert
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
carSearch: 'Porsche 911'
});
}).rejects.toThrow(/Expected cars step/i);
});
it('should detect when #set-track container is present instead of Cars page', async () => {
// Arrange: Navigate to Track page
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act & Assert: Error should mention we're 3 steps ahead
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
carSearch: 'Ferrari 488'
});
}).rejects.toThrow(/3 steps ahead|Track page/i);
});
it('should pass validation when actually on Cars page', async () => {
// Arrange: Navigate to correct page (Step 8 - Cars)
await adapter.navigateToPage(server.getFixtureUrl(8));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act: Execute Step 9 (should succeed)
const result = await adapter.executeStep(StepId.create(9), {
carSearch: 'Mazda MX-5'
});
// Assert: Should complete successfully
expect(result.success).toBe(true);
});
it('should fail fast on Step 8 if already past Cars page', async () => {
// Arrange: Navigate to Track page (Step 11)
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act & Assert: Step 8 should also fail validation
await expect(async () => {
await adapter.executeStep(StepId.create(8), {});
}).rejects.toThrow(/Step 8 FAILED validation/i);
});
it('should provide detailed error context in validation failure', async () => {
// Arrange: Navigate to Track page
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act: Capture error details
let errorMessage = '';
try {
await adapter.executeStep(StepId.create(9), {
carSearch: 'BMW M4'
});
} catch (error) {
errorMessage = error instanceof Error ? error.message : String(error);
}
// Assert: Error should contain diagnostic information
expect(errorMessage).toContain('Step 9');
expect(errorMessage).toMatch(/validation|mismatch|wrong page/i);
});
it('should validate page state before attempting any Step 9 actions', async () => {
// Arrange: Navigate to wrong page
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
const page = adapter.getPage();
if (!page) {
throw new Error('Page not available');
}
// Track if any car-related actions were attempted
let carModalOpened = false;
page.on('framenavigated', () => {
// If we navigate, it means we got past validation (bad!)
carModalOpened = true;
});
// Act: Try to execute Step 9
let validationError = false;
try {
await adapter.executeStep(StepId.create(9), {
carSearch: 'Audi R8'
});
} catch (error) {
validationError = true;
}
// Assert: Should fail validation before attempting any actions
expect(validationError).toBe(true);
expect(carModalOpened).toBe(false);
});
it('should check wizard footer state in Step 9', async () => {
// This test verifies the wizard footer check is working
// Arrange: Navigate to Track page
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act & Assert: Error should reference wizard footer state
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
carSearch: 'McLaren 720S'
});
}).rejects.toThrow(); // Will throw due to validation failure
});
});
describe('Step 8 State Validation Regression Test', () => {
let server: FixtureServer;
let adapter: PlaywrightAutomationAdapter;
let logger: PinoLogAdapter;
beforeEach(async () => {
server = new FixtureServer();
const serverInfo = await server.start();
logger = new PinoLogAdapter();
adapter = new PlaywrightAutomationAdapter(
{
headless: true,
timeout: 5000,
mode: 'mock',
baseUrl: serverInfo.url,
},
logger
);
await adapter.connect();
});
afterEach(async () => {
await adapter.disconnect();
await server.stop();
});
it('should validate page state in Step 8 before proceeding', async () => {
// Arrange: Navigate to wrong page (Track instead of Cars)
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act & Assert: Step 8 should fail validation
await expect(async () => {
await adapter.executeStep(StepId.create(8), {});
}).rejects.toThrow(/Step 8 FAILED validation/i);
});
it('should pass Step 8 validation when on correct page', async () => {
// Arrange: Navigate to Cars page
await adapter.navigateToPage(server.getFixtureUrl(8));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act: Execute Step 8
const result = await adapter.executeStep(StepId.create(8), {});
// Assert: Should succeed
expect(result.success).toBe(true);
});
});
describe('Step 11 State Validation Regression Test', () => {
let server: FixtureServer;
let adapter: PlaywrightAutomationAdapter;
let logger: PinoLogAdapter;
beforeEach(async () => {
server = new FixtureServer();
const serverInfo = await server.start();
logger = new PinoLogAdapter();
adapter = new PlaywrightAutomationAdapter(
{
headless: true,
timeout: 5000,
mode: 'mock',
baseUrl: serverInfo.url,
},
logger
);
await adapter.connect();
});
afterEach(async () => {
await adapter.disconnect();
await server.stop();
});
it('should validate Step 11 is on Track page', async () => {
// Arrange: Navigate to wrong page (Cars instead of Track)
await adapter.navigateToPage(server.getFixtureUrl(8));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act & Assert: Step 11 should fail validation
await expect(async () => {
await adapter.executeStep(StepId.create(11), {});
}).rejects.toThrow(/Step 11 FAILED validation/i);
});
it('should pass Step 11 validation when on Track page', async () => {
// Arrange: Navigate to Track page
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
// Act: Execute Step 11
const result = await adapter.executeStep(StepId.create(11), {});
// Assert: Should succeed
expect(result.success).toBe(true);
});
});

View File

@@ -0,0 +1,70 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { PlaywrightAutomationAdapter, FixtureServer } from 'packages/infrastructure/adapters/automation';
import { StepId } from 'packages/domain/value-objects/StepId';
import { PinoLogAdapter } from 'packages/infrastructure/adapters/logging/PinoLogAdapter';
describe('Step 6 admins', () => {
let server: FixtureServer;
let adapter: PlaywrightAutomationAdapter;
let logger: PinoLogAdapter;
beforeEach(async () => {
server = new FixtureServer();
const serverInfo = await server.start();
logger = new PinoLogAdapter();
adapter = new PlaywrightAutomationAdapter(
{
headless: true,
timeout: 5000,
mode: 'mock',
baseUrl: serverInfo.url,
},
logger,
);
await adapter.connect();
});
afterEach(async () => {
await adapter.disconnect();
await server.stop();
});
it('completes successfully from Set Admins page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(5));
const page = adapter.getPage();
expect(page).not.toBeNull();
const sidebarAdmins = await page!.textContent('#wizard-sidebar-link-set-admins');
expect(sidebarAdmins).toContain('Admins');
const result = await adapter.executeStep(StepId.create(6), {
adminSearch: 'Marc',
});
expect(result.success).toBe(true);
const footerText = await page!.textContent('.wizard-footer');
expect(footerText).toContain('Time Limit');
});
it('handles Add Admin drawer state without regression', async () => {
await adapter.navigateToPage(server.getFixtureUrl(6));
const page = adapter.getPage();
expect(page).not.toBeNull();
const header = await page!.textContent('#set-admins .card-header');
expect(header).toContain('Set Admins');
const result = await adapter.executeStep(StepId.create(6), {
adminSearch: 'Mintel',
});
expect(result.success).toBe(true);
const footerText = await page!.textContent('.wizard-footer');
expect(footerText).toContain('Time Limit');
});
});

View File

@@ -0,0 +1,44 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import path from 'path';
import { PlaywrightAutomationAdapter } from 'packages/infrastructure/adapters/automation';
import { StepId } from 'packages/domain/value-objects/StepId';
describe('Step 7 time limits', () => {
let adapter: PlaywrightAutomationAdapter;
const fixtureBaseUrl = `file://${path.resolve(process.cwd(), 'html-dumps')}`;
beforeAll(async () => {
adapter = new PlaywrightAutomationAdapter({
headless: true,
timeout: 5000,
baseUrl: fixtureBaseUrl,
mode: 'mock',
});
await adapter.connect();
});
afterAll(async () => {
await adapter.disconnect();
});
it('executes on Time Limits page and navigates to Cars', async () => {
await adapter.navigateToPage(`${fixtureBaseUrl}/step-07-time-limits.html`);
const page = adapter.getPage();
expect(page).not.toBeNull();
const stepIndicatorBefore = await page!.textContent('[data-indicator]');
expect(stepIndicatorBefore).toContain('Time Limits');
const result = await adapter.executeStep(StepId.create(7), {
practice: 10,
qualify: 10,
race: 20,
});
expect(result.success).toBe(true);
expect(result.error).toBeUndefined();
const stepIndicatorAfter = await page!.textContent('[data-indicator]');
expect(stepIndicatorAfter).toContain('Set Cars');
});
});

View File

@@ -0,0 +1,98 @@
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
import path from 'path';
import { PlaywrightAutomationAdapter, FixtureServer } from 'packages/infrastructure/adapters/automation';
import { StepId } from 'packages/domain/value-objects/StepId';
import { PinoLogAdapter } from 'packages/infrastructure/adapters/logging/PinoLogAdapter';
describe('Step 8 cars', () => {
describe('alignment', () => {
let adapter: PlaywrightAutomationAdapter;
const fixtureBaseUrl = `file://${path.resolve(process.cwd(), 'html-dumps')}`;
beforeAll(async () => {
adapter = new PlaywrightAutomationAdapter({
headless: true,
timeout: 5000,
baseUrl: fixtureBaseUrl,
mode: 'mock',
});
await adapter.connect();
});
afterAll(async () => {
await adapter.disconnect();
});
it('executes on Cars page in mock wizard', async () => {
await adapter.navigateToPage(`${fixtureBaseUrl}/step-08-set-cars.html`);
const page = adapter.getPage();
expect(page).not.toBeNull();
const stepIndicatorBefore = await page!.textContent('[data-indicator]');
expect(stepIndicatorBefore).toContain('Set Cars');
const result = await adapter.executeStep(StepId.create(8), {});
expect(result.success).toBe(true);
expect(result.error).toBeUndefined();
});
});
describe('state validation', () => {
let server: FixtureServer;
let adapter: PlaywrightAutomationAdapter;
let logger: PinoLogAdapter;
beforeEach(async () => {
server = new FixtureServer();
const serverInfo = await server.start();
logger = new PinoLogAdapter();
adapter = new PlaywrightAutomationAdapter(
{
headless: true,
timeout: 5000,
mode: 'mock',
baseUrl: serverInfo.url,
},
logger,
);
await adapter.connect();
});
afterEach(async () => {
await adapter.disconnect();
await server.stop();
});
it('fails validation when executed on Track page instead of Cars page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(8), {});
}).rejects.toThrow(/Step 8 FAILED validation/i);
});
it('fails fast on Step 8 if already past Cars page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(8), {});
}).rejects.toThrow(/Step 8 FAILED validation/i);
});
it('passes validation when on Cars page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(8));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
const result = await adapter.executeStep(StepId.create(8), {});
expect(result.success).toBe(true);
});
});
});

View File

@@ -0,0 +1,173 @@
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
import path from 'path';
import { PlaywrightAutomationAdapter, FixtureServer } from 'packages/infrastructure/adapters/automation';
import { StepId } from 'packages/domain/value-objects/StepId';
import { PinoLogAdapter } from 'packages/infrastructure/adapters/logging/PinoLogAdapter';
describe('Step 9 add car', () => {
describe('happy path', () => {
let adapter: PlaywrightAutomationAdapter;
const fixtureBaseUrl = `file://${path.resolve(process.cwd(), 'html-dumps')}`;
beforeAll(async () => {
adapter = new PlaywrightAutomationAdapter({
headless: true,
timeout: 5000,
baseUrl: fixtureBaseUrl,
mode: 'mock',
});
await adapter.connect();
});
afterAll(async () => {
await adapter.disconnect();
});
it('executes on Add Car modal from Cars step', async () => {
await adapter.navigateToPage(`${fixtureBaseUrl}/step-09-add-car.html`);
const page = adapter.getPage();
expect(page).not.toBeNull();
const modalTitleBefore = await page!.textContent('[data-indicator="add-car"]');
expect(modalTitleBefore).toContain('Add a Car');
const result = await adapter.executeStep(
StepId.create(9),
{ carSearch: 'Porsche 911 GT3 R' },
);
expect(result.success).toBe(true);
expect(result.error).toBeUndefined();
});
});
describe('state validation', () => {
let server: FixtureServer;
let adapter: PlaywrightAutomationAdapter;
let logger: PinoLogAdapter;
beforeEach(async () => {
server = new FixtureServer();
const serverInfo = await server.start();
logger = new PinoLogAdapter();
adapter = new PlaywrightAutomationAdapter(
{
headless: true,
timeout: 5000,
mode: 'mock',
baseUrl: serverInfo.url,
},
logger,
);
await adapter.connect();
});
afterEach(async () => {
await adapter.disconnect();
await server.stop();
});
it('throws when executed on Track page instead of Cars page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
carSearch: 'Mazda MX-5',
});
}).rejects.toThrow(/Step 9 FAILED validation/i);
});
it('detects state mismatch when Cars button is missing', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
carSearch: 'Porsche 911',
});
}).rejects.toThrow(/Expected cars step/i);
});
it('detects when Track container is present instead of Cars page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
carSearch: 'Ferrari 488',
});
}).rejects.toThrow(/3 steps ahead|Track page/i);
});
it('passes validation when on Cars page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(8));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
const result = await adapter.executeStep(StepId.create(9), {
carSearch: 'Mazda MX-5',
});
expect(result.success).toBe(true);
});
it('provides detailed error context in validation failure', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
let errorMessage = '';
try {
await adapter.executeStep(StepId.create(9), {
carSearch: 'BMW M4',
});
} catch (error) {
errorMessage = error instanceof Error ? error.message : String(error);
}
expect(errorMessage).toContain('Step 9');
expect(errorMessage).toMatch(/validation|mismatch|wrong page/i);
});
it('validates page state before attempting any Step 9 actions', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
const page = adapter.getPage();
if (!page) {
throw new Error('Page not available');
}
let carModalOpened = false;
page.on('framenavigated', () => {
carModalOpened = true;
});
let validationError = false;
try {
await adapter.executeStep(StepId.create(9), {
carSearch: 'Audi R8',
});
} catch {
validationError = true;
}
expect(validationError).toBe(true);
expect(carModalOpened).toBe(false);
});
it('checks wizard footer state in Step 9', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
carSearch: 'McLaren 720S',
});
}).rejects.toThrow();
});
});
});

View File

@@ -0,0 +1,54 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { PlaywrightAutomationAdapter, FixtureServer } from 'packages/infrastructure/adapters/automation';
import { StepId } from 'packages/domain/value-objects/StepId';
import { PinoLogAdapter } from 'packages/infrastructure/adapters/logging/PinoLogAdapter';
describe('Step 11 track', () => {
describe('state validation', () => {
let server: FixtureServer;
let adapter: PlaywrightAutomationAdapter;
let logger: PinoLogAdapter;
beforeEach(async () => {
server = new FixtureServer();
const serverInfo = await server.start();
logger = new PinoLogAdapter();
adapter = new PlaywrightAutomationAdapter(
{
headless: true,
timeout: 5000,
mode: 'mock',
baseUrl: serverInfo.url,
},
logger,
);
await adapter.connect();
});
afterEach(async () => {
await adapter.disconnect();
await server.stop();
});
it('fails validation when executed on Cars page instead of Track page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(8));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(11), {});
}).rejects.toThrow(/Step 11 FAILED validation/i);
});
it('passes validation when on Track page', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
const result = await adapter.executeStep(StepId.create(11), {});
expect(result.success).toBe(true);
});
});
});

View File

@@ -0,0 +1,43 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import path from 'path';
import { PlaywrightAutomationAdapter } from 'packages/infrastructure/adapters/automation';
import { StepId } from 'packages/domain/value-objects/StepId';
describe('Workflow steps 79 cars flow', () => {
let adapter: PlaywrightAutomationAdapter;
const fixtureBaseUrl = `file://${path.resolve(process.cwd(), 'html-dumps')}`;
beforeAll(async () => {
adapter = new PlaywrightAutomationAdapter({
headless: true,
timeout: 5000,
baseUrl: fixtureBaseUrl,
mode: 'mock',
});
await adapter.connect();
});
afterAll(async () => {
await adapter.disconnect();
});
it('executes time limits, cars, and add car in sequence', async () => {
await adapter.navigateToPage(`${fixtureBaseUrl}/step-07-time-limits.html`);
const step7Result = await adapter.executeStep(StepId.create(7), {
practice: 10,
qualify: 10,
race: 20,
});
expect(step7Result.success).toBe(true);
await adapter.navigateToPage(`${fixtureBaseUrl}/step-08-set-cars.html`);
const step8Result = await adapter.executeStep(StepId.create(8), {});
expect(step8Result.success).toBe(true);
await adapter.navigateToPage(`${fixtureBaseUrl}/step-09-add-car.html`);
const step9Result = await adapter.executeStep(StepId.create(9), {
carSearch: 'Porsche 911 GT3 R',
});
expect(step9Result.success).toBe(true);
});
});