Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri IPC mock, the in-memory workspace, and output folders, instead of its own copy. The tests keep their interactions and assertions. Mock handlers that the app never calls are gone. - Split the four mixed regression scripts into 18 feature tests. - Update tests that broke when the app changed on purpose. Each update cites the app source that shows the new behavior. - Mark two real app defects with @known-issue: the settings window controls are 1px shorter than the main window controls, and plugin tabs cannot be reordered by dragging without a workspace. - Merge three palette unit tests into one table-driven test. - The native tests load Playwright through the harness and read NATIVE_CDP_URL, with their old variable names as fallbacks. - A failed smoke test saves a screenshot and prints the console errors. - The runner runs failed tests once more, alone, and reports a test that then passes as flaky. Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78 passed.
132 lines
9.1 KiB
JavaScript
132 lines
9.1 KiB
JavaScript
// Writer interactions: code selection and copy, caret and scroll restore, Ctrl+click links, shared heading typography, and spelling targets.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("editor/interactions", async ({ page }) => {
|
|
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
|
await mockTauri(page, {
|
|
commands: test => ({
|
|
...test.workspace({
|
|
root: "C:\\editor-interactions-smoke",
|
|
files: {
|
|
"note.md": "# Stack\n\nHardware can be reused.\nAssume speeds of 1 Gb/s.\n\n## Hardware\n\n### Router\n\n- [ ] First task\n- [ ] Second task\n\n[Local](other.md) and [Web](https://example.com) and [[other|Wiki]]\n\n```sh\npnpm install --frozen-lockfile\npnpm check\npnpm test\n```\n\n" + Array.from({ length: 80 }, (_, i) => `Paragraph ${i}.\n\n`).join("") + "```js\nconst preserve = 42;\nconsole.log(preserve);\n```\n",
|
|
"other.md": "# Other document\n\nKeep the original tab.\n",
|
|
},
|
|
}),
|
|
"plugin:opener|open_url": () => null,
|
|
spelling_menu_install: () => null,
|
|
}),
|
|
});
|
|
async function writer() {
|
|
await page.locator(".cm-content").waitFor();
|
|
await page.evaluate(async () => {
|
|
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
|
window.writerView = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
|
});
|
|
}
|
|
async function top() {
|
|
await writer();
|
|
await page.evaluate(() => { window.writerView.dispatch({ selection: { anchor: 0 } }); window.writerView.scrollDOM.scrollTop = 0; });
|
|
}
|
|
await page.goto(smokeUrl);
|
|
await page.locator('[data-tree-rel="note.md"]').dblclick();
|
|
await writer();
|
|
const code = page.locator(".writer-code-line").filter({ hasText: "pnpm install" });
|
|
await code.scrollIntoViewIfNeeded();
|
|
const points = await page.evaluate(() => {
|
|
const view = window.writerView, from = view.state.doc.toString().indexOf("pnpm install");
|
|
return { from: view.coordsAtPos(from), to: view.coordsAtPos(from + 12) };
|
|
});
|
|
await page.mouse.move(points.from.left + 1, (points.from.top + points.from.bottom) / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(points.to.left, (points.to.top + points.to.bottom) / 2, { steps: 8 });
|
|
await page.mouse.up();
|
|
assert.match(await page.evaluate(() => { const view = window.writerView; return view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to); }), /pnpm install/);
|
|
// A selection inside a code block shows its source and hides the copy button (src/lib/editor/liveMarkdown.ts:246-247).
|
|
// Move the caret out of the block, as a reader would before copying.
|
|
await page.evaluate(() => { window.writerView.dispatch({ selection: { anchor: 0 } }); });
|
|
await page.getByRole("button", { name: "Copy code", exact: true }).first().click();
|
|
assert.equal((await page.evaluate(() => navigator.clipboard.readText())).replace(/\r\n/g, "\n"), "pnpm install --frozen-lockfile\npnpm check\npnpm test\n");
|
|
console.log("PASS: first drag selects code and the copy button copies only the code body");
|
|
|
|
await page.evaluate(() => { const view = window.writerView; view.dispatch({ selection: { anchor: view.state.doc.toString().indexOf("preserve =") + 5 }, scrollIntoView: true }); view.focus(); });
|
|
await page.keyboard.type("X");
|
|
await page.waitForTimeout(250);
|
|
const saved = await page.evaluate(() => ({ head: window.writerView.state.selection.main.head, scroll: window.writerView.scrollDOM.scrollTop, doc: window.writerView.state.sliceDoc(), height: window.writerView.scrollDOM.scrollHeight, caret: window.writerView.coordsAtPos(window.writerView.state.selection.main.head) }));
|
|
assert.ok(saved.scroll > 1000);
|
|
await page.locator('[data-tree-rel="other.md"]').dblclick();
|
|
await writer();
|
|
await page.getByRole("tab", { name: "note.md", exact: true }).click();
|
|
await writer();
|
|
await page.waitForTimeout(250);
|
|
const restored = await page.evaluate(() => ({ head: window.writerView.state.selection.main.head, scroll: window.writerView.scrollDOM.scrollTop, doc: window.writerView.state.sliceDoc(), height: window.writerView.scrollDOM.scrollHeight, caret: window.writerView.coordsAtPos(window.writerView.state.selection.main.head) }));
|
|
assert.equal(restored.head, saved.head);
|
|
assert.equal(restored.doc, saved.doc);
|
|
assert.ok(Math.abs(restored.caret.top - saved.caret.top) < 3, JSON.stringify({ saved, restored }));
|
|
await page.evaluate(() => { window.dispatchEvent(new Event("blur")); window.dispatchEvent(new Event("focus")); });
|
|
await page.waitForTimeout(150);
|
|
assert.equal(await page.evaluate(() => window.writerView.state.selection.main.head), saved.head);
|
|
console.log("PASS: code edit, caret, and scroll survive tab and window focus changes");
|
|
|
|
await top();
|
|
await page.locator('.writer-link[data-href="other.md"]').click({ modifiers: ["Control"] });
|
|
await page.getByRole("tab", { name: "other.md", exact: true }).waitFor();
|
|
assert.equal(await page.getByRole("tab", { name: "note.md", exact: true }).count(), 1);
|
|
await page.getByRole("tab", { name: "note.md", exact: true }).click();
|
|
await top();
|
|
await page.locator('.writer-link[data-href="https://example.com"]').click({ modifiers: ["Control"] });
|
|
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "plugin:opener|open_url" && call.args.url === "https://example.com"));
|
|
await page.keyboard.press("Control+e");
|
|
await page.locator(".monaco-editor").waitFor();
|
|
const linkPoint = await page.evaluate(async () => {
|
|
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
|
const view = monaco.editor.getEditors().find(view => view.getDomNode()?.isConnected);
|
|
const position = view.getModel().getPositionAt(view.getValue().indexOf("[Local]") + 3);
|
|
view.revealPositionInCenter(position);
|
|
view.setPosition(position); view.focus();
|
|
return position;
|
|
});
|
|
await page.waitForTimeout(300);
|
|
const point = await page.evaluate(async position => {
|
|
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
|
const view = monaco.editor.getEditors().find(view => view.getDomNode()?.isConnected), rect = view.getDomNode().getBoundingClientRect(), coords = view.getScrolledVisiblePosition(position);
|
|
return { x: rect.left + coords.left + 2, y: rect.top + coords.top + coords.height / 2 };
|
|
}, linkPoint);
|
|
await page.keyboard.down("Control"); await page.mouse.click(point.x, point.y); await page.keyboard.up("Control");
|
|
await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent.includes("other.md"));
|
|
console.log("PASS: Writer and IDE Ctrl+click open workspace links while retaining the source tab");
|
|
|
|
await page.getByRole("tab", { name: "note.md", exact: true }).click();
|
|
await page.keyboard.press("Control+e");
|
|
await top();
|
|
const output = await outputDir("editor/interactions");
|
|
for (const theme of ["dark", "light"]) {
|
|
await page.evaluate(async mode => {
|
|
const { applyAppearance, parseAppearance } = await import("/src/lib/theme/appearance.ts");
|
|
applyAppearance({ ...parseAppearance(null), mode });
|
|
}, theme);
|
|
const writing = await page.locator(".writer-h1").first().evaluate(node => { const style = getComputedStyle(node); return { size: style.fontSize, line: style.lineHeight, family: style.fontFamily, weight: style.fontWeight }; });
|
|
await page.screenshot({ path: `${output}/editor-typography-${theme}.png` });
|
|
await page.getByRole("group", { name: "Document view", exact: true }).hover();
|
|
await page.getByRole("button", { name: "Read", exact: true }).click();
|
|
const reading = await page.locator(".reading h1:not(.document-title)").first().evaluate(node => { const style = getComputedStyle(node); return { size: style.fontSize, line: style.lineHeight, family: style.fontFamily, weight: style.fontWeight }; });
|
|
assert.deepEqual(writing, reading);
|
|
await page.screenshot({ path: `${output}/reader-typography-${theme}.png` });
|
|
await page.getByRole("group", { name: "Document view", exact: true }).hover();
|
|
await page.getByRole("button", { name: "Edit", exact: true }).click();
|
|
await top();
|
|
}
|
|
await page.setViewportSize({ width: 640, height: 750 });
|
|
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
|
await page.screenshot({ path: `${output}/editor-typography-narrow.png` });
|
|
assert.ok(await page.locator(".cm-content").evaluate(node => node.getBoundingClientRect().width <= node.closest(".cm-scroller").getBoundingClientRect().width + 1));
|
|
const spelling = await page.evaluate(async () => {
|
|
const { isSpellingTarget } = await import("/src/lib/editor/spellingMenu.ts");
|
|
const area = document.createElement("textarea"); area.spellcheck = true; document.body.append(area);
|
|
const active = isSpellingTarget(area); area.readOnly = true; const readOnly = isSpellingTarget(area); area.remove();
|
|
return { active, readOnly };
|
|
});
|
|
assert.deepEqual(spelling, { active: true, readOnly: false });
|
|
console.log("PASS: shared heading typography in both themes, narrow Writer, and textarea spelling target");
|
|
}, { viewport: { width: 1280, height: 900 }, timeout: 15000 });
|