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.
82 lines
4.7 KiB
JavaScript
82 lines
4.7 KiB
JavaScript
// File tree drags into Writer and the IDE: documents become escaped links, images embed, and undo restores the source.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("links/fileDragLinks", async ({ page }) => {
|
|
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="80"><rect width="100" height="80" fill="#639"/></svg>';
|
|
const workspace = test.workspace({
|
|
root: "C:\\file-drag-links",
|
|
files: { "notes/draft.md": "Before.\n\nAfter.\n", "files/report [Q1] (#1).pdf": "PDF fixture", "images/diagram (#1).svg": btoa(svg) },
|
|
});
|
|
return {
|
|
...workspace,
|
|
workspace_read_data_url: ({ rel }) => "data:image/svg+xml;base64," + workspace.files.get(rel),
|
|
plugins_snapshot: () => ({ plugins: [], issues: [] }),
|
|
spelling_menu_install: () => null,
|
|
};
|
|
},
|
|
});
|
|
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
|
async function drag(path, target) {
|
|
const from = await row(path).boundingBox(), to = await page.locator(target).boundingBox();
|
|
assert.ok(from && to, "The file and editor must be visible");
|
|
await page.mouse.move(from.x + Math.min(80, from.width / 2), from.y + from.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(to.x + 45, to.y + 12, { steps: 15 });
|
|
await page.locator(".image-drop-target").waitFor();
|
|
await page.mouse.up();
|
|
}
|
|
const writerSource = () => page.evaluate(() => window.dragWriter.state.doc.toString());
|
|
const ideSource = () => page.evaluate(() => window.dragMonaco.getValue());
|
|
|
|
await page.goto(smokeUrl);
|
|
await row("notes").click();
|
|
await row("notes/draft.md").dblclick();
|
|
await page.locator(".cm-content").waitFor();
|
|
await page.evaluate(async () => {
|
|
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
|
window.dragWriter = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
|
});
|
|
await row("files").click();
|
|
const original = await writerSource();
|
|
await drag("files/report [Q1] (#1).pdf", ".cm-content");
|
|
await page.waitForFunction(() => window.dragWriter.state.doc.toString().includes(".pdf)"));
|
|
const linked = await writerSource();
|
|
assert.ok(linked.includes("[report \\[Q1\\] (#1).pdf](../files/report%20%5BQ1%5D%20%28%231%29.pdf)"), linked);
|
|
assert.ok(!linked.includes(""));
|
|
await page.evaluate(() => window.dragWriter.focus());
|
|
await page.keyboard.press("Control+z");
|
|
assert.equal(await writerSource(), original);
|
|
console.log("PASS: Writer drags insert escaped document links and image embeds, and undo restores the source");
|
|
|
|
await page.keyboard.press("Control+e");
|
|
await page.locator(".monaco-editor textarea").waitFor();
|
|
await page.evaluate(async () => {
|
|
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
|
window.dragMonaco = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
|
|
});
|
|
const originalIde = await ideSource();
|
|
await drag("files/report [Q1] (#1).pdf", ".monaco-editor .view-lines");
|
|
await page.waitForFunction(() => window.dragMonaco.getValue().includes(".pdf)"));
|
|
assert.ok((await ideSource()).includes("[report \\[Q1\\] (#1).pdf](../files/report%20%5BQ1%5D%20%28%231%29.pdf)"));
|
|
await page.evaluate(() => window.dragMonaco.focus());
|
|
assert.equal(await page.evaluate(() => window.dragMonaco.hasTextFocus()), true);
|
|
await page.keyboard.press("Control+z");
|
|
await page.waitForFunction(expected => window.dragMonaco.getValue() === expected, originalIde, { timeout: 3000 });
|
|
assert.equal(await ideSource(), originalIde, "IDE undo restores the exact source");
|
|
await drag("images/diagram (#1).svg", ".monaco-editor .view-lines");
|
|
assert.ok((await ideSource()).includes(""));
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(call => ["workspace_rename", "workspace_write_bytes"].includes(call.command)).length), 0);
|
|
console.log("PASS: IDE drags insert escaped document links and image embeds, undo restores the source, and no file moves");
|
|
}, { timeout: 15000 });
|