fix(ui): harden theme toggle accessibility

This commit is contained in:
vince 2026-06-20 00:58:30 +02:00
parent cdb269e505
commit b923ac8947
8 changed files with 75 additions and 9 deletions

View file

@ -2,6 +2,7 @@ import { describe, expect, test } from "vitest";
import {
getNextUiTheme,
isUiTheme,
persistUiTheme,
resolveInitialUiTheme,
UI_THEME_STORAGE_KEY,
} from "./theme";
@ -25,6 +26,26 @@ describe("UI theme preference", () => {
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);