Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/tone.test.mjs
iris 25965341e0 frontend: one tone vocabulary for badges, hints, banners and toasts
Part of the unification order in the UI sweep issue (step b).

A badge named its tones positive/warning/negative, a hint muted/warn/error/ok,
a banner info/warning/error and a toast info/ok/error. They now all take the
shared Tone: neutral, info, ok, warn, error (a badge adds accent for a selected
choice). Warn is amber everywhere (a hint used yellow), info is cyan everywhere
(a toast used purple). A test pins the list against each component's CSS.
2026-11-25 21:47:01 +01:00

50 lines
1.8 KiB
JavaScript

// The shared tone list. Run by `npm test`. Each component that takes a `Tone`
// must style every value it accepts, so a tone added to the list without a
// matching CSS rule (or an old spelling left in a stylesheet) fails here.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { test } from "node:test";
import { TONES } from "../../shared/src/tone.ts";
const css = (rel) => readFileSync(new URL(rel, import.meta.url), "utf8");
test("the list is the five agreed spellings", () => {
assert.deepEqual([...TONES], ["neutral", "info", "ok", "warn", "error"]);
});
// `neutral` is the default look, so a component may leave it unstyled.
const COMPONENTS = [
["badge", "../../shared/src/badge/Badge.css", "ui-badge-", ["neutral"]],
["hint", "../src/ui/hint/Hint.css", "ui-hint-", []],
["toast", "../src/ui/toast/Toast.css", "ui-toast-", ["neutral"]],
];
for (const [name, file, prefix, unstyled] of COMPONENTS) {
test(`${name} styles every tone it takes`, () => {
const text = css(file);
for (const tone of TONES) {
if (unstyled.includes(tone)) continue;
assert.ok(
text.includes(`.${prefix}${tone}`),
`${name}: no .${prefix}${tone}`,
);
}
});
test(`${name} keeps no old tone spelling`, () => {
const text = css(file);
for (const old of ["positive", "negative", "warning", "muted"]) {
assert.ok(
!text.includes(`.${prefix}${old}`),
`${name}: .${prefix}${old}`,
);
}
});
}
test("the banner styles info and error, and warn is its base look", () => {
const text = css("../../shared/src/warn-banner/WarnBanner.css");
assert.ok(text.includes(".warn-banner-info"));
assert.ok(text.includes(".warn-banner-error"));
assert.ok(!text.includes(".warn-banner-warning"));
});