Files
RuneStone/tests/smoke/editor/markdownMenu.smoke.mjs
T
Knotty Wyvern 69f90df571 Move the smoke tests onto the shared harness
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.
2026-10-27 20:58:55 -07:00

154 lines
9.6 KiB
JavaScript

// Markdown text menu in source and writing modes: formatting, paragraphs, tables, links, extraction, clipboard, and stale selections.
import assert from "node:assert/strict";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("editor/markdownMenu", async ({ page }) => {
await mockTauri(page, {
commands: test => {
const workspace = test.workspace({
root: "C:\\smoke-workspace",
files: {
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
"notes/second.md": "# Second note\n",
"src/hello.py": "print('hello')\n",
},
writeEvents: true,
});
test.files = workspace.files;
return {
...workspace,
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
workspace_write: args => {
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
return workspace.workspace_write(args);
},
};
},
});
const output = await outputDir("editor/markdownMenu");
async function quickOpen(name) {
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
await page.getByRole("tab", { selected: true }).click({ button: "right" });
await page.getByRole("menuitem", { name: "Source mode", exact: true }).click();
await page.locator(".monaco-editor textarea").waitFor();
}
async function waitForText(text) {
await page.evaluate(async () => { window.__MONACO__ = (await import("/src/lib/editor/monacoEnv.ts")).monaco; });
await page.waitForFunction(expected => window.__MONACO__.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getValue() === expected), text);
}
await page.goto(smokeUrl);
await page.getByText("smoke-workspace", { exact: true }).waitFor();
await quickOpen("welcome.md");
const source = "First paragraph.\n\nSecond paragraph.\n";
await page.evaluate(async value => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
editor.setValue(value);
editor.setSelection(new monaco.Selection(1, 1, 1, 6)); editor.focus();
}, source);
const menu = page.getByRole("menu", { name: "Markdown text actions", exact: true });
await page.keyboard.press("Shift+F10");
await menu.waitFor();
await menu.getByRole("menuitem", { name: "Format", exact: true }).hover();
await menu.getByRole("menuitem", { name: "Bold", exact: true }).click();
await waitForText("**First** paragraph.\n\nSecond paragraph.\n");
await page.keyboard.press("Control+z"); await waitForText(source);
await page.getByRole("tab", { selected: true }).click({ button: "right" });
await page.getByRole("menuitem", { name: "Writing mode", exact: true }).click();
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
await writer.click(); await page.keyboard.press("Control+Home");
await page.keyboard.press("Control+Shift+ArrowRight");
await page.keyboard.press("Shift+F10"); await menu.waitFor();
await menu.getByRole("menuitem", { name: "Format", exact: true }).hover();
await menu.getByRole("menuitem", { name: "Italic", exact: true }).click();
await page.keyboard.press("Control+s");
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md") === "*First* paragraph.\n\nSecond paragraph.\n");
await page.keyboard.press("Control+z");
await page.keyboard.press("Control+Home");
await page.keyboard.press("Shift+F10");
await menu.getByRole("menuitem", { name: "Paragraph", exact: true }).hover();
await menu.getByRole("menuitem", { name: "Heading 2", exact: true }).click();
await page.keyboard.press("Control+s");
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("## First paragraph."));
await page.keyboard.press("Control+z");
await page.keyboard.press("Control+End");
await page.keyboard.press("Shift+F10");
await menu.getByRole("menuitem", { name: "Insert", exact: true }).hover();
await menu.getByRole("menuitem", { name: "Table", exact: true }).click();
await page.locator(".live-writer table").waitFor();
await page.keyboard.press("Control+z");
await page.keyboard.press("Control+Home");
await page.keyboard.press("Control+Shift+ArrowRight");
// Mouse invocation must preserve the selection, too.
await page.locator(".cm-line").filter({ hasText: "First paragraph." }).click({ button: "right", position: { x: 12, y: 10 } });
await menu.waitFor();
await menu.getByRole("menuitem", { name: "Format", exact: true }).hover();
await menu.getByRole("menuitem", { name: "Highlight", exact: true }).click();
await page.keyboard.press("Control+s");
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("==First== paragraph."));
await page.keyboard.press("Control+End");
await page.locator(".writer-highlight").waitFor();
assert.equal(await page.locator(".writer-highlight").textContent(), "First");
await page.keyboard.press("Control+z");
await page.keyboard.press("Control+End");
await page.keyboard.press("Shift+F10");
await menu.getByRole("menuitem", { name: "Insert", exact: true }).hover();
await page.screenshot({ path: `${output}/markdown-insert-menu.png` });
await page.keyboard.press("Escape");
await page.setViewportSize({ width: 760, height: 600 });
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
await writer.focus();
await page.keyboard.press("Shift+F10");
await menu.getByRole("menuitem", { name: "Paragraph", exact: true }).focus();
await page.keyboard.press("ArrowRight");
assert.equal(await page.evaluate(() => document.activeElement.textContent), "Bullet list");
const rect = await menu.getByRole("menu", { name: "Paragraph", exact: true }).boundingBox();
assert.ok(rect.x >= 0 && rect.y >= 0 && rect.x + rect.width <= 760 && rect.y + rect.height <= 600);
await page.screenshot({ path: `${output}/markdown-paragraph-menu.png` });
await page.keyboard.press("ArrowLeft");
assert.equal(await page.evaluate(() => document.activeElement.textContent), "Paragraph");
await page.keyboard.press("Escape");
await page.keyboard.press("Control+Home");
await page.keyboard.press("Control+Shift+ArrowRight");
await page.keyboard.press("Shift+F10");
await menu.getByRole("menuitem", { name: "Add external link", exact: true }).click();
// External links insert `[label]()` with the caret in the URL, without a dialog (src/lib/editor/markdownMenu.ts:57, src/lib/editor/linkCommands.ts:3-8).
assert.equal(await page.getByRole("dialog").count(), 0);
await page.keyboard.type("https://example.com/a");
await page.keyboard.press("Control+s");
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("[First](https://example.com/a) paragraph."));
// Undo the typed URL, then the link, which restores the selected label.
await page.keyboard.press("Control+z");
await page.keyboard.press("Control+z");
await page.evaluate(async () => {
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
});
await page.waitForFunction(() => window.__CM__.state.sliceDoc().startsWith("First paragraph."));
await page.keyboard.press("Shift+F10");
await menu.getByRole("menuitem", { name: "Extract current selection…", exact: true }).click();
await page.getByRole("textbox", { name: "Extract selection to a new note (workspace relative path)" }).fill("notes/extracted.md");
await page.getByRole("button", { name: "Continue", exact: true }).click();
await page.keyboard.press("Control+s");
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("[[/notes/extracted.md|First]] paragraph."));
assert.equal(await page.evaluate(() => window.__TEST__.files.get("notes/extracted.md")), "First\n");
await page.keyboard.press("Control+z");
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
await page.evaluate(() => navigator.clipboard.writeText("Pasted"));
await page.keyboard.press("Shift+F10");
await menu.getByRole("menuitem", { name: "Paste as plain text", exact: true }).click();
await page.waitForFunction(() => document.querySelector(".cm-content")?.textContent.includes("Pasted paragraph."));
await page.keyboard.press("Control+s");
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("Pasted paragraph."));
await page.evaluate(() => { navigator.clipboard.readText = () => new Promise(resolve => { window.__finishPaste = resolve; }); });
await page.keyboard.press("Shift+F10");
await menu.getByRole("menuitem", { name: "Paste as plain text", exact: true }).click();
await writer.focus(); await page.keyboard.press("End"); await page.keyboard.type(" kept");
await page.evaluate(async () => { window.__finishPaste("STALE"); await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); });
assert.ok(!(await writer.textContent()).includes("STALE"));
assert.ok((await writer.textContent()).includes("kept"));
console.log("PASS: Markdown menus in source/writing modes, selection retention, formatting, paragraph conversion, table insertion, undo, keyboard navigation, narrow viewport, links, extraction, clipboard and stale-selection guards.");
});