Files
RuneStone/tests/smoke/editor/imageNavigation.smoke.mjs
T
Knotty Wyvern 9cf82503d0 Show one view control and name the file once
Phase 5-3.

- One radio group shows Write, Source, and Read at all times, with an
  icon and a name. Narrow panes show only the icons. The arrow keys
  move the choice, and the group has one Tab stop. The current choice
  gets the selection fill and an accent bar. Hover gets only a fill.
- A Split toggle shows Read beside Write or Source. Each document pane
  keeps a split flag beside its reading flag. Read ends Split.
- Ctrl+Shift+E switches between Read and the editor. Ctrl+E still
  switches between Write and Source.
- "IDE" becomes "Source" in the Chrome type, the tab menu (a View
  submenu), the status bar, the catalog, the tests, and the docs.
- Settings, General, File name title hides the title in Write and
  Read. It is on by default.
- The breadcrumb shows only the folder of the file. The status bar
  shows the view, not the path.
- ModeSwitcher.svelte and its hover test are gone. The new test
  layout/viewModes covers the control.
- The command palette from 5-2 gets its row in docs/menu-surfaces.json.
- The user guide Format table is whole again. The 5-2 edit had put
  the Paragraph and Insert rows under the shortcut table.
- 8 new catalog rows and 10 removed rows, in French, Japanese, and
  Simplified Chinese.
- Docs: UI-049, the user guide, ui-design.md, document-tools.md,
  development.md, and the README feature list.

Tests: the new layout/viewModes, new cases in documentPanes.spec.ts
and settings.spec.ts, and the chooseView harness helper. 21 smoke
tests use the new control. Tests that read the full path from the
breadcrumb now read its tooltip.
2026-10-28 19:45:08 -07:00

154 lines
9.0 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 { chooseView, 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("![](../images/picture%20%28%231%29.svg)\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()), "![](../images/picture%20%28%231%29.svg)");
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 ![](../images/replacement.svg) 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 ![](../images/replacement.svg) 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.
await chooseView(page, "Source");
await page.locator(".source-editor .cm-content").waitFor();
await dragFromTree(".source-editor .cm-content");
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.");
});