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.
156 lines
9.3 KiB
JavaScript
156 lines
9.3 KiB
JavaScript
// Images dragged from the file tree: hidden source, selection, image menu actions, cancel, and source mode.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("editor/imageNavigation", async ({ page }) => {
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
// Image files hold base64 SVG.
|
|
const svg = btoa('<svg xmlns="http://www.w3.org/2000/svg" width="640" height="360"><rect width="640" height="360" fill="#486077"/><circle cx="320" cy="180" r="110" fill="#93cab5"/></svg>');
|
|
const workspace = test.workspace({
|
|
root: "C:\\smoke-workspace",
|
|
files: {
|
|
"notes/welcome.md": "Above.\n\nBelow.\n",
|
|
"notes/second.md": "# Second note\n",
|
|
"src/hello.py": "print('hello')\n",
|
|
"images/picture (#1).svg": svg,
|
|
"images/replacement.svg": svg,
|
|
},
|
|
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);
|
|
},
|
|
workspace_read_data_url: ({ rel }) => {
|
|
if (!workspace.files.has(rel)) throw new Error("missing image");
|
|
return "data:image/svg+xml;base64," + workspace.files.get(rel);
|
|
},
|
|
workspace_reveal: () => null,
|
|
};
|
|
},
|
|
});
|
|
const output = await outputDir("editor/imageNavigation");
|
|
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.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
|
});
|
|
}
|
|
async function source() { return page.evaluate(() => window.__CM__.state.doc.toString()); }
|
|
async function dragFromTree(selector = ".cm-content", cancel = false) {
|
|
const row = page.locator('[data-tree-rel="images/picture (#1).svg"]');
|
|
const from = await row.boundingBox(), to = await page.locator(selector).boundingBox();
|
|
await page.mouse.move(from.x + 60, from.y + from.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(to.x + 40, to.y + 10, { steps: 12 });
|
|
await page.getByText("Insert image", { exact: true }).waitFor();
|
|
assert.equal(await page.locator(".image-drop-target").count(), 1);
|
|
if (cancel) await page.keyboard.press("Escape");
|
|
await page.mouse.up();
|
|
}
|
|
async function imageMenu() {
|
|
await page.locator(".md-image-frame").first().click({ button: "right" });
|
|
await page.getByRole("menu", { name: "Image actions" }).waitFor();
|
|
}
|
|
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
|
await page.goto(smokeUrl);
|
|
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).click();
|
|
await writer();
|
|
await page.locator('[data-tree-rel="images"]').click();
|
|
await dragFromTree();
|
|
await page.locator(".md-image-frame img").waitFor();
|
|
const linked = await source();
|
|
assert.ok(linked.startsWith("\n\nAbove."), linked);
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => ["workspace_write_bytes", "workspace_rename"].includes(c.command)).length), 0);
|
|
assert.equal(await page.locator(".cm-line").filter({ hasText: "picture%20" }).count(), 0);
|
|
// Neither caret movement nor selection exposes an image's Markdown.
|
|
await page.evaluate(() => window.__CM__.dispatch({ selection: { anchor: 0, head: 38 } }));
|
|
assert.equal(await page.locator(".cm-line").filter({ hasText: "picture%20" }).count(), 0);
|
|
await page.locator(".md-image-frame img").click();
|
|
assert.equal(await page.locator(".md-image-frame.is-selected").count(), 1);
|
|
await page.keyboard.press("Shift+F10");
|
|
await page.getByRole("menu", { name: "Image actions" }).waitFor();
|
|
assert.equal(await page.locator(".md-image-frame.is-selected").count(), 1);
|
|
await page.screenshot({ path: `${output}/image-context-menu.png` });
|
|
await page.getByRole("menuitem", { name: "Copy Markdown", exact: true }).click();
|
|
assert.equal(await page.evaluate(() => navigator.clipboard.readText()), "");
|
|
await imageMenu();
|
|
await page.getByRole("menuitem", { name: "Copy image", exact: true }).click();
|
|
await page.waitForFunction(async () => (await navigator.clipboard.read()).some(item => item.types.includes("image/png")));
|
|
await imageMenu();
|
|
await page.getByRole("menuitem", { name: "Show in Explorer", exact: true }).click();
|
|
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "workspace_reveal" && c.args.rel === "images/picture (#1).svg"));
|
|
await imageMenu();
|
|
await page.getByRole("menuitem", { name: "Remove image", exact: true }).click();
|
|
assert.ok(!(await source()).includes("picture%20"));
|
|
assert.ok(await page.evaluate(() => window.__TEST__.files.has("images/picture (#1).svg")));
|
|
await page.keyboard.press("Control+z");
|
|
assert.equal(await source(), linked);
|
|
|
|
await page.locator(".md-image-frame").hover();
|
|
await page.getByRole("button", { name: "Edit image source", exact: true }).click();
|
|
await page.locator(".cm-line").filter({ hasText: "picture%20" }).waitFor();
|
|
assert.equal(await page.locator(".md-image-frame img").count(), 1);
|
|
await page.getByRole("button", { name: "Hide image source", exact: true }).click();
|
|
assert.equal(await page.locator(".cm-line").filter({ hasText: "picture%20" }).count(), 0);
|
|
await imageMenu();
|
|
await page.getByRole("menuitem", { name: "Swap image…", exact: true }).click();
|
|
await page.getByRole("textbox", { name: "Image path relative to this note, or https URL" }).fill("../images/replacement.svg");
|
|
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
|
await page.waitForFunction(() => window.__CM__.state.doc.toString().includes("replacement.svg"));
|
|
assert.equal(await page.locator(".cm-line").filter({ hasText: "replacement.svg" }).count(), 0);
|
|
await imageMenu();
|
|
await page.getByRole("menuitem", { name: "Open in new tab", exact: true }).click();
|
|
await page.getByRole("tab", { name: "replacement.svg", exact: true }).waitFor();
|
|
await page.getByRole("tab", { name: /welcome.md/ }).click();
|
|
await writer();
|
|
|
|
const beforeCancel = await source();
|
|
await dragFromTree(".cm-content", true);
|
|
assert.equal(await source(), beforeCancel);
|
|
assert.equal(await page.locator(".image-drop-target").count(), 0);
|
|
// Inline images remain independently selectable without hiding adjacent prose.
|
|
await page.evaluate(() => {
|
|
const view = window.__CM__;
|
|
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "Before  between ![[../images/replacement.svg]] after.\n" }, selection: { anchor: 0 } });
|
|
});
|
|
await page.waitForFunction(() => document.querySelectorAll(".md-image-frame").length === 2);
|
|
assert.ok((await page.locator(".cm-content").innerText()).includes("Before"));
|
|
assert.ok(!(await page.locator(".cm-content").innerText()).includes("![]"));
|
|
await page.locator(".md-image-frame img").nth(1).click();
|
|
await page.keyboard.press("Delete");
|
|
assert.equal(await source(), "Before  between after.\n");
|
|
await page.keyboard.press("Control+z");
|
|
assert.ok((await source()).includes("![[../images/replacement.svg]]"));
|
|
// Reference-image editing affects only the selected embed, not its definition.
|
|
await page.evaluate(() => {
|
|
const view = window.__CM__;
|
|
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "![Reference][pic]\n\nBelow.\n\n[pic]: ../images/replacement.svg\n" }, selection: { anchor: 0 } });
|
|
});
|
|
await page.locator(".md-image-frame").hover();
|
|
assert.equal(await page.locator(".cm-line").filter({ hasText: "![Reference]" }).count(), 0);
|
|
await page.getByRole("button", { name: "Edit image source", exact: true }).click();
|
|
await page.locator(".cm-line").filter({ hasText: "![Reference]" }).waitFor();
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await page.locator(".cm-line").filter({ hasText: "![Reference]" }).count(), 0);
|
|
// The same navigator drag works in the source editor.
|
|
// The layout switcher names its buttons by mode (src/lib/layout/EditorPane.svelte:200-208, src/lib/ui/ModeSwitcher.svelte:96).
|
|
await page.getByRole("group", { name: "Editor layout", exact: true }).hover();
|
|
await page.getByRole("button", { name: "IDE", exact: true }).click();
|
|
await page.locator(".monaco-editor textarea").waitFor();
|
|
await dragFromTree(".monaco-editor .view-lines");
|
|
await page.keyboard.press("Control+s");
|
|
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").includes("picture%20"));
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_write_bytes").length), 0);
|
|
console.log("Navigator image drag, hidden source, selection, copy, swap, remove, open, reveal, cancel and source mode passed.");
|
|
});
|