// Which rows a folded list shows. Run by `npm test`, which Node runs with its // built-in test runner and type stripping. import assert from "node:assert/strict"; import { test } from "node:test"; import { CAP, capRows } from "../src/ui/capped-rows/cap-rows.ts"; const rows = (n) => Array.from({ length: n }, (_, i) => i); test("a list no longer than the cap shows whole", () => { assert.deepEqual(capRows(rows(CAP), false), { shown: rows(CAP), hidden: 0, }); }); test("a longer list folds to the first rows and counts the rest", () => { assert.deepEqual(capRows(rows(CAP + 3), false), { shown: rows(CAP), hidden: 3, }); }); test("expanded, every row shows", () => { assert.deepEqual(capRows(rows(CAP + 3), true), { shown: rows(CAP + 3), hidden: 0, }); }); test("a kept row past the cap still shows, and is not counted as hidden", () => { const out = capRows(rows(CAP + 3), false, (r) => r === CAP + 1); assert.deepEqual(out.shown, [...rows(CAP), CAP + 1]); assert.equal(out.hidden, 2); });