76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { PERMS } from "@/lib/permission-slugs";
|
|
import { anyCapability, type HousekeepingDomainManifest } from "../contracts";
|
|
import { createHousekeepingRegistry } from "../registry";
|
|
import type { HousekeepingRouteHandler } from "./route-handler";
|
|
import { createHousekeepingRouteRuntime } from "./runtime";
|
|
|
|
const peopleManifest = {
|
|
id: "people",
|
|
labelKey: "pages.housekeeping.domains.people.title",
|
|
descriptionKey: "pages.housekeeping.domains.people.description",
|
|
iconId: "users",
|
|
canonicalHref: "/ase-next/people",
|
|
capability: anyCapability(PERMS.USERS_VIEW),
|
|
routes: [
|
|
{
|
|
id: "people.users",
|
|
labelKey: "pages.housekeeping.people.users.title",
|
|
href: "/ase-next/people/users",
|
|
capability: anyCapability(PERMS.USERS_VIEW),
|
|
},
|
|
{
|
|
id: "people.user-detail",
|
|
labelKey: "pages.housekeeping.people.userDetail.title",
|
|
href: "/ase-next/people/users/:id",
|
|
capability: anyCapability(PERMS.USERS_VIEW),
|
|
},
|
|
],
|
|
searchProviders: [],
|
|
inboxSources: [],
|
|
widgets: [],
|
|
} satisfies HousekeepingDomainManifest;
|
|
|
|
const registry = createHousekeepingRegistry([peopleManifest]);
|
|
|
|
const handler = (routeId: string): HousekeepingRouteHandler => ({
|
|
routeId,
|
|
render: async () => `Rendered ${routeId}`,
|
|
});
|
|
|
|
describe("createHousekeepingRouteRuntime", () => {
|
|
it("indexes handlers and delegates canonical route matching", () => {
|
|
const runtime = createHousekeepingRouteRuntime(registry, [
|
|
handler("people.users"),
|
|
handler("people.user-detail"),
|
|
]);
|
|
|
|
expect([...runtime.handlers]).toHaveLength(2);
|
|
expect(runtime.match("/ase-next/people/users/42")).toMatchObject({
|
|
routeId: "people.user-detail",
|
|
params: { id: "42" },
|
|
});
|
|
});
|
|
|
|
it("rejects a route without a handler", () => {
|
|
expect(() => createHousekeepingRouteRuntime(registry, [])).toThrow(
|
|
"missing route handler: people.users",
|
|
);
|
|
});
|
|
|
|
it("rejects duplicate handlers", () => {
|
|
expect(() =>
|
|
createHousekeepingRouteRuntime(registry, [
|
|
handler("people.users"),
|
|
handler("people.users"),
|
|
]),
|
|
).toThrow("duplicate route handler: people.users");
|
|
});
|
|
|
|
it("rejects a handler without a route", () => {
|
|
expect(() =>
|
|
createHousekeepingRouteRuntime(registry, [handler("people.unknown")]),
|
|
).toThrow("handler without route: people.unknown");
|
|
});
|
|
});
|