RuneStone 1.0.0

This commit is contained in:
Knotty Wyvern
2026-11-03 00:23:07 -07:00
commit 5557443ed1
818 changed files with 239368 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
// Settings density: title bars and window controls match the main window, compact plugin rows, narrow layouts, Git dialog focus, many categories.
// @known-issue The settings window controls are 35px high and the main window's are 36px: the settings header draws its divider as a border inside the shared title bar height.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("settings/density", async ({ browser }) => {
const output = await outputDir("settings/density");
const context = await browser.newContext({ viewport: { width: 1152, height: 815 } });
await mockTauri(context, {
commands: () => ({
plugins_snapshot: () => ({ root: "D:/RuneStone/plugins", plugins: Array.from({ length: 7 }, (_, index) => ({
manifest: { schemaVersion: 1, id: `org.example.plugin-${index}`, name: `Example plugin ${index + 1}`, author: "RuneStone Team", description: "A plugin description with enough text to check readable wrapping.", version: "0.1.1", apiVersion: 1, entry: "main.js", access: "full-app" },
enabled: false, hash: "test", installedAt: 1791390000000, path: `D:/RuneStone/plugins/plugin-${index}`, error: null, removal: false,
})) }),
workspace_last_path: () => null,
"plugin:window|is_maximized": () => false,
}),
});
const main = await openPage(context, { timeout: 7000 });
const settings = await openPage(context, { timeout: 7000 });
await main.goto(smokeUrl);
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.getByRole("heading", { name: "General", exact: true }).waitFor();
const header = settings.locator("dialog > header");
const mainHeader = main.locator(".header");
assert.equal((await header.boundingBox()).height, (await mainHeader.boundingBox()).height, "Settings and main title bars share their height");
for (const name of ["Minimize window", "Maximize window", "Close window"]) {
const a = await main.getByRole("button", { name, exact: true }).boundingBox();
const b = await settings.getByRole("button", { name, exact: true }).boundingBox();
assert.equal(a.width, b.width);
assert.equal(a.height, b.height, `${name} has the same dimensions in both windows`);
}
await settings.getByRole("button", { name: "Plug-ins", exact: true }).click();
await settings.getByRole("switch", { name: "Example plugin 1", exact: true }).waitFor();
const content = settings.locator(".content");
const pluginRows = content.locator(".row");
assert.equal(await pluginRows.count(), 7);
for (const theme of ["dark", "light"]) {
await settings.evaluate(value => { document.documentElement.dataset.theme = value; }, theme);
for (const width of [1152, 540, 360]) {
await settings.setViewportSize({ width, height: width === 1152 ? 815 : 420 });
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
assert(await content.evaluate(element => element.scrollWidth <= element.clientWidth), "The plugin content does not scroll horizontally");
const rows = await pluginRows.evaluateAll(elements => elements.map(element => element.getBoundingClientRect().height));
if (width === 1152) {
assert(rows.every(height => height <= 100), `Desktop plugin rows stay compact: ${rows}`);
const count = await pluginRows.evaluateAll(elements => {
const container = elements[0].closest(".content").getBoundingClientRect();
return elements.filter(element => element.getBoundingClientRect().bottom <= container.bottom).length;
});
assert(count >= 5, `At least five complete plugin rows fit at the screenshot size, got ${count}`);
}
const copy = pluginRows.first().locator(".plugin-copy");
const controls = pluginRows.first().locator(".controls");
const a = await copy.boundingBox(), b = await controls.boundingBox();
assert(a.x + a.width <= b.x + 1 || a.y + a.height <= b.y + 1, "Plugin text does not overlap its actions");
for (const button of await controls.getByRole("button").all()) {
const bounds = await button.boundingBox();
assert(bounds.width >= 28 && bounds.height >= 28);
assert(await button.getAttribute("aria-label"));
}
await settings.screenshot({ path: path.join(output, `${theme}-${width}.png`) });
}
}
await settings.setViewportSize({ width: 540, height: 420 });
await settings.getByRole("button", { name: "Install from Git link", exact: true }).click();
const install = settings.getByRole("dialog", { name: "Install from Git link", exact: true });
await install.waitFor();
assert(await install.getByRole("textbox", { name: "Repository link", exact: true }).isVisible());
assert.equal(await settings.evaluate(() => document.activeElement?.textContent), "Cancel");
await settings.keyboard.press("Escape");
await install.waitFor({ state: "detached" });
assert.equal(await settings.evaluate(() => document.activeElement?.textContent), "Install from Git link");
await settings.getByRole("button", { name: "General", exact: true }).click();
assert(await settings.getByRole("spinbutton", { name: "Auto-save interval", exact: true }).isVisible());
await settings.evaluate(async () => {
const { pluginTools } = await import("/src/lib/plugins/external.ts");
pluginTools.set(Array.from({ length: 12 }, (_, index) => ({ owner: "org.example.plugin-0", id: `settings-${index}`, title: `Plugin settings ${index + 1}`, surface: "settings" })));
});
await settings.setViewportSize({ width: 360, height: 420 });
const sidebar = settings.locator("dialog aside");
assert((await sidebar.boundingBox()).height <= 154, "Many plugin categories leave space for setting controls");
assert(await sidebar.evaluate(element => element.scrollWidth <= element.clientWidth));
await settings.getByRole("button", { name: "Plugin settings 12", exact: true }).scrollIntoViewIfNeeded();
const category = await settings.getByRole("button", { name: "Plugin settings 12", exact: true }).boundingBox();
const navigation = await sidebar.boundingBox();
assert(category.y >= navigation.y && category.y + category.height <= navigation.y + navigation.height, "Every plugin category remains reachable");
assert(await settings.getByRole("spinbutton", { name: "Auto-save interval", exact: true }).isVisible());
assert.deepEqual([...main.errors, ...settings.errors], []);
console.log("Settings density smoke passed: matching title bars and window controls, seven plugin rows, compact layout, readable text, accessible actions, both themes, narrow layouts, Git dialog focus, and many plugin categories.");
});
@@ -0,0 +1,114 @@
// Display language: four locales, persistence, cross-window updates, menu keyboard focus, translated editor menus, and transparency settings.
import assert from 'node:assert/strict';
import path from 'node:path';
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
await runSmoke('settings/displayLanguage', async ({ browser }) => {
const output = await outputDir('settings/displayLanguage');
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 settings = await openPage(context, { timeout: 15000 });
const main = await openPage(context, { timeout: 15000 });
const languagePicker = settings.locator('#language-picker');
const surfaceOpacity = () => settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-surface-opacity').trim());
await main.goto(smokeUrl);
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await languagePicker.waitFor();
for (const [language, name, heading, appearance, enabled, files] of [
['fr', 'Français', 'Paramètres', 'Apparence', 'Surfaces transparentes', 'Fichiers'],
['ja', '日本語', '設定', '外観', '背景を透過', 'ファイル'],
['zh-CN', '简体中文', '设置', '外观', '透明界面', '文件'],
['en', 'English', 'Settings', 'Appearance', 'Transparent surfaces', 'Files'],
]) {
await languagePicker.click();
await settings.getByRole('menuitemradio', { name, exact: true }).click();
await settings.getByRole('heading', { name: heading, exact: true }).waitFor();
await main.getByRole('button', { name: files, exact: true }).waitFor();
assert.equal(await settings.locator('html').getAttribute('lang'), language);
assert.equal(await main.locator('html').getAttribute('lang'), language);
assert.equal(await settings.evaluate(() => window.__TEST__.settings('language')), language);
await settings.reload();
await settings.getByRole('heading', { name: heading, exact: true }).waitFor();
// Arrow keys and Escape retain shared menu focus behavior.
await languagePicker.focus();
await settings.keyboard.press('Enter');
await settings.keyboard.press('End');
await settings.keyboard.press('Home');
await settings.keyboard.press('Escape');
assert(await languagePicker.evaluate(node => node === document.activeElement));
assert(await main.evaluate(async () => {
const { imageControls } = await import('/src/lib/editor/imageControls.ts');
const root = document.createElement('div'); root.innerHTML = '<img data-md-src="sample.png" alt="sample">'; document.body.append(root);
let removed = false;
const cleanup = imageControls(root, { remove: () => { removed = true; } });
root.querySelector('.md-image-frame').dispatchEvent(new KeyboardEvent('keydown', { key: 'Delete', bubbles: true }));
cleanup(); root.remove(); return removed;
}), `${language}: Delete image keyboard action`);
assert(await main.evaluate(async () => {
const { tableSelectionControls } = await import('/src/lib/editor/tableSelectionControls.ts');
const root = document.createElement('div'); root.innerHTML = '<div><table><tr><th>A</th><th>B</th></tr><tr><td>one</td><td>two</td></tr></table></div>'; document.body.append(root);
const wrapper = root.firstElementChild, table = root.querySelector('table');
let text = '| A | B |\n| --- | --- |\n| one | two |';
const view = { posAtDOM: () => 0, dom: root, focus() {} };
const controls = tableSelectionControls(root, wrapper, table, view, () => text, () => {}, next => { text = next; }, { get: () => undefined, activate() {}, editSource() {} }, {});
controls.select({ anchor: { row: 1, column: 0 }, head: { row: 1, column: 0 } });
wrapper.dispatchEvent(new KeyboardEvent('keydown', { key: 'Delete', bubbles: true }));
controls.destroy(); root.remove(); return !text.includes('one') && text.includes('two');
}), `${language}: Delete selected table cell keyboard action`);
await settings.screenshot({ path: path.join(output, `${language}-general.png`) });
await main.locator('[data-tree-rel="theme-0.py"]').click();
await main.locator('.source-editor .cm-content').waitFor();
await main.locator('.source-editor .cm-content').click({ button: 'right' });
await main.locator('.rs-menu').waitFor();
const copyLabels = { fr: 'Copier', ja: 'コピー', 'zh-CN': '复制', en: 'Copy' };
await main.locator('.rs-menu .action-label').filter({ hasText: new RegExp('^' + copyLabels[language] + '$') }).waitFor();
await main.screenshot({ path: path.join(output, `${language}-workbench-editor-menu.png`) });
await main.keyboard.press('Escape');
await settings.getByRole('button', { name: appearance, exact: true }).click();
for (const mode of ['dark', 'light']) {
await settings.evaluate(async mode => {
const appearance = await import('/src/lib/theme/appearance.ts');
appearance.saveAppearance({ theme: 'default', mode, transparency: { enabled: true, amount: 18 } });
window.dispatchEvent(new Event('focus'));
}, mode);
const toggle = settings.getByRole('switch', { name: enabled, exact: true });
await toggle.uncheck();
assert.equal(await settings.locator('html').getAttribute('data-transparency'), 'off');
await main.waitForFunction(() => document.documentElement.dataset.transparency === 'off');
assert.equal(await surfaceOpacity(), '100%');
// 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`);
await settings.screenshot({ path: path.join(output, `${language}-${mode}-narrow.png`) });
await settings.setViewportSize({ width: 1100, height: 800 });
}
await settings.reload();
}
assert.deepEqual([...settings.errors, ...main.errors], []);
console.log('PASS: 4 locales, persistence, cross-window updates, keyboard menu focus, both themes, opaque menus, transparency levels, narrow layout.');
});
+165
View File
@@ -0,0 +1,165 @@
// General settings: auto-save timers, manual saves, persistence, cross-window updates, validation, storage failure, help, search, focus, narrow layout.
import { readFileSync } from "node:fs";
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
const { version } = JSON.parse(readFileSync(path.join(repoRoot, "package.json"), "utf8"));
await runSmoke("settings/general", async ({ browser }) => {
const output = await outputDir("settings/general");
const context = await browser.newContext({ viewport: { width: 1100, height: 800 } });
await mockTauri(context, {
state: { writes: [] },
commands: test => {
const workspace = test.workspace({ root: "D:\\Notes", files: { "note.txt": "Original note" } });
return {
...workspace,
workspace_write: args => { workspace.workspace_write(args); test.state.writes.push(args); },
plugins_snapshot: () => ({ root: "D:\\AppData\\RuneStone\\plugins", plugins: [] }),
settings_open_window: () => null,
};
},
});
const page = await openPage(context);
const settingsPage = await openPage(context);
const settings = settingsPage.getByRole("dialog", { name: "Settings", exact: true });
const trigger = page.getByRole("button", { name: "Settings (Ctrl+,)", exact: true });
async function showSettings(shortcut = false) {
if (shortcut) await page.keyboard.press("Control+,");
else await trigger.click();
await settingsPage.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.waitFor();
}
async function closeSettings() {
await settingsPage.goto("about:blank");
await page.bringToFront();
}
const interval = settings.getByRole("spinbutton", { name: "Auto-save interval" });
const enabled = settings.getByRole("switch", { name: "Auto-save", exact: true });
async function changeSeconds(value) {
await interval.fill(String(value));
await interval.press("Tab");
}
async function edit(value) {
await page.evaluate(async text => {
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
const view = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: text } });
}, value);
}
const writes = () => page.evaluate(() => window.__TEST__.state.writes.length);
await page.clock.install();
await page.goto(smokeUrl);
await page.locator(".ws").filter({ hasText: "Notes" }).waitFor();
await showSettings();
assert.equal(await interval.inputValue(), "5");
assert(await enabled.isChecked());
await changeSeconds(2);
await settings.getByRole("status").filter({ hasText: "Changes saved." }).waitFor();
await closeSettings();
await page.reload();
await showSettings();
assert.equal(await interval.inputValue(), "2", "Interval survives reload");
await changeSeconds(0);
await settings.getByRole("alert").filter({ hasText: "whole number" }).waitFor();
assert.equal(await page.evaluate(() => window.__TEST__.settings("general").autosaveSeconds), 2);
await changeSeconds(2);
await settings.getByRole("textbox", { name: "Search settings" }).fill("plugins");
await settings.getByText("No plugins installed.", { exact: true }).waitFor();
assert(await settings.getByRole("button", { name: "Install plugin ZIP", exact: true }).isEnabled());
await settings.getByRole("textbox", { name: "Search settings" }).fill("no such setting");
await settings.getByText("No settings found", { exact: true }).waitFor();
await settings.getByRole("button", { name: "Clear search" }).click();
await settingsPage.screenshot({ path: path.join(output, "general.png") });
await closeSettings();
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill("note.txt");
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.txt" }).first().click();
await page.locator(".source-editor .cm-content").waitFor();
await page.clock.pauseAt(new Date(await page.evaluate(() => Date.now()) + 1000));
await showSettings();
await changeSeconds(3);
await closeSettings();
await edit("Saved at three seconds");
const before = await writes();
await page.clock.runFor(2100);
assert.equal(await writes(), before, "Old two-second timer is removed");
await page.clock.runFor(1000);
assert.equal(await writes(), before + 1, "New interval saves the dirty buffer");
await page.clock.runFor(3100);
assert.equal(await writes(), before + 1, "Clean files are not rewritten");
await showSettings();
await enabled.uncheck();
assert(await interval.isDisabled());
await closeSettings();
await edit("Manual save while auto-save is disabled");
await page.clock.runFor(10000);
assert.equal(await writes(), before + 1);
await page.keyboard.press("Control+s");
await page.waitForFunction(count => window.__TEST__.state.writes.length === count, before + 2);
await page.locator(".source-editor .cm-content").focus();
await showSettings(true);
await settings.waitFor();
await closeSettings();
await page.locator(".source-editor .cm-content").focus();
await page.keyboard.press("F1");
await page.getByRole("dialog", { name: "Help and about", exact: true }).waitFor();
await page.keyboard.press("Escape");
const other = await openPage(context);
await other.goto(`${smokeUrl}/?settingsWindow=true`);
assert.equal(await other.getByRole("spinbutton", { name: "Auto-save interval" }).inputValue(), "3");
assert.equal(await other.getByRole("switch", { name: "Auto-save", exact: true }).isChecked(), false);
await other.getByRole("button", { name: "Restore defaults" }).click();
await page.waitForFunction(() => window.__TEST__.settings("general").autosaveEnabled);
await showSettings();
await enabled.waitFor();
assert(await enabled.isChecked(), "Other windows receive changes");
assert.equal(await interval.inputValue(), "5");
await closeSettings();
await edit("Auto-save enabled from another window");
await page.clock.runFor(5100);
assert.equal(await writes(), before + 3);
await other.close();
await showSettings();
await settingsPage.evaluate(() => {
window.__SET_ITEM__ = Storage.prototype.setItem;
Storage.prototype.setItem = () => { throw new Error("Storage unavailable"); };
});
await changeSeconds(7);
await settings.getByRole("alert").filter({ hasText: "Could not save" }).waitFor();
await settingsPage.evaluate(() => { Storage.prototype.setItem = window.__SET_ITEM__; });
await closeSettings();
await showSettings();
assert.equal(await interval.inputValue(), "5", "Failed writes preserve applied settings");
await closeSettings();
await page.getByRole("button", { name: "Help and about (F1)" }).click();
const help = page.getByRole("dialog", { name: "Help and about", exact: true });
await help.getByRole("heading", { name: "RuneStone", exact: true }).waitFor();
await help.getByText(`Version ${version}`, { exact: false }).waitFor();
await page.screenshot({ path: path.join(output, "help.png") });
await page.keyboard.press("Escape");
await page.keyboard.press("Control+Backslash");
await showSettings(true);
await settings.waitFor();
await closeSettings();
await page.keyboard.press("F1");
await help.waitFor();
await page.keyboard.press("Escape");
await settingsPage.setViewportSize({ width: 540, height: 420 });
await showSettings(true);
await settings.waitFor();
assert(await settings.evaluate(el => el.scrollWidth === el.clientWidth), "Narrow layout fits");
await settingsPage.screenshot({ path: path.join(output, "narrow.png") });
for (let i = 0; i < 12; i++) {
await settingsPage.keyboard.press("Tab");
assert(await settings.evaluate(el => el.contains(document.activeElement)), "Focus stays in the modal");
}
assert.deepEqual([...page.errors, ...settingsPage.errors], []);
console.log("Settings smoke passed: timer changes, disabled auto-save, manual saves, persistence, cross-window updates, validation, storage failure, help, search, focus, shortcuts, and narrow layout.");
});
+86
View File
@@ -0,0 +1,86 @@
// Settings window title bar: scoped permissions, drag regions, minimize, maximize, restore, close, Escape, focus, errors, themes, and the browser fallback.
import { readFileSync } from "node:fs";
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("settings/titlebar", async ({ browser }) => {
const settingsCapability = JSON.parse(readFileSync(path.join(repoRoot, "src-tauri/capabilities/settings.json"), "utf8"));
assert.deepEqual(settingsCapability.windows, ["settings-main", "settings-workspace-*"]);
for (const action of ["close", "minimize", "toggle-maximize", "start-dragging"]) {
assert(settingsCapability.permissions.includes(`core:window:allow-${action}`));
}
const output = await outputDir("settings/titlebar");
const context = await browser.newContext({ viewport: { width: 920, height: 650 } });
await mockTauri(context, {
label: "settings-main",
state: { maximized: false, failMinimize: false },
commands: test => ({
plugins_snapshot: () => ({ root: "D:\\SettingsTest\\plugins", plugins: [] }),
"plugin:window|is_maximized": () => test.state.maximized,
"plugin:window|toggle_maximize": () => { test.state.maximized = !test.state.maximized; },
"plugin:window|minimize": () => { if (test.state.failMinimize) throw new Error("Window action failed"); },
"plugin:window|close": () => null,
}),
});
const page = await openPage(context, { timeout: 5000 });
await page.goto(`${smokeUrl}/?settingsWindow=true`);
const dialog = page.getByRole("dialog", { name: "Settings", exact: true });
await dialog.waitFor();
assert.equal(await dialog.getByRole("button", { name: /^Close/ }).count(), 1);
assert(await dialog.locator("header[data-tauri-drag-region] h1[data-tauri-drag-region]").isVisible());
assert.equal(await dialog.locator(".window-controls [data-tauri-drag-region]").count(), 0);
const calls = () => page.evaluate(() => window.__TEST__.calls.map(call => call.command));
const closes = async () => (await calls()).filter(command => command === "plugin:window|close").length;
const button = name => page.getByRole("button", { name, exact: true });
await button("Minimize window").click();
assert((await calls()).includes("plugin:window|minimize"));
await button("Maximize window").click();
await button("Restore window").waitFor();
await button("Restore window").focus();
await page.keyboard.press("Enter");
await button("Maximize window").waitFor();
await page.evaluate(() => { window.__TEST__.state.maximized = true; window.__TEST__.emit("tauri://resize", {}); });
await button("Restore window").waitFor();
await button("Close window").focus();
await page.getByRole("tooltip", { name: "Close window", exact: true }).waitFor();
await page.keyboard.press("Space");
const beforeEscape = await closes();
assert.equal(beforeEscape, 1);
await page.getByRole("textbox", { name: "Search settings" }).focus();
await page.keyboard.press("Escape");
assert.equal(await closes(), beforeEscape + 1);
await page.mouse.move(400, 180);
for (const theme of ["dark", "light"]) {
await page.evaluate(value => document.documentElement.setAttribute("data-theme", value), theme);
for (const size of [{ width: 920, height: 650 }, { width: 540, height: 420 }]) {
await page.setViewportSize(size);
assert(await dialog.evaluate(element => element.scrollWidth === element.clientWidth));
for (const label of ["Minimize window", "Restore window", "Close window"]) {
const control = dialog.getByRole("button", { name: label, exact: true });
const bounds = await control.boundingBox();
assert(bounds.x >= 0 && bounds.x + bounds.width <= size.width && bounds.height >= 28);
// Caption buttons are square (src/lib/ui/WindowControls.svelte).
assert.equal(await control.evaluate(element => getComputedStyle(element).borderTopLeftRadius), "0px");
}
await page.screenshot({ path: path.join(output, `${theme}-${size.width}.png`) });
}
}
await page.evaluate(() => { window.__TEST__.state.failMinimize = true; });
await button("Minimize window").click();
await dialog.getByRole("alert").filter({ hasText: "Window action failed" }).waitFor();
await page.evaluate(() => { window.__TEST__.state.failMinimize = false; });
await button("Minimize window").focus();
await page.keyboard.press("Shift+Tab");
assert.equal(await page.evaluate(() => document.activeElement?.textContent), "Restore defaults");
await page.keyboard.press("Tab");
assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Minimize window");
// Without the Tauri mock, the page is a plain browser preview.
const web = await openPage(browser);
await web.goto(`${smokeUrl}/?settingsWindow=true`);
await web.getByRole("button", { name: "Close settings", exact: true }).waitFor();
assert.equal(await web.getByRole("group", { name: "Window controls" }).count(), 0);
assert.deepEqual(page.errors, []);
console.log("Settings window smoke passed: scoped permissions, drag regions, minimize, maximize, restore, resize, close, Escape, keyboard focus, tooltips, errors, both themes, narrow layout, and browser fallback.");
});
+79
View File
@@ -0,0 +1,79 @@
// Settings window: browser preview fallback, standalone layout, two-way save sync, failed saves, native open requests, and close. The OS title bar is not tested.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("settings/window", async ({ browser }) => {
const output = await outputDir("settings/window");
const context = await browser.newContext({ viewport: { width: 1100, height: 760 } });
const autosaveSeconds = page => page.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds);
// The main window and settings run as browser previews, without the Tauri mock.
const main = await openPage(context);
await main.goto(smokeUrl);
await main.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).click();
assert.equal(await main.locator("dialog:modal").count(), 1, "Browser preview retains the settings dialog");
const settings = await openPage(context);
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.getByRole("heading", { name: "General", exact: true }).waitFor();
assert.equal(await settings.locator(".workbench").count(), 0);
const interval = settings.getByRole("spinbutton", { name: "Auto-save interval" });
await interval.fill("17"); await interval.press("Tab");
await main.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "17");
await main.getByRole("spinbutton", { name: "Auto-save interval" }).fill("29");
await main.getByRole("spinbutton", { name: "Auto-save interval" }).press("Tab");
await settings.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "29");
await settings.reload();
await settings.waitForFunction(() => document.querySelector("#autosave-seconds")?.value === "29");
await interval.fill("301"); await interval.press("Tab");
await settings.getByRole("alert").filter({ hasText: "Choose a whole number" }).waitFor();
assert.equal(await autosaveSeconds(settings), 29);
await settings.evaluate(() => { Storage.prototype.setItem = () => { throw new Error("Storage full"); }; });
await interval.fill("40"); await interval.press("Tab");
await settings.getByRole("alert").filter({ hasText: "Could not save these settings" }).waitFor();
assert.equal(await autosaveSeconds(settings), 29);
await settings.reload();
await settings.getByRole("button", { name: "Plug-ins", exact: true }).click();
await settings.getByRole("heading", { name: "Plug-ins", exact: true }).waitFor();
await settings.getByRole("button", { name: "General", exact: true }).click();
await settings.screenshot({ path: path.join(output, "settings-window.png") });
await settings.setViewportSize({ width: 540, height: 420 });
assert.equal(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
await settings.keyboard.press("Escape");
await settings.waitForURL(`${smokeUrl}/`);
// A desktop window with the Tauri mock opens settings in a native window.
const desktop = await openPage(context);
await mockTauri(desktop, {
state: { opens: 0, fail: false, closes: 0 },
commands: test => ({
settings_open_window: async () => {
test.state.opens++;
if (test.state.fail) throw new Error("Native window creation failed");
await new Promise(resolve => setTimeout(resolve, 150));
},
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
workspace_last_path: () => null,
"plugin:window|is_maximized": () => false,
"plugin:window|close": () => { test.state.closes++; },
}),
});
const desktopState = () => desktop.evaluate(() => window.__TEST__.state);
await desktop.goto(smokeUrl);
await desktop.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).dblclick();
assert.equal((await desktopState()).opens, 1, "Rapid requests share the pending native open");
assert.equal(await desktop.locator("dialog:modal").count(), 0, "Native open does not block the workbench");
await desktop.waitForTimeout(180);
await desktop.keyboard.press("Control+,");
await desktop.waitForFunction(() => window.__TEST__.state.opens === 2);
await desktop.waitForTimeout(180);
await desktop.evaluate(() => { window.__TEST__.state.fail = true; });
await desktop.keyboard.press("Control+,");
await desktop.getByText(/Could not open settings: .*Native window creation failed/).waitFor();
await desktop.goto(`${smokeUrl}/?settingsWindow=true`);
await desktop.getByRole("heading", { name: "General", exact: true }).waitFor();
await desktop.getByRole("button", { name: "Close window", exact: true }).click();
assert.equal((await desktopState()).closes, 1);
assert.deepEqual([main, settings, desktop].flatMap(page => page.errors), []);
console.log("Settings window smoke passed: preview fallback, standalone layout, two-way save sync, persistence, failed saves, native open requests, and close.");
});