pcbjam/tests/e2e/aui.spec.ts
Viktor Vaczi 4c3a4cacd4 test(determinism): deterministic waits + stableShot screenshots; drop blind sleeps/ifs/retries
Make the Playwright e2e + kicad suites deterministic so screenshot flake stops
tracing to timing races.

- Blind page.waitForTimeout -> condition waits (expect.poll, web-first
  assertions, waitUntil) + readiness helpers (waitForWxApp, waitForCanvasApp).
  Remaining sleeps are documented interaction dwells (annotated).
- Defensive "if element exists" branches -> loud asserts; label-fallback chains
  -> normalized clickMenuItemByText. First-run wizard for/if loops removed by
  seeding calculator/gerbview/pcbnew HTMLs.
- Screenshots: new stableShot(page, name) settles the render in-page (canvas
  hash over rAF) then writes a raw PNG to test-results/ for the existing offline
  gate (tools/screenshots vs baseline-screenshots). Replaces toHaveScreenshot,
  which did inline compare + its own baselines and had decoupled the specs from
  the real gate. scale:'css' pinned.
- retries: 0 in both configs.
- Guard: tests/tools/lint-determinism.ts (npm run lint:determinism) bans blind
  sleeps / toHaveScreenshot / inline retries / swallowed catches in specs;
  documented exceptions carry a marker. Rules in tests/TESTING.md.

Assertions, coverage, and renders unchanged (semantic-equivalence reviewed;
captures pixel-identical modulo inherent timer/timestamp/3d-raytrace variance).
Both suites green at retries:0 (e2e 340, kicad 92); ~35-61% faster.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVX1pHMvRPYHdp6ZfEawrk
2026-07-07 10:50:24 +02:00

92 lines
4.2 KiB
TypeScript

// wxAuiManager Tests - AUI docking system KiCad uses extensively
import { test, expect, MAIN_CANVAS, waitForWxApp, getCanvasBox } from './utils/fixtures';
import { clickAuiButton, clickAuiPaneContent, findRenderedByLabel, findRenderedByType, stableShot } from './utils/element-tracker';
test.describe('wxAuiManager Tests', () => {
test('AUI test app loads successfully', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
await waitForWxApp(page);
const hasStartup = testLogger.consoleLogs.some(l => l.includes('AUI test app started'));
await stableShot(page, 'aui-01-loaded.png', { fullPage: true });
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
test('AUI dockable panels are visible', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
await waitForWxApp(page);
await expect
.poll(() => testLogger.consoleLogs.some(l => l.includes('dockable panels')), {
message: 'AUI dockable panels log should be emitted',
})
.toBe(true);
await stableShot(page, 'aui-02-panels.png', { fullPage: true });
});
test('Panel close button can be clicked', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
await waitForWxApp(page);
// Find all AUI parts to verify they're registered
const auiParts = await findRenderedByType(page, 'auipart');
expect(auiParts.length, 'Should have AUI parts registered').toBeGreaterThan(0);
// Click on Properties panel close button using element registry
const clicked = await clickAuiButton(page, 'close', 'Properties');
expect(clicked, 'Properties close button should be found and clicked').toBe(true);
await stableShot(page, 'aui-03-close-clicked.png', { fullPage: true });
});
test('Panel can be dragged', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
await waitForWxApp(page);
const box = await getCanvasBox(page);
// Get Properties panel caption using element registry
const caption = await findRenderedByLabel(page, 'Properties', { elementType: 'auipart', subType: 'caption' });
expect(caption, 'Properties caption should be found in registry').not.toBeNull();
// Drag panel title bar using registry coordinates
await page.mouse.move(caption!.centerX, caption!.centerY);
await page.mouse.down();
await page.mouse.move(box.x + 300, box.y + 200, { steps: 10 });
await page.mouse.up();
await stableShot(page, 'aui-04-dragged.png', { fullPage: true });
});
test('Multiple panels can be interacted with', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
await waitForWxApp(page);
// Click in Properties panel using element tracking
const propsClicked = await clickAuiPaneContent(page, 'Properties');
expect(propsClicked, 'Should be able to click Properties pane').toBe(true);
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: no observable event; lets the pane-content click commit before the next click
// Click in Layers panel using element tracking
const layersClicked = await clickAuiPaneContent(page, 'Layers');
expect(layersClicked, 'Should be able to click Layers pane').toBe(true);
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: no observable event; lets the pane-content click commit before the next click
// Click in Messages panel using element tracking
const messagesClicked = await clickAuiPaneContent(page, 'Messages');
expect(messagesClicked, 'Should be able to click Messages pane').toBe(true);
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: no observable event; lets the pane-content click commit before the next click
// Click in Event Log panel using element tracking
const eventLogClicked = await clickAuiPaneContent(page, 'Event Log');
expect(eventLogClicked, 'Should be able to click Event Log pane').toBe(true);
await stableShot(page, 'aui-05-multi-panel.png', { fullPage: true });
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
});