Files
RuneStone/tests/smoke/appearance/themeVariants.smoke.mjs
T
Knotty Wyvern 5d5ba9e1f7 Keep preferences in one settings file and move tab transfer to the host
Keep the user preferences in settings.json in the app config folder.
WebView storage can be lost, and the host cannot read it. The file has
a schema number, a revision number, and one value for each section:
general, appearance, customThemes, customThemesLegacy, and language.
- settings_read gives all sections, the revision, and a one-time
  notice.
- settings_write replaces one section, writes the file atomically, and
  sends settings-changed to all windows. The limit is 8 MiB.
- settings_migrate writes the first file only when no file exists.
- The host moves a damaged file to settings.corrupt-<seconds>.json,
  starts from the defaults, and reports this one time.

Each window loads the sections before its first render. One store in
src/lib/settings/store.ts replaces the storage listeners. When no file
exists, the window normalizes the old localStorage values and migrates
them. The old keys stay in place for one release. The window layout
and the open tabs stay in localStorage on purpose. The browser preview
keeps all preferences in localStorage.

Keep tab transfer offers in host memory, not in localStorage, because
an offer can hold unsaved text. A window takes an offer once. The host
checks the workspace root and a 120 second expiry. When the receiver
accepts the tab, the host sends tab-transfer-accepted to the source
window only. A refused offer stays open, and the source tab stays open.
A new window and a drop on the tab ribbon use one check.

The smoke harness serves the new commands from one shared state for
each browser context. Tests read saved values from the mock settings
file. Rust, unit, and smoke tests cover the changes.
2026-10-27 23:56:00 -07:00

85 lines
6.1 KiB
JavaScript

// Theme variants: transparency slider in eight variants, custom theme fonts, a single tooltip, and slideshow command icons.
import assert from 'node:assert/strict';
import path from 'node:path';
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
await runSmoke('appearance/themeVariants', async ({ browser }) => {
const output = await outputDir('appearance/themeVariants');
const context = await browser.newContext({ viewport: { width: 1100, height: 800 } });
await mockTauri(context, {
commands: test => ({
...test.workspace({
root: 'C:\\appearance-smoke',
files: Object.fromEntries(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`])),
}),
plugins_snapshot: () => ({ root: 'C:/appearance-smoke-plugins', plugins: [] }),
'plugin:window|is_maximized': () => false,
}),
});
const page = await openPage(context);
await page.goto(`${smokeUrl}/?settingsWindow=true`);
await page.getByRole('button', { name: 'Appearance', exact: true }).click();
const transparent = page.getByRole('switch', { name: 'Transparent surfaces', exact: true });
for (const [theme, mode] of [['default', 'dark'], ['default', 'light'], ['claude', 'dark'], ['claude', 'light'], ['sakura', 'light'], ['harvest-moon', 'dark'], ['crimson-pilot', 'dark'], ['silver-serpent', 'dark']]) {
await page.evaluate(async ({ theme, mode }) => {
(await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme, mode, transparency: { enabled: true, amount: 18 } });
window.dispatchEvent(new Event('focus'));
}, { theme, mode });
const slider = page.locator('#surface-transparency');
await slider.fill('100');
assert.equal(await page.evaluate(() => window.__TEST__.settings('appearance').transparency.amount), 100);
await slider.focus(); await page.keyboard.press('Home'); assert.equal(await slider.inputValue(), '0');
await page.keyboard.press('End'); assert.equal(await slider.inputValue(), '100');
await page.screenshot({ path: path.join(output, `${theme}-${mode}-slider-focus.png`) });
await transparent.uncheck();
assert(await slider.isDisabled());
await page.screenshot({ path: path.join(output, `${theme}-${mode}-slider-disabled.png`) });
await transparent.check();
await page.setViewportSize({ width: 360, height: 740 }); await slider.scrollIntoViewIfNeeded();
assert(await page.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth));
await page.screenshot({ path: path.join(output, `${theme}-${mode}-narrow.png`) });
await page.setViewportSize({ width: 1100, height: 800 });
}
await page.evaluate(async () => {
const { installTheme } = await import('/src/lib/theme/customThemes.ts');
const { saveAppearance, exportAppearanceTheme } = await import('/src/lib/theme/appearance.ts');
const theme = exportAppearanceTheme('default'); theme.fonts = { ui: 'Arial, sans-serif', prose: 'Georgia, serif', heading: 'Georgia, serif', mono: 'Consolas, monospace' };
installTheme(theme); saveAppearance({ theme: 'custom:my-theme', mode: 'dark' }); window.dispatchEvent(new Event('focus'));
});
assert.match(await page.locator('.preview-prose').evaluate(node => getComputedStyle(node).fontFamily), /Georgia/);
assert.match(await page.evaluate(async () => (await import('/src/lib/theme/appearance.ts')).exportAppearanceTheme('custom:my-theme').fonts.ui), /Arial/);
await page.screenshot({ path: path.join(output, 'custom-fonts.png') });
const main = await openPage(context); await main.goto(smokeUrl);
await main.bringToFront();
await main.getByRole('button', { name: 'Files', exact: true }).waitFor();
await main.evaluate(async () => {
const loaded = performance.getEntriesByType('resource').map(entry => entry.name).find(name => new URL(name).pathname === '/src/lib/plugins/external.ts');
const { pluginTools, refreshPlugins } = await import(loaded || '/src/lib/plugins/external.ts');
await refreshPlugins();
const invoke = window.__TAURI_INTERNALS__.invoke;
window.__TAURI_INTERNALS__.invoke = (command, args) => command === 'plugins_snapshot' ? Promise.resolve(null) : invoke(command, args);
const commands = [{ owner: 'runestone.background-slideshow', id: 'next-image', title: 'Next background image', kind: 'command', surface: 'commands', icon: 'skip-forward' }, { owner: 'runestone.background-slideshow', id: 'pause-resume', title: 'Pause or resume background slideshow', kind: 'command', surface: 'commands', icon: 'pause' }];
pluginTools.set(commands);
});
const visibleTooltips = () => main.locator('[role=tooltip]:visible').count();
for (const mode of ['dark', 'light']) {
await main.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme: 'default', mode }), mode);
const button = main.getByRole('button', { name: 'Commands', exact: true });
assert.equal(await button.getAttribute('title'), null);
await button.hover(); await main.waitForTimeout(1100);
assert.equal(await visibleTooltips(), 1);
await main.screenshot({ path: path.join(output, `${mode}-single-tooltip.png`) });
await main.keyboard.press('Escape'); assert.equal(await visibleTooltips(), 0);
await main.mouse.move(400, 400);
await button.evaluate(node => node.blur());
await button.focus(); await main.waitForTimeout(600); assert.equal(await visibleTooltips(), 1);
await button.click(); await main.getByRole('menu').waitFor();
const paths = await main.locator('.rs-menu svg').evaluateAll(nodes => nodes.map(node => node.innerHTML));
assert(paths.some(path => path.includes('M7 4v16'))); assert(paths.some(path => path.includes('m4 4 12 8')));
await main.screenshot({ path: path.join(output, `${mode}-slideshow-command-icons.png`) }); await main.keyboard.press('Escape');
}
assert.deepEqual([...page.errors, ...main.errors], []);
console.log('PASS: eight theme variants, slider endpoints, persistence, disabled states, narrow layout, font import/export, single tooltip, and command icons.');
});