A pure move (git mv, history kept): 333 files leave components/, which now holds only the platform layer (ui/) and the legal pages. The shell is the frame (App, header, nav rail, palette, boot); each page lives in modules/<page>/ with its rail, store and tests; what several pages share sits in features/<name>/; the shared-link page is watch/. Domain-free helpers went straight to ui/ (ViewSwitcher, FilterRail, the confirm dialog, the language switcher, the copy rows). Every relative specifier was rewritten (imports, dynamic imports, vi.mock, new URL), and the contract tests that scan sources now scan the whole app source, not only components/ — each glob was counted before and after so none went green over fewer files. The locale-format rule matched `/src/components/` only, so the move would have taken ~300 files out from under its i18n-singleton check; it now covers every folder that holds components, with a test per folder.
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { readdirSync, readFileSync } from "node:fs";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
// DESIGN.md 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 `<h1>` 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([
|
|
"shell/Welcome.tsx",
|
|
"watch/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 <h1>", () => {
|
|
const own = sources()
|
|
.filter(([name]) => !STANDALONE.has(name))
|
|
.filter(([, src]) => /<h1[\s>]/.test(src))
|
|
.map(([name]) => name);
|
|
expect(own).toEqual([]);
|
|
});
|
|
});
|