import { readdirSync, readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
// E28 S3d4 (B4, UX-15). One `h1` per page: the shell's hidden page name, or a view's own visible
// title through `PageHeading`, which makes the shell's step aside. A hand-written `
` inside the
// shell would be a second one, beside the page name the shell already put there.
function sources(): Array<[string, string]> {
const walk = (u: URL, prefix: string): Array<[string, string]> =>
readdirSync(u, { withFileTypes: true }).flatMap((e) => {
if (e.isDirectory()) return walk(new URL(`${e.name}/`, u), `${prefix}${e.name}/`);
if (!/\.tsx$/.test(e.name) || e.name.includes(".test.")) return [];
return [
[`${prefix}${e.name}`, readFileSync(new URL(e.name, u), "utf-8")] as [string, string],
];
});
return walk(new URL("../", import.meta.url), "");
}
// Pages that render OUTSIDE the app shell own their h1 (no shell, no hidden page name).
const STANDALONE = new Set([
"components/Welcome.tsx",
"components/WatchPage.tsx",
"components/legal/LegalLayout.tsx",
"design-lab/DesignLab.tsx",
// The shell's hidden h1 and the primitive itself.
"components/ui/PageShell.tsx",
"components/ui/Headings.tsx",
]);
describe("the page heading", () => {
it("is written as PageHeading inside the shell, never as a hand ", () => {
const own = sources()
.filter(([name]) => !STANDALONE.has(name))
.filter(([, src]) => /]/.test(src))
.map(([name]) => name);
expect(own).toEqual([]);
});
});