fieldnotes-rag / citations.test.mjs
iankamar's picture
Polish interface copy, link citations to evidence, and verify navigation and exports
9dd41f2 verified
Raw History Blame Contribute Delete
1.04 kB
import test from "node:test";
import assert from "node:assert/strict";
import { citationParts } from "./citations.mjs";
test("valid citations point to the actual source anchor", () =>
assert.deepEqual(citationParts("A fact [2]", 2), [
{ text: "A fact " },
{ text: "[2]", href: "#source-2" },
]));
test("invalid and zero citation IDs remain plain text", () =>
assert.deepEqual(citationParts("[0] [99]", 2), [
{ text: "[0]" },
{ text: " " },
{ text: "[99]" },
]));
test("brief citations use separate source namespaces", () =>
assert.equal(
citationParts("[1]", 1, "brief-2-source")[0].href,
"#brief-2-source-1",
));
test("markup and user text are never converted to HTML", () =>
assert.equal(
citationParts("<script>alert(1)</script> [1]", 1)[0].text,
"<script>alert(1)</script> ",
));
test("citation splitting preserves complete answer text", () => {
const s = "One [1].\nTwo [2].";
assert.equal(
citationParts(s, 2)
.map((p) => p.text)
.join(""),
s,
);
});