forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

ui-conventions.test.ts47 lines, 1.9 KiBHistoryRawDownload
1import { readdirSync, readFileSync, statSync } from "node:fs";
2import { join, relative } from "node:path";
3
4/**
5 * Guardrails for the UI rules in docs/ui and the ui-conventions skill. Each
6 * one was broken somewhere before the 2026-09 UI pass fixed it; this keeps it
7 * from drifting back.
8 */
9const SRC = join(__dirname, "..");
10
11function sourceFiles(dir: string): string[] {
12 return readdirSync(dir).flatMap((name) => {
13 const path = join(dir, name);
14 if (statSync(path).isDirectory()) return sourceFiles(path);
15 return /\.tsx?$/.test(name) && !/\.test\.tsx?$/.test(name) ? [path] : [];
16 });
17}
18
19const files = sourceFiles(SRC).map((path) => ({ path: relative(SRC, path), text: readFileSync(path, "utf8") }));
20const offenders = (pattern: RegExp, allow: (path: string) => boolean = () => false) =>
21 files.filter((file) => !allow(file.path) && pattern.test(file.text)).map((file) => file.path);
22
23it("domain code renders tables through DataTable, not raw <table>", () => {
24 // The insight run report is a print document; DataTable's toolbar and
25 // phone card layout would break the printed page.
26 expect(
27 offenders(/<table[\s>]/, (path) => path.startsWith("components/ui/") || path === "components/insights/insight-run-report.tsx"),
28 ).toEqual([]);
29});
30
31it("no text below 11px, bar the two avatar-initial circles", () => {
32 expect(
33 offenders(/text-\[(?:[0-9]|10)px\]/, (path) => path === "components/users/user-avatar.tsx" || path === "pages/questions-page.tsx"),
34 ).toEqual([]);
35});
36
37it("colored text uses the contrast-safe -text tokens", () => {
38 expect(offenders(/(?<![\w-])text-(?:primary|success|warning|info|destructive)(?![\w/-])/)).toEqual([]);
39});
40
41it("the back button never calls window.history.back()", () => {
42 expect(offenders(/window\.history\.back\(\)/)).toEqual([]);
43});
44
45it("no native browser dialogs", () => {
46 expect(offenders(/window\.(?:confirm|prompt|alert)\(/)).toEqual([]);
47});