import { test } from "node:test"; import assert from "node:assert/strict"; import { ASK_SCOPE_LINE, LIVE_CHAT_MISSING, NO_ARCHIVES_IN_SCOPE, NO_ARCHIVES_ON_HUB, copy, link, } from "./hubScopeCopy"; // The hub's copy lines carry their link in the line itself — copy`…${link("…")}…` // — so nothing is parsed out of the words (it used to be a [bracketed] phrase // found by a regex; the operator ruled that out, 2026-09-28). test("a line with a link: its text, and the words either side of the link", () => { assert.deepEqual(copy`Choose some on the ${link("hub's front page")} to ask.`, { before: "Choose some on the ", link: "hub's front page", after: " to ask.", text: "Choose some on the hub's front page to ask.", }); }); test("a line with no link is all text; plain interpolations are text, brackets too", () => { const n = 3; assert.deepEqual(copy`Searching ${n} of ${"4"} [archives].`, { before: "Searching 3 of 4 [archives].", after: "", text: "Searching 3 of 4 [archives].", }); // A link may sit anywhere, and text after it may interpolate too. assert.deepEqual(copy`${link("Here")} — ${2} left`, { before: "", link: "Here", after: " — 2 left", text: "Here — 2 left", }); }); test("two links in one line throw (a programmer error, caught when the line is built)", () => { assert.throws( () => copy`${link("one")} and ${link("two")}`, /links one phrase at most: "one" and "two"/, ); }); test("the four shipped lines read as the operator ruled them (2026-09-28)", () => { assert.equal(NO_ARCHIVES_IN_SCOPE.text, "No archives selected. Choose some on the hub's front page to ask."); assert.equal(NO_ARCHIVES_IN_SCOPE.link, "hub's front page"); assert.equal(NO_ARCHIVES_ON_HUB.text, "This hub has no archives yet. Add one on the hub's front page to ask."); assert.equal(NO_ARCHIVES_ON_HUB.link, "hub's front page"); assert.equal(LIVE_CHAT_MISSING, "live chat didn't load"); assert.deepEqual(ASK_SCOPE_LINE(1, 2), { before: "Searching 1 of 2 archives — ", link: "change on the front page", after: ".", text: "Searching 1 of 2 archives — change on the front page.", }); assert.equal(ASK_SCOPE_LINE(1, 1)?.text, "Searching 1 of 1 archive — change on the front page."); });