File
Blob: tests/client/lib/page-archive.test.ts
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { createPage } from "@tests/client/util/fixtures"; |
| 3 | import { buildPageTreeIndex } from "@/client/lib/page-tree-model"; |
| 4 | import { |
| 5 | getActiveDescendantIds, |
| 6 | getArchivePageConfirmMessage, |
| 7 | shouldNavigateAwayAfterArchive, |
| 8 | } from "@/client/lib/page-archive"; |
| 9 | |
| 10 | describe("page archive helpers", () => { |
| 11 | it("counts every active descendant and ignores archived descendants", () => { |
| 12 | const index = buildPageTreeIndex([ |
| 13 | createPage({ id: "root", title: "Root" }), |
| 14 | createPage({ id: "child-a", parent_id: "root", position: 1 }), |
| 15 | createPage({ id: "grandchild", parent_id: "child-a", position: 1 }), |
| 16 | createPage({ id: "child-b", parent_id: "root", position: 2 }), |
| 17 | createPage({ |
| 18 | id: "archived-child", |
| 19 | parent_id: "root", |
| 20 | position: 3, |
| 21 | archived_at: "2026-04-01T00:00:00.000Z", |
| 22 | archive_root_id: "archived-child", |
| 23 | }), |
| 24 | ]); |
| 25 | |
| 26 | expect(getActiveDescendantIds(index, "root")).toEqual(["child-a", "grandchild", "child-b"]); |
| 27 | }); |
| 28 | |
| 29 | it("uses archive copy without child-promotion language", () => { |
| 30 | expect(getArchivePageConfirmMessage("Roadmap", 0)).toBe('"Roadmap" will be archived.'); |
| 31 | expect(getArchivePageConfirmMessage("Roadmap", 1)).toBe('"Roadmap" and 1 subpage will be archived.'); |
| 32 | expect(getArchivePageConfirmMessage("Roadmap", 3)).toBe('"Roadmap" and 3 subpages will be archived.'); |
| 33 | }); |
| 34 | |
| 35 | it("navigates away when the active route is any archived descendant", () => { |
| 36 | expect(shouldNavigateAwayAfterArchive("grandchild", ["root", "child", "grandchild"])).toBe(true); |
| 37 | expect(shouldNavigateAwayAfterArchive("other", ["root", "child", "grandchild"])).toBe(false); |
| 38 | }); |
| 39 | }); |