pcbjam/tests/kicad/dark-mode.spec.ts
Viktor Vaczi c1eb08108b test(screenshots): restore screenshot-neutrality after the determinism refactor
The determinism conversion silently dropped/renamed screenshots vs the committed
baselines, so CI flagged ~35 baselines as "removed". Restore them:

- pl_editor-*: re-add the "pl_editor-" prefix the conversion dropped (5).
- Buffer screenshots that lost their path: (eeschema draw-wires/loaded-css,
  pcbnew draw-lines/loaded-css, pcbnew-move, dark-mode, eeschema-crosshair,
  aui-resize) re-add path:'test-results/<name>' so they SAVE and still feed the
  in-test pixel-diff analysis (17).
- Dropped animating/loading captures re-added via stableShot / raw screenshot:
  timer-03/05/06, dialogs-timer-running/started, wxgrid-02/03, 01-loading (7).

Delete 5 obsolete wizard baselines (eeschema/gerbview/pl_editor/symbol_editor/
generic -wizard-00-initial): every app is now seeded to bypass the first-run
setup wizard (that was the point of removing the wizard for/if loop), so those
states are no longer produced — pl_editor.spec asserts "no wizard appears"
instead.

Net: every committed baseline has a producer again (0 "removed"); determinism
guard green; affected specs pass (e2e 40, kicad 12) and emit the restored PNGs.

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

53 lines
2.5 KiB
TypeScript

import { test, expect } from './fixtures';
import { compareToReference, hideCursor, PCBNEW_REFERENCE, PCBNEW_HEADER_REGION } from './utils/screenshot-compare';
import { waitForEditorReady } from '../e2e/utils/element-tracker';
/**
* Dark-mode regression test.
*
* The wasm/wxUniversal UI always renders a light theme regardless of the
* browser's prefers-color-scheme; KIPLATFORM::UI::IsDarkTheme() must report
* that rendered theme, not the browser preference. When it reported the
* browser preference, a dark-mode browser got dark-variant (light-stroke)
* icons and dark widget colours painted onto the light UI.
*
* This test loads pcbnew with the browser forced to dark mode and asserts the
* header (menubar + top toolbar, where the icons live) renders identically to
* the light-mode reference used by pcbnew.spec.ts.
*/
// colorScheme emulation alone is lost in Firefox on cross-origin-isolated
// pages (the COOP/COEP headers serve.json adds for SharedArrayBuffer put the
// page in an isolated process the override doesn't reach), so also set the
// browser-wide dark-theme pref for the firefox project. launchOptions forces a
// new worker, so this must be top-level rather than inside the describe.
test.use({
colorScheme: 'dark',
launchOptions: { firefoxUserPrefs: { 'ui.systemUsesDarkTheme': 1 } },
});
test.describe('PCBnew dark-mode browser', () => {
test('toolbar icons render the light theme under a dark-mode browser', async ({ page }) => {
await page.goto('/kicad/pcbnew.html');
// Sanity-check the browser really reports dark mode to the app.
expect(await page.evaluate(() =>
window.matchMedia('(prefers-color-scheme: dark)').matches
)).toBe(true);
await waitForEditorReady(page);
await hideCursor(page);
const cssScreenshot = await page.screenshot({
path: 'test-results/pcbnew-dark-mode-loaded.png',
scale: 'css'
});
const reference = await compareToReference(page, cssScreenshot, PCBNEW_REFERENCE, PCBNEW_HEADER_REGION);
expect(reference.actualWidth).toBe(reference.referenceWidth);
expect(reference.actualHeight).toBe(reference.referenceHeight);
expect(reference.diffRatio, 'header diff ratio vs light-mode reference').toBeLessThan(PCBNEW_HEADER_REGION.maxDiffRatio);
expect(reference.meanChannelDiff, 'header mean channel diff vs light-mode reference').toBeLessThan(PCBNEW_HEADER_REGION.maxMeanChannelDiff);
});
});