Files
stack/tests/lex/views-payment.test.mjs
kert 2bfd36858c
Some checks failed
CI / lint (push) Successful in 54s
CI / notebooks-smoke (push) Successful in 3m10s
Deploy / changes (push) Successful in 21s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Successful in 2m19s
CI / test (push) Failing after 7m56s
Deploy / api (push) Successful in 3m35s
Deploy / bcda (push) Successful in 3m18s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 1m49s
Deploy / report (push) Successful in 21s
fix(lex): Payment view opens clear of the sticky column, CF to four decimals, CF notes collapse by run, filters read the current code (S1)
2026-11-13 04:18:23 -05:00

165 lines
10 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 · Payment view.
import { test } from "node:test";
import { equal as eq, deepEqual as deq, ok } from "node:assert/strict";
import { readFileSync } from "node:fs";
import { parseLocation } from "../../infra/gitea/custom/public/assets/dossier/state.js";
import * as payment from "../../infra/gitea/custom/public/assets/dossier/view-payment.js";
const fx = (name) => JSON.parse(readFileSync(new URL(`./fixtures/${name}.json`, import.meta.url), "utf8"));
const H = fx("header");
const P = fx("payment");
const st = (url) => parseLocation(new URL(url, "https://lex.test"));
const count = (s, sub) => s.split(sub).length - 1;
const page = (url = "/payment?family=HOME-VISITS", p = P) => payment.render({ header: H, payment: p }, st(url));
test("payment: every cell fact, a hatched proposed column, the unplaced fact", () => {
const p = page();
for (const [k, id] of Object.entries(P.cells)) ok(p.includes(`data-fact="${id}"`), k);
ok(p.includes('data-fact="F18"') && p.includes("proposed") && p.includes("pcol"));
eq(payment.needs.join(), "header,payment");
ok(p.includes("Unplaced payment facts") && p.includes("Invented orphan payment."));
});
test("payment: the proposed column sits before its year's final column, apart", () => {
const t = payment.payTable(P, { metric: "pay_nf", group: "all" });
const heads = t.match(/<th[^>]*>.*?<\/th>/g);
const i27 = heads.findIndex((h) => h.includes("CY2027"));
ok(heads[i27].includes("pcol") && heads[i27].includes("proposed"));
ok(heads.findIndex((h) => h.includes("CY2023")) < i27);
eq(heads.length, 1 + 3, "code, CY2022, CY2023, CY2027 proposed");
// the proposed cell is in the hatched column, the final one is not
ok(/class="[^"]*pcol[^"]*"[^>]*data-fact="F12"|data-fact="F12"[^>]*class="[^"]*pcol/.test(t));
ok(!/pcol[^>]*data-fact="F11"|data-fact="F11"[^>]*pcol/.test(t));
});
test("payment: every group shows by default, the buttons only filter", () => {
const all = page();
for (const c of ["99341", "99343", "G0318"]) ok(all.includes(`data-code="${c}"`), c);
ok(all.includes("Active 1") && all.includes("Deleted 1") && all.includes("Linked 1"));
const del = payment.payTable(P, { metric: "pay_nf", group: "deleted" });
ok(del.includes('data-code="99343"') && !del.includes('data-code="99341"'));
});
test("payment: metric buttons, the value follows the metric", () => {
const pay = payment.payTable(P, { metric: "pay_nf", group: "all" });
const work = payment.payTable(P, { metric: "work", group: "all" });
const tot = payment.payTable(P, { metric: "total_nf", group: "all" });
ok(pay.includes("$69.30") && !pay.includes(">2.10<"));
ok(work.includes(">1.00<") && !work.includes("$69.30"));
ok(tot.includes(">2.10<"));
const h = page();
ok(h.includes("Payment $") && h.includes("Work RVU") && h.includes("Total RVU"));
});
test("payment: an unpaid status shows its letter with the note, a missing row a dash", () => {
const rows = P.rows.map((r) => (r.code === "99341" && r.year === 2023 ? { ...r, status: "B", pay_nf: null, status_note: "bundled — no separate PFS payment" } : r));
const t = payment.payTable({ ...P, rows }, { metric: "pay_nf", group: "all" });
ok(/title="bundled — no separate PFS payment"[^>]*>B</.test(t));
ok(t.includes(">—<"));
});
test("payment: CF row, source row, CF notes unchanged and escaped", () => {
const rows = P.rows.map((r) => (r.vintage === "CY2027 proposed" ? { ...r, cf_note: "proposed; QP CF $33.1693 <b>", citation: "CY2027 <i>RVU</i>" } : r));
const p = page("/payment?family=HOME-VISITS", { ...P, rows });
ok(p.includes("Conv. factor") && p.includes("Source") && p.includes("33.00"));
ok(p.includes("proposed; QP CF $33.1693 &lt;b&gt;") && !p.includes("<b>\n"));
ok(p.includes("CY2027 &lt;i&gt;RVU&lt;/i&gt;") && !p.includes("<i>RVU"));
ok(p.includes('href="https://example.test/rvu"'));
});
test("payment: the payment chart is a final line with proposed rings", () => {
const c = payment.payChart(P.rows, "99341");
ok(c.includes("<path") && c.includes('fill="none"') && c.includes("var(--s-prop)") && c.includes("<svg"));
ok(c.includes("99341 · CY2027 proposed"));
ok(payment.payChart(P.rows, "99999").includes("No RVU-based payment for 99999"));
const unpaid = P.rows.map((r) => ({ ...r, status: "B", pay_nf: null }));
ok(payment.payChart(unpaid, "99341").includes("status B"));
ok(!payment.payChart(P.rows, '<x>').includes("<x>"));
});
test("payment: the volume chart bars one year each", () => {
const v = payment.volChart(P.utilization, "99341");
eq(count(v, "services\""), 2);
ok(v.includes("<svg") && v.includes("99341 · 2023 · 600 services"));
ok(payment.volChart(P.utilization, "99343").includes("No national utilization rows for 99343"));
});
test("payment: the selected code drives the charts", () => {
ok(page().includes("99341: national non-facility payment"), "default is the first active code");
const p = page("/payment?family=HOME-VISITS#code=99343");
ok(p.includes("99343: national non-facility payment") && p.includes("99343: Medicare allowed services"));
ok(/<tr[^>]*data-code="99343"[^>]*class="sel"|<tr[^>]*class="sel"[^>]*data-code="99343"/.test(p));
});
test("payment: no payment rows is a plain message", () => {
const p = page("/payment?family=HOME-VISITS", { ...P, rows: [], cells: {}, unplaced: [], utilization: [], years: [], code_groups: { active: [], deleted: [], linked: [] } });
ok(p.includes("No payment rows"));
});
test("payment: the CF row shows four decimals", () => {
const rows = P.rows.map((r) => (r.vintage === "CY2022 final" ? { ...r, cf: 35.9335 } : r));
ok(payment.payTable({ ...P, rows }, { metric: "pay_nf", group: "all" }).includes(">35.9335<"));
});
test("payment: CF notes stay literal; identical consecutive notes collapse", () => {
const mk = (year, proposed, note) => ({ ...P.rows[0], year, proposed, vintage: `CY${year} ${proposed ? "proposed" : "final"}`, cf_note: note });
const rows = [mk(2016, false, "std <x>"), mk(2017, false, "std <x>"), mk(2018, false, "std <x>"), mk(2019, false, "other"), mk(2020, false, "std <x>"), mk(2020, true, "std <x>")];
const runs = payment.cfNoteRuns(rows);
eq(runs.length, 4);
deq([runs[0].from, runs[0].to, runs[0].note], [2016, 2018, "std <x>"]);
const h = page("/payment?family=HOME-VISITS", { ...P, rows, cells: {}, unplaced: [] });
ok(h.includes("<b>CY2016–CY2018 final</b> std &lt;x&gt;") && h.includes("<b>CY2020 proposed</b>") && h.includes("<b>CY2020 final</b>"));
eq(count(h, "std &lt;x&gt;"), 3);
});
test("payment: the opening scroll leaves the first visible column clear of the sticky column", () => {
// sticky 100 wide; columns start at 100, 200, 300, 400; table 500 in a 300 box (max 200)
eq(payment.openScroll([100, 200, 300, 400], 100, 200), 200, "column at 300 sits right at the sticky edge");
eq(payment.openScroll([100, 200, 300, 400], 100, 250), 300, "the next boundary past the end; the caller pads");
eq(payment.openScroll([100, 200], 100, 0), 0, "a table that fits stays put");
eq(payment.openScroll([100, 200], 100, 500), 500, "no boundary reaches the end: the end itself");
});
function fakeRoot(P, geometry) {
const handlers = {};
const mkEl = (extra = {}) => ({ innerHTML: "", addEventListener: (t, f) => (handlers[t + (extra.id || "")] = f), querySelectorAll: () => [], ...extra });
const sc = { style: {}, scrollLeft: -1, scrollWidth: geometry.sw, clientWidth: geometry.cw, querySelectorAll: () => geometry.heads.map(([l, w]) => ({ offsetLeft: l, offsetWidth: w })) };
const els = { "#pay-tbl": mkEl({ id: "tbl" }), "#pay-scroll": sc, "#pay-f": mkEl({ id: "bar" }) };
return { els, handlers, root: { querySelector: (s) => els[s] || null } };
}
test("payment: mount opens scrolled clear of the sticky column", () => {
const f = fakeRoot(P, { sw: 500, cw: 300, heads: [[0, 100], [100, 100], [200, 100], [300, 100], [400, 100]] });
payment.mount(f.root, { header: H, payment: P }, st("/payment?family=HOME-VISITS"), { go() {} });
eq(f.els["#pay-scroll"].scrollLeft, 200);
const g = fakeRoot(P, { sw: 500, cw: 300, heads: [[0, 100], [100, 120], [220, 100], [320, 100], [420, 80]] });
payment.mount(g.root, { header: H, payment: P }, st("/payment?family=HOME-VISITS"), { go() {} });
eq(g.els["#pay-scroll"].scrollLeft, 220, "boundary 320 - sticky 100");
eq(g.els["#pay-scroll"].style.paddingRight, "20px", "padding so the position exists");
});
test("payment: filters redraw with the current code; a code click re-mounts through nav.go", () => {
const gone = [];
const f = fakeRoot(P, { sw: 500, cw: 300, heads: [[0, 100], [100, 100]] });
payment.mount(f.root, { header: H, payment: P }, st("/payment?family=HOME-VISITS#code=99343"), { go: (p, o) => gone.push([p, o]) });
f.handlers.clickbar({ target: { closest: () => ({ dataset: { g: "deleted" } }) } });
ok(/<tr data-code="99343" class="sel"/.test(f.els["#pay-tbl"].innerHTML) && !f.els["#pay-tbl"].innerHTML.includes('data-code="99341"'));
f.handlers.clicktbl({ target: { closest: (s) => (s.includes("data-fact") ? null : { dataset: { code: "99341" } }) } });
eq(gone[0][0].code, "99341");
// app.js re-renders (and so re-mounts) on a code change: the new mount carries the new code
const g = fakeRoot(P, { sw: 500, cw: 300, heads: [[0, 100], [100, 100]] });
payment.mount(g.root, { header: H, payment: P }, st("/payment?family=HOME-VISITS#code=99341"), { go() {} });
g.handlers.clickbar({ target: { closest: () => ({ dataset: { g: "all" } }) } });
g.handlers.clickbar({ target: { closest: () => ({ dataset: { m: "work" } }) } });
ok(/<tr data-code="99341" class="sel"/.test(g.els["#pay-tbl"].innerHTML));
});
test("payment: the table scrolls inside its wrapper, the page does not", () => {
const css = readFileSync(new URL("../../dev/scripts/dossier_page/template.html", import.meta.url), "utf8");
ok(/\.tbl-wrap\s*\{[^}]*overflow-x:\s*auto/.test(css));
ok(payment.payTable(P, { metric: "pay_nf", group: "all" }).startsWith('<div class="tbl-wrap" id="pay-scroll">'));
ok(/\.pay-tbl|\.tbl\b/.test(css) && !/body\s*\{[^}]*overflow-x:\s*scroll/.test(css));
ok(/\.stick\s*\{[^}]*position:\s*sticky/.test(css));
});