Phase 5-2. - Ctrl+Shift+P opens the command palette: every workbench command with its shortcut, then the plugin commands (UI-048). - In Write, Ctrl+B, Ctrl+I, Ctrl+Shift+X, and Ctrl+Shift+H format the selection, and Ctrl+K inserts a Markdown link. The Format menu shows these shortcuts. - Ctrl+\ toggles the side pane. It matches the physical key on every keyboard layout. Ctrl+B now belongs to Write. - Help lists every shortcut in groups, open by default. The list comes from the command table. - src/lib/ui/shortcuts.ts writes shortcut labels for the platform: Ctrl+Shift+P on Windows and Linux, and the macOS symbols on a Mac. The catalog uses placeholders, so no translation contains "Ctrl". - 19 new catalog rows, and 10 rows converted to placeholders, in French, Japanese, and Simplified Chinese. - Docs: UI-048, the user guide keyboard tables, and a label rule in ui-design.md. New tests: layout/commands, tests/unit/ui/shortcuts.spec.ts, and new cases in workbenchKeys.spec.ts. Tests that read the old labels or pressed Ctrl+B for the side pane now use the new names and Ctrl+\. The smoke harness raises the resource timing buffer to 5000 entries. The new modules pushed the CodeMirror language module past the default 250 entries, so editor/markdownPaste could not find its URL.
166 lines
8.0 KiB
JavaScript
166 lines
8.0 KiB
JavaScript
// 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.");
|
|
});
|