Files
EpicNext-Cms/src/features/catalog/client/catalog-selection-url.test.ts
T
Simo 193b6686a9
CI / check (push) Successful in 1m16s
CI / deploy (push) Successful in 28s
refactor(catalog): unify commands and embed guarded catalog workspace
2026-09-06 19:40:52 +02:00

36 lines
1.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
readCatalogSelection,
writeCatalogSelection,
} from "./catalog-selection-url";
describe("catalog selection URL", () => {
it("restores category context without disturbing catalog, search or pagination", () => {
const url = new URL(
"https://cms.test/admin/catalog?catalog=bc&search=chair&page=4",
);
const selected = writeCatalogSelection(url, { rootId: 8, pageId: 12 });
expect(readCatalogSelection(selected)).toEqual({ rootId: 8, pageId: 12 });
expect(selected.searchParams.get("catalog")).toBe("bc");
expect(selected.searchParams.get("search")).toBe("chair");
expect(selected.searchParams.get("page")).toBe("4");
expect(url.searchParams.has("category")).toBe(false);
expect(
writeCatalogSelection(selected, {
rootId: 8,
pageId: null,
}).searchParams.has("category"),
).toBe(false);
});
it.each(["-1", "0", "1.5", "1abc", "Infinity", "9007199254740992"])(
"rejects invalid identifiers: %s",
(id) => {
expect(
readCatalogSelection(
new URL(`https://cms.test/?root=${id}&category=${id}`),
),
).toEqual({ rootId: null, pageId: null });
},
);
});