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.
113 lines
7.8 KiB
JavaScript
113 lines
7.8 KiB
JavaScript
// Theme picker cards and the theme editor tab: keyboard selection, the check mark, a live preview, contrast badges, Save, Discard, Duplicate, and narrow windows.
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("appearance/themeEditor", async ({ browser }) => {
|
|
const output = await outputDir("appearance/themeEditor");
|
|
const context = await browser.newContext({ viewport: { width: 1200, height: 820 } });
|
|
const commands = test => ({
|
|
...test.workspace({ root: "C:\\theme-editor", files: { "a.md": "# Note\n\nSome text with a [link](https://example.com).\n" } }),
|
|
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
|
spelling_menu_install: () => null,
|
|
"plugin:window|is_maximized": () => false,
|
|
});
|
|
// The Settings window label names the window that opened it (src-tauri/src/settings.rs).
|
|
const main = await openPage(context);
|
|
await mockTauri(main, { label: "main", commands });
|
|
const settings = await openPage(context);
|
|
await mockTauri(settings, { label: "settings-main", commands });
|
|
await main.goto(smokeUrl);
|
|
await main.locator('[data-tree-rel="a.md"]').waitFor();
|
|
await settings.goto(smokeUrl + "/?settingsWindow=true");
|
|
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
|
|
const token = (page, role) => page.evaluate(role => getComputedStyle(document.documentElement).getPropertyValue(`--rs-${role}`).trim(), role);
|
|
|
|
// Picker cards: one radio group with a check mark on the current theme.
|
|
const cards = settings.getByRole("radiogroup", { name: "Color theme", exact: true });
|
|
const card = name => cards.getByRole("radio", { name, exact: true });
|
|
assert.equal(await card("RuneStone Dark").getAttribute("aria-checked"), "true");
|
|
assert.equal(await card("RuneStone Dark").locator(".card-name svg").count(), 1, "The current card shows a check mark");
|
|
assert.equal(await card("Claude Light").locator(".card-name svg").count(), 0);
|
|
await card("RuneStone Dark").focus();
|
|
await settings.keyboard.press("ArrowRight");
|
|
await settings.waitForFunction(() => document.documentElement.dataset.palette === "claude" && document.documentElement.dataset.theme === "light");
|
|
assert.equal(await card("Claude Light").evaluate(node => node === document.activeElement && node.getAttribute("aria-checked") === "true"), true);
|
|
await settings.keyboard.press("ArrowLeft");
|
|
await settings.waitForFunction(() => document.documentElement.dataset.palette === "default" && document.documentElement.dataset.theme === "dark");
|
|
await main.waitForFunction(() => document.documentElement.dataset.palette === "default");
|
|
await settings.screenshot({ path: path.join(output, "picker-cards.png") });
|
|
|
|
// Edit theme opens the editor tab in the window that opened Settings.
|
|
await settings.getByRole("button", { name: "Edit theme", exact: true }).click();
|
|
const editor = main.getByRole("region", { name: "Theme editor", exact: true });
|
|
await editor.waitFor();
|
|
await main.getByRole("tab", { name: /Theme editor/ }).waitFor();
|
|
assert.equal(await editor.getByRole("textbox", { name: "Theme name", exact: true }).inputValue(), "RuneStone Dark copy");
|
|
assert.match(await editor.getByRole("status").textContent(), /All readability checks pass/);
|
|
|
|
// A change shows at once in this window, and not in Settings before a save.
|
|
const hex = role => editor.getByRole("textbox", { name: `Hex value of ${role}`, exact: true });
|
|
await hex("accent").fill("#ff7a1a");
|
|
await hex("accent").press("Tab");
|
|
await main.waitForFunction(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-accent").trim() === "#ff7a1a");
|
|
assert.equal(await token(settings, "accent"), "#55dcf5");
|
|
await main.getByRole("tab", { name: "• Theme editor", exact: true }).waitFor();
|
|
|
|
// A color that fails a rule shows the failure on its row and in the summary. Reset takes the base color again.
|
|
await hex("text-dim").fill("#3a3a3a");
|
|
await hex("text-dim").press("Tab");
|
|
await editor.getByRole("status").filter({ hasText: /readability checks fail/ }).waitFor();
|
|
const dimRow = hex("text-dim").locator("xpath=..");
|
|
assert.equal(await dimRow.locator(".badge.fail").count(), 1);
|
|
await main.screenshot({ path: path.join(output, "editor-failing-role.png") });
|
|
await editor.getByRole("button", { name: "Reset text-dim", exact: true }).click();
|
|
assert.equal(await dimRow.locator(".badge.fail").count(), 0);
|
|
assert.equal(await token(main, "text-dim"), "#ababab");
|
|
|
|
// Save copies the built-in theme to a custom theme with a base, and every window selects it.
|
|
await editor.getByRole("button", { name: "Save", exact: true }).click();
|
|
await editor.getByRole("status").filter({ hasText: "Saved RuneStone Dark copy." }).waitFor();
|
|
await settings.waitForFunction(() => document.documentElement.dataset.palette === "custom:runestone-dark-copy");
|
|
assert.equal(await token(settings, "accent"), "#ff7a1a");
|
|
const saved = await main.evaluate(() => window.__TEST__.settings("customThemes"));
|
|
assert.deepEqual(saved.map(theme => [theme.id, theme.base, theme.mode, theme.colors]), [["runestone-dark-copy", "default", "dark", { accent: "#ff7a1a" }]]);
|
|
assert.equal(await card("RuneStone Dark copy").getAttribute("aria-checked"), "true");
|
|
await main.getByRole("tab", { name: "Theme editor", exact: true }).waitFor();
|
|
|
|
// Discard returns to the saved colors.
|
|
await hex("bg").fill("#202040");
|
|
await hex("bg").press("Tab");
|
|
await main.waitForFunction(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-bg").trim() === "#202040");
|
|
await editor.getByRole("button", { name: "Discard", exact: true }).click();
|
|
await main.waitForFunction(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-bg").trim() === "#151617");
|
|
|
|
// Duplicate saves a copy and selects it.
|
|
await editor.getByRole("button", { name: "Duplicate", exact: true }).click();
|
|
await editor.getByRole("status").filter({ hasText: "Saved RuneStone Dark copy copy." }).waitFor();
|
|
await settings.waitForFunction(() => document.documentElement.dataset.palette === "custom:runestone-dark-copy-copy");
|
|
assert.equal((await main.evaluate(() => window.__TEST__.settings("customThemes"))).length, 2);
|
|
|
|
// Narrow windows keep the editor inside the window, and keyboard focus is visible.
|
|
await main.setViewportSize({ width: 600, height: 760 });
|
|
await hex("accent").focus();
|
|
assert.equal(await editor.evaluate(node => node.scrollWidth <= node.clientWidth + 1), true, "The editor does not scroll sideways at 600 pixels");
|
|
assert.notEqual(await hex("accent").evaluate(node => getComputedStyle(node).outlineStyle), "none");
|
|
await main.screenshot({ path: path.join(output, "editor-600.png") });
|
|
await settings.setViewportSize({ width: 360, height: 640 });
|
|
assert.equal(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "Narrow settings do not overflow");
|
|
const box = await cards.boundingBox();
|
|
assert(box.x >= 0 && box.x + box.width <= 360, "The cards fit at 360 pixels");
|
|
await settings.screenshot({ path: path.join(output, "picker-cards-360.png") });
|
|
|
|
// Closing the editor with a change keeps the saved theme in the window.
|
|
await hex("accent").fill("#00ff00");
|
|
await hex("accent").press("Tab");
|
|
await main.waitForFunction(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-accent").trim() === "#00ff00");
|
|
await main.getByRole("button", { name: /^Close .*Theme editor$/ }).click();
|
|
await editor.waitFor({ state: "detached" });
|
|
await main.waitForFunction(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-accent").trim() === "#ff7a1a");
|
|
assert.deepEqual([...main.errors, ...settings.errors], []);
|
|
console.log("PASS: picker cards, the editor tab, live preview, contrast badges, Save, Discard, Duplicate, and narrow windows");
|
|
});
|