nandi/oripublic Fork 0
b6cd929ab1425a4ef6073ea9c189917cca02cf3c
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

theme.test.ts · 54 lines · 1.4 KBTypeScript Blame HistoryRaw
✨ Workspace panel, selectors, previews, desktop app, sandbox template, resizable file tree, light/dark theme 76d62ac k33g yesterday1import { beforeEach, describe, expect, it } from "vitest";
2import {
3 DEFAULT_THEME,
4 THEME_KEY,
5 isTheme,
6 resetTheme,
7 setTheme,
8 toggleTheme,
9 useTheme,
10} from "./theme";
11
12describe("theme store", () => {
13 beforeEach(() => {
14 localStorage.clear();
15 resetTheme();
16 });
17
18 it("starts light and stamps the document", () => {
19 expect(useTheme.getState().theme).toBe(DEFAULT_THEME);
20 expect(document.documentElement.dataset.theme).toBe("light");
21 });
22
23 it("setTheme applies, stamps and remembers the theme", () => {
24 setTheme("dark");
25 expect(useTheme.getState().theme).toBe("dark");
26 expect(document.documentElement.dataset.theme).toBe("dark");
27 expect(localStorage.getItem(THEME_KEY)).toBe("dark");
28 });
29
30 it("toggleTheme alternates between light and dark", () => {
31 toggleTheme();
32 expect(useTheme.getState().theme).toBe("dark");
33 toggleTheme();
34 expect(useTheme.getState().theme).toBe("light");
35 expect(document.documentElement.dataset.theme).toBe("light");
36 });
37
38 it("resetTheme goes back to light", () => {
39 setTheme("dark");
40 resetTheme();
41 expect(useTheme.getState().theme).toBe("light");
42 expect(localStorage.getItem(THEME_KEY)).toBe("light");
43 });
44});
45
46describe("isTheme", () => {
47 it("accepts the two themes and rejects anything else", () => {
48 expect(isTheme("light")).toBe(true);
49 expect(isTheme("dark")).toBe(true);
50 expect(isTheme("system")).toBe(false);
51 expect(isTheme(null)).toBe(false);
52 expect(isTheme(42)).toBe(false);
53 });
54});