Improve workspace navigation, search, and tab actions
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\smoke-workspace";
|
||||
const files = new Map([
|
||||
["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"],
|
||||
]);
|
||||
const callbacks = new Map();
|
||||
const listeners = new Map();
|
||||
let sequence = 0;
|
||||
const calls = [];
|
||||
const emit = (event, payload) => {
|
||||
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
|
||||
};
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === "plugin:event|listen") {
|
||||
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "smoke-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
|
||||
}
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "";
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "pty_open") {
|
||||
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
|
||||
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
|
||||
emit("pty-data", { id: args.id, data: data.slice(8) });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return;
|
||||
}
|
||||
if (command.startsWith("pty_")) return;
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.__TEST__ = { files, calls, emit, root };
|
||||
});
|
||||
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
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" }).first().click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
const contents = () => page.evaluate(() => window.__CM__.state.sliceDoc());
|
||||
const cursor = () => page.evaluate(() => window.__CM__.state.selection.main.head);
|
||||
async function select(anchor, head = anchor) {
|
||||
await page.evaluate(({ anchor, head }) => {
|
||||
window.__CM__.dispatch({ selection: { anchor, head }, scrollIntoView: true });
|
||||
window.__CM__.focus();
|
||||
}, { anchor, head });
|
||||
}
|
||||
for (const block of ["```js\nconst value = 123;\nsecond line\n```", "~~~text\nconst value = 123;\nsecond line\n~~~", " const value = 123;\n second line"]) {
|
||||
const original = `Above.\n\n${block}\n\nBelow.\n`;
|
||||
await page.evaluate(value => {
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: value }, selection: { anchor: 0 } });
|
||||
}, original);
|
||||
await page.locator(".writer-preview pre").click();
|
||||
await page.locator(".writer-code-source").first().waitFor();
|
||||
const position = original.indexOf("123") + 1;
|
||||
await select(position);
|
||||
await page.keyboard.press("Backspace");
|
||||
assert.equal(await contents(), original.slice(0, position - 1) + original.slice(position));
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await contents(), original);
|
||||
await select(position);
|
||||
await page.keyboard.press("Delete");
|
||||
assert.equal(await contents(), original.slice(0, position) + original.slice(position + 1));
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await contents(), original);
|
||||
await select(position);
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await cursor(), position + 1);
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await cursor(), position);
|
||||
await page.keyboard.type("X");
|
||||
assert.equal(await contents(), original.slice(0, position) + "X" + original.slice(position));
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await contents(), original);
|
||||
await select(position - 1, position + 2);
|
||||
await page.keyboard.press("Backspace");
|
||||
const edited = original.slice(0, position - 1) + original.slice(position + 2);
|
||||
assert.equal(await contents(), edited);
|
||||
await select(0);
|
||||
assert.ok((await page.locator(".writer-preview pre").textContent()).includes("const value = ;"));
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(value => window.__TEST__.files.get("notes/welcome.md") === value, edited);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: Fenced and indented code editing, character deletion, selection deletion, cursor movement, undo, preview and save.");
|
||||
} catch (error) {
|
||||
console.error("Browser errors:", errors);
|
||||
await page.screenshot({ path: ".audit/code-blocks-failure.png" });
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,138 @@
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\smoke-workspace";
|
||||
const files = new Map([
|
||||
["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"],
|
||||
]);
|
||||
const callbacks = new Map();
|
||||
const listeners = new Map();
|
||||
let sequence = 0;
|
||||
const calls = [];
|
||||
const emit = (event, payload) => {
|
||||
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
|
||||
};
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === "plugin:event|listen") {
|
||||
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "smoke-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
|
||||
}
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "";
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "pty_open") {
|
||||
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
|
||||
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
|
||||
emit("pty-data", { id: args.id, data: data.slice(8) });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return;
|
||||
}
|
||||
if (command.startsWith("pty_")) return;
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.__TEST__ = { files, calls, emit, root };
|
||||
});
|
||||
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
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" }).first().click();
|
||||
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await writer.waitFor();
|
||||
const dividers = "content\n___\ncontent\n***\n\n---\n\n* * *\n\n_ _ _\n\n- - -\n\nHeading\n---\n\n`___`\n\n```text\n___\n```\n\n ***\n\nEnd\n";
|
||||
await page.evaluate(async value => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: value }, selection: { anchor: 0 } });
|
||||
}, dividers);
|
||||
await page.waitForFunction(() => document.querySelectorAll(".writer-divider").length === 6);
|
||||
assert.equal(await page.getByRole("separator").and(page.locator(".writer-divider")).count(), 6);
|
||||
const dividerStyle = await page.locator(".writer-divider").first().evaluate(node => ({
|
||||
width: node.getBoundingClientRect().width,
|
||||
lineWidth: node.parentElement.getBoundingClientRect().width,
|
||||
border: getComputedStyle(node, "::after").borderTopWidth,
|
||||
color: getComputedStyle(node, "::after").borderTopColor,
|
||||
}));
|
||||
assert.ok(Math.abs(dividerStyle.width - dividerStyle.lineWidth) < 2);
|
||||
assert.equal(dividerStyle.border, "1px");
|
||||
assert.notEqual(dividerStyle.color, "rgba(0, 0, 0, 0)");
|
||||
await page.setViewportSize({ width: 1100, height: 900 });
|
||||
await page.screenshot({ path: ".audit/markdown-dividers.png" });
|
||||
|
||||
await page.locator(".writer-divider").first().click();
|
||||
assert.equal(await page.locator(".writer-divider").count(), 5);
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.doc.lineAt(window.__CM__.state.selection.main.head).text), "___");
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.press("Control+Home");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 5);
|
||||
assert.ok((await writer.textContent()).includes("__"));
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+Home");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 6);
|
||||
await page.keyboard.press("ArrowDown");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 5);
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.doc.lineAt(window.__CM__.state.selection.main.head).text), "___");
|
||||
await page.keyboard.press("Control+a");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 0);
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), dividers);
|
||||
await page.keyboard.press("Control+Home");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 6);
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(value => window.__TEST__.files.get("notes/welcome.md") === value, dividers);
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: "Above\n\n ___\n\n> ***\n\nEnd" }, selection: { anchor: 0 } });
|
||||
});
|
||||
assert.equal(await page.locator(".writer-divider").count(), 2);
|
||||
for (const divider of await page.locator(".writer-divider").all()) {
|
||||
assert.ok(await divider.evaluate(node => node.getBoundingClientRect().right <= node.parentElement.getBoundingClientRect().right + 1));
|
||||
}
|
||||
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: Divider syntax, width, source editing, keyboard navigation, selection, undo and save.");
|
||||
} catch (error) {
|
||||
console.error("Browser errors:", errors);
|
||||
await page.screenshot({ path: ".audit/markdown-dividers-failure.png" });
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
@@ -24,6 +24,53 @@ function setup() {
|
||||
return { docs, disk, io };
|
||||
}
|
||||
|
||||
test("tab moves preserve selection, dirty buffers, and in-flight saves", async () => {
|
||||
const { docs, io, disk } = setup();
|
||||
await docs.open(entry("note.md"));
|
||||
const note = docs.active!;
|
||||
docs.edit(note.id, "my edits");
|
||||
docs.setChrome("Ide");
|
||||
await docs.open(entry("script.py"));
|
||||
docs.newTab();
|
||||
const blank = docs.active!;
|
||||
const gate = deferred<void>();
|
||||
const write = io.write;
|
||||
io.write = async (...args) => { await gate.promise; await write(...args); };
|
||||
const pending = docs.save(note.id);
|
||||
await Promise.resolve();
|
||||
docs.move(note.relPath, 2);
|
||||
assert.deepEqual(docs.buffers.map(b => b.relPath), ["script.py", blank.relPath, "note.md"]);
|
||||
assert.equal(docs.active, blank);
|
||||
assert.equal(docs.buffers[2], note);
|
||||
assert.equal(note.contents, "my edits");
|
||||
assert.equal(note.saved, "original");
|
||||
assert.equal(note.chromeOverride, "Ide");
|
||||
docs.move(blank.relPath, 0);
|
||||
assert.equal(docs.active, blank);
|
||||
gate.resolve();
|
||||
await pending;
|
||||
assert.equal(disk.get("note.md"), "my edits");
|
||||
docs.close(blank.relPath);
|
||||
assert.equal(docs.activePath, "script.py");
|
||||
});
|
||||
|
||||
test("tab moves ignore stale paths and invalid indices and clamp to the tab strip", async () => {
|
||||
const { docs } = setup();
|
||||
await docs.open(entry("note.md"));
|
||||
await docs.open(entry("script.py"));
|
||||
docs.move("missing.md", 0);
|
||||
docs.move("script.py", NaN);
|
||||
docs.move("script.py", 0.5);
|
||||
assert.deepEqual(docs.buffers.map(b => b.relPath), ["note.md", "script.py"]);
|
||||
docs.move("script.py", -1);
|
||||
assert.deepEqual(docs.buffers.map(b => b.relPath), ["script.py", "note.md"]);
|
||||
docs.move("script.py", 99);
|
||||
assert.deepEqual(docs.buffers.map(b => b.relPath), ["note.md", "script.py"]);
|
||||
docs.dispose();
|
||||
docs.move("script.py", 0);
|
||||
assert.deepEqual(docs.buffers.map(b => b.relPath), ["note.md", "script.py"]);
|
||||
});
|
||||
|
||||
test("empty tabs are independent, preserve dirty documents, and never access disk", async () => {
|
||||
const { docs, io } = setup();
|
||||
await docs.open(entry("note.md"));
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\smoke-workspace";
|
||||
const files = new Map([
|
||||
["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"],
|
||||
]);
|
||||
const callbacks = new Map();
|
||||
const listeners = new Map();
|
||||
let sequence = 0;
|
||||
const calls = [];
|
||||
const emit = (event, payload) => {
|
||||
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
|
||||
};
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === "plugin:event|listen") {
|
||||
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "smoke-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
|
||||
}
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "";
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "pty_open") {
|
||||
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
|
||||
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
|
||||
emit("pty-data", { id: args.id, data: data.slice(8) });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return;
|
||||
}
|
||||
if (command.startsWith("pty_")) return;
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.__TEST__ = { files, calls, emit, root };
|
||||
});
|
||||
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
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" }).first().click();
|
||||
const editor = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await editor.waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: "# Alpha\n\nalpha Alpha alphabet\n\n## Beta\n\nBeta text\n" }, selection: { anchor: 0 } });
|
||||
window.__CM__.focus();
|
||||
});
|
||||
await page.keyboard.press("Control+f");
|
||||
const find = page.getByRole("textbox", { name: "Find in document", exact: true });
|
||||
await find.waitFor();
|
||||
assert.equal(await find.evaluate(el => document.activeElement === el), true);
|
||||
assert.equal(await page.locator(".cm-panels-top .rs-writer-search").count(), 1);
|
||||
const panelBounds = await page.locator(".rs-writer-search").boundingBox();
|
||||
const scrollBounds = await page.locator(".cm-scroller").boundingBox();
|
||||
assert.ok(panelBounds.y + panelBounds.height <= scrollBounds.y + 1);
|
||||
await find.fill("Alpha");
|
||||
await page.keyboard.press("Enter");
|
||||
const first = await page.evaluate(() => window.__CM__.state.selection.main.from);
|
||||
await page.keyboard.press("Enter");
|
||||
const second = await page.evaluate(() => window.__CM__.state.selection.main.from);
|
||||
assert.notEqual(first, second);
|
||||
await page.keyboard.press("Shift+Enter");
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.selection.main.from), first);
|
||||
await page.getByRole("checkbox", { name: "Match case" }).check();
|
||||
await page.getByRole("checkbox", { name: "Whole word" }).check();
|
||||
await page.getByRole("textbox", { name: "Replace with" }).fill("Gamma");
|
||||
await page.getByRole("button", { name: "Replace all", exact: true }).click();
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /# Gamma\n\nalpha Gamma alphabet/);
|
||||
await page.getByRole("checkbox", { name: "Regex" }).check();
|
||||
await find.fill("[");
|
||||
assert.equal(await find.getAttribute("aria-invalid"), "true");
|
||||
assert.equal(await page.getByRole("button", { name: "Replace all", exact: true }).isDisabled(), true);
|
||||
await page.getByText("Invalid expression", { exact: true }).waitFor();
|
||||
await find.fill("Gamma");
|
||||
await page.getByRole("checkbox", { name: "Regex" }).uncheck();
|
||||
await page.evaluate(async () => {
|
||||
const moduleUrl = performance.getEntriesByType("resource").find(entry => entry.name.includes("/@codemirror_search.js"))?.name;
|
||||
if (!moduleUrl) throw new Error("Search module was not loaded");
|
||||
const { SearchQuery, setSearchQuery } = await import(moduleUrl);
|
||||
window.__CM__.dispatch({ effects: setSearchQuery.of(new SearchQuery({ search: "Beta" })) });
|
||||
});
|
||||
await page.waitForFunction(() => document.querySelector('input[name="search"]').value === "Beta");
|
||||
await find.focus();
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await find.count(), 0);
|
||||
assert.equal(await editor.evaluate(el => document.activeElement === el), true);
|
||||
await page.keyboard.press("Control+f");
|
||||
await find.waitFor();
|
||||
await page.getByRole("button", { name: "Next match (Enter)" }).focus();
|
||||
await page.getByRole("tooltip", { name: "Next match (Enter)" }).waitFor({ state: "visible" });
|
||||
await find.focus();
|
||||
|
||||
const outline = page.getByRole("region", { name: "Outline", exact: true });
|
||||
if (!await outline.count()) await page.getByRole("button", { name: "Outline", exact: true }).click();
|
||||
await outline.focus();
|
||||
await page.keyboard.press("Control+f");
|
||||
const outlineFind = page.getByRole("textbox", { name: "Find in outline", exact: true });
|
||||
await outlineFind.fill("beta");
|
||||
assert.equal(await outline.locator("li").count(), 1);
|
||||
assert.equal(await outline.locator("li button").textContent(), "Beta");
|
||||
await outlineFind.fill("missing");
|
||||
await outline.getByText("No matching headings or symbols.").waitFor();
|
||||
await outlineFind.fill("Gamma");
|
||||
await page.screenshot({ path: ".audit/find-bars.png" });
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await outlineFind.count(), 0);
|
||||
assert.equal(await outline.locator("li").count(), 2);
|
||||
assert.equal(await outline.evaluate(el => document.activeElement === el), true);
|
||||
await page.keyboard.press("Control+f");
|
||||
await outlineFind.fill("Beta");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.waitForFunction(() => window.__CM__.state.doc.lineAt(window.__CM__.state.selection.main.head).text === "## Beta");
|
||||
assert.equal(await editor.evaluate(el => document.activeElement === el), true);
|
||||
|
||||
await page.setViewportSize({ width: 880, height: 760 });
|
||||
await find.focus();
|
||||
await page.screenshot({ path: ".audit/find-bars-narrow.png" });
|
||||
for (const selector of [".rs-writer-search", ".outline-search"]) {
|
||||
assert.equal(await page.locator(selector).evaluate(el => el.scrollWidth <= el.clientWidth), true, selector);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: Top search panel, shortcuts, replacement, query sync, invalid regex, focus tooltip, outline filtering, focus return and narrow layout.");
|
||||
} catch (error) {
|
||||
console.error("Browser errors:", errors);
|
||||
await page.screenshot({ path: ".audit/find-failure.png" });
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,46 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { tabsToClose } from "../src/lib/workspace/tabActions.ts";
|
||||
import { Documents } from "../src/lib/workspace/documents.ts";
|
||||
|
||||
function setup() {
|
||||
return new Documents({
|
||||
read: async () => "original", write: async () => {}, image: async () => "data:image/png;base64,",
|
||||
kind: () => "text", chrome: () => "Writing",
|
||||
}, () => {});
|
||||
}
|
||||
const entry = (path: string) => ({ rel_path: path, name: path, kind: "file" as const });
|
||||
|
||||
test("group closes follow tab order and preserve pins without changing the active tab", async () => {
|
||||
const docs = setup();
|
||||
for (const name of ["a.md", "b.md", "c.md", "d.md"]) await docs.open(entry(name));
|
||||
docs.togglePin("b.md");
|
||||
docs.move("d.md", 1);
|
||||
const paths = (scope: "one" | "others" | "after" | "all") => tabsToClose(docs.buffers, "d.md", scope).map(tab => tab.relPath);
|
||||
assert.deepEqual(paths("one"), ["d.md"]);
|
||||
assert.deepEqual(paths("others"), ["a.md", "c.md"]);
|
||||
assert.deepEqual(paths("after"), ["c.md"]);
|
||||
assert.deepEqual(paths("all"), ["a.md", "d.md", "c.md"]);
|
||||
assert.equal(docs.activePath, "d.md");
|
||||
assert.deepEqual(tabsToClose(docs.buffers, "missing.md", "all"), []);
|
||||
assert.equal(tabsToClose(docs.buffers, "b.md", "one")[0].pinned, true);
|
||||
});
|
||||
|
||||
test("pinning protects current and empty tabs from replacement, and survives rename", async () => {
|
||||
const docs = setup();
|
||||
await docs.open(entry("a.md"));
|
||||
docs.togglePin("a.md");
|
||||
await docs.open(entry("b.md"), "current");
|
||||
assert.deepEqual(docs.buffers.map(tab => tab.relPath), ["a.md", "b.md"]);
|
||||
docs.rename("a.md", "renamed.md");
|
||||
assert.equal(docs.buffers[0].pinned, true);
|
||||
docs.newTab();
|
||||
const blank = docs.active!;
|
||||
docs.togglePin(blank.relPath);
|
||||
await docs.open(entry("c.md"));
|
||||
assert.ok(docs.buffers.includes(blank));
|
||||
docs.select("renamed.md");
|
||||
docs.togglePin("renamed.md");
|
||||
await docs.open(entry("d.md"), "current");
|
||||
assert.ok(!docs.buffers.some(tab => tab.relPath === "renamed.md"));
|
||||
});
|
||||
@@ -0,0 +1,139 @@
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(15000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\tab-menu-workspace";
|
||||
const files = new Map(["a.md", "b.md", "c.md", "d.md"].map(name => [name, `# ${name}\n\nOriginal text.\n`]));
|
||||
window.tabMenuTest = { prompts: [], answer: "Cancel", revealed: null, clipboard: null };
|
||||
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { window.tabMenuTest.clipboard = text; } } });
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: () => ++sequence, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugin:event|listen") return ++sequence;
|
||||
if (command === "plugin:event|unlisten") return;
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "tab-menu-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_list") return args.rel ? [] : [...files.keys()].map(name => ({ name, rel_path: name, kind: "file" }));
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "workspace_write") throw new Error("Keep unsaved edits for the close test");
|
||||
if (command === "workspace_rename") { files.set(args.to, files.get(args.from)); files.delete(args.from); return; }
|
||||
if (command === "workspace_abs_path") return `${root}\\${args.rel}`;
|
||||
if (command === "workspace_reveal") { window.tabMenuTest.revealed = args.rel; return; }
|
||||
if (command === "plugin:dialog|message") { window.tabMenuTest.prompts.push(args.message); return window.tabMenuTest.answer; }
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
const menu = () => page.getByRole("menu", { name: "Tab actions", exact: true });
|
||||
const item = name => page.getByRole("menuitem", { name, exact: true });
|
||||
const order = () => page.getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path));
|
||||
async function open(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 tab(name).waitFor();
|
||||
}
|
||||
async function show(name) { await tab(name).click({ button: "right" }); await menu().waitFor(); }
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
await page.getByText("tab-menu-workspace", { exact: true }).waitFor();
|
||||
for (const name of ["a.md", "b.md", "c.md", "d.md"]) await open(name);
|
||||
await page.locator(".cm-content").filter({ hasText: "Original text." }).waitFor();
|
||||
await show("b.md");
|
||||
assert.equal(await tab("d.md").getAttribute("aria-selected"), "true");
|
||||
assert.equal(await item("Rename…").count(), 0);
|
||||
assert.equal(await item("Reading view").count(), 0);
|
||||
assert.doesNotMatch(await menu().innerText(), /Alt|Shift|Ctrl/);
|
||||
await page.screenshot({ path: ".audit/tab-menu-inactive.png" });
|
||||
await item("Pin").click();
|
||||
assert.equal(await tab("d.md").getAttribute("aria-selected"), "true");
|
||||
assert.ok(await tab("b.md").getAttribute("aria-describedby"));
|
||||
await show("d.md");
|
||||
assert.equal(await item("Close tabs after").isDisabled(), true);
|
||||
await page.screenshot({ path: ".audit/tab-menu-active.png" });
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await tab("d.md").evaluate(node => node === document.activeElement), true);
|
||||
await tab("d.md").press("Shift+F10");
|
||||
assert.equal(await item("Close").evaluate(node => node === document.activeElement), true);
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await item("Move tab left").evaluate(node => node === document.activeElement), true);
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.press("Escape");
|
||||
await show("d.md");
|
||||
await item("Reading view").click();
|
||||
await page.locator(".md-page").waitFor();
|
||||
await show("d.md");
|
||||
await item("Editing view").click();
|
||||
await page.locator(".cm-editor").waitFor();
|
||||
await show("d.md");
|
||||
await item("Source mode").click();
|
||||
await page.locator(".monaco-editor").waitFor();
|
||||
await show("d.md");
|
||||
await item("Writing mode").click();
|
||||
await page.locator(".cm-editor").waitFor();
|
||||
await show("d.md");
|
||||
await item("Copy path").click();
|
||||
await item("Workspace path").click();
|
||||
assert.equal(await page.evaluate(() => window.tabMenuTest.clipboard), "d.md");
|
||||
await show("d.md");
|
||||
await item("Show in system explorer").click();
|
||||
assert.equal(await page.evaluate(() => window.tabMenuTest.revealed), "d.md");
|
||||
await show("d.md");
|
||||
await item("Rename…").click();
|
||||
await page.getByRole("dialog").getByRole("textbox").fill("renamed.md");
|
||||
await page.getByRole("dialog").getByRole("button", { name: "Continue", exact: true }).click();
|
||||
await tab("renamed.md").waitFor();
|
||||
await show("a.md");
|
||||
await item("Close tabs after").click();
|
||||
await tab("renamed.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["a.md", "b.md"]);
|
||||
await open("c.md");
|
||||
await show("c.md");
|
||||
await item("Close others").click();
|
||||
await tab("a.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md", "c.md"]);
|
||||
await page.locator(".cm-content").click();
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.type("Unsaved text");
|
||||
await tab("c.md •").waitFor();
|
||||
await show("c.md •");
|
||||
await item("Close all").click();
|
||||
await page.waitForFunction(() => window.tabMenuTest.prompts.length === 1);
|
||||
assert.deepEqual(await order(), ["b.md", "c.md"]);
|
||||
await page.evaluate(() => { window.tabMenuTest.answer = "Ok"; });
|
||||
await show("c.md •");
|
||||
await item("Close all").click();
|
||||
await tab("c.md •").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md"]);
|
||||
await show("b.md");
|
||||
assert.equal(await item("Close all").isDisabled(), true);
|
||||
await item("Unpin").click();
|
||||
await show("b.md");
|
||||
await item("Close").click();
|
||||
await tab("b.md").waitFor({ state: "detached" });
|
||||
await page.getByRole("button", { name: "New tab (Ctrl T)", exact: true }).click();
|
||||
await show("New tab");
|
||||
assert.equal(await item("Rename…").count(), 0);
|
||||
assert.equal(await item("Reading view").count(), 0);
|
||||
await page.keyboard.press("Escape");
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: active/inactive menus, keyboard focus, pinning, view modes, file actions, ordered closes, cancelled discard, and empty tabs");
|
||||
} catch (error) {
|
||||
await page.screenshot({ path: ".audit/tab-menu-failure.png" });
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,125 @@
|
||||
// Run against pnpm dev with PLAYWRIGHT_MODULE set if Playwright is shared.
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\tab-order-workspace";
|
||||
const files = new Map(Array.from({ length: 16 }, (_, i) => [`note-${String(i).padStart(2, "0")}.md`, `# Note ${i}\n\nKeep this text.\n`]));
|
||||
files.set("note-00.md", Array.from({ length: 200 }, (_, i) => `Paragraph ${i}.\n\n`).join(""));
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: () => ++sequence,
|
||||
unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugin:event|listen") return ++sequence;
|
||||
if (command === "plugin:event|unlisten") return;
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "tab-order-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") { files.set(args.rel, args.contents); return; }
|
||||
if (command === "workspace_list") return args.rel ? [] : [...files.keys()].map(name => ({ name, rel_path: name, kind: "file" }));
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
const order = () => page.getByRole("tablist", { name: "Open files" }).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path));
|
||||
const settle = () => page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
||||
async function open(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 tab(name).waitFor();
|
||||
}
|
||||
async function drag(from, to, side, cancel) {
|
||||
const source = await tab(from).boundingBox();
|
||||
const target = await tab(to).boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(side === "before" ? target.x + 2 : target.x + target.width - 2, target.y + target.height / 2, { steps: 10 });
|
||||
if (cancel === "escape") await page.keyboard.press("Escape");
|
||||
if (cancel === "outside") await page.mouse.move(target.x, target.y + 100);
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
}
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
await page.getByText("tab-order-workspace", { exact: true }).waitFor();
|
||||
for (const name of ["note-00.md", "note-01.md", "note-02.md"]) await open(name);
|
||||
await drag("note-00.md", "note-02.md", "after");
|
||||
assert.deepEqual(await order(), ["note-01.md", "note-02.md", "note-00.md"]);
|
||||
assert.equal(await tab("note-02.md").getAttribute("aria-selected"), "true");
|
||||
await drag("note-00.md", "note-01.md", "before");
|
||||
assert.deepEqual(await order(), ["note-00.md", "note-01.md", "note-02.md"]);
|
||||
for (const cancel of ["escape", "outside"]) {
|
||||
await drag("note-00.md", "note-02.md", "after", cancel);
|
||||
assert.deepEqual(await order(), ["note-00.md", "note-01.md", "note-02.md"]);
|
||||
}
|
||||
await tab("note-00.md").click();
|
||||
assert.equal(await tab("note-00.md").getAttribute("aria-selected"), "true");
|
||||
await page.locator(".cm-scroller").evaluate(node => { node.scrollTop = 1200; });
|
||||
await settle();
|
||||
const scrollTop = await page.locator(".cm-scroller").evaluate(node => node.scrollTop);
|
||||
assert.ok(scrollTop > 1000);
|
||||
await tab("note-00.md").press("Alt+Shift+ArrowRight");
|
||||
await settle();
|
||||
assert.deepEqual(await order(), ["note-01.md", "note-00.md", "note-02.md"]);
|
||||
assert.ok(Math.abs(await page.locator(".cm-scroller").evaluate(node => node.scrollTop) - scrollTop) < 5);
|
||||
assert.equal(await tab("note-00.md").evaluate(node => document.activeElement === node), true);
|
||||
await tab("note-00.md").press("ArrowRight");
|
||||
assert.equal(await tab("note-02.md").getAttribute("aria-selected"), "true");
|
||||
await tab("note-02.md").press("Shift+F10");
|
||||
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
|
||||
assert.equal(await page.getByRole("menuitem", { name: /Move tab right/ }).isDisabled(), true);
|
||||
await page.getByRole("menuitem", { name: /Move tab left/ }).click();
|
||||
assert.deepEqual(await order(), ["note-01.md", "note-02.md", "note-00.md"]);
|
||||
await tab("note-01.md").click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
|
||||
assert.equal(await page.getByRole("menuitem", { name: /Move tab left/ }).isDisabled(), true);
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await page.getByRole("menu", { name: "Tab actions" }).count(), 0);
|
||||
console.log("PASS: pointer moves, cancellation, keyboard moves, and tab menus");
|
||||
|
||||
await page.getByRole("button", { name: "New tab (Ctrl T)", exact: true }).click();
|
||||
await tab("New tab").press("Alt+Shift+Home");
|
||||
assert.match((await order())[0], /^empty:/);
|
||||
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
|
||||
await tab("note-01.md").click({ button: "middle" });
|
||||
assert.deepEqual(await order(), ["note-02.md", "note-00.md"]);
|
||||
console.log("PASS: empty tabs and middle-click close after reorder");
|
||||
|
||||
for (let i = 3; i < 16; i++) await open(`note-${String(i).padStart(2, "0")}.md`);
|
||||
const bar = page.getByRole("tablist", { name: "Open files" });
|
||||
assert.ok(await bar.evaluate(node => node.scrollLeft > 0));
|
||||
await tab("note-15.md").press("Alt+Shift+Home");
|
||||
assert.equal((await order())[0], "note-15.md");
|
||||
assert.equal(await bar.evaluate(node => node.scrollLeft), 0);
|
||||
const source = await tab("note-15.md").boundingBox();
|
||||
const bounds = await bar.boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2, { steps: 10 });
|
||||
await page.waitForFunction(() => {
|
||||
const bar = document.querySelector('[aria-label="Open files"]');
|
||||
return bar.scrollLeft >= bar.scrollWidth - bar.clientWidth - 2;
|
||||
});
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
assert.equal((await order()).at(-1), "note-15.md");
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: automatic scrolling and drag to the end of an overflowing tab bar");
|
||||
if (process.env.SCREENSHOT_PATH) await page.screenshot({ path: process.env.SCREENSHOT_PATH });
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\tree-actions-test";
|
||||
const files = new Map([
|
||||
["notes/a.md", "# A"], ["notes/nested/b.md", "# B"],
|
||||
["target/a.md", "# Existing"], ["a.md", "# A"], ["b.md", "# B"], ["c.md", "# C"],
|
||||
]);
|
||||
const calls = [];
|
||||
const state = { files, calls, answer: "Ok", fail: "", clipboard: "" };
|
||||
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { state.clipboard = text; } } });
|
||||
let sequence = 0;
|
||||
const contains = (parent, path) => path === parent || path.startsWith(parent + "/");
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: () => ++sequence,
|
||||
unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === "plugin:event|listen") return ++sequence;
|
||||
if (command === "plugin:event|unlisten") return;
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "tree-actions-test", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") { files.set(args.rel, args.contents); return; }
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "";
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length);
|
||||
const name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_delete") {
|
||||
if (args.rel === state.fail) throw new Error("Access denied");
|
||||
for (const path of [...files.keys()]) if (contains(args.rel, path)) files.delete(path);
|
||||
return;
|
||||
}
|
||||
if (command === "workspace_copy") {
|
||||
const to = args.rel + "-copy";
|
||||
for (const [path, text] of [...files]) if (contains(args.rel, path)) files.set(to + path.slice(args.rel.length), text);
|
||||
return { name: to.split("/").pop(), rel_path: to, kind: files.has(to) ? "file" : "folder" };
|
||||
}
|
||||
if (command === "workspace_rename") {
|
||||
if ([...files.keys()].some(path => contains(args.to, path))) throw new Error("Destination exists");
|
||||
for (const [path, text] of [...files]) if (contains(args.from, path)) {
|
||||
files.delete(path);
|
||||
files.set(args.to + path.slice(args.from.length), text);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (command === "workspace_abs_path") return root + "\\" + args.rel.replaceAll("/", "\\");
|
||||
if (command === "workspace_reveal") return;
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "plugin:dialog|message") return state.answer;
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
window.__TEST__ = state;
|
||||
});
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
const selected = () => page.locator('[role="treeitem"][aria-selected="true"]').evaluateAll(nodes => nodes.map(node => node.dataset.treeRel));
|
||||
const calls = command => page.evaluate(command => window.__TEST__.calls.filter(call => call.command === command).map(call => call.args), command);
|
||||
const settle = () => page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
||||
async function reset() {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
await row("notes").waitFor();
|
||||
}
|
||||
async function action(path, name) {
|
||||
await row(path).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name, exact: true }).click();
|
||||
await settle();
|
||||
}
|
||||
async function selectFiles() {
|
||||
await row("a.md").click();
|
||||
await page.getByRole("tab", { name: "a.md", exact: true }).waitFor();
|
||||
await settle();
|
||||
await row("b.md").click({ modifiers: ["Control"] });
|
||||
await settle();
|
||||
}
|
||||
async function drag(sourcePath, targetPath, place = "inside") {
|
||||
const source = await row(sourcePath).boundingBox();
|
||||
const target = await row(targetPath).boundingBox();
|
||||
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(target.x + target.width / 2, target.y + target.height * (place === "before" ? 0.1 : place === "after" ? 0.9 : 0.5), { steps: 10 });
|
||||
await page.mouse.up();
|
||||
await settle();
|
||||
}
|
||||
try {
|
||||
await reset();
|
||||
await selectFiles();
|
||||
await row("a.md").click({ button: "right" });
|
||||
assert.deepEqual(await selected(), ["a.md", "b.md"]);
|
||||
assert.equal(await page.getByRole("menuitem", { name: "Rename", exact: true }).isDisabled(), true);
|
||||
await page.keyboard.press("Escape");
|
||||
await action("a.md", "Copy workspace paths");
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.clipboard), "a.md\nb.md");
|
||||
await action("b.md", "Copy system paths");
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.clipboard), "C:\\tree-actions-test\\a.md\nC:\\tree-actions-test\\b.md");
|
||||
await action("a.md", "Show in Explorer");
|
||||
assert.deepEqual((await calls("workspace_reveal")).map(args => args.rel), ["a.md", "b.md"]);
|
||||
await action("a.md", "Bookmark");
|
||||
await action("b.md", "Pin");
|
||||
let marks = await page.evaluate(() => JSON.parse(window.__TEST__.files.get(".runestone/marks.json")));
|
||||
assert.deepEqual(marks.bookmarks, ["a.md", "b.md"]);
|
||||
assert.deepEqual(marks.pins, ["a.md", "b.md"]);
|
||||
await action("a.md", "Unpin");
|
||||
await action("a.md", "Remove bookmarks");
|
||||
await action("a.md", "Make copies (2)");
|
||||
assert.deepEqual((await calls("workspace_copy")).map(args => args.rel), ["a.md", "b.md"]);
|
||||
await row("c.md").click({ button: "right" });
|
||||
assert.deepEqual(await selected(), ["c.md"]);
|
||||
assert.equal(await page.getByRole("menuitem", { name: "Rename", exact: true }).isDisabled(), false);
|
||||
await page.keyboard.press("Escape");
|
||||
console.log("PASS: selection, clipboard paths, marks, copies, reveal, and single-item menus");
|
||||
|
||||
await reset();
|
||||
await selectFiles();
|
||||
await page.evaluate(() => { window.__TEST__.answer = "Cancel"; });
|
||||
await action("a.md", "Delete (2)");
|
||||
assert.equal((await calls("workspace_delete")).length, 0);
|
||||
assert.deepEqual(await selected(), ["a.md", "b.md"]);
|
||||
await page.evaluate(() => { window.__TEST__.answer = "Ok"; window.__TEST__.fail = "a.md"; });
|
||||
await row("c.md").click({ modifiers: ["Control"] });
|
||||
await action("a.md", "Delete (3)");
|
||||
await row("c.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual((await calls("workspace_delete")).map(args => args.rel), ["a.md", "b.md", "c.md"]);
|
||||
assert.match(await page.locator(".tree .error").textContent(), /a.md: Access denied/);
|
||||
assert.deepEqual(await selected(), ["a.md"]);
|
||||
console.log("PASS: cancellation, one confirmation per batch, partial failure, and selection after deletion");
|
||||
|
||||
await reset();
|
||||
await row("notes").click();
|
||||
await row("notes/nested").click();
|
||||
await row("notes").click({ modifiers: ["Control"] });
|
||||
await row("notes/a.md").click({ modifiers: ["Control"] });
|
||||
await row("notes/nested/b.md").click({ modifiers: ["Control"] });
|
||||
await row("c.md").click({ modifiers: ["Control"] });
|
||||
await action("notes/a.md", "Make copies (5)");
|
||||
assert.deepEqual((await calls("workspace_copy")).map(args => args.rel), ["notes", "c.md"]);
|
||||
await action("notes/nested/b.md", "Delete (5)");
|
||||
await row("notes").waitFor({ state: "detached" });
|
||||
assert.deepEqual((await calls("workspace_delete")).map(args => args.rel), ["notes", "c.md"]);
|
||||
assert.equal((await calls("plugin:dialog|message")).length, 1);
|
||||
console.log("PASS: recursive copy and delete process selected folders and children once");
|
||||
|
||||
await reset();
|
||||
await selectFiles();
|
||||
await drag("a.md", "target");
|
||||
await row("target/b.md").waitFor();
|
||||
assert.deepEqual((await calls("workspace_rename")), [{ from: "a.md", to: "target/a 2.md" }, { from: "b.md", to: "target/b.md" }]);
|
||||
assert.deepEqual(await selected(), ["target/a 2.md", "target/b.md"]);
|
||||
console.log("PASS: group move into a collapsed folder preserves an existing same-name file");
|
||||
|
||||
await reset();
|
||||
await row("notes").click();
|
||||
await row("notes/a.md").click({ modifiers: ["Control"] });
|
||||
await row("c.md").click({ modifiers: ["Control"] });
|
||||
await drag("notes/a.md", "notes/nested");
|
||||
assert.equal((await calls("workspace_rename")).length, 0);
|
||||
await drag("notes/a.md", "target");
|
||||
await row("target/notes").waitFor();
|
||||
assert.deepEqual(await calls("workspace_rename"), [{ from: "notes", to: "target/notes" }, { from: "c.md", to: "target/c.md" }]);
|
||||
assert.deepEqual(await selected(), ["target/notes", "target/c.md"]);
|
||||
await row("target/notes").click();
|
||||
await row("target/notes/a.md").waitFor();
|
||||
console.log("PASS: mixed folder and file moves skip selected descendants and reject drops into the same folder");
|
||||
|
||||
await reset();
|
||||
await selectFiles();
|
||||
await drag("a.md", "c.md", "after");
|
||||
marks = await page.evaluate(() => JSON.parse(window.__TEST__.files.get(".runestone/marks.json")));
|
||||
assert.deepEqual(marks.order[""].filter(name => name.endsWith(".md")), ["c.md", "a.md", "b.md"]);
|
||||
await drag("b.md", "c.md", "before");
|
||||
marks = await page.evaluate(() => JSON.parse(window.__TEST__.files.get(".runestone/marks.json")));
|
||||
assert.deepEqual(marks.order[""].filter(name => name.endsWith(".md")), ["a.md", "b.md", "c.md"]);
|
||||
assert.deepEqual(errors, []);
|
||||
if (process.env.SCREENSHOT_PATH) {
|
||||
await row("a.md").click({ button: "right" });
|
||||
await page.screenshot({ path: process.env.SCREENSHOT_PATH });
|
||||
}
|
||||
console.log("PASS: group reorder preserves selected row order in both directions");
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { actionEntries, selectionRoots, setSelectedMarks, runTreeActions } from "../src/lib/workspace/treeActions.ts";
|
||||
import { planDrop } from "../src/lib/workspace/treeDrop.ts";
|
||||
import type { TreeEntry } from "../src/lib/workspace/types.ts";
|
||||
|
||||
const entry = (rel_path: string, kind: "file" | "folder" = "file"): TreeEntry => ({ rel_path, name: rel_path.split("/").pop()!, kind });
|
||||
const entries = [entry("notes", "folder"), entry("notes/a.md"), entry("notes/sub", "folder"), entry("notes/sub/b.md"), entry("notes-old/c.md"), entry("z.md")];
|
||||
const visible = entries.map(item => item.rel_path);
|
||||
const find = (path: string) => entries.find(item => item.rel_path === path) ?? null;
|
||||
|
||||
test("context actions use all selected visible rows in display order", () => {
|
||||
assert.deepEqual(actionEntries(entries[1], new Set(["z.md", "missing", "notes/a.md"]), visible, find), [entries[1], entries[5]]);
|
||||
assert.deepEqual(actionEntries(entries[0], new Set(["z.md", "notes/a.md"]), visible, find), [entries[0]]);
|
||||
});
|
||||
|
||||
test("recursive actions process each selected folder once without including similar names", () => {
|
||||
assert.deepEqual(selectionRoots([...entries].reverse()), [entries[5], entries[4], entries[0]]);
|
||||
assert.deepEqual(selectionRoots(entries.slice(1)), [entries[1], entries[2], entries[4], entries[5]]);
|
||||
});
|
||||
|
||||
test("mixed marks become uniformly enabled or disabled and preserve other marks", () => {
|
||||
const current = ["outside.md", "notes/a.md"];
|
||||
const selection = [entries[1], entries[5]];
|
||||
assert.deepEqual(setSelectedMarks(current, selection, true), ["outside.md", "notes/a.md", "z.md"]);
|
||||
assert.deepEqual(setSelectedMarks(current, selection, false), ["outside.md"]);
|
||||
assert.deepEqual(current, ["outside.md", "notes/a.md"]);
|
||||
});
|
||||
|
||||
test("a failed action does not skip later items or lose successful results", async () => {
|
||||
const visited: string[] = [];
|
||||
const result = await runTreeActions(entries, async item => {
|
||||
visited.push(item.rel_path);
|
||||
if (item === entries[1]) throw new Error("Access denied");
|
||||
return item.name;
|
||||
});
|
||||
assert.deepEqual(visited, visible);
|
||||
assert.deepEqual(result.completed.map(item => item.entry), entries.filter(item => item !== entries[1]));
|
||||
assert.deepEqual(result.failures, ["notes/a.md: Access denied"]);
|
||||
});
|
||||
|
||||
test("moving beside an existing same-name file preserves both files in the destination order", () => {
|
||||
const plan = planDrop("notes/a.md", entry("a.md"), "after", parent => parent === "notes" ? ["a.md"] : ["a.md", "z.md"]);
|
||||
assert.equal(plan.action, "move");
|
||||
if (plan.action === "move") {
|
||||
assert.equal(plan.to, "a 2.md");
|
||||
assert.deepEqual(plan.orderTo, ["a.md", "a 2.md", "z.md"]);
|
||||
}
|
||||
assert.deepEqual(planDrop("notes", entries[1], "before", () => []), { action: "noop" });
|
||||
});
|
||||
Reference in New Issue
Block a user