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.4 kB ยท 90 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import { describe, expect, it } from "vitest";
import { getActions, toComponentSections, toGroupNameLookup,} from "./page-components.client";
const groups = [ { id: 1, name: "API" }, { id: 2, name: "Empty" },];
function component( id: number, order: number, groupId: number | null = null, groupOrder: number | null = null,) { return { id, name: `c${id}`, order, groupId, groupOrder };}
function shape(sections: ReturnType<typeof toComponentSections>) { return sections.map((s) => ({ group: s.group?.name ?? null, items: s.items.map((c) => c.id), }));}
describe("toComponentSections", () => { it("places a group at its first member's order and sorts members by groupOrder", () => { const sections = toComponentSections( [ component(10, 0), component(11, 3, 1, 2), component(12, 2, 1, 1), component(13, 5), ], groups, ); expect(shape(sections)).toEqual([ { group: null, items: [10] }, { group: "API", items: [12, 11] }, { group: null, items: [13] }, ]); });
it("merges consecutive ungrouped components into one section", () => { const sections = toComponentSections( [component(3, 2), component(1, 0), component(2, 1)], groups, ); expect(shape(sections)).toEqual([{ group: null, items: [1, 2, 3] }]); });
it("drops empty groups and treats unknown groupIds as ungrouped", () => { const sections = toComponentSections([component(1, 0, 99)], groups); expect(shape(sections)).toEqual([{ group: null, items: [1] }]); });
it("treats missing order as 0", () => { const sections = toComponentSections( [component(1, 1), { id: 2, name: "c2" }], [], ); expect(shape(sections)).toEqual([{ group: null, items: [2, 1] }]); });});
describe("toGroupNameLookup", () => { it("maps grouped components to their group name only", () => { const lookup = toGroupNameLookup( [ { id: 1, groupId: 1 }, { id: 2, groupId: null }, { id: 3, groupId: 99 }, ], groups, ); expect([...lookup]).toEqual([[1, "API"]]); });});
describe("getActions", () => { it("attaches the delete handler", () => { const onDelete = () => {}; expect(getActions({ delete: onDelete })[0].onClick).toBe(onDelete); expect(getActions({})[0].onClick).toBeUndefined(); });});