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.
This commit is contained in:
@@ -177,8 +177,8 @@ function installMock(options, commands) {
|
||||
// `crypto.randomUUID` needs a secure context, which `about:blank` is not.
|
||||
const pageId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
||||
const channel = typeof BroadcastChannel === "function" ? new BroadcastChannel("runestone-smoke-host") : { postMessage() {} };
|
||||
channel.addEventListener?.("message", ({ data }) => { if (!data.target || data.target === pageId) emit(data.event, data.payload); });
|
||||
// `target` is a page ID. Without it, every page of the context receives the event, this page too.
|
||||
channel.addEventListener?.("message", ({ data }) => { if ((!data.target || data.target === pageId) && (!data.label || data.label === options.label)) emit(data.event, data.payload); });
|
||||
// `target` is a page ID. Without it, every page of the context receives the event, this page too. `label` limits the event to pages with that window label.
|
||||
const broadcast = (event, payload, target) => {
|
||||
if (!target || target === pageId) emit(event, payload);
|
||||
if (target !== pageId) channel.postMessage({ event, payload, target });
|
||||
@@ -267,7 +267,14 @@ function installMock(options, commands) {
|
||||
return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return null; }
|
||||
if (command === "plugin:event|emit" || command === "plugin:event|emit_to") { emit(args.event, args.payload); return null; }
|
||||
// An app event reaches every window. A targeted event reaches the windows with the target label (Tauri emit and emitTo).
|
||||
if (command === "plugin:event|emit") { broadcast(args.event, args.payload); return null; }
|
||||
if (command === "plugin:event|emit_to") {
|
||||
const label = typeof args.target === "string" ? args.target : args.target?.label;
|
||||
if (!label || label === options.label) emit(args.event, args.payload);
|
||||
channel.postMessage({ event: args.event, payload: args.payload, label });
|
||||
return null;
|
||||
}
|
||||
const handler = typeof table[command] === "function" ? table[command] : defaults[command];
|
||||
if (typeof handler === "function") {
|
||||
const result = await handler(args, test);
|
||||
|
||||
@@ -76,14 +76,14 @@ await runSmoke('appearance/backgroundImages', async ({ browser }) => {
|
||||
await settings.getByLabel('Image overlay', { exact: true }).fill('-40');
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('255, 255, 255, 0.4'));
|
||||
|
||||
// The Color theme picker now chooses the theme and its light or dark mode together (src/lib/theme/AppearanceSettings.svelte:20, 113).
|
||||
// A theme card chooses the theme and its light or dark mode together (src/lib/theme/ThemePicker.svelte).
|
||||
for (const mode of ['dark', 'light']) {
|
||||
await picker('Color theme').click();
|
||||
await settings.getByRole('menuitemradio', { name: mode === 'dark' ? 'RuneStone Dark' : 'RuneStone Light', exact: true }).click();
|
||||
await settings.getByRole('radio', { name: mode === 'dark' ? 'RuneStone Dark' : 'RuneStone Light', exact: true }).click();
|
||||
await main.waitForFunction(mode => document.documentElement.dataset.theme === mode, mode);
|
||||
assert.equal(await background(), url, 'Theme changes reuse the current image URL');
|
||||
await main.screenshot({ path: `${output}/background-${mode}.png` });
|
||||
for (const name of ['Color theme']) {
|
||||
// The image position menu is a shared menu of Appearance settings.
|
||||
for (const name of ['Image position']) {
|
||||
await picker(name).click();
|
||||
const menu = settings.getByRole('menu', { name, exact: true });
|
||||
assert.equal(await menu.evaluate(node => getComputedStyle(node).fontSize), '13px');
|
||||
@@ -99,8 +99,9 @@ await runSmoke('appearance/backgroundImages', async ({ browser }) => {
|
||||
}
|
||||
|
||||
await settings.setViewportSize({ width: 360, height: 480 });
|
||||
await settings.getByRole('button', { name: 'Color theme', exact: true }).click();
|
||||
const box = await settings.getByRole('menu', { name: 'Color theme', exact: true }).boundingBox();
|
||||
await picker('Image position').scrollIntoViewIfNeeded();
|
||||
await picker('Image position').click();
|
||||
const box = await settings.getByRole('menu', { name: 'Image position', exact: true }).boundingBox();
|
||||
assert.ok(box.x >= 0 && box.x + box.width <= 360 && box.y + box.height <= 480);
|
||||
await settings.screenshot({ path: `${output}/menu-narrow.png` });
|
||||
await settings.keyboard.press('Escape');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Character themes: colors, fonts, IDE syntax, export, window sync, narrow menus, selection fills, and legacy or removed theme IDs.
|
||||
// Character themes: colors, fonts, IDE syntax, export, window sync, narrow theme cards, selection fills, and legacy or removed theme IDs.
|
||||
import assert from 'node:assert/strict';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
@@ -47,11 +47,9 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
|
||||
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
|
||||
await settings.getByRole('img', { name: 'Color theme preview' }).waitFor();
|
||||
};
|
||||
const picker = name => settings.locator('.picker').and(settings.getByRole('button', { name, exact: true }));
|
||||
const choose = async (name, value) => {
|
||||
await picker(name).click();
|
||||
await settings.getByRole('menuitemradio', { name: value, exact: true }).click();
|
||||
};
|
||||
// The Color theme cards are one radio group (src/lib/theme/ThemePicker.svelte).
|
||||
const card = name => settings.getByRole('radiogroup', { name: 'Color theme', exact: true }).getByRole('radio', { name, exact: true });
|
||||
const choose = async (_, value) => { await card(value).click(); };
|
||||
const waitForAppearance = (theme, mode) => Promise.all(pages.map(page => page.waitForFunction(({ theme, mode }) => document.documentElement.dataset.palette === theme && document.documentElement.dataset.theme === mode, { theme, mode })));
|
||||
// Settings and the app import external.ts with a version query, so reuse the loaded module URL.
|
||||
const setPluginTools = count => settings.evaluate(async count => {
|
||||
@@ -60,13 +58,11 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
|
||||
}, count);
|
||||
|
||||
await openSettings();
|
||||
await picker('Color theme').click();
|
||||
assert.equal(await settings.getByRole('menuitemradio', { name: 'Renamon', exact: true }).count(), 0);
|
||||
assert.equal(await settings.getByRole('menuitemradio', { name: 'Asuka School Uniform', exact: true }).count(), 0);
|
||||
assert.equal(await card('Renamon').count(), 0);
|
||||
assert.equal(await card('Asuka School Uniform').count(), 0);
|
||||
for (const label of ['Holo', 'Asuka Langley Soryu', 'Malfoid']) {
|
||||
assert.equal(await settings.getByRole('menuitemradio', { name: label, exact: true }).count(), 0);
|
||||
assert.equal(await card(label).count(), 0);
|
||||
}
|
||||
await settings.keyboard.press('Escape');
|
||||
const cases = [
|
||||
['harvest-moon', 'Harvest Moon', 'dark', { ui: 'Candara', prose: 'Constantia', heading: 'Constantia' }],
|
||||
['crimson-pilot', 'Crimson Pilot', 'dark', { ui: 'Bahnschrift', prose: 'Segoe UI', heading: 'Bahnschrift' }],
|
||||
@@ -164,25 +160,22 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
|
||||
await main.screenshot({ path: path.join(output, `${theme}-${mode}-document.png`) });
|
||||
await settings.reload();
|
||||
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
|
||||
assert.equal((await picker('Color theme').textContent()).trim(), label);
|
||||
assert.equal(await card(label).getAttribute('aria-checked'), 'true');
|
||||
await settings.setViewportSize({ width: 360, height: 480 });
|
||||
const content = settings.locator('dialog .content');
|
||||
assert(await content.evaluate(node => node.scrollWidth <= node.clientWidth), 'Narrow settings fit the content area');
|
||||
await picker('Color theme').scrollIntoViewIfNeeded();
|
||||
await picker('Color theme').focus();
|
||||
await settings.keyboard.press('Enter');
|
||||
const current = settings.getByRole('menuitemradio', { name: label, exact: true });
|
||||
await current.waitFor();
|
||||
assert.equal(await current.getAttribute('aria-checked'), 'true');
|
||||
assert(await current.evaluate(node => document.activeElement === node), 'The menu focuses the current theme');
|
||||
const bounds = await settings.getByRole('menu', { name: 'Color theme', exact: true }).boundingBox();
|
||||
assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.y >= 0 && bounds.y + bounds.height <= 480, 'The menu stays within the viewport');
|
||||
await settings.screenshot({ path: path.join(output, `${theme}-${mode}-360-menu.png`) });
|
||||
await settings.keyboard.press('ArrowDown');
|
||||
await settings.keyboard.press('ArrowUp');
|
||||
assert(await current.evaluate(node => document.activeElement === node));
|
||||
await settings.keyboard.press('Escape');
|
||||
assert(await picker('Color theme').evaluate(node => document.activeElement === node), 'Dismissal returns focus');
|
||||
// The current card is the one Tab stop of the group, and its focus outline shows.
|
||||
const current = card(label);
|
||||
await current.scrollIntoViewIfNeeded();
|
||||
await current.focus();
|
||||
// Reach the card with the keyboard, so :focus-visible applies.
|
||||
await settings.keyboard.press('Shift+Tab');
|
||||
await settings.keyboard.press('Tab');
|
||||
assert(await current.evaluate(node => document.activeElement === node), 'Tab returns to the current card');
|
||||
assert.equal(await current.getAttribute('tabindex'), '0');
|
||||
assert.notEqual(await current.evaluate(node => getComputedStyle(node).outlineStyle), 'none', 'Keyboard focus shows an outline');
|
||||
const bounds = await settings.getByRole('radiogroup', { name: 'Color theme', exact: true }).boundingBox();
|
||||
assert(bounds.x >= 0 && bounds.x + bounds.width <= 360, 'The cards stay within the viewport');
|
||||
await settings.screenshot({ path: path.join(output, `${theme}-${mode}-360-focus.png`) });
|
||||
await setPluginTools(16);
|
||||
const navigation = settings.locator('dialog aside');
|
||||
@@ -192,12 +185,12 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
|
||||
await settings.getByRole('button', { name: 'Plugin settings 16', exact: true }).scrollIntoViewIfNeeded();
|
||||
await settings.screenshot({ path: path.join(output, `${theme}-${mode}-360-long-navigation.png`) });
|
||||
await setPluginTools(0);
|
||||
console.log(`PASS: ${theme} ${mode}, colors, fonts, IDE syntax, export, saved state, window sync, narrow menu, keyboard and focus`);
|
||||
console.log(`PASS: ${theme} ${mode}, colors, fonts, IDE syntax, export, saved state, window sync, narrow theme cards, keyboard and focus`);
|
||||
}
|
||||
for (const [previous, theme, label] of [['holo', 'harvest-moon', 'Harvest Moon'], ['asuka', 'crimson-pilot', 'Crimson Pilot'], ['malfoid', 'silver-serpent', 'Silver Serpent']]) {
|
||||
await settings.evaluate(theme => window.__TEST__.writeSettings('appearance', { theme, mode: 'dark' }), previous);
|
||||
await openSettings();
|
||||
assert.equal((await picker('Color theme').textContent()).trim(), label);
|
||||
assert.equal(await card(label).getAttribute('aria-checked'), 'true');
|
||||
assert.equal(await settings.evaluate(() => document.documentElement.dataset.palette), theme);
|
||||
await choose('Color theme', label);
|
||||
assert.equal(await settings.evaluate(() => window.__TEST__.settings('appearance').theme), theme);
|
||||
@@ -207,7 +200,7 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
|
||||
await settings.setViewportSize({ width: 1100, height: 780 });
|
||||
await openSettings();
|
||||
await waitForAppearance('default', mode);
|
||||
assert.equal((await picker('Color theme').textContent()).trim(), `RuneStone ${mode === 'light' ? 'Light' : 'Dark'}`);
|
||||
assert.equal(await card(`RuneStone ${mode === 'light' ? 'Light' : 'Dark'}`).getAttribute('aria-checked'), 'true');
|
||||
assert((await settings.evaluate(() => getComputedStyle(document.body).fontFamily)).includes('Segoe UI'), 'The default font returns after a palette change');
|
||||
await settings.screenshot({ path: path.join(output, `${removed}-fallback-${mode}-settings.png`) });
|
||||
await settings.setViewportSize({ width: 360, height: 480 });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// The Color theme menu in Settings works from the keyboard, has no color inputs, and the main window's empty tab uses the new theme background.
|
||||
// The Color theme cards in Settings work from the keyboard, Settings has no color inputs, and the main window's empty tab uses the new theme background.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, openPage, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
@@ -18,11 +18,10 @@ await runSmoke("appearance/colorThemeMenu", async ({ browser }) => {
|
||||
const settings = await openPage(context);
|
||||
await settings.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
await settings.getByRole("button", { name: "Color theme", exact: true }).click();
|
||||
// Menu entries now name the mode ("RuneStone Dark" is the default; src/lib/theme/AppearanceSettings.svelte:20-22). The next entry is Claude Light.
|
||||
await settings.getByRole("menuitemradio", { name: "RuneStone Dark", exact: true }).focus();
|
||||
// Cards name the mode ("RuneStone Dark" is the default). The next card is Claude Light, and an arrow key selects it (src/lib/theme/ThemePicker.svelte).
|
||||
await settings.getByRole("radio", { name: "RuneStone Dark", exact: true }).focus();
|
||||
await settings.keyboard.press("ArrowDown");
|
||||
await settings.keyboard.press("Enter");
|
||||
await settings.waitForFunction(() => document.documentElement.dataset.palette === "claude");
|
||||
assert.equal(await settings.evaluate(() => document.documentElement.dataset.palette), "claude");
|
||||
assert.equal(await settings.locator("input[type=color]").count(), 0);
|
||||
await page.getByRole("button", { name: "New tab (Ctrl T)", exact: true }).click();
|
||||
|
||||
@@ -51,14 +51,15 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
|
||||
}
|
||||
const themeName = (theme, mode) => theme === "sakura" ? "Sakura" : `${({ default: "RuneStone", claude: "Claude" })[theme]} ${mode === "light" ? "Light" : "Dark"}`;
|
||||
const picker = (page, name) => page.locator(".picker").filter({ has: page.locator("svg") }).and(page.getByRole("button", { name, exact: true }));
|
||||
// The Color theme cards are one radio group (src/lib/theme/ThemePicker.svelte).
|
||||
const card = (page, name) => page.getByRole("radiogroup", { name: "Color theme", exact: true }).getByRole("radio", { name, exact: true });
|
||||
async function choose(page, theme, mode) {
|
||||
await picker(page, "Color theme").click();
|
||||
await page.getByRole("menuitemradio", { name: themeName(theme, mode), exact: true }).click();
|
||||
await card(page, themeName(theme, mode)).click();
|
||||
}
|
||||
async function openAppearance(page) {
|
||||
await page.goto(`${smokeUrl}/?settingsWindow=true`);
|
||||
await page.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
await picker(page, "Color theme").waitFor();
|
||||
await page.getByRole("radiogroup", { name: "Color theme", exact: true }).waitFor();
|
||||
}
|
||||
await openCode(0);
|
||||
await openAppearance(settings);
|
||||
@@ -68,7 +69,7 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
|
||||
await page.waitForFunction(({ theme, mode }) => document.documentElement.dataset.palette === theme && document.documentElement.dataset.theme === mode, { theme, mode });
|
||||
assert.equal(await page.evaluate(() => getComputedStyle(document.documentElement).colorScheme), mode);
|
||||
}
|
||||
assert.equal((await picker(secondSettings, "Color theme").textContent()).trim(), themeName(theme, mode));
|
||||
assert.equal(await card(secondSettings, themeName(theme, mode)).getAttribute("aria-checked"), "true");
|
||||
await main.waitForFunction(() => {
|
||||
const root = document.documentElement;
|
||||
const probe = document.createElement("i");
|
||||
@@ -121,9 +122,7 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
|
||||
}
|
||||
}
|
||||
assert.equal(backgrounds.size, 5, "All supported combinations have distinct backgrounds");
|
||||
await picker(settings, "Color theme").click();
|
||||
assert.deepEqual(await settings.getByRole("menuitemradio").allTextContents(), ["RuneStone Light", "RuneStone Dark", "Claude Light", "Claude Dark", "Sakura", "Harvest Moon", "Crimson Pilot", "Silver Serpent"]);
|
||||
await settings.keyboard.press("Escape");
|
||||
assert.deepEqual((await settings.getByRole("radiogroup", { name: "Color theme", exact: true }).getByRole("radio").allTextContents()).map(name => name.trim()), ["RuneStone Light", "RuneStone Dark", "Claude Light", "Claude Dark", "Sakura", "Harvest Moon", "Crimson Pilot", "Silver Serpent"]);
|
||||
assert.equal(await picker(settings, "Appearance").count(), 0);
|
||||
assert.equal(await picker(secondSettings, "Appearance").count(), 0);
|
||||
const sakura = await settings.evaluate(() => {
|
||||
@@ -151,10 +150,10 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
|
||||
await settings.setViewportSize({ width: 360, height: 480 });
|
||||
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "Narrow settings do not overflow the viewport");
|
||||
assert(await settings.locator("dialog .content").evaluate(node => node.scrollWidth <= node.clientWidth), "Appearance controls do not overflow the content area");
|
||||
const control = picker(settings, "Color theme");
|
||||
const control = card(settings, themeName(theme, mode));
|
||||
await control.scrollIntoViewIfNeeded();
|
||||
const bounds = await control.boundingBox();
|
||||
assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.height >= 28, "Color theme remains reachable at 360px");
|
||||
assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.height >= 28, "The current theme card remains reachable at 360px");
|
||||
await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}-360.png`) });
|
||||
}
|
||||
assert.deepEqual(pages.flatMap(page => page.errors), []);
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
// 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");
|
||||
});
|
||||
@@ -22,9 +22,8 @@ await runSmoke(name, async ({ page }) => {
|
||||
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:70), and the light/dark select became the Color theme menu (AppearanceSettings.svelte:20-31, :113).
|
||||
await page.getByRole("button", { name: "Color theme", exact: true }).click();
|
||||
await page.getByRole("menuitemradio", { name: "RuneStone Light", exact: true }).click();
|
||||
// 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");
|
||||
|
||||
@@ -51,7 +51,7 @@ await runSmoke('appearance/typography', async ({ browser }) => {
|
||||
const { pluginTools } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
pluginTools.set(Array.from({ length: count }, (_, index) => ({ owner: 'org.example.font-check', id: `settings-${index}`, title: `Plugin settings ${index + 1}`, surface: 'settings' })));
|
||||
}, count);
|
||||
const selectors = { ui: '.picker[aria-label="Color theme"]', prose: '.cm-line:not(.writer-heading):not(.writer-blank)', heading: '.writer-h1' };
|
||||
const selectors = { ui: '.theme-actions button', prose: '.cm-line:not(.writer-heading):not(.writer-blank)', heading: '.writer-h1' };
|
||||
const cases = [
|
||||
['harvest-moon', 'Harvest Moon', 'Constantia', 'Candara', 'Constantia', 'Constantia'],
|
||||
['crimson-pilot', 'Crimson Pilot', 'Bahnschrift', 'Bahnschrift', 'Segoe UI', 'Bahnschrift'],
|
||||
@@ -59,9 +59,7 @@ await runSmoke('appearance/typography', async ({ browser }) => {
|
||||
];
|
||||
for (const [theme, label, oldFont, ui, prose, heading] of cases) {
|
||||
await settings.setViewportSize({ width: 1100, height: 780 });
|
||||
const picker = settings.locator('.picker').and(settings.getByRole('button', { name: 'Color theme', exact: true }));
|
||||
await picker.click();
|
||||
await settings.getByRole('menuitemradio', { name: label, exact: true }).click();
|
||||
await settings.getByRole('radio', { name: label, exact: true }).click();
|
||||
await main.waitForFunction(theme => document.documentElement.dataset.palette === theme, theme);
|
||||
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).press('Control+Home');
|
||||
await main.evaluate(() => { getSelection().removeAllRanges(); document.activeElement?.blur(); });
|
||||
@@ -104,13 +102,12 @@ await runSmoke('appearance/typography', async ({ browser }) => {
|
||||
await settings.setViewportSize({ width: 360, height: 480 });
|
||||
const content = settings.locator('dialog .content');
|
||||
assert(await content.evaluate(node => node.scrollWidth <= node.clientWidth), `${theme}: narrow overflow`);
|
||||
await picker.scrollIntoViewIfNeeded(); await picker.focus(); await settings.keyboard.press('Enter');
|
||||
const current = settings.getByRole('menuitemradio', { name: label, exact: true });
|
||||
await current.waitFor();
|
||||
// The current theme card stays reachable from the keyboard in a narrow window.
|
||||
const current = settings.getByRole('radio', { name: label, exact: true });
|
||||
await current.scrollIntoViewIfNeeded(); await current.focus();
|
||||
assert.equal(await current.getAttribute('aria-checked'), 'true');
|
||||
assert(await current.evaluate(node => node === document.activeElement));
|
||||
await settings.screenshot({ path: path.join(output, `${theme}-narrow-menu.png`) });
|
||||
await settings.keyboard.press('Escape');
|
||||
assert(await picker.evaluate(node => node === document.activeElement));
|
||||
await settings.screenshot({ path: path.join(output, `${theme}-narrow-cards.png`) });
|
||||
await setPluginTools(16);
|
||||
const bodyBounds = await settings.locator('dialog .body').boundingBox();
|
||||
assert((await settings.locator('dialog aside').boundingBox()).height <= bodyBounds.height * .4 + 1);
|
||||
|
||||
@@ -85,14 +85,22 @@ await runSmoke('settings/displayLanguage', async ({ browser }) => {
|
||||
assert.equal(await settings.locator('html').getAttribute('data-transparency'), 'off');
|
||||
await main.waitForFunction(() => document.documentElement.dataset.transparency === 'off');
|
||||
assert.equal(await surfaceOpacity(), '100%');
|
||||
await settings.locator('.picker').first().click();
|
||||
const bg = await settings.getByRole('menu').evaluate(node => getComputedStyle(node).backgroundColor);
|
||||
assert(!bg.endsWith('/ 0.82)') && !bg.startsWith('rgba'), `Opaque menu: ${bg}`);
|
||||
await settings.screenshot({ path: path.join(output, `${language}-${mode}-opaque-menu.png`) });
|
||||
await settings.keyboard.press('Escape');
|
||||
// Without a background image, menus are opaque at every transparency amount (UI-043).
|
||||
const menuBackground = async () => {
|
||||
await main.locator('.source-editor .cm-content').click({ button: 'right' });
|
||||
const bg = await main.locator('.rs-menu').first().evaluate(node => getComputedStyle(node).backgroundColor);
|
||||
await main.keyboard.press('Escape');
|
||||
return bg;
|
||||
};
|
||||
let bg = await menuBackground();
|
||||
assert(bg.startsWith('rgb('), `Opaque menu: ${bg}`);
|
||||
await toggle.check();
|
||||
await settings.locator('#surface-transparency').fill('30');
|
||||
assert.equal(await surfaceOpacity(), '70%');
|
||||
await main.waitForFunction(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-surface-opacity').trim() === '70%');
|
||||
bg = await menuBackground();
|
||||
assert(bg.startsWith('rgb('), `Opaque menu at 30% transparency: ${bg}`);
|
||||
await main.screenshot({ path: path.join(output, `${language}-${mode}-opaque-menu.png`) });
|
||||
await settings.setViewportSize({ width: 360, height: 640 });
|
||||
await settings.locator('#surface-transparency').scrollIntoViewIfNeeded();
|
||||
assert(await settings.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth), `${language} ${mode}: narrow overflow`);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// The theme editor model (src/lib/theme/themeEditor.ts): role groups, drafts, saved files, and the results of each role.
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { ROLE_GROUPS, builtinDraft, customDraft, draftColors, draftFindings, draftTheme, roleStatus, uniqueThemeId } from '../../../src/lib/theme/themeEditor.ts';
|
||||
import { ROLES, resolveColors } from '../../../src/lib/theme/roles.ts';
|
||||
import { parseCustomTheme } from '../../../src/lib/theme/customThemes.ts';
|
||||
import { BUILTIN_THEMES } from '../../../src/lib/theme/themes/index.ts';
|
||||
|
||||
test('The editor groups show every role once', () => {
|
||||
const shown = ROLE_GROUPS.flatMap(group => group.roles);
|
||||
assert.equal(new Set(shown).size, shown.length);
|
||||
assert.deepEqual([...shown].sort(), [...ROLES].sort());
|
||||
});
|
||||
|
||||
test('A built-in draft has the colors of its theme', () => {
|
||||
for (const theme of BUILTIN_THEMES) for (const [mode, colors] of Object.entries(theme.variants)) {
|
||||
const draft = builtinDraft(theme.id, mode as 'light' | 'dark', theme.name);
|
||||
assert.deepEqual(draftColors(draft), resolveColors(colors!, mode as 'light' | 'dark'));
|
||||
}
|
||||
});
|
||||
|
||||
test('A saved draft is a short schema 3 theme that the parser accepts and that keeps its colors', () => {
|
||||
const draft = { ...builtinDraft('harvest-moon', 'dark', 'Harvest Moon copy'), overrides: { accent: '#00c8ff', selection: '#20406080' } };
|
||||
const theme = draftTheme(draft, 'harvest-moon-copy', 'Harvest Moon copy');
|
||||
assert.deepEqual(theme, { schema: 3, id: 'harvest-moon-copy', name: 'Harvest Moon copy', mode: 'dark', base: 'harvest-moon', colors: { accent: '#00c8ff', selection: '#20406080' } });
|
||||
const parsed = parseCustomTheme(theme);
|
||||
assert.deepEqual(draftColors(customDraft(parsed)), draftColors(draft));
|
||||
});
|
||||
|
||||
test('Theme IDs from names are valid and unique', () => {
|
||||
assert.equal(uniqueThemeId('RuneStone Dark copy', []), 'runestone-dark-copy');
|
||||
assert.equal(uniqueThemeId('RuneStone Dark copy', ['runestone-dark-copy', 'runestone-dark-copy-2']), 'runestone-dark-copy-3');
|
||||
assert.equal(uniqueThemeId('2026 theme', []), 't-2026-theme');
|
||||
assert.equal(uniqueThemeId('桜', []), 'theme');
|
||||
for (const name of ['RuneStone Dark copy', '2026 theme', '桜', 'x'.repeat(100), '--Ünïcode--']) assert.match(uniqueThemeId(name, []), /^[a-z][a-z0-9-]{0,63}$/);
|
||||
});
|
||||
|
||||
test('A role shows the results where it is the color, the surface, or one of a pair', () => {
|
||||
const draft = { ...builtinDraft('default', 'dark', 'Test'), overrides: { 'text-dim': '#3a3a3a', ok: '#55dcf5' } };
|
||||
const findings = draftFindings(draft);
|
||||
const dim = roleStatus('text-dim', findings);
|
||||
assert(dim.failures.length > 0 && dim.failures.every(finding => finding.subject.startsWith('text-dim on ')));
|
||||
assert(dim.lowest && dim.lowest.value < 4.5);
|
||||
assert(roleStatus('bg', findings).failures.some(finding => finding.subject === 'text-dim on bg'), 'A surface shows the text that fails on it');
|
||||
assert(roleStatus('ok', findings).failures.some(finding => finding.subject === 'accent and ok'), 'A status color shows a pair that is too close');
|
||||
assert.deepEqual(roleStatus('syntax-keyword', findings).failures, []);
|
||||
});
|
||||
Reference in New Issue
Block a user