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.
4.8 kB ยท 160 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161import { expect } from "@std/expect";import { describe, it } from "@std/testing/bdd";
import { HELP_LINKS } from "@/config/help";import { SETTINGS_TABS } from "@/config/settings";
import { createGroup, createMaintenanceItem, createStatusReportItem, helpGroup, navigationGroup, settingsGroup, themeGroup,} from "./static";
describe("navigationGroup", () => { it("places Incidents right after Overview", () => { const labels = navigationGroup().items.map((i) => i.label); expect(labels.slice(0, 2)).toEqual(["Overview", "Incidents"]); });
it("lists Incidents exactly once", () => { const labels = navigationGroup().items.map((i) => i.label); expect(labels.filter((l) => l === "Incidents")).toHaveLength(1); });
it("navigates to each item's href", () => { expect(navigationGroup().items.map((item) => item.action)).toEqual( [ "/overview", "/incidents", "/monitors", "/status-pages", "/notifications", "/chat", "/agents/slack", "/agents/cli", "/agents/mcp", ].map((href) => ({ type: "navigate", href })), ); });
it("keeps values unique", () => { const values = navigationGroup().items.map((i) => i.value); expect(new Set(values).size).toBe(values.length); });});
describe("createStatusReportItem / createMaintenanceItem", () => { it("opens the sheet without a page at the root", () => { expect(createStatusReportItem().action).toEqual({ type: "sheet", sheet: { sheet: "status-report", pageId: undefined }, }); expect(createMaintenanceItem().action).toEqual({ type: "sheet", sheet: { sheet: "maintenance", pageId: undefined }, }); });
it("passes the page id through when scoped", () => { expect(createStatusReportItem(7).action).toEqual({ type: "sheet", sheet: { sheet: "status-report", pageId: 7 }, }); expect(createMaintenanceItem(7).action).toEqual({ type: "sheet", sheet: { sheet: "maintenance", pageId: 7 }, }); });
it("uses a distinct value when scoped so it never collides with the root item", () => { expect(createStatusReportItem().value).toBe("Create Status Report"); expect(createStatusReportItem(7).value).toBe("create-status-report"); expect(createMaintenanceItem().value).toBe("Create Maintenance"); expect(createMaintenanceItem(7).value).toBe("create-maintenance"); });});
describe("createGroup", () => { it("leads with Declare Incident", () => { const [first] = createGroup().items; expect(first.label).toBe("Declare Incident"); expect(first.action).toEqual({ type: "sheet", sheet: { sheet: "declare-incident" }, }); });
it("routes monitor and status page creation to their pages", () => { const hrefs = createGroup().items.flatMap((i) => i.action.type === "navigate" ? [i.action.href] : [], ); expect(hrefs).toEqual(["/monitors/create", "/status-pages/create"]); });});
describe("settingsGroup", () => { it("starts with every settings tab", () => { const items = settingsGroup().items; expect(items.slice(0, SETTINGS_TABS.length).map((i) => i.label)).toEqual( SETTINGS_TABS.map((t) => t.label), ); });
it("deep-links to settings anchors", () => { const apiKeys = settingsGroup().items.find((i) => i.label === "API Keys"); expect(apiKeys?.action).toEqual({ type: "navigate", href: "/settings/general#api-keys", }); });
it("keeps values unique", () => { const values = settingsGroup().items.map((i) => i.value); expect(new Set(values).size).toBe(values.length); });});
describe("helpGroup", () => { it("opens the support sheet first", () => { const [support] = helpGroup().items; expect(support.action).toEqual({ type: "sheet", sheet: { sheet: "support" }, }); });
it("opens help links externally", () => { const links = helpGroup().items.slice(1); expect(links.map((i) => i.action)).toEqual( HELP_LINKS.map((l) => ({ type: "external", href: l.href })), ); });});
describe("themeGroup", () => { function toggle(resolvedTheme: string | undefined) { const calls: string[] = []; const [item] = themeGroup(resolvedTheme, (t) => calls.push(t)).items; if (item.action.type === "run") item.action.run(); return { label: item.label, calls }; }
it("switches dark to light", () => { expect(toggle("dark")).toEqual({ label: "Switch to light theme", calls: ["light"], }); });
it("switches light or unknown to dark", () => { expect(toggle("light").calls).toEqual(["dark"]); expect(toggle(undefined)).toEqual({ label: "Switch to dark theme", calls: ["dark"], }); });});