import { describe, expect, test } from "vitest"; import { getNextUiTheme, isUiTheme, persistUiTheme, resolveInitialUiTheme, UI_THEME_STORAGE_KEY, } from "./theme"; describe("UI theme preference", () => { test("defaults to dark when no stored preference exists", () => { const storage = new Map(); expect(resolveInitialUiTheme(storage)).toBe("dark"); }); test("restores a valid stored preference", () => { const storage = new Map([[UI_THEME_STORAGE_KEY, "light"]]); expect(resolveInitialUiTheme(storage)).toBe("light"); }); test("ignores invalid stored preferences", () => { const storage = new Map([[UI_THEME_STORAGE_KEY, "solarized"]]); expect(resolveInitialUiTheme(storage)).toBe("dark"); }); test("falls back when stored preferences cannot be read", () => { const storage = { getItem() { throw new Error("storage blocked"); }, }; expect(resolveInitialUiTheme(storage)).toBe("dark"); }); test("ignores persistence failures", () => { const storage = { setItem() { throw new Error("quota exceeded"); }, }; expect(() => persistUiTheme("light", storage)).not.toThrow(); }); test("detects and toggles supported themes", () => { expect(isUiTheme("light")).toBe(true); expect(isUiTheme("dark")).toBe(true); expect(isUiTheme("contrast")).toBe(false); expect(getNextUiTheme("dark")).toBe("light"); expect(getNextUiTheme("light")).toBe("dark"); }); });