Files
WebHooker/tests/admin-path.test.ts
T
翅膀 535bfa98ce feat(console): give each group its own routes URL
Resolve the selected group from /admin/groups/{groupId}, validate console paths, and use browser history for back navigation. Keep Groups active and let an active mobile-tab tap return to the list. Scope pending route loads to their group and retain the count beside long headings.
2026-10-17 11:13:09 +08:00

37 lines
1.5 KiB
TypeScript

import { describe, it, expect } from "bun:test";
import { adminGroupPath, parseAdminPath } from "../app/utils/admin-path";
describe("parseAdminPath", () => {
it("maps the console pages", () => {
expect(parseAdminPath(undefined)).toEqual({ view: "overview", groupId: null });
expect(parseAdminPath([])).toEqual({ view: "overview", groupId: null });
expect(parseAdminPath("logs")).toEqual({ view: "logs", groupId: null });
expect(parseAdminPath(["groups"])).toEqual({ view: "groups", groupId: null });
expect(parseAdminPath(["metrics"])).toEqual({ view: "metrics", groupId: null });
});
it("opens a group's routes under /admin/groups/{groupId}", () => {
expect(parseAdminPath(["groups", "inst-12345678"])).toEqual({
view: "groups",
groupId: "inst-12345678",
});
// A trailing slash adds an empty segment.
expect(parseAdminPath(["groups", ""])).toEqual({ view: "groups", groupId: null });
expect(parseAdminPath(["groups", "acme", ""])).toEqual({ view: "groups", groupId: "acme" });
});
it("rejects unknown pages and sub-pages", () => {
expect(parseAdminPath(["foo"])).toBeNull();
expect(parseAdminPath(["logs", "x"])).toBeNull();
expect(parseAdminPath(["groups", "acme", "routes"])).toBeNull();
expect(parseAdminPath(["constructor"])).toBeNull();
});
});
describe("adminGroupPath", () => {
it("encodes the group id", () => {
expect(adminGroupPath("acme")).toBe("/admin/groups/acme");
expect(adminGroupPath("a/b c")).toBe("/admin/groups/a%2Fb%20c");
});
});