Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.3 kB ยท 81 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182import { THEMES } from "@openstatus/theme-store";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { THEME_DRAFT_STORAGE_KEY, clearThemeDraft, readThemeDraft, saveThemeDraft,} from "./theme-draft";
// Node only exposes Web Storage by default from v25; a Map-backed stand-in// keeps the suite independent of the runtime version.function memoryStorage(): Storage { const items = new Map<string, string>(); return { get length() { return items.size; }, clear: () => items.clear(), getItem: (key) => items.get(key) ?? null, key: (index) => [...items.keys()][index] ?? null, removeItem: (key) => void items.delete(key), setItem: (key, value) => void items.set(key, String(value)), };}
beforeEach(() => vi.stubGlobal("sessionStorage", memoryStorage()));afterEach(() => vi.unstubAllGlobals());
const theme = Object.values(THEMES)[0];
describe("theme draft storage", () => { it("returns null when nothing is stored", () => { expect(readThemeDraft()).toBeNull(); });
it("round-trips a saved theme", () => { saveThemeDraft(theme); expect(readThemeDraft()).toEqual(theme); });
it("clears the draft", () => { saveThemeDraft(theme); clearThemeDraft(); expect(readThemeDraft()).toBeNull(); });
it("fills in id, name and author for bare CSS variables", () => { sessionStorage.setItem( THEME_DRAFT_STORAGE_KEY, "--background: oklch(1 0 0);", ); expect(readThemeDraft()).toEqual({ id: "draft", name: "Draft", author: { name: "", url: "" }, light: { "--background": "oklch(1 0 0)" }, dark: {}, }); });
it("rejects an entry without supported variables", () => { sessionStorage.setItem(THEME_DRAFT_STORAGE_KEY, "garbage"); expect(readThemeDraft()).toBeNull(); });
it("does not let a hand-edited value break out of the declaration", () => { sessionStorage.setItem( THEME_DRAFT_STORAGE_KEY, JSON.stringify({ light: { "--background": "red;}</style><script>alert(1)</script>" }, dark: {}, }), ); const draft = readThemeDraft(); const values = draft ? [...Object.values(draft.light), ...Object.values(draft.dark)] : []; expect(values.some((v) => /[;{}<>]/.test(String(v)))).toBe(false); });});