2026-03-25 09:27:12 +08:00
|
|
|
import { expect, test } from "./helpers";
|
2026-03-22 19:28:57 +08:00
|
|
|
|
|
|
|
|
test.describe("Theme System", () => {
|
|
|
|
|
test("page defaults to light theme", async ({ loggedInPage: page }) => {
|
|
|
|
|
// Check that html element does not have 'dark' class by default
|
|
|
|
|
const html = page.locator("html");
|
|
|
|
|
const classList = await html.getAttribute("class");
|
|
|
|
|
// Default is light, so 'dark' should not be present initially
|
|
|
|
|
// (unless system preference is dark)
|
|
|
|
|
expect(classList).toBeDefined();
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-28 18:57:53 +08:00
|
|
|
test("top nav has a theme toggle that flips the dark class", async ({ loggedInPage: page }) => {
|
|
|
|
|
// 2.0 removed the footer. The theme toggle now lives in the top nav.
|
|
|
|
|
const themeBtn = page.locator("button[title='Toggle theme']");
|
2026-03-23 11:46:45 +08:00
|
|
|
await expect(themeBtn).toBeVisible({ timeout: 10_000 });
|
2026-06-28 18:57:53 +08:00
|
|
|
|
|
|
|
|
const isDark = () => page.evaluate(() => document.documentElement.classList.contains("dark"));
|
|
|
|
|
const before = await isDark();
|
|
|
|
|
|
|
|
|
|
await themeBtn.click();
|
|
|
|
|
await expect.poll(isDark, { timeout: 5_000 }).toBe(!before);
|
|
|
|
|
|
|
|
|
|
// Theme persists in localStorage under the "snapotter-theme" key.
|
|
|
|
|
const persisted = await page.evaluate(() => localStorage.getItem("snapotter-theme"));
|
|
|
|
|
expect(persisted).toContain(before ? "light" : "dark");
|
|
|
|
|
|
|
|
|
|
// Toggling back restores the original state.
|
|
|
|
|
await themeBtn.click();
|
|
|
|
|
await expect.poll(isDark, { timeout: 5_000 }).toBe(before);
|
2026-03-22 19:28:57 +08:00
|
|
|
});
|
|
|
|
|
|
2026-06-28 18:57:53 +08:00
|
|
|
test("privacy policy is reachable at /privacy", async ({ loggedInPage: page }) => {
|
|
|
|
|
// 2.0 removed the footer privacy link; the policy still lives at /privacy.
|
|
|
|
|
await page.goto("/privacy");
|
|
|
|
|
await expect(page.getByRole("heading", { name: "Privacy Policy" })).toBeVisible({
|
|
|
|
|
timeout: 10_000,
|
|
|
|
|
});
|
2026-03-22 19:28:57 +08:00
|
|
|
});
|
|
|
|
|
});
|