Files
stack/tests/lex/views-book.test.mjs
kert 55bc6bda63
Some checks failed
CI / lint (push) Successful in 1m8s
CI / notebooks-smoke (push) Successful in 2m8s
Deploy / changes (push) Successful in 18s
CI / test (push) Failing after 5m36s
Infra CI / notebooks (push) Successful in 2m24s
Infra CI / zotero (push) Successful in 34s
Infra CI / docs (push) Successful in 1m49s
Infra CI / api (push) Successful in 1m54s
Infra CI / llm (push) Successful in 1m34s
Deploy / report (push) Has been cancelled
Deploy / notebooks (push) Has been cancelled
Deploy / zotero (push) Has been cancelled
Deploy / docs (push) Has been cancelled
Deploy / api (push) Has been cancelled
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Infra CI / bcda (push) Has been cancelled
Infra CI / mc (push) Has been cancelled
fix(lex): consecutive identical cites collapse to one counted chip with a drawer list (S1-P11); held review items show text, kind and CMS's summary year; live cite-object fixture
2026-11-13 03:53:56 -05:00

75 lines
4.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// lex · Contents, Dossier, Review and the coming views.
import { test } from "node:test";
import { equal as eq, ok } from "node:assert/strict";
import { readFileSync } from "node:fs";
import { esc } from "../../infra/gitea/custom/public/assets/dossier/fmt.js";
import { parseLocation } from "../../infra/gitea/custom/public/assets/dossier/state.js";
import * as contents from "../../infra/gitea/custom/public/assets/dossier/view-contents.js";
import * as dossier from "../../infra/gitea/custom/public/assets/dossier/view-dossier.js";
import * as review from "../../infra/gitea/custom/public/assets/dossier/view-review.js";
import * as coming from "../../infra/gitea/custom/public/assets/dossier/view-coming.js";
const fx = (name) => JSON.parse(readFileSync(new URL(`./fixtures/${name}.json`, import.meta.url), "utf8"));
const C = fx("contents");
const H = fx("header");
const st = (url) => parseLocation(new URL(url, "https://lex.test"));
test("contents tiles", () => {
const c = contents.render({ contents: C }, st("/contents"));
ok(c.includes('href="/dossier?family=HOME-VISITS"') && c.includes("CY2022–CY2027") && c.includes("Planned"));
ok(/disabled[^>]*>Propose a new family/.test(c) && c.includes("coming · S2"));
const C0 = { ...C, families: [{ ...C.families[0], sections: { ...C.families[0].sections, payment: 0 } }] };
ok(contents.render({ contents: C0 }, st("/contents")).includes("Payment 0"));
ok(c.includes("tracker comes with S6") && c.includes("citation check passed") && c.includes("codes set at curation"));
ok(c.includes("CY2023 PFS final PETM225D"));
eq(contents.needs[0], "contents");
});
test("dossier view", () => {
const h = dossier.render({ header: H }, st("/dossier?family=HOME-VISITS"));
for (const id of ["F1", "F2", "F16"]) ok(h.includes(`data-fact="${id}"`), id);
ok(h.includes('class="code del"') && h.includes('class="code lnk"'));
eq((h.match(/data-ref="F3"/g) || []).length, 1);
for (const g of H.gaps) ok(h.includes(esc(g)));
ok(h.includes("3 items held for review") && h.includes('href="/review?family=HOME-VISITS"'));
ok(h.includes("citation check passed") && h.includes("CY2021 formation") && h.includes("Origin and formation"));
ok(h.includes('href="/timeline?family=HOME-VISITS"') && /disabled[^>]*>Flag this/.test(h));
ok(h.includes("Invented governance excerpt."));
});
test("dossier with no governance and a failed check", () => {
const H2 = { ...H, governance: [], check_passed: false, facts: {}, gaps: ["No governance findings captured."] };
const h = dossier.render({ header: H2 }, st("/dossier?family=HOME-VISITS"));
ok(h.includes("No governance findings yet") && h.includes("No governance findings captured.") && h.includes("citation check failed"));
});
const cite = (label, url) => ({ kind: "fr_para", label, url, item_key: "K", p_id: 1, page: 0, locator: "" });
// The live API gives a held summary's cite and response as cite objects.
const HR = {
...H,
review: [
H.review[0],
H.review[1],
{ fact_id: "", kind: "cms_summary", rule_year: 2007, reason: "held summary sentence", quote: "Invented held sentence.", cite: cite("CY2007 PFS final PETM225D ¶1", "https://example.test/c"), response: cite("CY2007 PFS final PETM225D ¶2", "https://example.test/r") },
{ fact_id: "", kind: "origin", reason: "model paraphrase failed its grounding check", text: "Invented origin text <b>.", cite: cite("CY2018 PFS final X ¶2", "https://example.test/o") },
],
};
test("review view", () => {
const r = review.render({ header: HR }, st("/review?family=HOME-VISITS"));
eq((r.match(/<tr /g) || []).length, 4);
eq((r.match(/disabled/g) || []).length, 12);
ok(r.includes("model extract, unreviewed") && r.includes("<blockquote>Invented held sentence.</blockquote>"));
ok(r.includes('href="https://example.test/c"') && r.includes('href="https://example.test/r"') && r.includes("never overwrites"));
ok(r.includes("CMS&#39;s summary · CY2007") && r.includes("Origin"));
ok(r.includes("<p>Invented origin text &lt;b&gt;.</p>") && r.includes('href="https://example.test/o"'));
});
test("coming panels", () => {
for (const [v, s] of [["grid", "S3"], ["evaluate", "S4"], ["predict", "S5"], ["draft", "S6"]]) {
const c = coming.render({}, st(`/${v}?family=HOME-VISITS`));
ok(c.includes(`Coming · ${s}`) && /disabled/.test(c), v);
}
});