Files
lolympus-tournament-support/apps/web/test/design-tokens.test.ts
T
dahyeon b115072005 feat: polish double-elimination bracket navigation
Highlight connected routes, add readable round labels and accessible path descriptions, widen routing gaps, and centralize brand colors for winner progression.
2026-07-13 23:17:19 -07:00

76 lines
2.2 KiB
TypeScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
const stylesheet = await readFile(
new URL("../src/index.css", import.meta.url),
"utf8",
);
const BRAND_COLORS = {
coral: "oklch(0.708008 0.234375 24)",
violet: "oklch(0.481934 0.285938 285)",
gold: "oklch(0.853027 0.2 90)",
cyan: "oklch(70% 0.14523 200)",
} as const;
test("defines each brand color once as a primitive token", () => {
for (const [name, value] of Object.entries(BRAND_COLORS)) {
assert.match(
stylesheet,
new RegExp(`--color-brand-${name}: ${escapeRegExp(value)};`),
);
assert.equal(
stylesheet.split(value).length - 1,
1,
`${name} should have one literal source`,
);
}
});
test("maps the light theme semantic roles to the brand primitives", () => {
const lightTheme = cssBlocksForSelector('[data-theme="light"]');
const mappings = [
["--color-primary", "--color-brand-coral"],
["--color-secondary", "--color-brand-violet"],
["--color-accent", "--color-brand-gold"],
["--color-info", "--color-brand-cyan"],
] as const;
for (const [semanticToken, primitiveToken] of mappings) {
assert.match(
lightTheme,
new RegExp(
`${escapeRegExp(semanticToken)}: var\\(${escapeRegExp(primitiveToken)}\\);`,
),
);
}
});
test("keeps coral scopes without overriding the global dark primary", () => {
assert.match(
stylesheet,
/--color-bracket-winner: var\(--color-brand-coral\);/,
);
assert.match(
stylesheet,
/\.competition-series-history\s*{\s*--color-primary: var\(--color-brand-coral\);\s*}/,
);
const darkTheme = cssBlocksForSelector('[data-theme="dark"]');
assert.doesNotMatch(darkTheme, /--color-primary/);
});
function cssBlocksForSelector(selector: string): string {
const blocks = stylesheet.matchAll(
new RegExp(`${escapeRegExp(selector)}\\s*{([^}]*)}`, "g"),
);
const contents = [...blocks].map((match) => match[1] ?? "").join("\n");
assert.notEqual(contents, "", `${selector} should have a CSS block`);
return contents;
}
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}