diff options
| author | Adam Malczewski <[email protected]> | 2026-06-01 11:44:27 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-01 11:44:27 +0900 |
| commit | 0a5eea4c06371df756aea40f53bb6dbe71df664a (patch) | |
| tree | 443e454e1edf1814f1a5c8e77507f63812739122 /packages/frontend/tests | |
| parent | 00922f6136ff0c6e047bb4a6165682f236971450 (diff) | |
| parent | 03e58f69e77b7a27e235210158f3f8e499a817c3 (diff) | |
| download | dispatch-0a5eea4c06371df756aea40f53bb6dbe71df664a.tar.gz dispatch-0a5eea4c06371df756aea40f53bb6dbe71df664a.zip | |
merge: dev into r1/claude-reset-fix
Brings in the n2/ntfy-notifications feature (ntfy.sh push notifications
with per-event toggles, subagent-suppression flag, topic-only input,
Settings UI, dispatcher + transport + config modules, 12+ new tests),
the header declutter (theme picker + Debug panel moved into Settings /
sidebar), the shared theme boot-apply module, and an a11y label for the
remove-panel button.
No code changes from this branch were touched by the merge — the
overlap was purely textual.
Conflict resolution:
1. HANDOFF.md (add/add conflict). Both branches independently put a
single-purpose HANDOFF.md at the repo root for their respective
in-flight feature, matching the existing convention (c351719 did
the same for this branch; 29bdd00 did the same for ntfy). After
this merge both features ship, so neither is in-flight anymore.
Archive both into notes/:
- notes/wake-schedule-handoff.md (this branch — git tracks as a
rename from HANDOFF.md)
- notes/ntfy-notifications-handoff.md (dev — recovered from
MERGE_HEAD before deletion)
The root HANDOFF.md is intentionally absent post-merge; the next
in-flight branch will create its own.
2. packages/api/tests/routes.test.ts (auto-merged). dev appended ntfy
stubs to the vi.mock('@dispatch/core', ...) factory; this branch
appended a 'Wake schedule routes' describe block at the bottom.
The two regions don't overlap and the textual auto-merge is correct
(verified: 6 describe blocks, both mock-stub regions and the new
describe present, no conflict markers).
Verification on the merge commit:
bun run test → 31 files, 495 / 495 passing
(was 431 on the branch + 64 from dev)
bun run check → biome clean, 156 files
bun run --cwd packages/frontend typecheck
→ svelte-check 0 errors, 0 warnings
dev can now fast-forward to this commit:
git checkout dev && git merge --ff-only r1/claude-reset-fix
Diffstat (limited to 'packages/frontend/tests')
| -rw-r--r-- | packages/frontend/tests/theme.test.ts | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/packages/frontend/tests/theme.test.ts b/packages/frontend/tests/theme.test.ts new file mode 100644 index 0000000..63a343d --- /dev/null +++ b/packages/frontend/tests/theme.test.ts @@ -0,0 +1,144 @@ +/** + * Tests for `src/lib/theme.ts` — the shared theme picker module. + * + * Covers the post-Gemini-review fix where `App.svelte` (boot apply) + * and `SettingsPanel.svelte` (UI picker) used to hand-roll their own + * defaults and could disagree. After consolidation, both call into + * this module and the bug class is gone — these tests pin that + * invariant. + */ +import { beforeEach, describe, expect, it, vi } from "vitest"; +import { applyTheme, DEFAULT_THEME, loadStoredTheme, THEMES } from "../src/lib/theme.js"; + +const LS_KEY = "dispatch-theme"; + +function makeLocalStorageMock(): Storage { + const store = new Map<string, string>(); + return { + getItem: (k: string) => store.get(k) ?? null, + setItem: (k: string, v: string) => { + store.set(k, v); + }, + removeItem: (k: string) => { + store.delete(k); + }, + clear: () => { + store.clear(); + }, + get length() { + return store.size; + }, + key: (i: number) => Array.from(store.keys())[i] ?? null, + }; +} + +function makeDocumentMock(): { documentElement: { setAttribute: (k: string, v: string) => void } } { + const attrs = new Map<string, string>(); + return { + documentElement: { + setAttribute: (k: string, v: string) => { + attrs.set(k, v); + }, + // expose for assertions + // @ts-expect-error — test-only escape hatch + _attrs: attrs, + }, + }; +} + +beforeEach(() => { + vi.stubGlobal("localStorage", makeLocalStorageMock()); + vi.stubGlobal("document", makeDocumentMock()); +}); + +describe("DEFAULT_THEME", () => { + it("is one of the THEMES (sanity check that they can't drift)", () => { + expect((THEMES as readonly string[]).includes(DEFAULT_THEME)).toBe(true); + }); +}); + +describe("loadStoredTheme", () => { + it("returns DEFAULT_THEME when localStorage is empty (first-ever load)", () => { + expect(loadStoredTheme()).toBe(DEFAULT_THEME); + }); + + it("returns the stored theme when it's a known theme", () => { + localStorage.setItem(LS_KEY, "dracula"); + expect(loadStoredTheme()).toBe("dracula"); + }); + + it("returns DEFAULT_THEME when the stored value isn't a known theme", () => { + // Guards against a stale storage entry from a removed theme, + // or a hand-edited bad value, falling through to daisyUI's own + // fallback (which is `light`, not our DEFAULT). + localStorage.setItem(LS_KEY, "solarized-rainbow"); + expect(loadStoredTheme()).toBe(DEFAULT_THEME); + }); + + it("returns DEFAULT_THEME when localStorage.getItem throws", () => { + vi.stubGlobal("localStorage", { + getItem: () => { + throw new Error("SecurityError"); + }, + setItem: () => {}, + removeItem: () => {}, + clear: () => {}, + length: 0, + key: () => null, + }); + expect(loadStoredTheme()).toBe(DEFAULT_THEME); + }); + + it("returns DEFAULT_THEME when localStorage is undefined (SSR)", () => { + vi.stubGlobal("localStorage", undefined); + expect(loadStoredTheme()).toBe(DEFAULT_THEME); + }); +}); + +describe("applyTheme", () => { + it("writes data-theme on the document element", () => { + applyTheme("nord"); + // @ts-expect-error — test mock exposes `_attrs` + expect(document.documentElement._attrs.get("data-theme")).toBe("nord"); + }); + + it("persists the theme to localStorage", () => { + applyTheme("forest"); + expect(localStorage.getItem(LS_KEY)).toBe("forest"); + }); + + it("round-trips through loadStoredTheme", () => { + applyTheme("luxury"); + expect(loadStoredTheme()).toBe("luxury"); + }); + + it("does not throw when localStorage.setItem throws (quota etc.)", () => { + vi.stubGlobal("localStorage", { + getItem: () => null, + setItem: () => { + throw new Error("QuotaExceededError"); + }, + removeItem: () => {}, + clear: () => {}, + length: 0, + key: () => null, + }); + expect(() => applyTheme("cyberpunk")).not.toThrow(); + }); + + it("still writes to the DOM even if localStorage write throws", () => { + vi.stubGlobal("localStorage", { + getItem: () => null, + setItem: () => { + throw new Error("QuotaExceededError"); + }, + removeItem: () => {}, + clear: () => {}, + length: 0, + key: () => null, + }); + applyTheme("coffee"); + // @ts-expect-error — test mock exposes `_attrs` + expect(document.documentElement._attrs.get("data-theme")).toBe("coffee"); + }); +}); |
