Files
archie/ui/test/needs-attention.test.ts
T
sam 61d486fdc0 fix(ui): count what needs a person from served reads (#2145)
The shell's attention badge counted the task board's summary, which the binary
does not serve, so #2121 removed the badge with the board and nothing said, on
every page, how much work waits on a person.

The count now comes from the two operations that answer it: pending approval
requests and parked runs. The rule lives in ui/src/lib/needs-attention.ts, so
the dashboard's list and the shell's badge agree on what waiting means, and the
count is read through a small store so both read it once.
2026-11-27 19:37:46 +11:00

26 lines
1.3 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { needsAttention, waitsOnPerson } from "../src/lib/needs-attention.ts";
// Guards #2145: the shell used to count what needs a person from the task
// board's summary, which the binary does not serve, so the count went with the
// board. It now counts the two things the binary does serve.
test("what waits on a person is a pending approval or a parked run", () => {
const approval = (state: string) => ({ state }) as never;
const run = (state: string) => ({ state }) as never;
assert.equal(waitsOnPerson(approval("pending"), undefined), true);
assert.equal(waitsOnPerson(approval("approved"), undefined), false);
assert.equal(waitsOnPerson(approval("refused"), undefined), false);
assert.equal(waitsOnPerson(undefined, run("parked")), true);
assert.equal(waitsOnPerson(undefined, run("running")), false);
});
test("the count adds approvals and runs, and reads nothing as zero", () => {
const approvals = [{ state: "pending" }, { state: "pending" }, { state: "approved" }] as never[];
const runs = [{ state: "parked" }, { state: "running" }, { state: "succeeded" }] as never[];
assert.equal(needsAttention(approvals, runs), 3);
assert.equal(needsAttention([], []), 0);
assert.equal(needsAttention(undefined, undefined), 0);
});