pcbjam/tests/e2e/filedialog-folder-nav.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

35 lines
1.9 KiB
TypeScript

// Regression coverage for the wxFileDialog folder-navigation fix
// (wxGenericFileDialog::OnOk now navigates into directories instead of
// closing the dialog with the folder path as a "file").
//
// Reproduces the original bug: select a folder, press Enter, expect the
// dialog to navigate into the folder rather than close.
import { test, expect, waitForWxApp, clickByLabel } from './utils/fixtures';
import { stableShot } from './utils/element-tracker';
test('folder navigation: Enter on a folder navigates instead of closing the dialog', async ({ page, testLogger }) => {
await page.goto('/standalone/filedialog/filedialog_test.html');
await waitForWxApp(page);
await clickByLabel(page, 'Open File...');
await page.waitForTimeout(800); // eslint-disable-line -- documented interaction dwell: let the file dialog open + take focus (no dialog-open event to observe)
// Type a path that's a folder in Emscripten's MEMFS and press Enter.
// Before the fix, OnOk treated /dev as a file → either showed "Please
// choose an existing file" (wxFD_FILE_MUST_EXIST) or closed the dialog
// and surfaced /dev to the calling app as if it were a file.
await page.keyboard.type('/dev');
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: keystroke commit into the path field
await page.keyboard.press('Enter');
await page.waitForTimeout(800); // eslint-disable-line -- documented interaction dwell: negative assertion — give OnOk time to (wrongly) emit the "Selected file:" event before asserting it did not
await stableShot(page, 'filedlg-folder-nav.png', { fullPage: true });
// No "Selected file:" log should appear — the dialog must NOT have closed
// with /dev as the picked file.
const closedWithDev = testLogger.consoleLogs.some(l =>
l.includes('[FILEDIALOG_EVENT] Selected file:') && l.includes('/dev')
);
expect(closedWithDev, 'dialog must not close and report /dev as the selected file').toBe(false);
});