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.
This commit is contained in:
parent
c205c6115b
commit
25965341e0
2 changed files with 164 additions and 86 deletions
|
|
@ -27,10 +27,10 @@ test("every outcome has a label and a tone", () => {
|
|||
assert.deepEqual(Object.keys(OUTCOME_LABEL).sort(), [...OUTCOMES].sort());
|
||||
});
|
||||
|
||||
test("a run that failed or could not post reads as negative", () => {
|
||||
assert.equal(OUTCOME_TONE.failed, "negative");
|
||||
assert.equal(OUTCOME_TONE["post-failed"], "negative");
|
||||
assert.equal(OUTCOME_TONE.approved, "positive");
|
||||
test("a run that failed or could not post reads as an error", () => {
|
||||
assert.equal(OUTCOME_TONE.failed, "error");
|
||||
assert.equal(OUTCOME_TONE["post-failed"], "error");
|
||||
assert.equal(OUTCOME_TONE.approved, "ok");
|
||||
});
|
||||
|
||||
test("the triggers are named for the operator", () => {
|
||||
|
|
|
|||
50
frontend/packages/swarm-ui/test/tone.test.mjs
Normal file
50
frontend/packages/swarm-ui/test/tone.test.mjs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// 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"));
|
||||
});
|
||||
Loading…
Reference in a new issue