frontend: remove the stylix overlay and add hyperhive and Catppuccin light and dark themes
This commit is contained in:
parent
989d1d578c
commit
91e2d26133
2 changed files with 486 additions and 413 deletions
|
|
@ -27,25 +27,36 @@ function boot(stored) {
|
|||
return dataset;
|
||||
}
|
||||
|
||||
test("nothing stored sets the dark default and leaves motion to the system", () => {
|
||||
assert.deepEqual(boot({}), { theme: "dark" });
|
||||
test("nothing stored sets the hyperhive dark default and leaves motion to the system", () => {
|
||||
assert.deepEqual(boot({}), { theme: "hyperhive-dark" });
|
||||
});
|
||||
|
||||
test("a stored light theme and a motion override are set", () => {
|
||||
test("a stored theme and a motion override are set", () => {
|
||||
const set = boot({
|
||||
"swarm-ui:theme-override": '"light"',
|
||||
"swarm-ui:motion-override": '"reduce"',
|
||||
});
|
||||
assert.deepEqual(set, { theme: "light", motion: "reduce" });
|
||||
assert.deepEqual(set, { theme: "hyperhive-light", motion: "reduce" });
|
||||
assert.deepEqual(
|
||||
boot({ "swarm-ui:theme-override": '"catppuccin-mocha-mauve"' }),
|
||||
{ theme: "catppuccin-mocha-mauve" },
|
||||
);
|
||||
});
|
||||
|
||||
test("system leaves the attribute off, so the media query decides", () => {
|
||||
test("a stored dark, from before themes existed, is hyperhive dark", () => {
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"dark"' }), {
|
||||
theme: "hyperhive-dark",
|
||||
});
|
||||
});
|
||||
|
||||
test("auto, and system from before themes existed, leave the attribute off, so the media query decides", () => {
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"auto"' }), {});
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"system"' }), {});
|
||||
});
|
||||
|
||||
test("a value that is not JSON, or not one of the choices, is ignored", () => {
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": "light" }), {
|
||||
theme: "dark",
|
||||
theme: "hyperhive-dark",
|
||||
});
|
||||
assert.deepEqual(boot({ "swarm-ui:theme-override": '"blue"' }), {});
|
||||
});
|
||||
|
|
@ -60,7 +71,31 @@ test("storage that throws behaves as if nothing were stored", () => {
|
|||
},
|
||||
document: { documentElement: { dataset } },
|
||||
});
|
||||
assert.deepEqual(dataset, { theme: "dark" });
|
||||
assert.deepEqual(dataset, { theme: "hyperhive-dark" });
|
||||
});
|
||||
|
||||
test("the theme ids are the registry's", () => {
|
||||
const registry = readFileSync(
|
||||
new URL("../../shared/src/settings/themes.ts", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
const ids = (text) =>
|
||||
[...text.matchAll(/"((?:hyperhive|catppuccin)-[a-z-]+)"/g)].map(
|
||||
(m) => m[1],
|
||||
);
|
||||
const listed = script.slice(
|
||||
script.indexOf("var themes"),
|
||||
script.indexOf("];"),
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(listed),
|
||||
ids(
|
||||
registry.slice(
|
||||
registry.indexOf("THEMES"),
|
||||
registry.indexOf("AUTO_THEME"),
|
||||
),
|
||||
).filter((id, i, all) => all.indexOf(id) === i),
|
||||
);
|
||||
});
|
||||
|
||||
test("the keys are the shell's", () => {
|
||||
|
|
|
|||
36
frontend/packages/swarm-ui/test/themes.test.mjs
Normal file
36
frontend/packages/swarm-ui/test/themes.test.mjs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// The theme registry and how a stored choice reads. Run by `npm test`, which
|
||||
// imports the `.ts` module as it is.
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import {
|
||||
AUTO_THEME,
|
||||
DEFAULT_THEME,
|
||||
THEMES,
|
||||
themeChoice,
|
||||
} from "../../shared/src/settings/themes.ts";
|
||||
|
||||
test("the default is one of the themes", () => {
|
||||
assert.ok(THEMES.some((t) => t.id === DEFAULT_THEME));
|
||||
});
|
||||
|
||||
test("every theme is light or dark, and the ids and labels are distinct", () => {
|
||||
for (const t of THEMES) assert.ok(["light", "dark"].includes(t.scheme));
|
||||
assert.equal(new Set(THEMES.map((t) => t.id)).size, THEMES.length);
|
||||
assert.equal(new Set(THEMES.map((t) => t.label)).size, THEMES.length);
|
||||
});
|
||||
|
||||
test("a theme id and auto read as themselves", () => {
|
||||
assert.equal(themeChoice("catppuccin-mocha-mauve"), "catppuccin-mocha-mauve");
|
||||
assert.equal(themeChoice(AUTO_THEME), AUTO_THEME);
|
||||
});
|
||||
|
||||
test("the values from before themes existed read as their successors", () => {
|
||||
assert.equal(themeChoice("system"), AUTO_THEME);
|
||||
assert.equal(themeChoice("light"), "hyperhive-light");
|
||||
assert.equal(themeChoice("dark"), "hyperhive-dark");
|
||||
});
|
||||
|
||||
test("an unknown value reads as the fallback", () => {
|
||||
assert.equal(themeChoice("blue"), DEFAULT_THEME);
|
||||
assert.equal(themeChoice(undefined, "hyperhive-light"), "hyperhive-light");
|
||||
});
|
||||
Loading…
Reference in a new issue