83 lines
4.7 KiB
JavaScript
83 lines
4.7 KiB
JavaScript
// 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 years label reads years_on_file, falls back to years_active", () => {
|
||
const st0 = st("/dossier?family=HOME-VISITS");
|
||
const old = dossier.render({ header: H }, st0);
|
||
ok(old.includes("Years on file") && old.includes(esc(H.years_active)));
|
||
const cur = dossier.render({ header: { ...H, years_on_file: "2019–2027" } }, st0);
|
||
ok(cur.includes("Years on file") && cur.includes("2019–2027") && !cur.includes(esc(H.years_active)));
|
||
});
|
||
|
||
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's summary · CY2007") && r.includes("Origin"));
|
||
ok(r.includes("<p>Invented origin text <b>.</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);
|
||
}
|
||
});
|