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

@@ -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);
});
});
});