Files
RuneStone/tests/smoke/regressions/treeDragLinksAndGitToolbar.smoke.mjs
T
Knotty Wyvern c66ea1ce83 Add a smoke test runner, a shared harness, and safer build scripts
- pnpm smoke runs tests/smoke/ in parallel. It starts Vite when nothing
  serves SMOKE_URL, finds an installed Chrome when Playwright has no
  Chromium, and skips a test with a reason when a requirement that the
  test declares with "// @requires" is missing. Logs go to
  output/smoke/logs/.
- tests/smoke/_harness/ holds the Playwright launch, page error
  collection, the Tauri IPC mock with an in-memory workspace, and output
  folders. tabs/order uses it as the first converted test.
- Pin Playwright 1.63.0, the version that browser-runtime uses.
- RUNESTONE_PLUGIN_REPOS names the folder of the sibling plugin
  checkouts for buildPlugins, the menu audit, and the smoke tests.
- buildInstaller restores the version fields after Ctrl+C, keeps the
  backups of each attempt, stops when the browser runtime is not staged,
  and writes the file name instead of absolute paths to host.json.
- buildPlugins clears the staged Table Formulas package before copying.
- plugins/choiceMenus used the wrong Local Autocomplete folder name.
2026-10-27 19:55:49 -07:00

164 lines
10 KiB
JavaScript

// @requires repo:RuneStone_Git/dist
// Run against the host dev server with PLAYWRIGHT_MODULE and CHROME_PATH when needed.
import { createRequire } from "node:module";
import { readFile, mkdir } from "node:fs/promises";
import { resolve } from "node:path";
import assert from "node:assert/strict";
const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || "playwright");
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
const page = await context.newPage();
page.setDefaultTimeout(15000);
const errors = [];
page.on("pageerror", error => errors.push(error.message));
await page.addInitScript(() => {
window.isTauri = true;
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
const root = "C:\\kanban-root-smoke";
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="80"><rect width="100" height="80" fill="#639"/></svg>';
const files = new Map([
["notes/draft.md", "Before.\n\nAfter.\n"],
["files/report [Q1] (#1).pdf", "PDF fixture"],
["images/diagram (#1).svg", btoa(svg)],
]);
const calls = [], callbacks = new Map(), listeners = new Map(); let sequence = 0;
window.kanbanRootSmoke = { files, calls };
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
transformCallback(callback) { callbacks.set(++sequence, callback); return sequence; },
unregisterCallback(id) { callbacks.delete(id); },
async invoke(command, args = {}) {
calls.push({ command, args });
if (command === "plugin:event|listen") { const values = listeners.get(args.event) || []; values.push(args.handler); listeners.set(args.event, values); return args.handler; }
if (command === "plugin:event|unlisten" || command === "spelling_menu_install" || command === "spelling_menu_uninstall") return;
if (command === "workspace_last_path") return root;
if (command === "workspace_open") return { root, name: "kanban-root-smoke", watch_mode: "native" };
if (command === "workspace_read") { if (!files.has(args.rel)) throw Error("File missing"); return files.get(args.rel); }
if (command === "workspace_read_data_url") return "data:image/svg+xml;base64," + files.get(args.rel);
if (command === "workspace_write") {
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw Error("Save conflict");
files.set(args.rel, args.contents); return;
}
if (command === "workspace_list") {
const prefix = args.rel ? args.rel + "/" : "", entries = new Map();
for (const path of files.keys()) {
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
const tail = path.slice(prefix.length), name = tail.split("/")[0];
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
}
return [...entries.values()];
}
if (command === "workspace_search") return [];
if (command === "workspace_recent") return [root];
if (command === "plugins_snapshot") return { plugins: [], issues: [] };
if (command === "plugin:dialog|message") return "Cancel";
if (command.startsWith("plugin:window|") || command === "browser_stop") return;
throw Error("Unhandled IPC: " + command);
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener() {} };
});
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();
}
async function writerSource() { return page.evaluate(() => window.kanbanWriter.state.doc.toString()); }
async function ideSource() {
return page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
return monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected)?.getValue();
});
}
try {
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:5173");
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.kanbanWriter = 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.kanbanWriter.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("!["), "A document must be a link, not an image");
await page.evaluate(() => window.kanbanWriter.focus()); await page.keyboard.press("Control+z");
assert.equal(await writerSource(), original, "Writer undo restores the exact source");
await row("images").click();
await drag("images/diagram (#1).svg", ".cm-content");
await page.locator(".md-image-frame img").waitFor();
assert.ok((await writerSource()).includes("![](../images/diagram%20%28%231%29.svg)"));
await page.evaluate(() => window.kanbanWriter.focus()); await page.keyboard.press("Control+z");
assert.equal(await writerSource(), original);
await page.keyboard.press("Control+e");
await page.locator(".monaco-editor textarea").waitFor();
const originalIde = await ideSource();
await page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
window.kanbanMonaco = editor;
});
await drag("files/report [Q1] (#1).pdf", ".monaco-editor .view-lines");
await page.waitForFunction(() => window.kanbanMonaco.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.kanbanMonaco.focus());
assert.equal(await page.evaluate(() => window.kanbanMonaco.hasTextFocus()), true);
await page.keyboard.press("Control+z");
await page.waitForFunction(expected => window.kanbanMonaco.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("![](../images/diagram%20%28%231%29.svg)"));
assert.equal(await page.evaluate(() => window.kanbanRootSmoke.calls.filter(call => ["workspace_rename", "workspace_write_bytes"].includes(call.command)).length), 0);
console.log("PASS: real FileTree pointer drags insert escaped document links in Writer and IDE, undo restores both, and image drags still embed.");
// Load current Git source through the host origin without creating a distributable.
const gitRoot = process.env.RUNESTONE_GIT_ROOT || resolve("../RuneStone_Git");
const sources = new Map(await Promise.all(["view.js", "model.js"].map(async file => [file, await readFile(resolve(gitRoot, "src", file), "utf8")])));
await page.route("**/__kanban_git/*", route => route.fulfill({ contentType: "text/javascript", body: sources.get(new URL(route.request().url()).pathname.split("/").pop()) || "" }));
const css = await readFile(resolve(gitRoot, "src/style.css"), "utf8");
await page.evaluate(async css => {
const { mountSidebar } = await import("/__kanban_git/view.js");
const container = document.createElement("div"); container.id = "git-smoke"; container.style.cssText = "position:fixed;inset:45px 0 0 0;z-index:1000;background:var(--rs-bg)";
document.body.append(container);
window.gitGraphOpens = 0;
window.disposeGitSmoke = mountSidebar(container, {
workspace: {},
git: { status: async () => ({ available: true, repository: true, branch: "main", changes: [] }), pull: async () => {}, push: async () => {} },
openView: () => window.gitGraphOpens++,
}, css, () => {});
}, css);
const graph = page.locator("#git-smoke").getByRole("button", { name: "Graph", exact: true });
for (const theme of ["dark", "light"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
await graph.waitFor();
assert.equal(await graph.locator("svg").count(), 1);
assert.equal(await graph.getAttribute("title"), "Graph");
assert.equal(await graph.evaluate(node => [...node.childNodes].filter(child => child.nodeType === Node.TEXT_NODE && child.textContent.trim()).length), 0);
assert.equal(await graph.locator(":scope > :not(.rs-git-icon):not(.rs-git-tooltip)").count(), 0, "Graph has no visible text label");
await page.mouse.move(800, 800); await graph.evaluate(node => node.blur());
assert.equal(await graph.locator(".rs-git-tooltip").isVisible(), false);
await graph.hover(); await graph.locator(".rs-git-tooltip").waitFor({ state: "visible" });
await page.mouse.move(800, 800); await page.keyboard.press("Tab"); await graph.focus();
assert.equal(await graph.evaluate(node => node.matches(":focus-visible")), true);
await graph.locator(".rs-git-tooltip").waitFor({ state: "visible" });
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: `.audit/kanban-git-toolbar-${theme}.png` });
}
await graph.click(); assert.equal(await page.evaluate(() => window.gitGraphOpens), 1);
await page.evaluate(() => window.disposeGitSmoke());
assert.deepEqual(errors, []);
console.log("PASS: current Git Graph toolbar control is icon-only, keeps its accessible name, shows hover and focus tooltips in both themes, and opens Graph.");
} catch (error) {
await mkdir(".audit", { recursive: true });
await page.screenshot({ path: ".audit/kanban-root-failure.png" });
console.error(errors); throw error;
} finally { await browser.close(); }