// 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")); });