Files
gridpilot.gg/tests/e2e/step-8-9-11-state-sync.e2e.test.ts
2025-11-27 14:46:11 +01:00

75 lines
2.8 KiB
TypeScript

import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import path from 'path';
import { PlaywrightAutomationAdapter } from '../../packages/infrastructure/adapters/automation/PlaywrightAutomationAdapter';
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);
});