import { readdirSync, readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; // The whole app source (shell, modules, features, ui): the checkable menus live in all of them. const root = new URL("../../", import.meta.url); const sources = () => readdirSync(root, { recursive: true, encoding: "utf8" }) .filter((f) => f.endsWith(".tsx") && !f.includes(".test.")) .map((f) => ({ f, src: readFileSync(new URL(f.replace(/\\/g, "/"), root), "utf8") })); /** Checkable menu rows a file renders: a literal `role="menuitemradio"`, and a role CHOSEN by an * expression that can come out checkable — FilterSelect's and ActionMenu's rows, every filter select * and checkable action menu in the app, which a literal-only count skipped. */ function checkableRoles(src: string): number { const literal = (src.match(/role="menuitem(?:radio|checkbox)"/g) ?? []).length; const chosen = [...src.matchAll(/role=\{([^{}]*)\}/g)].filter(([, e]) => /"menuitem(?:radio|checkbox)"/.test(e!), ).length; return literal + chosen; } // `ui/MenuCheck` is the ONE drawn check box of a checkable row (S3e3b replaced seven // hand-drawn copies), yet FilterSelect and Combobox still painted their own — a 14px box beside the // menus' 16px one. The filled-box paint is the tell: it may live in MenuCheck only. describe("the drawn check box", () => { it("is painted by MenuCheck alone", () => { const offenders = sources() .filter(({ f }) => !f.endsWith("MenuCheck.tsx")) .filter(({ src }) => /border-accent bg-accent text-accent-fg/.test(src)) .map(({ f }) => f); expect(offenders).toEqual([]); }); // The player's track rows marked the choice only by an accent label — which the // highlight's white text wiped — and four more menus ticked it their own way (a trailing tick, a // dot, a filled row). A file with a checkable menu row draws MenuCheck, and no tick of its own. it("marks every checkable menu row, with no tick of its own beside it", () => { const offenders = sources() .filter(({ src }) => { const checkable = checkableRoles(src); const drawn = (src.match(/ drawn || (checkable > 0 && / f); expect(offenders).toEqual([]); }); });