feat(ui): add light theme toggle

This commit is contained in:
vince 2026-06-20 00:49:22 +02:00
parent bbc81cea0d
commit cdb269e505
17 changed files with 415 additions and 24 deletions

35
src/lib/ui/theme.test.ts Normal file
View file

@ -0,0 +1,35 @@
import { describe, expect, test } from "vitest";
import {
getNextUiTheme,
isUiTheme,
resolveInitialUiTheme,
UI_THEME_STORAGE_KEY,
} from "./theme";
describe("UI theme preference", () => {
test("defaults to dark when no stored preference exists", () => {
const storage = new Map<string, string>();
expect(resolveInitialUiTheme(storage)).toBe("dark");
});
test("restores a valid stored preference", () => {
const storage = new Map<string, string>([[UI_THEME_STORAGE_KEY, "light"]]);
expect(resolveInitialUiTheme(storage)).toBe("light");
});
test("ignores invalid stored preferences", () => {
const storage = new Map<string, string>([[UI_THEME_STORAGE_KEY, "solarized"]]);
expect(resolveInitialUiTheme(storage)).toBe("dark");
});
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");
});
});