57ceb984af
Missing or legacy preferences resolve to the pinned Dark theme (not system-resolved, so nobody is surprised by light mode) and the default contrast is 50. Classic remains the flag-off look.
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { getDashboardPreferences } from "~/services/dashboardPreferences.server";
|
|
import { normalizeThemePreference, type ThemePreference } from "~/utils/themePreference";
|
|
|
|
const VALID_THEMES: ThemePreference[] = ["classic", "system", "dark", "light"];
|
|
|
|
describe("normalizeThemePreference", () => {
|
|
it("returns each valid value unchanged", () => {
|
|
for (const theme of VALID_THEMES) {
|
|
expect(normalizeThemePreference(theme)).toBe(theme);
|
|
}
|
|
});
|
|
|
|
it("falls back to dark for legacy/unknown values", () => {
|
|
expect(normalizeThemePreference("solarized")).toBe("dark");
|
|
expect(normalizeThemePreference("")).toBe("dark");
|
|
expect(normalizeThemePreference(42)).toBe("dark");
|
|
expect(normalizeThemePreference(null)).toBe("dark");
|
|
});
|
|
|
|
it("falls back to dark for undefined", () => {
|
|
expect(normalizeThemePreference(undefined)).toBe("dark");
|
|
});
|
|
});
|
|
|
|
describe("DashboardPreferences theme schema", () => {
|
|
it("accepts all four theme values", () => {
|
|
for (const theme of VALID_THEMES) {
|
|
const result = getDashboardPreferences({ version: "1", projects: {}, theme });
|
|
expect(result.theme).toBe(theme);
|
|
}
|
|
});
|
|
|
|
it("accepts preferences without a theme", () => {
|
|
const result = getDashboardPreferences({ version: "1", projects: {} });
|
|
expect(result.theme).toBeUndefined();
|
|
});
|
|
|
|
it("rejects an invalid theme by falling back to defaults", () => {
|
|
const result = getDashboardPreferences({ version: "1", projects: {}, theme: "neon" });
|
|
expect(result.theme).toBeUndefined();
|
|
});
|
|
});
|