mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-13 02:56:39 +07:00
Theme previously followed only the OS's prefers-color-scheme, which switches automatically on this user's Mac at sunset/sunrise. Adds an explicit override in Settings: Light/Dark/System, System being the previous (default) auto-follow-the-OS behavior. Persisted client-side in localStorage (lib/theme.ts, same pattern as language) rather than server-side like currency — it's a pure display preference, and synchronous localStorage reads are what make the anti-FOUC inline script in index.html possible. index.css already had the [data-theme] CSS variables laid in ahead of time; only the JS to actually set the attribute, and the Settings UI, were missing. Covered by 2 new Playwright specs (theme-switcher.spec.ts) run against the isolated e2e stack: explicit choice overrides a dark OS and survives reload; switching back to "system" doesn't leave a stale forced theme.
36 lines
1.7 KiB
TypeScript
36 lines
1.7 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
|
|
// The theme picker (Settings → Тема оформления): light/dark/system, with
|
|
// system meant to follow the OS live and light/dark meant to override it.
|
|
// See frontend/src/lib/theme.ts and index.html's anti-FOUC inline script.
|
|
|
|
async function surface0(page: import("@playwright/test").Page): Promise<string> {
|
|
return page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--surface-0").trim());
|
|
}
|
|
|
|
test.describe("theme picker", () => {
|
|
test.use({ colorScheme: "dark" }); // simulates the OS being in dark mode
|
|
|
|
test("an explicit choice overrides the OS theme, and persists across reload", async ({ page }) => {
|
|
await page.goto("/settings");
|
|
await expect(await surface0(page)).toBe("#0d0d0d"); // "system" follows the dark OS by default
|
|
|
|
await page.getByRole("button", { name: "Светлая", exact: true }).click();
|
|
await expect(await surface0(page)).toBe("#f9f9f7"); // forced light despite the dark OS
|
|
|
|
await page.reload();
|
|
await expect(await surface0(page)).toBe("#f9f9f7"); // survives a reload, not just in-memory state
|
|
|
|
await page.getByRole("button", { name: "Системная", exact: true }).click();
|
|
await expect(await surface0(page)).toBe("#0d0d0d"); // back to following the (still-dark) OS
|
|
});
|
|
|
|
test("switching back to system never leaves a stale forced theme behind", async ({ page }) => {
|
|
await page.goto("/settings");
|
|
await page.getByRole("button", { name: "Тёмная", exact: true }).click();
|
|
await page.getByRole("button", { name: "Системная", exact: true }).click();
|
|
const dataTheme = await page.evaluate(() => document.documentElement.getAttribute("data-theme"));
|
|
expect(dataTheme).toBeNull();
|
|
});
|
|
});
|