refactor(catalog): unify commands and embed guarded catalog workspace
This commit is contained in:
1 parent
16f35568f5
commit
193b6686a9
57 files changed
+3268
-728
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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 });
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user