test: enforce admin theme isolation
This commit is contained in:
1 parent
1c581ca5df
commit
d4bcf89449
1 file changed
+37
@@ -10,6 +10,23 @@ const GRAPHICAL_ALLOWLIST = [
|
||||
"src/components/admin/catalog/items-shop-preview.tsx",
|
||||
];
|
||||
|
||||
const DATA_COLOR_ALLOWLIST = [
|
||||
"src/app/admin/alerts/page.tsx",
|
||||
"src/app/admin/banners/banners-manager.tsx",
|
||||
"src/app/admin/events/events-table.tsx",
|
||||
"src/app/admin/events/types/event-types-manager.tsx",
|
||||
"src/app/admin/favicon/favicon-generator.tsx",
|
||||
"src/app/admin/help-questions/new/page.tsx",
|
||||
"src/app/admin/help-questions/[id]/page.tsx",
|
||||
"src/app/admin/prefixes/prefixes-client.tsx",
|
||||
"src/app/admin/tags/page.tsx",
|
||||
"src/app/admin/teams/page.tsx",
|
||||
"src/app/admin/theme/page.tsx",
|
||||
];
|
||||
|
||||
const PUBLIC_STRUCTURAL_TOKEN = /var\(--(?:color-(?:background|surface|dropdown|navbar|navbar-text|text|text-muted|primary|primary-hover)|border-subtle|border-color)\)/g;
|
||||
const HARDCODED_UI_PALETTE = /(?:text|bg|border|ring|from|to|via)-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:[1-9]00|50)(?:\/\d+)?/g;
|
||||
|
||||
function sourceFiles(directory: string): string[] {
|
||||
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
||||
const path = join(directory, entry.name);
|
||||
@@ -31,4 +48,24 @@ describe("admin theme source audit", () => {
|
||||
}
|
||||
expect(violations).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps admin chrome independent from public structural colors", () => {
|
||||
const violations: string[] = [];
|
||||
for (const root of ROOTS) {
|
||||
for (const file of sourceFiles(root)) {
|
||||
const normalized = relative(process.cwd(), file).replaceAll("\\", "/");
|
||||
if (normalized.endsWith("admin-theme-source-audit.test.ts")) continue;
|
||||
const source = readFileSync(file, "utf8");
|
||||
const risky = [
|
||||
...(source.match(PUBLIC_STRUCTURAL_TOKEN) ?? []),
|
||||
...(source.match(HARDCODED_UI_PALETTE) ?? []),
|
||||
];
|
||||
const filtered = DATA_COLOR_ALLOWLIST.includes(normalized)
|
||||
? risky.filter((match) => match.startsWith("var("))
|
||||
: risky;
|
||||
if (filtered.length) violations.push(`${normalized}: ${[...new Set(filtered)].join(", ")}`);
|
||||
}
|
||||
}
|
||||
expect(violations).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user