feat(ui): helper de thème dark/light persisté (TDD)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { nextTheme, getInitialTheme } from "./theme.js";
|
||||
|
||||
describe("nextTheme", () => {
|
||||
it("bascule dark <-> light", () => {
|
||||
expect(nextTheme("dark")).toBe("light");
|
||||
expect(nextTheme("light")).toBe("dark");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getInitialTheme", () => {
|
||||
beforeEach(() => {
|
||||
// @ts-expect-error - environnement node sans localStorage
|
||||
delete globalThis.localStorage;
|
||||
});
|
||||
it("retombe sur dark sans localStorage", () => {
|
||||
expect(getInitialTheme()).toBe("dark");
|
||||
});
|
||||
it("lit la valeur persistée si présente", () => {
|
||||
const store: Record<string, string> = { "su-theme": "light" };
|
||||
// @ts-expect-error - stub minimal
|
||||
globalThis.localStorage = { getItem: (k: string) => store[k] ?? null };
|
||||
expect(getInitialTheme()).toBe("light");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user