Move the tests from scripts/ to tests/ by feature
Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const origin = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
try {
|
||||
const context = await browser.newContext({ viewport: { width: 1152, height: 815 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
let sequence = 0;
|
||||
const callbacks = new Map();
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugins_snapshot") return { 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,
|
||||
})) };
|
||||
if (command === "workspace_last_path") return null;
|
||||
if (command === "plugin:event|listen") return args.handler;
|
||||
if (command === "plugin:window|is_maximized") return false;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const main = await context.newPage();
|
||||
const settings = await context.newPage();
|
||||
for (const page of [main, settings]) {
|
||||
page.setDefaultTimeout(7000);
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
}
|
||||
await main.goto(origin);
|
||||
await settings.goto(`${origin}/?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: `.audit/settings-density-${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(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.");
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,125 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
||||
const origin = process.env.SMOKE_URL || 'http://127.0.0.1:1420';
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const errors = [];
|
||||
await mkdir('.audit/appearance-language', { recursive: true });
|
||||
try {
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 800 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\appearance-smoke";
|
||||
const files = new Map(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`]));
|
||||
const callbacks = new Map();
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugins_snapshot") return { root: "C:/appearance-smoke-plugins", plugins: [] };
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "appearance-smoke", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("File absent"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") { files.set(args.rel, args.contents); return; }
|
||||
if (command === "workspace_list") return [...files.keys()].filter(path => !path.startsWith(".")).map(path => ({ name: path, rel_path: path, kind: "file" }));
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "plugin:event|listen") return args.handler;
|
||||
if (command === "plugin:window|is_maximized") return false;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const settings = await context.newPage();
|
||||
const main = await context.newPage();
|
||||
for (const page of [settings, main]) { page.on('pageerror', error => errors.push(error.message)); page.setDefaultTimeout(15000); }
|
||||
await main.goto(origin);
|
||||
await settings.goto(`${origin}/?settingsWindow=true`);
|
||||
await settings.locator('#language-picker').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 settings.locator('#language-picker').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(() => localStorage.getItem('runestone.language')), language);
|
||||
await settings.reload();
|
||||
await settings.getByRole('heading', { name: heading, exact: true }).waitFor();
|
||||
// Arrow keys and Escape retain shared menu focus behavior.
|
||||
await settings.locator('#language-picker').focus();
|
||||
await settings.keyboard.press('Enter');
|
||||
await settings.keyboard.press('End');
|
||||
await settings.keyboard.press('Home');
|
||||
await settings.keyboard.press('Escape');
|
||||
assert(await settings.locator('#language-picker').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: `.audit/appearance-language/${language}-general.png` });
|
||||
await main.locator('[data-tree-rel="theme-0.py"]').click();
|
||||
await main.locator('.monaco-editor textarea').waitFor();
|
||||
await main.locator('.view-lines').first().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: `.audit/appearance-language/${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');
|
||||
const opacity = await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-surface-opacity').trim());
|
||||
assert.equal(opacity, '100%');
|
||||
await settings.locator('.picker').first().click();
|
||||
const menu = settings.getByRole('menu');
|
||||
const bg = await menu.evaluate(node => getComputedStyle(node).backgroundColor);
|
||||
assert(!bg.endsWith('/ 0.82)') && !bg.startsWith('rgba'), `Opaque menu: ${bg}`);
|
||||
await settings.screenshot({ path: `.audit/appearance-language/${language}-${mode}-opaque-menu.png` });
|
||||
await settings.keyboard.press('Escape');
|
||||
await toggle.check();
|
||||
await settings.locator('#surface-transparency').fill('30');
|
||||
assert.equal(await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-surface-opacity').trim()), '70%');
|
||||
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: `.audit/appearance-language/${language}-${mode}-narrow.png` });
|
||||
await settings.setViewportSize({ width: 1100, height: 800 });
|
||||
}
|
||||
await settings.reload();
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('PASS: 4 locales, persistence, cross-window updates, keyboard menu focus, both themes, opaque menus, transparency levels, narrow layout.');
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,175 @@
|
||||
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
|
||||
import { createRequire } from "node:module";
|
||||
import { mkdirSync, readFileSync } from "node:fs";
|
||||
import assert from "node:assert/strict";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { version } = JSON.parse(readFileSync(new URL("../../../package.json", import.meta.url), "utf8"));
|
||||
mkdirSync(".audit", { recursive: true });
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 800 } });
|
||||
const page = await context.newPage();
|
||||
const settingsPage = await context.newPage();
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
settingsPage.on("pageerror", error => errors.push(error.message));
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const disk = { "note.txt": "Original note" };
|
||||
const writes = [];
|
||||
window.__TEST__ = { disk, writes };
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: () => 1, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugins_snapshot") return { root: "D:\\AppData\\RuneStone\\plugins", plugins: [] };
|
||||
if (command === "workspace_last_path") return "D:\\Notes";
|
||||
if (command === "workspace_open") return { root: "D:\\Notes", name: "Notes", watch_mode: "native" };
|
||||
if (command === "workspace_list") return args.rel ? [] : [{ name: "note.txt", rel_path: "note.txt", kind: "file" }];
|
||||
if (command === "workspace_read") { if (args.rel in disk) return disk[args.rel]; throw "Missing file"; }
|
||||
if (command === "workspace_write") { disk[args.rel] = args.contents; writes.push(args); return; }
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
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(`${url}/?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 { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
||||
monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected).setValue(text);
|
||||
}, value);
|
||||
}
|
||||
const writes = () => page.evaluate(() => window.__TEST__.writes.length);
|
||||
try {
|
||||
await page.clock.install();
|
||||
await page.goto(url);
|
||||
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(() => JSON.parse(localStorage.getItem("runestone.settings")).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: ".audit/settings-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(".monaco-editor textarea").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__.writes.length === count, before + 2);
|
||||
await page.locator(".monaco-editor textarea").focus();
|
||||
await showSettings(true);
|
||||
await settings.waitFor();
|
||||
await closeSettings();
|
||||
await page.locator(".monaco-editor textarea").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 context.newPage();
|
||||
await other.goto(`${url}/?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(() => JSON.parse(localStorage.getItem("runestone.settings")).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: ".audit/settings-help.png" });
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Control+b");
|
||||
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: ".audit/settings-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(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.");
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,96 @@
|
||||
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
|
||||
import { createRequire } from "node:module";
|
||||
import { mkdirSync, readFileSync } from "node:fs";
|
||||
import assert from "node:assert/strict";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
mkdirSync(".audit", { recursive: true });
|
||||
const settingsCapability = JSON.parse(readFileSync(new URL("../../../src-tauri/capabilities/settings.json", import.meta.url), "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 errors = [];
|
||||
try {
|
||||
const context = await browser.newContext({ viewport: { width: 920, height: 650 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const callbacks = new Map();
|
||||
const listeners = new Map();
|
||||
window.__TEST__ = { calls: [], maximized: false, fail: "", resize: () => callbacks.get(listeners.get("tauri://resize"))?.({ payload: {} }) };
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "settings-main" }, currentWebview: { label: "settings-main" } },
|
||||
transformCallback: callback => { const id = callbacks.size + 1; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
window.__TEST__.calls.push(command);
|
||||
if (window.__TEST__.fail === command) throw new Error("Window action failed");
|
||||
if (command === "plugins_snapshot") return { root: "D:\\SettingsTest\\plugins", plugins: [] };
|
||||
if (command === "plugin:event|listen") { listeners.set(args.event, args.handler); return args.handler; }
|
||||
if (command === "plugin:window|is_maximized") return window.__TEST__.maximized;
|
||||
if (command === "plugin:window|toggle_maximize") window.__TEST__.maximized = !window.__TEST__.maximized;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const page = await context.newPage();
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
page.setDefaultTimeout(5000);
|
||||
await page.goto(`${url}/?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);
|
||||
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
|
||||
assert((await calls()).includes("plugin:window|minimize"));
|
||||
await page.getByRole("button", { name: "Maximize window", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Restore window", exact: true }).focus();
|
||||
await page.keyboard.press("Enter");
|
||||
await page.getByRole("button", { name: "Maximize window", exact: true }).waitFor();
|
||||
await page.evaluate(() => { window.__TEST__.maximized = true; window.__TEST__.resize(); });
|
||||
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Close window", exact: true }).focus();
|
||||
await page.getByRole("tooltip", { name: "Close window", exact: true }).waitFor();
|
||||
await page.keyboard.press("Space");
|
||||
const beforeEscape = (await calls()).filter(command => command === "plugin:window|close").length;
|
||||
assert.equal(beforeEscape, 1);
|
||||
await page.getByRole("textbox", { name: "Search settings" }).focus();
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal((await calls()).filter(command => command === "plugin:window|close").length, 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 button = dialog.getByRole("button", { name: label, exact: true });
|
||||
const bounds = await button.boundingBox();
|
||||
assert(bounds.x >= 0 && bounds.x + bounds.width <= size.width && bounds.height >= 28);
|
||||
assert.notEqual(await button.evaluate(element => getComputedStyle(element).borderTopLeftRadius), "0px");
|
||||
}
|
||||
await page.screenshot({ path: `.audit/settings-window-${theme}-${size.width}.png` });
|
||||
}
|
||||
}
|
||||
await page.evaluate(() => { window.__TEST__.fail = "plugin:window|minimize"; });
|
||||
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
|
||||
await dialog.getByRole("alert").filter({ hasText: "Window action failed" }).waitFor();
|
||||
await page.evaluate(() => { window.__TEST__.fail = ""; });
|
||||
await page.getByRole("button", { name: "Minimize window", exact: true }).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");
|
||||
const web = await browser.newPage();
|
||||
await web.goto(`${url}/?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(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.");
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,92 @@
|
||||
// Run against pnpm dev. Native IPC is mocked; this does not test the operating system title bar.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const origin = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const errors = [];
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 760 } });
|
||||
const watch = page => page.on("pageerror", error => errors.push(error.message));
|
||||
try {
|
||||
const main = await context.newPage(); watch(main);
|
||||
await main.goto(origin);
|
||||
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 context.newPage(); watch(settings);
|
||||
await settings.goto(`${origin}/?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 settings.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds), 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 settings.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds), 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 mkdir(".audit", { recursive: true });
|
||||
await settings.screenshot({ path: ".audit/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(`${origin}/`);
|
||||
|
||||
const desktop = await context.newPage(); watch(desktop);
|
||||
await desktop.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const callbacks = new Map();
|
||||
let sequence = 0;
|
||||
window.settingsTest = { opens: 0, fail: false, closes: 0 };
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "settings_open_window") {
|
||||
window.settingsTest.opens++;
|
||||
if (window.settingsTest.fail) throw new Error("Native window creation failed");
|
||||
await new Promise(resolve => setTimeout(resolve, 150));
|
||||
return;
|
||||
}
|
||||
if (command === "plugins_snapshot") return { root: "C:/plugins", plugins: [] };
|
||||
if (command === "workspace_last_path") return null;
|
||||
if (command === "plugin:event|listen") return args.handler;
|
||||
if (command === "plugin:event|unlisten") return;
|
||||
if (command === "plugin:window|is_maximized") return false;
|
||||
if (command === "plugin:window|close") { window.settingsTest.closes++; return; }
|
||||
throw new Error(`Unexpected IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
});
|
||||
await desktop.goto(origin);
|
||||
await desktop.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).dblclick();
|
||||
assert.equal(await desktop.evaluate(() => window.settingsTest.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.settingsTest.opens === 2);
|
||||
await desktop.waitForTimeout(180);
|
||||
await desktop.evaluate(() => { window.settingsTest.fail = true; });
|
||||
await desktop.keyboard.press("Control+,");
|
||||
await desktop.getByText(/Could not open settings: .*Native window creation failed/).waitFor();
|
||||
await desktop.goto(`${origin}/?settingsWindow=true`);
|
||||
await desktop.getByRole("heading", { name: "General", exact: true }).waitFor();
|
||||
await desktop.getByRole("button", { name: "Close window", exact: true }).click();
|
||||
assert.equal(await desktop.evaluate(() => window.settingsTest.closes), 1);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("Settings window smoke passed: preview fallback, standalone layout, two-way save sync, persistence, failed saves, native open requests, and close.");
|
||||
} finally { await browser.close(); }
|
||||
Reference in New Issue
Block a user