Add Playwright e2e tests to verify the dark mode feature — theme toggle, localStorage persistence, system preference detection, and visual correctness across all components. Tests auto-start the dev server on port 7777 using NeDB (no external DB required).
- Install
@playwright/test+ browsers - Create
playwright.config.tswithwebServerconfig →yarn devon port 7777 - Update
.gitignorewith Playwright artifacts (test-results/,playwright-report/,playwright/.cache) - Add npm scripts:
test:e2eandtest:e2e:ui
e2e/dark-mode/theme-toggle.spec.ts— Toggle button exists, click switcheshtml[data-theme]light↔dark, correct ARIA attributes, keyboard accessible (Tab + Enter/Space)e2e/dark-mode/theme-persistence.spec.ts— Saved tolocalStoragekeycodex-docs-theme, restored on reload, defaults to light when no preferencee2e/dark-mode/system-preference.spec.ts— Uses Playwright'scolorSchemeemulation to testprefers-color-scheme: darkas fallback, saved preference overrides system
e2e/dark-mode/components.spec.ts— Header, sidebar, page content, buttons, auth form, toggle icon visibility — all verified in both themes viagetComputedStyleon CSS variablese2e/dark-mode/no-fouc.spec.ts— Set localStorage before navigation, verifydata-themeis correct on first meaningful paint
e2e/fixtures/setup.ts— Auth helper (POST/authwith passwordsecretpassword), page creation helper, shared selectors
- Test against
/authpage for guaranteedlayout.twig— the greeting page (/with empty DB) doesn't includemain.bundle.js, so ThemeManager won't run there - CSS variable assertions — use
getComputedStyleto verify--color-bg-mainresolves to#1E1E1Ein dark,#ffffffin light - Icon visibility — assert
style.displayon sun/moon SVGs (set inline by JS) - System preference — Playwright's built-in
colorScheme: 'dark'context option emulatesprefers-color-scheme
| File | Action |
|---|---|
playwright.config.ts |
Create |
e2e/dark-mode/*.spec.ts (5 files) |
Create |
e2e/fixtures/setup.ts |
Create |
package.json |
Modify (scripts + devDep) |
.gitignore |
Modify |
npx playwright installsucceedsyarn test:e2e— all tests pass (server auto-starts/stops)yarn test:e2e:ui— interactive mode works- All dark mode acceptance criteria from Requirements.md covered
The greeting page (/ with empty DB) does not load main.bundle.js — ThemeManager is inactive there. All tests target pages using layout.twig (i.e., /auth or created pages).