import { describe, it, expect, beforeAll, afterAll } from 'vitest'; import { PlaywrightAutomationAdapter, FixtureServer, } from 'packages/infrastructure/adapters/automation'; import { StepId } from 'packages/domain/value-objects/StepId'; import { IRACING_SELECTORS } from 'packages/infrastructure/adapters/automation/dom/IRacingSelectors'; describe('Workflow – steps 7–9 cars flow (fixture-backed)', () => { let adapter: PlaywrightAutomationAdapter; let server: FixtureServer; let baseUrl: string; beforeAll(async () => { server = new FixtureServer(); const info = await server.start(); baseUrl = info.url; adapter = new PlaywrightAutomationAdapter( { headless: true, timeout: 5000, baseUrl, mode: 'mock', }, ); await adapter.connect(); }); afterAll(async () => { await adapter.disconnect(); await server.stop(); }); it('executes time limits, cars, and add car in sequence using fixtures and leaves JSON-backed state', async () => { await adapter.navigateToPage(server.getFixtureUrl(7)); const step7Result = await adapter.executeStep(StepId.create(7), { practice: 10, qualify: 10, race: 20, }); expect(step7Result.success).toBe(true); const page = adapter.getPage(); expect(page).not.toBeNull(); const raceSlider = page! .locator(IRACING_SELECTORS.steps.race) .first(); const raceSliderValue = (await raceSlider.getAttribute('data-value')) ?? (await raceSlider.inputValue().catch(() => null)); expect(raceSliderValue).toBe('20'); await adapter.navigateToPage(server.getFixtureUrl(8)); const step8Result = await adapter.executeStep(StepId.create(8), {}); expect(step8Result.success).toBe(true); const carsContainer = page! .locator(IRACING_SELECTORS.wizard.stepContainers.cars) .first(); expect(await carsContainer.count()).toBeGreaterThan(0); const addCarButton = page! .locator(IRACING_SELECTORS.steps.addCarButton) .first(); expect(await addCarButton.count()).toBeGreaterThan(0); await adapter.navigateToPage(server.getFixtureUrl(9)); const step9Result = await adapter.executeStep(StepId.create(9), { carSearch: 'Acura ARX-06', }); expect(step9Result.success).toBe(true); const carsTable = page! .locator('#select-car-set-cars table.table.table-striped') .first(); expect(await carsTable.count()).toBeGreaterThan(0); const acuraCell = carsTable.locator('tbody tr td >> text=Acura ARX-06 GTP'); expect(await acuraCell.count()).toBeGreaterThan(0); }); });