CI / verify (pull_request) Successful in 1m10s
CI / infrastructure-smoke (pull_request) Successful in 34s
CI / package-release (pull_request) Successful in 52s
CI / migration-smoke (pull_request) Successful in 2m20s
CI / image-build (pull_request) Successful in 1m5s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / package-publication (pull_request) Successful in 58s
CI / deploy-smoke (split) (pull_request) Successful in 2m38s
The theme foundation DESIGN.md requires (ADR 0060): - A design token may carry a `dark` value and a `reduced` value. The token stylesheet selects them in CSS alone: dark under prefers-color-scheme unless the host chose light, or when it chose dark; motion durations zero under prefers-reduced-motion unless it allowed motion, or when it chose reduce. `color-scheme` travels with the tokens. System is live, an explicit choice wins, and every module root follows through custom-property inheritance, with no module contract change. - @ekklesia/design-tokens adds a small appearance API: system/light/dark and system/reduce/allow, parsers for untrusted stored values, resolvers, and a controller that applies the attributes immediately. The shell applies it before React renders. That is the hook the account preferences work will feed; nothing is persisted. The Dashboard page declares `color-scheme: light dark` so a dark system never flashes white. Displays stay light. - A designed dark theme: teal-tinted charcoal, never pure black or white, the same teal accent. - WCAG AA contrast is tested for 41 element pairings in both schemes. Two light pairings failed and are fixed visibly: text.muted darkens, and form controls get a new border.control (3:1). background.placeholder keeps skeletons visible in dark. - Motion tokens (duration-short, duration-ambient) replace literal durations and every per-element reduced-motion rule. radius.scale multiplies sm/md/lg, unchanged at its default of 1. - The sign-in card and module loading/error text move from literal colours to tokens. Guards keep raw colours and literal radii out of Dashboard product source and @ekklesia/ui. - Fixes ConfirmationDialog's phrase input, which used a class that does not exist (`ek-input`) and so was unstyled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
146 lines
5.3 KiB
TypeScript
146 lines
5.3 KiB
TypeScript
// @vitest-environment happy-dom
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
DESIGN_TOKEN_CATEGORIES,
|
|
DESIGN_TOKEN_STYLE_ATTRIBUTE,
|
|
DESIGN_TOKEN_VARIABLE_PREFIX,
|
|
designToken,
|
|
ekklesiaDesignTokens,
|
|
ekklesiaDesignTokenStylesheet,
|
|
installEkklesiaDesignTokens,
|
|
} from "../src/index.js";
|
|
|
|
describe("the Ekklesia design token registry", () => {
|
|
it("is enumerable and deterministic", () => {
|
|
const first = ekklesiaDesignTokens.list();
|
|
const second = ekklesiaDesignTokens.list();
|
|
|
|
expect(first).toBe(second);
|
|
expect(Object.isFrozen(first)).toBe(true);
|
|
expect(first.length).toBeGreaterThan(0);
|
|
expect(first.map((token) => token.name)).toEqual(second.map((token) => token.name));
|
|
expect(ekklesiaDesignTokenStylesheet()).toBe(ekklesiaDesignTokenStylesheet());
|
|
});
|
|
|
|
it("declares a unique name and CSS variable for every token", () => {
|
|
const names = ekklesiaDesignTokens.list().map((token) => token.name);
|
|
const variables = ekklesiaDesignTokens.list().map((token) => token.cssVariable);
|
|
|
|
expect(new Set(names).size).toBe(names.length);
|
|
expect(new Set(variables).size).toBe(variables.length);
|
|
expect(variables.every((variable) => variable.startsWith(DESIGN_TOKEN_VARIABLE_PREFIX))).toBe(
|
|
true,
|
|
);
|
|
});
|
|
|
|
it("gives every token a human-readable label, description, and derived category", () => {
|
|
for (const token of ekklesiaDesignTokens.list()) {
|
|
expect(token.label.trim().length).toBeGreaterThan(0);
|
|
expect(token.description.trim().length).toBeGreaterThan(0);
|
|
expect(DESIGN_TOKEN_CATEGORIES).toContain(token.category);
|
|
expect(token.name.startsWith(`${token.category}.`)).toBe(true);
|
|
}
|
|
});
|
|
|
|
it("covers the semantic families the platform promises", () => {
|
|
const names = new Set(ekklesiaDesignTokens.list().map((token) => token.name));
|
|
|
|
for (const required of [
|
|
"background.page",
|
|
"background.canvas",
|
|
"background.surface",
|
|
"background.raised",
|
|
"background.overlay",
|
|
"background.inset",
|
|
"text.primary",
|
|
"text.secondary",
|
|
"text.muted",
|
|
"text.inverse",
|
|
"text.success",
|
|
"text.warning",
|
|
"text.danger",
|
|
"accent.base",
|
|
"accent.hover",
|
|
"accent.active",
|
|
"accent.focus",
|
|
"border.base",
|
|
"border.divider",
|
|
"state.hover-background",
|
|
"state.pressed-background",
|
|
"state.selected-background",
|
|
"state.disabled-opacity",
|
|
"state.focus-visible-width",
|
|
"typography.family-sans",
|
|
"typography.size-md",
|
|
"typography.weight-bold",
|
|
"typography.line-height-normal",
|
|
"typography.size-heading-1",
|
|
"spacing.md",
|
|
"radius.md",
|
|
"shadow.md",
|
|
"control.height-md",
|
|
]) {
|
|
expect(names).toContain(required);
|
|
}
|
|
});
|
|
|
|
it("pairs every status colour with a non-colour symbol", () => {
|
|
for (const status of ["success", "warning", "danger", "info"]) {
|
|
expect(ekklesiaDesignTokens.has(`status.${status}-background`)).toBe(true);
|
|
expect(ekklesiaDesignTokens.has(`status.${status}-border`)).toBe(true);
|
|
const symbol = ekklesiaDesignTokens.get(`status.${status}-symbol`);
|
|
expect(symbol?.value.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
it("hands component code a var() reference rather than a raw colour", () => {
|
|
expect(designToken("text.primary")).toBe("var(--ekklesia-text-primary)");
|
|
expect(ekklesiaDesignTokens.variable("text.primary")).toBe("--ekklesia-text-primary");
|
|
});
|
|
|
|
it("emits a stylesheet declaring every token once in its base rule, and again only where it varies", () => {
|
|
const stylesheet = ekklesiaDesignTokenStylesheet();
|
|
const base = stylesheet.slice(0, stylesheet.indexOf("}"));
|
|
|
|
for (const token of ekklesiaDesignTokens.list()) {
|
|
expect(base.split(`${token.cssVariable}:`).length, token.name).toBe(2);
|
|
// Once more in each of the two dark rules (system and explicit), and in each of the two
|
|
// reduced-motion rules, and nowhere else (ADR 0060).
|
|
const expected =
|
|
1 + (token.dark === undefined ? 0 : 2) + (token.reduced === undefined ? 0 : 2);
|
|
expect(stylesheet.split(`${token.cssVariable}:`).length - 1, token.name).toBe(expected);
|
|
}
|
|
});
|
|
|
|
it("installs the default theme at a document root exactly once and removes what it added", () => {
|
|
const remove = installEkklesiaDesignTokens(document);
|
|
const installedAgain = installEkklesiaDesignTokens(document);
|
|
|
|
expect(document.querySelectorAll(`style[${DESIGN_TOKEN_STYLE_ATTRIBUTE}]`).length).toBe(1);
|
|
expect(
|
|
document
|
|
.querySelector(`style[${DESIGN_TOKEN_STYLE_ATTRIBUTE}]`)
|
|
?.textContent?.includes("--ekklesia-background-page"),
|
|
).toBe(true);
|
|
|
|
installedAgain();
|
|
expect(document.querySelectorAll(`style[${DESIGN_TOKEN_STYLE_ATTRIBUTE}]`).length).toBe(1);
|
|
|
|
remove();
|
|
remove();
|
|
expect(document.querySelectorAll(`style[${DESIGN_TOKEN_STYLE_ATTRIBUTE}]`).length).toBe(0);
|
|
});
|
|
|
|
it("installs host-scoped values into an isolated shadow root", () => {
|
|
const host = document.createElement("div");
|
|
document.body.appendChild(host);
|
|
const shadow = host.attachShadow({ mode: "open" });
|
|
|
|
installEkklesiaDesignTokens(shadow, { scope: "host" });
|
|
|
|
const style = shadow.querySelector(`style[${DESIGN_TOKEN_STYLE_ATTRIBUTE}]`);
|
|
expect(style?.textContent?.startsWith(":host {")).toBe(true);
|
|
host.remove();
|
|
});
|
|
});
|