Files
gerbeur/api/test/mail/theme-tokens.test.ts
khannurien 62e51f1622
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 55s
Build and Deploy Static Documentation Site / build-and-push (push) Successful in 26s
v4: the six styles are reworked, each around one idea of its own, and the tab row stops painting the page — a pass over every theme, then the faults it showed in what they share. Brutalist draws every box in ink with a solid offset shadow and sets the palette's colors as flat blocks (a teal tag, an apricot quote, an inked label); its dark scheme keeps that ink darker than the page, on Twilight Indigo, where eggshell lines glared across every frame. GeoCities goes to the desktop of its day: the header is the taskbar, the site's name its Start button, the controls grey bevels, and a marquee crawls under the header (Marquee.tsx, drawn in that style alone), with Comic Neue where the system has no Comic Sans. Melange leaves its browns and Fraunces for a sorbet blend in Bricolage Grotesque, run along the header, through the site's name, where it drifts, and between a journal's blocks; its two schemes are one print and its negative, trading ink and paper while the pink and the plum written on it stay, and they share one fine grain where the light one had a coarse tile that greyed the page. Kanagawa opens the comments and the related dumps on a status line and reads on Lotus's brightest paper; its page is flat. Times draws its heavy rules in a mid grey at night, where ink is near white, and sets a journal cell with no picture as text. In what the styles share: a row of tabs (TabBar) hid the tabs scrolled under its scope switcher, and faded its ends, by painting the page's color over them, which showed as a patch on any page that is a gradient or a picture. The switcher now sits before the row that scrolls, which clips the tabs at its edge, and the fades are a mask (--tab-fade-start and --tab-fade-end); useRoomBeside measures the row through that one more level. A page's title keeps a word whole unless it alone is wider than the line: Firefox sizes a title set with negative letter-spacing a hair narrower than it lays it out, which dropped its last letter to a second line in any style that tightened it, so the rule is the base's and the two styles' copies go. A card holding one paragraph, such as the instances a new account hasn't signed in to on /settings, is spaced by its padding and not by the paragraph's margins as well. The site's name answers the pointer as a card's title does in each style, where two of them left it still. The emails follow the styles' tokens, Melange's blend among them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 19:30:57 +00:00

83 lines
2.7 KiB
TypeScript

import "../setup.ts";
import {
assert,
assertEquals,
assertMatch,
assertNotEquals,
} from "@std/assert";
import { readTokens } from "../../mail/theme-tokens.ts";
import { EMAIL_STYLES } from "../../mail/styles.ts";
import { STYLE_NAMES } from "../../../shared/theme.ts";
Deno.test("readTokens: light-dark() picks the scheme's value", () => {
assertEquals(readTokens("smooth", "light").color("--color-bg"), "#faf5e9");
assertEquals(readTokens("smooth", "dark").color("--color-bg"), "#01152a");
});
Deno.test("readTokens: a forced scheme's block overrides the theme's", () => {
// GeoCities draws a darker rainbow on its light pages.
assertEquals(readTokens("geocities", "light").stops("--geo-rainbow"), [
"#ff004d",
"#ff8a00",
"#ffcc00",
"#00aa1a",
"#0077dd",
"#8800cc",
]);
assertEquals(
readTokens("geocities", "dark").stops("--geo-rainbow")[2],
"#ffee00",
);
});
Deno.test("readTokens: var() follows tokens, color-mix() is computed", () => {
const melange = readTokens("melange", "light");
// The spice holds var()s, the accent among them, and drops its stops'
// positions.
assertEquals(melange.stops("--mel-spice"), [
"#ea6a45",
"#e2568f",
"#8262d8",
"#3a8fd4",
"#27a583",
]);
// 18% of the muted text over the card, as a badge shows on the site.
const smooth = readTokens("smooth", "light");
assertEquals(smooth.color("--color-badge-bg", "--color-surface"), "#dfe4e1");
assertEquals(smooth.color("--color-badge-bg"), "rgba(77,113,120,0.18)");
});
Deno.test("readTokens: fonts, lengths and the base tokens", () => {
assertEquals(
readTokens("smooth", "light").font("--font-body"),
"Saira, sans-serif",
);
assertEquals(
readTokens("kanagawa", "dark").font("--font-body"),
"'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace",
);
// Smooth keeps tokens.css's radii; Brutalist squares them.
assertEquals(readTokens("smooth", "light").px("--radius-xl"), 12);
assertEquals(readTokens("brutalist", "light").px("--radius-xl"), 0);
});
Deno.test("EMAIL_STYLES: every style reads plain colors from its theme", () => {
for (const name of STYLE_NAMES) {
const style = EMAIL_STYLES[name];
for (const palette of [style.light, style.dark]) {
for (const [role, color] of Object.entries(palette)) {
if (role === "gradient") continue;
assertMatch(
color,
role === "shadow" ? /^rgba\(/ : /^#[0-9a-f]{6}$/,
`${name} ${role}`,
);
}
}
assertNotEquals(style.light.card, style.dark.card, name);
if (style.rule === "gradient" || style.bar) {
assert((style.light.gradient?.length ?? 0) > 1, name);
}
}
});