Phase 4b. DocumentEditor.svelte replaces LiveWriter.svelte and the Monaco EditorHost.svelte. Each open document has one CodeMirror state. Write and Source are two compartment configurations of it, so they share the undo history. editorStates.ts keeps the state while the tab stays open. The Monaco model, the diff bridge, its timers, and sessions.ts are gone. - Source: syntax colors from the theme tokens, lazy language packages, line numbers, folding, and the current line in IDE, wrapped lines in Writing, several carets, and bracket matching and closing. - Lists (card 088e778b): Tab nests a list item and Shift+Tab moves it up, in Write and Source. Both renumber the list. The source keeps "1.". Write and Read show numbers, letters, then Roman numerals. - Indent (card 696c30ce): a fixed 4 spaces in Write and Source. - The code menu uses CodeMirror commands. The command palette item and the Monaco styles, search, theme, and workers are removed. - @codemirror/legacy-modes is pinned to 6.5.4. Version 6.5.5 uses parser types that do not match @codemirror/language 6.12. - 26 smoke tests use CodeMirror instead of Monaco. New tests: editor/listNesting and the markdownLists unit tests. - Docs: development, UI design, plugin host, user guide, and UI-040. pnpm check, pnpm test (341 of 341), and pnpm build pass. The full smoke suite passes, except one template test that passed on retry.
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+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: 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.");
|
|
});
|