// node --test umtool/lib/hrefs.test.mjs (Node strips hrefs.ts's types itself) import { test } from "node:test"; import assert from "node:assert/strict"; import * as H from "./hrefs.ts"; test("note is always the last parameter", () => { assert.equal(H.articleHref({ site: "articles", id: "x" }, { note: "n1", tab: "source" }), "/articles/x?tab=source¬e=n1"); assert.equal(H.projectHref("a/b", { note: "n2", all: true }), "/projects/a/b?all=1¬e=n2"); assert.equal(H.withQuery("/p", { note: "sneaky", z: "1", a: "2" }, "n3"), "/p?z=1&a=2¬e=n3"); // A note passed in the query map never lands anywhere but the end -- and only via `note`. assert.equal(H.withQuery("/p", { note: "sneaky", z: "1" }), "/p?z=1"); for (const href of [ H.clipBenchHref("p", "c04", { note: "n" }), H.claimBenchHref("p", "k1", { note: "n" }), H.takesHref("p", { note: "n" }), H.clipDeckHref("p", { show: "doubtful", note: "n" }), H.narrationHref("p", { note: "n" }), H.reviewHref("p", { note: "n" }), H.projectAtHref("tools/x", { note: "n" }), H.articleHref({ site: "jeralyzer", id: "r" }, { status: "draft", tab: "source", ws: "w", rel: "a.md", note: "n" }), ]) { assert.match(href, /[?&]note=n$/, href); } }); test("walk a take: /projects/

/takes//walk and …/clip/, `all` as 1, note last", () => { assert.equal(H.takeWalkHref("a/b", "tight-1"), "/projects/a/b/takes/tight-1/walk"); assert.equal(H.takeWalkHref("a/b", "tight-1", { all: true }), "/projects/a/b/takes/tight-1/walk?all=1"); assert.equal(H.takeClipHref("a/b", "tight-1", "t01a"), "/projects/a/b/takes/tight-1/clip/t01a"); assert.equal(H.takeClipHref("a/b", "tight-1", "t01a", { all: true, note: "n" }), "/projects/a/b/takes/tight-1/clip/t01a?all=1¬e=n"); }); test("the clip deck: /projects/

/clips, its filter in `show`", () => { assert.equal(H.clipDeckHref("a/b"), "/projects/a/b/clips"); assert.equal(H.clipDeckHref("a/b", { show: "unruled" }), "/projects/a/b/clips?show=unruled"); }); test("the clip editor: the deck's address, `mode=edit` and the clip; note last", () => { assert.equal(H.clipEditorHref("a/b"), "/projects/a/b/clips"); assert.equal(H.clipEditorHref("a/b", { clip: "r001" }), "/projects/a/b/clips?clip=r001"); assert.equal(H.clipEditorHref("a/b", { mode: "edit", clip: "r 2", note: "n" }), "/projects/a/b/clips?mode=edit&clip=r+2¬e=n"); }); test("withNote re-points an href and keeps note last, and the fragment after it", () => { assert.equal(H.withNote("/articles/x?note=old&tab=source", "new"), "/articles/x?tab=source¬e=new"); assert.equal(H.withNote("/projects/p", "n"), "/projects/p?note=n"); assert.equal(H.withNote("/sites/s?ws=a#files", "n"), "/sites/s?ws=a¬e=n#files"); }); test("project ids are encoded per segment, slashes kept", () => { assert.equal(H.projectHref("quartering-uh-song/videos/mortal-kombat"), "/projects/quartering-uh-song/videos/mortal-kombat"); assert.equal(H.projectHref("a b/c?d"), "/projects/a%20b/c%3Fd"); assert.equal(H.clipBenchHref("articles/x/i1", "c 04"), "/projects/articles/x/i1/clip/c%2004"); assert.equal(H.encodePath("/lead//trail/"), "lead/trail"); }); test("empty, null and false values are left out; true is 1", () => { assert.equal(H.workHref({}), "/work"); assert.equal(H.workHref({ kind: "", state: undefined, q: "x y" }), "/work?q=x+y"); assert.equal(H.projectHref("p", { all: false }), "/projects/p"); // A piece page's tab: first, the Overview written out (the bare address is the workspace, L7a), a note still last. assert.equal(H.projectHref("a/b", { tab: "build" }), "/projects/a/b?tab=build"); assert.equal(H.projectHref("a/b", { tab: "overview" }), "/projects/a/b?tab=overview"); assert.equal(H.workspaceHref("a/b"), "/projects/a/b"); assert.equal(H.workspaceHref("a/b", { block: "c01" }), "/projects/a/b?block=c01"); // L7b: the modes, a version reviewed or presented, a block and the seconds into it. assert.equal(H.workspaceHref("a/b", { mode: "review" }), "/projects/a/b?mode=review"); assert.equal(H.workspaceHref("a/b", { mode: "review", take: "v1" }), "/projects/a/b?mode=review&take=v1"); assert.equal(H.workspaceHref("a/b", { take: "v1" }), "/projects/a/b"); assert.equal(H.workspaceHref("a/b", { block: "c02", at: 1.234 }), "/projects/a/b?block=c02&at=1.23"); assert.equal(H.presentHref("a/b", { take: "v1", slide: "c01" }), "/projects/a/b?mode=present&take=v1#c01"); assert.equal(H.versionReviewHref("a/b", "v2"), "/projects/a/b?mode=review&take=v2"); // A take walk's old query rides into its review pass, note last; without a mode they are not the workspace's. assert.equal(H.workspaceHref("a/b", { mode: "review", take: "v2", all: true, note: "n1" }), "/projects/a/b?mode=review&take=v2&all=1¬e=n1"); assert.equal(H.workspaceHref("a/b", { all: true, note: "n1" }), "/projects/a/b"); assert.equal(H.projectHref("a/b", { tab: "cut", all: true, note: "n1" }), "/projects/a/b?tab=cut&all=1¬e=n1"); assert.equal(H.projectsHref({ kind: "k1", new: false }), "/projects?kind=k1"); assert.equal(H.projectsHref({ new: true }), "/projects?new=1"); assert.equal(H.homeHref({ hidden: true }), "/?hidden=1"); }); test("articles open in the store or on their site", () => { assert.equal(H.articleHref({ site: "articles", id: "poker" }), "/articles/poker"); assert.equal(H.articleHref({ site: "jeralyzer", id: "poker" }), "/sites/jeralyzer/poker"); assert.equal(H.articleEvidenceHref({ site: "jeralyzer", id: "poker" }, { c: "3" }), "/sites/jeralyzer/poker/evidence?c=3"); assert.equal(H.articleCompareHref("poker", { a: "1", b: "2" }), "/articles/poker/compare?a=1&b=2"); assert.equal(H.newArticleHref(), "/create?make=article"); // An article piece's tabs (P4a-2): the Overview is never written; another video project, the cut's every quote. assert.equal(H.articleHref({ site: "articles", id: "poker" }, { tab: "overview" }), "/articles/poker"); assert.equal( H.articleHref({ site: "articles", id: "poker" }, { note: "n", all: true, project: "gen/poker/i1", tab: "cut" }), "/articles/poker?tab=cut&all=1&project=gen%2Fpoker%2Fi1¬e=n", ); }); test("the places: Inbox, Work (and the lists it replaced), Settings", () => { assert.equal(H.decisionsHref({ severity: "blocking" }), "/"); assert.equal(H.browseHref({ kind: "k1" }), "/work?kind=k1"); assert.equal(H.articlesHref({ status: "draft" }), "/work?kind=article&site=articles&status=draft"); assert.equal(H.systemHref(), "/settings/system"); assert.equal(H.researchHref(), "/research"); }); test("every page address the builders make is still served or redirected", async () => { const { REDIRECTS } = await import("../redirects.mjs"); const old = ["/browse", "/browse/decisions", "/browse/find", "/browse/faces", "/browse/sources", "/browse/trim/:set", "/browse/at", "/browse/:path*", "/articles", "/sites", "/mix", "/bench", "/articles/new", "/"]; for (const s of old) assert.ok(REDIRECTS.some((r) => r.source === s), s); // Permanent (308) since P6b. for (const r of REDIRECTS) assert.equal(r.permanent, true, r.source); }); test("site pages, tools and piles", () => { assert.equal(H.siteHref("jeralyzer"), "/sites/jeralyzer"); assert.equal(H.siteHref("jeralyzer", { ws: "w", rel: "a/b.md" }), "/sites/jeralyzer?ws=w&rel=a%2Fb.md#files"); assert.equal(H.sitesHref({ status: "draft" }), "/work?by=site&status=draft"); assert.equal(H.findHref({ q: "um" }), "/tools/find?q=um"); assert.equal(H.phraseFinderHref(), "/tools/phrases"); assert.equal(H.phraseFinderHref({ q: "slow news day" }), "/tools/phrases?q=slow+news+day"); assert.equal(H.facesHref({ cover: "c 1" }), "/tools/faces?cover=c+1"); assert.equal(H.sourcesHref(), "/tools/sources"); assert.equal(H.trimHref("hooks"), "/tools/trim/hooks"); assert.equal(H.mixHref({ body: "/a/b.wav", from: "p", start: 1.5 }), "/tools/mix?body=%2Fa%2Fb.wav&from=p&start=1.5"); assert.equal(H.pileHref("sort", { limit: 5 }), "/tools/song/sort?limit=5"); assert.equal(H.benchHref({ run: "r1" }), "/tools/bench?run=r1"); assert.equal(H.toolsHref(), "/tools"); assert.equal(H.songToolsHref(), "/tools/song"); assert.equal(H.cutHref("yoshi", "wide", { plan: "p1" }), "/projects/yoshi/wide?plan=p1"); assert.equal(H.homeHref(), "/"); }); test("Create and Settings (P5)", () => { assert.equal(H.createHref(), "/create"); assert.equal(H.createHref({ from: "ch/vid" }), "/create?from=ch%2Fvid"); assert.equal(H.createHref({ make: "video-board", case: "c1" }), "/create?make=video-board&case=c1"); for (const m of H.MAKES) assert.ok(H.isMake(m), m); assert.equal(H.isMake("video"), false); assert.equal(H.generationPolicyHref(), "/settings/generation"); assert.equal(H.settingsHref(), "/settings"); }); test("Play the cut ↔ the clip bench: Edit this clip carries the way back, Back lands by clip and offset", () => { // Edit this clip: `from=play`, the offset into the clip, the take that was playing. assert.equal(H.clipBenchHref("a/b", "c02", { play: { at: 1.234 } }), "/projects/a/b/clip/c02?from=play&at=1.23"); assert.equal(H.clipBenchHref("a/b", "c02", { play: { at: 0, take: "short" } }), "/projects/a/b/clip/c02?from=play&take=short"); assert.equal(H.clipBenchHref("a/b", "c02", { play: null, note: "n" }), "/projects/a/b/clip/c02?note=n"); // Back: the project's cut at the clip; an offset of 0 is the clip's start, said by leaving it out. assert.equal(H.playHref("a/b", { clip: "c02", at: 0.5 }), "/projects/a/b/play?clip=c02&at=0.50"); assert.equal(H.playHref("a/b", { clip: "c02", at: 0 }), "/projects/a/b/play?clip=c02"); // No clip, no offset: `at` means nothing on its own. assert.equal(H.playHref("a/b", { at: 3 }), "/projects/a/b/play?cut=1"); // Play's own page always carries a query: a bare /play is the workspace's (a 308, L7b). assert.equal(H.playHref("a/b"), "/projects/a/b/play?cut=1"); assert.equal(H.playHref("a/b", { take: "t1", note: "n" }), "/projects/a/b/play?take=t1¬e=n"); }); test("ingredientHref: /ingredients//, a window as its two-decimal name", () => { assert.equal(H.ingredientHref("MommaOcco", "n8G_ysDV2bA"), "/ingredients/MommaOcco/n8G_ysDV2bA"); assert.equal(H.ingredientHref("MommaOcco", "n8G_ysDV2bA", { from: 1290, to: 1365 }), "/ingredients/MommaOcco/n8G_ysDV2bA?window=1290.00-1365.00"); assert.equal(H.ingredientHref("a b", "x/y", null), "/ingredients/a%20b/x%2Fy"); });