sdlc-hub/web/src/shell/theme.test.ts
Andrey Epifancev 13e7ae35bc feat(web): иконки и базовые компоненты дизайн-системы (#65)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 00:04:23 +04:00

32 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { afterEach, describe, expect, it, vi } from "vitest";
import { applyTheme, effectiveDark, readTheme, saveTheme } from "./theme.ts";
describe("тема", () => {
afterEach(() => document.documentElement.removeAttribute("data-theme"));
it("читает graph-theme, неизвестное значение — системная", () => {
localStorage.setItem("graph-theme", "dark");
expect(readTheme()).toBe("dark");
localStorage.setItem("graph-theme", "purple");
expect(readTheme()).toBe("");
});
it("без сохранённого значения readTheme возвращает пустую строку, а не null", () => {
expect(readTheme()).toBe("");
});
it("applyTheme ставит и снимает data-theme, saveTheme пишет ключ", () => {
applyTheme("light");
expect(document.documentElement.getAttribute("data-theme")).toBe("light");
applyTheme("");
expect(document.documentElement.hasAttribute("data-theme")).toBe(false);
saveTheme("dark");
expect(localStorage.getItem("graph-theme")).toBe("dark");
});
it("effectiveDark: системная следует matchMedia, light — всегда светлая, dark — тёмная", () => {
vi.stubGlobal("matchMedia", (q: string) => ({ matches: q.includes("dark"), media: q }));
expect(effectiveDark("")).toBe(true);
expect(effectiveDark("light")).toBe(false);
expect(effectiveDark("dark")).toBe(true);
vi.stubGlobal("matchMedia", undefined);
expect(effectiveDark("")).toBe(false);
});
});