This commit is contained in:
2025-11-30 14:00:46 +01:00
parent f8a1fbeb50
commit 9a1feb2912
37 changed files with 3079 additions and 7301 deletions

View File

@@ -1,41 +1,31 @@
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';
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import type { StepHarness } from '../support/StepHarness';
import { createStepHarness } from '../support/StepHarness';
describe('Step 9 add car', () => {
let harness: StepHarness;
beforeEach(async () => {
harness = await createStepHarness();
});
afterEach(async () => {
await harness.dispose();
});
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`);
await harness.navigateToFixtureStep(9);
const page = adapter.getPage();
const page = harness.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' },
);
const result = await harness.executeStep(9, {
carSearch: 'Porsche 911 GT3 R',
});
expect(result.success).toBe(true);
expect(result.error).toBeUndefined();
@@ -43,72 +33,44 @@ describe('Step 9 add car', () => {
});
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 harness.navigateToFixtureStep(11);
await harness.adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
await harness.executeStep(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 harness.navigateToFixtureStep(11);
await harness.adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
await harness.executeStep(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 harness.navigateToFixtureStep(11);
await harness.adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
await harness.executeStep(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');
await harness.navigateToFixtureStep(8);
await harness.adapter.getPage()?.waitForLoadState('domcontentloaded');
const result = await adapter.executeStep(StepId.create(9), {
const result = await harness.executeStep(9, {
carSearch: 'Mazda MX-5',
});
@@ -116,12 +78,12 @@ describe('Step 9 add car', () => {
});
it('provides detailed error context in validation failure', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await harness.navigateToFixtureStep(11);
await harness.adapter.getPage()?.waitForLoadState('domcontentloaded');
let errorMessage = '';
try {
await adapter.executeStep(StepId.create(9), {
await harness.executeStep(9, {
carSearch: 'BMW M4',
});
} catch (error) {
@@ -133,10 +95,10 @@ describe('Step 9 add car', () => {
});
it('validates page state before attempting any Step 9 actions', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await harness.navigateToFixtureStep(11);
await harness.adapter.getPage()?.waitForLoadState('domcontentloaded');
const page = adapter.getPage();
const page = harness.adapter.getPage();
if (!page) {
throw new Error('Page not available');
}
@@ -148,7 +110,7 @@ describe('Step 9 add car', () => {
let validationError = false;
try {
await adapter.executeStep(StepId.create(9), {
await harness.executeStep(9, {
carSearch: 'Audi R8',
});
} catch {
@@ -160,11 +122,11 @@ describe('Step 9 add car', () => {
});
it('checks wizard footer state in Step 9', async () => {
await adapter.navigateToPage(server.getFixtureUrl(11));
await adapter.getPage()?.waitForLoadState('domcontentloaded');
await harness.navigateToFixtureStep(11);
await harness.adapter.getPage()?.waitForLoadState('domcontentloaded');
await expect(async () => {
await adapter.executeStep(StepId.create(9), {
await harness.executeStep(9, {
carSearch: 'McLaren 720S',
});
}).rejects.toThrow();