Files
RuneStone/tests/smoke/appearance/themeImport.smoke.mjs
T
Knotty Wyvern 5483881bc2 Add the theme editor tab and theme preview cards
Phase 5a-5.

- Settings → Appearance shows a preview card for each theme. The cards
  are one radio group. The arrow keys move and select, and the current
  card has the selection outline and a check mark (UI-047).
- Edit theme opens the theme editor as a workbench tab in the window
  that opened Settings. The window shows each change at once.
- The editor shows all 51 color roles in seven groups. Each role has a
  color picker, a hex field, its lowest readability result, and a reset
  button. A failure shows a warning icon and its ratio, or "Too close".
- Save writes a short schema 3 theme with the built-in theme as its
  base. A built-in theme does not change. Discard returns to the saved
  colors, and Duplicate saves a copy.
- The editor is a built-in package, like the browser, so it uses the
  editor tab code of plugins.
- 23 new catalog rows with French, Japanese, and Simplified Chinese.
- The smoke harness sends emit to every page and emit_to to the pages
  with the target window label.
- Docs: UI-047, ui-design.md, and "Edit a theme" in guides/themes.md.

New tests: appearance/themeEditor and tests/unit/theme/themeEditor.spec.ts.
Six smoke tests use the cards instead of the theme menu.
2026-10-28 18:13:57 -07:00

47 lines
3.4 KiB
JavaScript

// Import custom theme files in Settings > Appearance: schema 1 palettes for each mode, and a short schema 3 file with a base theme.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
const name = "appearance/themeImport";
await runSmoke(name, async ({ page }) => {
const output = await outputDir(name);
await mockTauri(page, {
commands: test => ({
...test.workspace({ root: "C:\\theme-import", files: { "a.md": "# Alpha\n" } }),
plugins_snapshot: () => ({ plugins: [], issues: [] }),
}),
});
await page.goto(smokeUrl + "/?settingsWindow=true");
await page.getByRole("button", { name: "Appearance", exact: true }).click();
const theme = { schema: 1, id: "smoke", name: "Smoke theme", light: { bg: "#fefefe", text: "#222222", accent: "#334499" }, dark: { bg: "#181820", text: "#eeeeee", accent: "#aabbff" } };
const importTheme = (file = theme) => page.locator('input[type=file][aria-label="Theme JSON file"]').setInputFiles({ name: "smoke.json", mimeType: "application/json", buffer: Buffer.from(JSON.stringify(file)) });
const token = name => page.evaluate(name => getComputedStyle(document.documentElement).getPropertyValue(`--rs-${name}`).trim(), name);
const background = () => token("bg");
await importTheme();
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:smoke");
assert.equal(await background(), "#181820");
// A custom theme now keeps one palette. A schema 1 file converts with the current mode (src/lib/theme/customThemes.ts:38,
// src/lib/theme/AppearanceSettings.svelte), and the light/dark select became the Color theme cards (src/lib/theme/ThemePicker.svelte).
await page.getByRole("radio", { name: "RuneStone Light", exact: true }).click();
await page.waitForFunction(() => document.documentElement.dataset.palette !== "custom:smoke");
await importTheme();
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:smoke");
assert.equal(await background(), "#fefefe");
await page.screenshot({ path: path.join(output, "custom-theme-light.png") });
// A short schema 3 file takes the missing colors and fonts from its base theme. An earlier theme ID names the base.
await importTheme({ schema: 3, id: "short", name: "Short theme", mode: "dark", base: "holo", colors: { accent: "#00c8ff" } });
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:short");
assert.deepEqual([await background(), await token("accent"), await token("link"), await token("syntax-keyword")], ["#1c0f0a", "#00c8ff", "#00c8ff", "#f38c48"]);
assert.match(await token("font-ui"), /Candara/);
assert.equal(await page.evaluate(() => document.documentElement.dataset.theme), "dark");
await page.screenshot({ path: path.join(output, "custom-theme-short.png") });
// A base without a palette in the file's mode stops the installation with an error.
await importTheme({ schema: 3, id: "wrong", name: "Wrong base", mode: "dark", base: "sakura", colors: {} });
await page.getByRole("alert").filter({ hasText: "Use a built-in theme with a dark palette as the base." }).waitFor();
assert.equal(await page.evaluate(() => document.documentElement.dataset.palette), "custom:short");
console.log("PASS: custom theme import applies schema 1 palettes, a short schema 3 file with a base, and rejects a wrong base");
}, { timeout: 15000 });