RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
// File tree actions on multiple selections: clipboard paths, marks, copies, deletion, group moves, and reordering.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, settle as settleFrames, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/actions", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const contains = (parent, path) => path === parent || path.startsWith(parent + "/");
|
||||
const ws = test.workspace({
|
||||
root: "C:\\tree-actions-test",
|
||||
files: { "notes/a.md": "# A", "notes/nested/b.md": "# B", "target/a.md": "# Existing", "a.md": "# A", "b.md": "# B", "c.md": "# C" },
|
||||
});
|
||||
const files = ws.files;
|
||||
Object.assign(test, { files, answer: "Ok", fail: "", clipboard: "" });
|
||||
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { test.clipboard = text; } } });
|
||||
return {
|
||||
...ws,
|
||||
workspace_list: args => ws.workspace_list(args).filter(entry => !entry.rel_path.startsWith(".runestone")),
|
||||
workspace_delete: ({ rel }) => {
|
||||
if (rel === test.fail) throw new Error("Access denied");
|
||||
for (const path of [...files.keys()]) if (contains(rel, path)) files.delete(path);
|
||||
},
|
||||
workspace_copy: ({ rel }) => {
|
||||
const to = rel + "-copy";
|
||||
for (const [path, text] of [...files]) if (contains(rel, path)) files.set(to + path.slice(rel.length), text);
|
||||
return { name: to.split("/").pop(), rel_path: to, kind: files.has(to) ? "file" : "folder" };
|
||||
},
|
||||
workspace_rename: ({ from, to }) => {
|
||||
if ([...files.keys()].some(path => contains(to, path))) throw new Error("Destination exists");
|
||||
for (const [path, text] of [...files]) if (contains(from, path)) {
|
||||
files.delete(path);
|
||||
files.set(to + path.slice(from.length), text);
|
||||
}
|
||||
},
|
||||
workspace_reveal: () => null,
|
||||
"plugin:dialog|message": () => test.answer,
|
||||
};
|
||||
},
|
||||
});
|
||||
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 = () => settleFrames(page);
|
||||
const marks = () => page.evaluate(() => JSON.parse(window.__TEST__.files.get(".runestone/marks.json")));
|
||||
// Mutations name the workspace root they expect (src/lib/workspace/api.ts:63).
|
||||
const expectedRoot = "C:\\tree-actions-test";
|
||||
async function reset() {
|
||||
await page.goto(smokeUrl);
|
||||
await row("notes").waitFor();
|
||||
}
|
||||
// A name of the form "Copy path › Workspace path" opens a submenu first.
|
||||
async function action(path, name) {
|
||||
await row(path).click({ button: "right" });
|
||||
const [first, second] = name.split(" › ");
|
||||
if (second) await page.getByRole("menuitem", { name: first, exact: true }).hover();
|
||||
await page.getByRole("menuitem", { name: second ?? first, 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();
|
||||
}
|
||||
|
||||
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 path › Workspace path");
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.clipboard), "a.md\nb.md");
|
||||
await action("b.md", "Copy path › System path");
|
||||
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");
|
||||
assert.deepEqual((await marks()).bookmarks, ["a.md", "b.md"]);
|
||||
assert.deepEqual((await 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");
|
||||
|
||||
// Delete moves items to the trash (`permanent: false`). Several items still need one confirmation.
|
||||
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"), ["a.md", "b.md", "c.md"].map(rel => ({ rel, permanent: false })));
|
||||
assert.match(await page.locator(".tree .error").textContent(), /a.md: Access denied/);
|
||||
// A failed move to the trash offers a permanent delete only through Shift+Delete.
|
||||
assert.match(await page.locator(".tree .error").textContent(), /press Shift\+Delete/);
|
||||
assert.deepEqual(await selected(), ["a.md"]);
|
||||
console.log("PASS: cancellation, one confirmation per batch, partial failure, and selection after deletion");
|
||||
|
||||
// Changed for the move to the trash: one file needs no confirmation. A permanent delete always asks.
|
||||
await reset();
|
||||
await action("c.md", "Delete");
|
||||
await row("c.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await calls("workspace_delete"), [{ rel: "c.md", permanent: false }]);
|
||||
assert.equal((await calls("plugin:dialog|message")).length, 0);
|
||||
await page.evaluate(() => { window.__TEST__.answer = "Cancel"; });
|
||||
await action("b.md", "Delete permanently");
|
||||
assert.equal((await calls("plugin:dialog|message")).length, 1);
|
||||
assert.equal((await calls("workspace_delete")).length, 1);
|
||||
await page.evaluate(() => { window.__TEST__.answer = "Ok"; });
|
||||
await action("b.md", "Delete permanently");
|
||||
await row("b.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual((await calls("workspace_delete")).at(-1), { rel: "b.md", permanent: true });
|
||||
console.log("PASS: one file moves to the trash without confirmation, and a permanent delete asks first");
|
||||
|
||||
await reset();
|
||||
await row("a.md").click();
|
||||
await row("a.md").focus();
|
||||
await page.keyboard.press("Delete");
|
||||
await row("a.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await calls("workspace_delete"), [{ rel: "a.md", permanent: false }]);
|
||||
await row("b.md").click();
|
||||
await row("b.md").focus();
|
||||
await page.keyboard.press("Shift+Delete");
|
||||
await row("b.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual((await calls("workspace_delete")).at(-1), { rel: "b.md", permanent: true });
|
||||
assert.equal((await calls("plugin:dialog|message")).length, 1);
|
||||
console.log("PASS: Delete moves the selection to the trash, and Shift+Delete deletes it permanently after confirmation");
|
||||
|
||||
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", expectedRoot }, { from: "b.md", to: "target/b.md", expectedRoot }]);
|
||||
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", expectedRoot }, { from: "c.md", to: "target/c.md", expectedRoot }]);
|
||||
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");
|
||||
assert.deepEqual((await marks()).order[""].filter(name => name.endsWith(".md")), ["c.md", "a.md", "b.md"]);
|
||||
await drag("b.md", "c.md", "before");
|
||||
assert.deepEqual((await marks()).order[""].filter(name => name.endsWith(".md")), ["a.md", "b.md", "c.md"]);
|
||||
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");
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
// Folder actions in the tree: Open in terminal, and the Show .runestone folder setting from the settings window.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, openPage, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/folderActions", async ({ browser }) => {
|
||||
// The settings window shares the mock settings file with the main window, so both pages need one context.
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
await mockTauri(context, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({ root: "C:\\folder-actions", files: { "a.md": "# Alpha\n", "folder/keep.md": "# Keep\n", ".runestone/config.json": "{}" } });
|
||||
return {
|
||||
...workspace,
|
||||
workspace_list: args => workspace.workspace_list(args).filter(entry => args.rel || args.showInternal || entry.rel_path !== ".runestone"),
|
||||
workspace_open_terminal: () => null,
|
||||
settings_open_window: () => null,
|
||||
plugins_snapshot: () => ({ plugins: [], issues: [] }),
|
||||
spelling_menu_install: () => null,
|
||||
};
|
||||
},
|
||||
});
|
||||
const page = await openPage(context, { timeout: 15000 });
|
||||
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
||||
await page.goto(smokeUrl);
|
||||
await row("folder").click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Open in terminal", exact: true }).click();
|
||||
assert.ok(await page.evaluate(() => window.__TEST__.calls.some(call => call.command === "workspace_open_terminal" && call.args.rel === "folder")));
|
||||
console.log("PASS: Open in terminal");
|
||||
|
||||
await page.keyboard.press("Control+,");
|
||||
const settings = await openPage(context, { timeout: 15000 });
|
||||
await settings.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await settings.getByRole("switch", { name: "Show .runestone folder" }).check();
|
||||
await settings.close();
|
||||
await row(".runestone").waitFor();
|
||||
const errors = [...page.errors, ...settings.errors];
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: Show .runestone folder reveals the internal folder");
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
// File moves in the tree: cut and paste, Undo and Redo file move from the folder menu, Ctrl+Z, and drag into a folder.
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/moveUndo", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({ root: "C:\\move-undo", files: { "a.md": "# Alpha\n", "b.md": "# Beta\n", "folder/keep.md": "# Keep\n" } });
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
plugins_snapshot: () => ({ plugins: [], issues: [] }),
|
||||
spelling_menu_install: () => null,
|
||||
};
|
||||
},
|
||||
});
|
||||
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
||||
const menu = label => page.getByRole("menuitem", { name: label, exact: true });
|
||||
const has = path => page.waitForFunction(path => window.__TEST__.files.has(path), path);
|
||||
await page.goto(smokeUrl);
|
||||
await row("b.md").click({ button: "right" });
|
||||
await menu("Cut").click();
|
||||
await row("folder").click({ button: "right" });
|
||||
await menu("Paste").click();
|
||||
await has("folder/b.md");
|
||||
await row("folder").click({ button: "right" });
|
||||
await menu("Undo file move").click();
|
||||
await has("b.md");
|
||||
await row("folder").click({ button: "right" });
|
||||
await menu("Redo file move").click();
|
||||
await has("folder/b.md");
|
||||
await row("folder").focus();
|
||||
await page.keyboard.press("Control+z");
|
||||
await has("b.md");
|
||||
console.log("PASS: cut and paste, menu undo and redo, and Ctrl+Z");
|
||||
|
||||
const sourceBox = await row("b.md").boundingBox(), folderBox = await row("folder").boundingBox();
|
||||
await page.mouse.move(sourceBox.x + 50, sourceBox.y + sourceBox.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(folderBox.x + 70, folderBox.y + folderBox.height / 2, { steps: 12 });
|
||||
await page.mouse.up();
|
||||
await has("folder/b.md");
|
||||
await page.keyboard.press("Control+z");
|
||||
await has("b.md");
|
||||
console.log("PASS: drag into a folder, and Ctrl+Z");
|
||||
}, { timeout: 15000 });
|
||||
@@ -0,0 +1,113 @@
|
||||
// Splash actions and order, and New folder with inline rename in the root, collapsed, and empty folders, with and without a workspace.
|
||||
import assert from 'node:assert/strict';
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
await runSmoke('tree/navigation', async ({ browser }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 1280, height: 850 } });
|
||||
await mockTauri(context, {
|
||||
strict: false,
|
||||
commands: test => {
|
||||
const ws = test.workspace({ root: 'C:\\navigation-check', folders: ['Untitled', 'Parent', 'Empty'], files: { 'note.md': '# Note', 'Parent/existing.md': '# Existing' } });
|
||||
test.folders = ws.folders;
|
||||
return {
|
||||
...ws,
|
||||
workspace_last_path: () => test.noWorkspace ? null : ws.root,
|
||||
workspace_list: args => ws.workspace_list(args).filter(entry => !entry.rel_path.startsWith('.runestone')),
|
||||
workspace_search: () => [],
|
||||
plugins_snapshot: () => ({ root: 'C:/plugins', plugins: [] }),
|
||||
'plugin:window|is_maximized': () => false,
|
||||
};
|
||||
},
|
||||
});
|
||||
const page = await openPage(context);
|
||||
const output = await outputDir('tree/navigation');
|
||||
const shot = name => page.screenshot({ path: path.join(output, name) });
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
const input = () => page.locator('.tree input');
|
||||
const folderAction = () => page.getByRole('menuitem', { name: 'New folder', exact: true });
|
||||
async function checkRename(name) {
|
||||
await input().waitFor();
|
||||
await page.waitForFunction(() => document.activeElement?.matches('.tree input'));
|
||||
const state = await input().evaluate(node => ({ name: node.value, start: node.selectionStart, end: node.selectionEnd }));
|
||||
assert.deepEqual(state, { name, start: 0, end: name.length });
|
||||
assert.equal(await page.getByRole('dialog').count(), 0, 'New folder uses inline rename');
|
||||
}
|
||||
async function setMode(mode) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await row('Untitled').waitFor();
|
||||
const welcome = page.locator('.welcome-actions');
|
||||
await welcome.waitFor();
|
||||
await welcome.getByRole('button', { name: 'Open browser', exact: true }).waitFor();
|
||||
assert.deepEqual(await welcome.locator('button').allTextContents().then(values => values.map(value => value.replace(/Ctrl\+[NOP]/g, '').trim())), ['New file', 'New note', 'Find file', 'Open folder', 'Open browser']);
|
||||
const firstRow = welcome.locator('.welcome-row').first();
|
||||
assert.equal(await firstRow.locator('button').count(), 3);
|
||||
const tops = await firstRow.locator('button').evaluateAll(nodes => nodes.map(node => node.getBoundingClientRect().top));
|
||||
assert.ok(tops.every(top => top === tops[0]), 'Wide layout has three actions in the first row');
|
||||
await welcome.getByRole('button', { name: /^New file/ }).focus();
|
||||
for (const name of ['New note', 'Find file', 'Open folder', 'Open browser']) {
|
||||
await page.keyboard.press('Tab');
|
||||
assert.ok((await page.evaluate(() => document.activeElement.textContent)).includes(name), `Tab reaches ${name} in order`);
|
||||
}
|
||||
for (const mode of ['dark', 'light']) {
|
||||
await setMode(mode);
|
||||
await welcome.getByRole('button', { name: /^New file/ }).focus();
|
||||
await shot(`splash-${mode}.png`);
|
||||
await page.setViewportSize({ width: 850, height: 650 });
|
||||
await shot(`splash-${mode}-narrow.png`);
|
||||
assert.ok(await welcome.locator('button').evaluateAll(nodes => nodes.every(node => { const rect = node.getBoundingClientRect(); return rect.left >= 0 && rect.right <= innerWidth; })), 'Narrow splash controls fit');
|
||||
await page.setViewportSize({ width: 1280, height: 850 });
|
||||
}
|
||||
await page.getByRole('navigation', { name: 'Workspace files' }).click({ button: 'right', position: { x: 80, y: 320 } });
|
||||
await folderAction().focus();
|
||||
await page.keyboard.press('Enter');
|
||||
await checkRename('untitled 2');
|
||||
await input().fill('Created folder');
|
||||
await input().press('Enter');
|
||||
await row('Created folder').waitFor();
|
||||
await row('Parent').click();
|
||||
await row('Parent').click();
|
||||
assert.equal(await row('Parent').getAttribute('aria-expanded'), 'false');
|
||||
await row('Parent').click({ button: 'right' });
|
||||
await folderAction().click();
|
||||
await checkRename('untitled');
|
||||
assert.equal(await row('Parent').getAttribute('aria-expanded'), 'true', 'Cached collapsed parent opens for rename');
|
||||
await input().press('Escape');
|
||||
await row('Parent/untitled').waitFor();
|
||||
for (const mode of ['dark', 'light']) {
|
||||
await setMode(mode);
|
||||
await row('Parent').click({ button: 'right' });
|
||||
await folderAction().click();
|
||||
const expected = mode === 'dark' ? 'untitled 2' : 'untitled 3';
|
||||
await checkRename(expected);
|
||||
await shot(`new-folder-${mode}.png`);
|
||||
await page.setViewportSize({ width: 850, height: 650 });
|
||||
await shot(`new-folder-${mode}-narrow.png`);
|
||||
await input().press('Escape');
|
||||
await page.setViewportSize({ width: 1280, height: 850 });
|
||||
}
|
||||
await row('Empty').click({ button: 'right' });
|
||||
await folderAction().click();
|
||||
await checkRename('untitled');
|
||||
await input().fill('First folder');
|
||||
await input().press('Enter');
|
||||
await row('Empty/First folder').waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.folders.has('Empty/First folder')), true);
|
||||
|
||||
const emptyPage = await openPage(context);
|
||||
await emptyPage.addInitScript(() => { window.__TEST__.noWorkspace = true; });
|
||||
await emptyPage.goto(smokeUrl);
|
||||
await emptyPage.locator('.welcome-actions').waitFor();
|
||||
await emptyPage.locator('.welcome-actions').getByRole('button', { name: 'Open browser', exact: true }).waitFor();
|
||||
assert.deepEqual(await emptyPage.locator('.welcome-actions button').allTextContents().then(values => values.map(value => value.replace(/Ctrl\+O/g, '').trim())), ['Open folder', 'Open browser']);
|
||||
await emptyPage.screenshot({ path: path.join(output, 'splash-no-workspace.png') });
|
||||
await emptyPage.close();
|
||||
const errors = [...page.errors, ...emptyPage.errors];
|
||||
assert.deepEqual(errors, []);
|
||||
await writeFile(path.join(output, 'checks.json'), JSON.stringify({ passed: true, checks: ['Case-insensitive root name collision', 'Selected inline name and no dialog', 'Enter saves rename', 'Escape retains created folder', 'Collapsed cached parent opens', 'Empty parent', 'Repeated unique names', 'Splash order and three-column maximum', 'Keyboard tab order', 'No workspace actions', 'Dark/light wide/narrow screenshots'], errors }, null, 2));
|
||||
console.log(`Navigation checks passed. Evidence: ${output}`);
|
||||
});
|
||||
@@ -0,0 +1,128 @@
|
||||
// New files keep exact names and extensions, renames change the code language, and Writer menus work in both themes.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/newFiles", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const ws = test.workspace({
|
||||
root: "C:\\editor-files-smoke",
|
||||
files: {
|
||||
"note.md": "Mispelled text.\n\n| Word | Value |\n| --- | --- |\n| Speling | Other |\n",
|
||||
"hello.txt": "print('hello')\n",
|
||||
"notes/existing.md": "Existing note",
|
||||
},
|
||||
});
|
||||
const files = ws.files;
|
||||
test.files = files;
|
||||
return {
|
||||
...ws,
|
||||
workspace_list: args => ws.workspace_list(args).filter(entry => !entry.rel_path.startsWith(".runestone")),
|
||||
workspace_create: ({ rel }) => {
|
||||
if (files.has(rel)) throw new Error("path already exists");
|
||||
files.set(rel, "");
|
||||
},
|
||||
workspace_rename: ({ from, to }) => {
|
||||
if (files.has(to)) throw new Error("destination already exists");
|
||||
files.set(to, files.get(from));
|
||||
files.delete(from);
|
||||
},
|
||||
spelling_suggestions: ({ word }) => ({ language: "en-US", words: word === "Mispelled" ? ["Misspelled"] : [], misspelled: word === "Mispelled" }),
|
||||
};
|
||||
},
|
||||
});
|
||||
const row = name => page.locator(`[data-tree-rel="${name}"]`);
|
||||
// The file pane header offers New note and New folder (src/lib/layout/FileTree.svelte:886-887);
|
||||
// New file… is in the pane menu (src/lib/layout/FileTree.svelte:716-720).
|
||||
async function newRootFile() {
|
||||
await page.getByRole("navigation", { name: "Workspace files" }).click({ button: "right", position: { x: 80, y: 320 } });
|
||||
await page.getByRole("menuitem", { name: "New file…", exact: true }).click();
|
||||
}
|
||||
async function enterName(name) {
|
||||
await page.locator("#text-request").fill(name);
|
||||
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
||||
}
|
||||
async function modelDetails() {
|
||||
return page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
const view = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
|
||||
return view && { language: view.contentDOM.dataset.language, value: view.state.doc.toString(), fontSize: parseFloat(getComputedStyle(view.contentDOM).fontSize) };
|
||||
});
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await row("note.md").waitFor();
|
||||
await newRootFile();
|
||||
await enterName("LICENSE");
|
||||
await row("LICENSE").waitFor();
|
||||
await page.evaluate(() => window.__TEST__.files.set("LICENSE", "Keep this content"));
|
||||
await newRootFile();
|
||||
await enterName("LICENSE");
|
||||
await page.getByText("path already exists", { exact: true }).waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get("LICENSE")), "Keep this content");
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.has("LICENSE 2")), false);
|
||||
await row("notes").click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "New file…", exact: true }).click();
|
||||
await enterName("hello_world.py");
|
||||
await row("notes/hello_world.py").waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.has("notes/hello_world.py.md")), false);
|
||||
await row("hello.txt").dblclick();
|
||||
await page.waitForFunction(() => !!document.querySelector(".source-editor .cm-line"));
|
||||
await row("hello.txt").click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Rename", exact: true }).click();
|
||||
assert.equal(await row("hello.txt").locator("input.rename").inputValue(), "hello.txt");
|
||||
await row("hello.txt").locator("input.rename").fill("hello.py");
|
||||
await page.keyboard.press("Enter");
|
||||
await row("hello.py").waitFor();
|
||||
await page.waitForFunction(() => document.querySelector(".source-editor .cm-content")?.getAttribute("data-language") === "python");
|
||||
const code = await modelDetails();
|
||||
assert.equal(code.value, "print('hello')\n");
|
||||
assert.equal(code.fontSize, 13);
|
||||
await page.keyboard.press("Control+e");
|
||||
assert.equal((await modelDetails()).fontSize, code.fontSize, "Code size stays the same in both layouts");
|
||||
await row("note.md").dblclick();
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.writerTest = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
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);
|
||||
const nativeAllowed = await page.evaluate(() => {
|
||||
window.writerTest.dispatch({ selection: { anchor: 3 } });
|
||||
const line = document.querySelector(".cm-line"), rect = line.getBoundingClientRect();
|
||||
const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: rect.left + 15, clientY: rect.top + 5 });
|
||||
line.dispatchEvent(event);
|
||||
return !event.defaultPrevented;
|
||||
});
|
||||
// Writer combines spelling suggestions with the Markdown actions (docs/design-decisions.md UI-027;
|
||||
// the contextmenu handler of src/lib/editor/DocumentEditor.svelte prevents the native menu and passes the spelling offset).
|
||||
assert.equal(nativeAllowed, false, "Plain text opens the shared Markdown menu instead of the native one");
|
||||
const textMenu = page.getByRole("menu", { name: "Markdown text actions", exact: true });
|
||||
await textMenu.getByRole("menuitem", { name: "Misspelled", exact: true }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await page.getByRole("menu").count(), 0);
|
||||
await page.evaluate(() => { window.writerTest.focus(); });
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await page.getByRole("menu", { name: "Markdown text actions", exact: true }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.evaluate(() => window.writerTest.dispatch({ selection: { anchor: 0, head: 9 } }));
|
||||
await page.getByText("Mispelled text.", { exact: true }).click({ button: "right" });
|
||||
await page.getByRole("menu", { name: "Markdown text actions", exact: true }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator(".live-writer td").first().click({ button: "right" });
|
||||
await page.getByRole("menu", { name: "Table actions", exact: true }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator(".writer-cell-editor").click();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await page.locator(".writer-cell-editor p").evaluate(node => {
|
||||
const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true });
|
||||
node.dispatchEvent(event);
|
||||
return !event.defaultPrevented;
|
||||
}), true, "Active table text permits the native spelling menu");
|
||||
await page.locator(".cm-line").first().click();
|
||||
}
|
||||
}, { viewport: { width: 1280, height: 900 }, timeout: 15000 });
|
||||
@@ -0,0 +1,43 @@
|
||||
// Tree rename keeps pins and bookmarks: the file menu offers Copy path › System path, and Undo rename, Ctrl+Z, and Ctrl+Y restore the marks.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/renameMarks", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\rename-marks",
|
||||
files: { "a.md": "# Note\n\nOriginal text.", ".runestone/marks.json": JSON.stringify({ pins: ["a.md"], bookmarks: ["a.md"], order: { "": ["a.md"] } }) },
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
workspace_list: args => workspace.workspace_list(args).filter(entry => args.rel || entry.rel_path !== ".runestone"),
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
spelling_menu_install: () => null,
|
||||
};
|
||||
},
|
||||
});
|
||||
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
||||
const item = name => page.getByRole("menuitem", { name, exact: true });
|
||||
await page.goto(smokeUrl);
|
||||
await row("a.md").click({ button: "right" });
|
||||
// The file menu copies paths through the Copy path submenu, as the tab menu does.
|
||||
await item("Copy path").hover();
|
||||
assert.equal(await item("System path").count(), 1);
|
||||
await item("Rename").click();
|
||||
await page.locator(".tree input").fill("renamed.md");
|
||||
await page.locator(".tree input").press("Enter");
|
||||
await row("renamed.md").waitFor();
|
||||
await row("renamed.md").click({ button: "right" });
|
||||
assert.equal(await item("Undo rename").count(), 1);
|
||||
await page.keyboard.press("Escape");
|
||||
await row("renamed.md").focus();
|
||||
await page.keyboard.press("Control+z");
|
||||
await row("a.md").waitFor();
|
||||
assert.deepEqual(await page.evaluate(() => JSON.parse(window.__TEST__.files.get(".runestone/marks.json")).pins), ["a.md"]);
|
||||
await row("a.md").focus();
|
||||
await page.keyboard.press("Control+y");
|
||||
await row("renamed.md").waitFor();
|
||||
console.log("PASS: Copy path › System path, rename, Undo rename, and Ctrl+Z and Ctrl+Y with marks");
|
||||
}, { viewport: { width: 1200, height: 850 } });
|
||||
@@ -0,0 +1,46 @@
|
||||
// Rename fields select the file stem, the folder name, or the tab dialog name, in dark/wide and light/narrow layouts.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/renameSelection", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => test.workspace({
|
||||
root: "C:\\tree-actions-test",
|
||||
files: { "notes/a.md": "# A", "notes/nested/b.md": "# B", "target/a.md": "# Existing", "a.md": "# A", "b.md": "# B", "c.md": "# C" },
|
||||
}),
|
||||
});
|
||||
const output = await outputDir("tree/renameSelection");
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
const selection = input => input.evaluate(node => [node.selectionStart, node.selectionEnd, node.value]);
|
||||
await page.goto(smokeUrl);
|
||||
await row("notes").waitFor();
|
||||
for (const [theme, width] of [["dark", 1440], ["light", 620]]) {
|
||||
await page.setViewportSize({ width, height: 850 });
|
||||
// The side pane gives way below 800 pixels. The test opens it again.
|
||||
if (width < 800) { await page.locator("aside.left").waitFor({ state: "detached" }); await page.keyboard.press("Control+Backslash"); await row("a.md").waitFor(); }
|
||||
await page.evaluate(theme => { document.documentElement.dataset.theme = theme; document.documentElement.dataset.palette = "default"; }, theme);
|
||||
await row("a.md").click();
|
||||
await row("a.md").focus();
|
||||
await page.keyboard.press("F2");
|
||||
const input = row("a.md").locator("input");
|
||||
await input.waitFor();
|
||||
assert.deepEqual(await selection(input), [0, 1, "a.md"]);
|
||||
await page.screenshot({ path: path.join(output, `rename-selection-${theme}.png`) });
|
||||
await input.press("Escape");
|
||||
await row("notes").click();
|
||||
await row("notes").focus();
|
||||
await page.keyboard.press("F2");
|
||||
const folder = row("notes").locator("input");
|
||||
await folder.waitFor();
|
||||
assert.deepEqual(await selection(folder), [0, 5, "notes"]);
|
||||
await folder.press("Escape");
|
||||
await page.getByRole("tab", { name: "a.md", exact: true }).click();
|
||||
await page.getByRole("tab", { name: "a.md", exact: true }).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Rename…", exact: true }).click();
|
||||
const dialogInput = page.locator("#text-request");
|
||||
await dialogInput.waitFor();
|
||||
assert.deepEqual(await selection(dialogInput), [0, 1, "a.md"]);
|
||||
await dialogInput.press("Escape");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,121 @@
|
||||
// Inline note title rename: tabs and tree, undo of contents, Enter/Tab/Escape, validation, collisions, tab switches mid-rename, and reload.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/renameTitle", async ({ page }) => {
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const ws = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"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 files = ws.files;
|
||||
Object.assign(test, { files, root: ws.root });
|
||||
return {
|
||||
...ws,
|
||||
workspace_write: ({ rel, contents, expected }) => {
|
||||
if (expected !== undefined && files.get(rel) !== expected) throw new Error("Save blocked: file changed on disk");
|
||||
files.set(rel, contents);
|
||||
test.emit("workspace-event", { root: ws.root, kind: "modify", paths: [rel] });
|
||||
},
|
||||
workspace_rename: async ({ from, to }) => {
|
||||
if (test.delayRename) await new Promise(resolve => { test.resumeRename = resolve; });
|
||||
if (!files.has(from)) throw new Error("File is missing");
|
||||
if (files.has(to)) throw new Error("A file with that name already exists");
|
||||
files.set(to, files.get(from));
|
||||
files.delete(from);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir("tree/renameTitle");
|
||||
const title = page.getByRole("button", { name: "Rename note", exact: true });
|
||||
const input = page.getByRole("textbox", { name: "Note filename", exact: true });
|
||||
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
// Empty names and path separators share one message (src/lib/workspace/renamePath.ts:56-57, used by Workbench.svelte:958).
|
||||
const invalidName = "Enter a document name without a leading dot or reserved filename characters.";
|
||||
async function openNote(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 title.waitFor();
|
||||
}
|
||||
async function editTitle(value) { await title.click(); await input.fill(value); }
|
||||
const renamed = name => page.waitForFunction(expected => document.querySelector(".breadcrumb")?.title === expected, name);
|
||||
|
||||
try {
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await openNote("welcome.md");
|
||||
const original = await page.evaluate(() => window.__TEST__.files.get("notes/welcome.md"));
|
||||
await writer.click();
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.type("Unsaved text");
|
||||
await editTitle("Release 1.2");
|
||||
await input.press("Enter");
|
||||
await renamed("notes/Release 1.2.md");
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.has("notes/welcome.md")), false);
|
||||
await page.getByRole("tab", { name: /Release 1\.2\.md/ }).waitFor();
|
||||
await page.locator(".tree").getByText("notes", { exact: true }).click();
|
||||
await page.locator(".tree").getByText("Release 1.2", { exact: true }).waitFor();
|
||||
await writer.click();
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(text => window.__TEST__.files.get("notes/Release 1.2.md") === text, original);
|
||||
await page.keyboard.press("Control+y");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(text => window.__TEST__.files.get("notes/Release 1.2.md") === text, original + "Unsaved text");
|
||||
|
||||
await editTitle("Cancelled");
|
||||
await input.press("Escape");
|
||||
await renamed("notes/Release 1.2.md");
|
||||
assert.equal(await input.isVisible(), false);
|
||||
// Keyboard activation and filename errors stay outside Markdown editing.
|
||||
await title.focus(); await title.press("Enter");
|
||||
await input.fill(" "); await input.press("Enter");
|
||||
await page.getByRole("alert").filter({ hasText: invalidName }).waitFor();
|
||||
await input.fill("folder/note"); await input.press("Enter");
|
||||
await page.getByRole("alert").filter({ hasText: invalidName }).waitFor();
|
||||
await page.waitForFunction(() => !document.querySelector(".note-title-input[aria-busy]"));
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.calls.some(call => call.command === "workspace_rename" && call.args.to.includes("folder"))), false);
|
||||
await input.fill("second"); await input.press("Enter");
|
||||
await page.getByRole("alert").filter({ hasText: "already exists" }).waitFor();
|
||||
assert.equal(await input.inputValue(), "second");
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get("notes/second.md")), "# Second note\n");
|
||||
await input.fill("Renamed.md"); await input.press("Tab");
|
||||
await renamed("notes/Renamed.md");
|
||||
await page.mouse.move(10, 10);
|
||||
await page.screenshot({ path: path.join(output, "rename-title.png") });
|
||||
|
||||
// A pending rename belongs to its original document even if the tab changes.
|
||||
await page.evaluate(() => { window.__TEST__.delayRename = true; });
|
||||
await editTitle("Background"); await input.press("Enter");
|
||||
await page.waitForFunction(() => !!window.__TEST__.resumeRename);
|
||||
// A plain tree click replaces the current tab (src/lib/layout/Workbench.svelte:1347), so open the other note in a new tab.
|
||||
await page.locator('[data-tree-rel="notes/second.md"]').click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Open in new tab", exact: true }).click();
|
||||
await renamed("notes/second.md");
|
||||
await page.evaluate(() => { window.__TEST__.resumeRename(); window.__TEST__.delayRename = false; });
|
||||
await page.getByRole("tab", { name: "Background.md", exact: true }).waitFor();
|
||||
await renamed("notes/second.md");
|
||||
await page.getByRole("tab", { name: "Background.md", exact: true }).click();
|
||||
await renamed("notes/Background.md");
|
||||
// Disk reload after rename must not restore the old displayed title.
|
||||
await page.evaluate(() => {
|
||||
window.__TEST__.files.set("notes/Background.md", "Reloaded\n");
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "modify", paths: ["notes/Background.md"] });
|
||||
});
|
||||
await page.waitForFunction(() => document.querySelector(".cm-line")?.textContent === "Reloaded");
|
||||
assert.ok((await title.innerText()).startsWith("Background"));
|
||||
} catch (error) {
|
||||
console.error("Visible text:", (await page.locator("body").innerText()).slice(0, 3000));
|
||||
await page.screenshot({ path: path.join(output, "rename-title-failure.png") });
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,168 @@
|
||||
// Tree rename undo and redo keep folders expanded; New note templates, native Git navigation, and detached tab layout isolation.
|
||||
import assert from 'node:assert/strict';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
await runSmoke('tree/renameUndo', async ({ browser }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 1200, height: 850 } });
|
||||
await mockTauri(context, {
|
||||
strict: false,
|
||||
commands: test => {
|
||||
const ws = test.workspace({
|
||||
root: 'C:\\host-todo-test',
|
||||
files: {
|
||||
'a.md': '# Note\n\nOriginal text.', 'folder/nested/note.md': '# Nested', 'other/keep.md': '# Keep', '.runestone/templates/Daily.md': '# Daily\n\n## Tasks',
|
||||
'.runestone/marks.json': JSON.stringify({ pins: ['a.md'], bookmarks: ['a.md'], order: { '': ['a.md'] } }),
|
||||
},
|
||||
});
|
||||
const files = ws.files;
|
||||
const within = (from, path) => path === from || path.startsWith(from + '/');
|
||||
test.files = files;
|
||||
return {
|
||||
workspace_last_path: ws.workspace_last_path,
|
||||
workspace_open: ws.workspace_open,
|
||||
workspace_read: ws.workspace_read,
|
||||
workspace_list: args => ws.workspace_list(args).filter(entry => args.rel || !entry.rel_path.startsWith('.runestone')),
|
||||
workspace_create: ({ rel }) => { if (files.has(rel)) throw new Error('Destination exists'); files.set(rel, ''); },
|
||||
workspace_write: ({ rel, contents, expected }) => {
|
||||
if (expected !== undefined && files.get(rel) !== expected) throw new Error('Changed on disk');
|
||||
files.set(rel, contents);
|
||||
},
|
||||
workspace_rename: ({ from, to }) => {
|
||||
if (files.has(to)) throw new Error('Destination exists');
|
||||
if (![...files.keys()].some(path => within(from, path))) throw new Error('Missing file');
|
||||
for (const [path, contents] of [...files]) if (within(from, path)) { files.set(to + path.slice(from.length), contents); files.delete(path); }
|
||||
},
|
||||
workspace_delete: ({ rel }) => { files.delete(rel); },
|
||||
workspace_search: () => [],
|
||||
plugins_snapshot: () => ({ root: 'C:/plugins', plugins: [] }),
|
||||
git_status: () => ({ available: true, repository: true, branch: 'main', changes: [] }),
|
||||
'plugin:window|is_maximized': () => false,
|
||||
'plugin:dialog|message': () => 'Ok',
|
||||
};
|
||||
},
|
||||
});
|
||||
const page = await openPage(context, { timeout: 30000 });
|
||||
const output = await outputDir('tree/renameUndo');
|
||||
const shot = (target, name) => target.screenshot({ path: path.join(output, name) });
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
const item = name => page.getByRole('menuitem', { name, exact: true });
|
||||
const setMode = (target, mode) => target.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
||||
async function paneMenu() { await page.getByRole('navigation', { name: 'Workspace files' }).click({ button: 'right', position: { x: 90, y: 360 } }); }
|
||||
async function rename(rel, name) {
|
||||
await row(rel).click({ button: 'right' }); await item('Rename').click();
|
||||
await page.locator('.tree input').fill(name); await page.locator('.tree input').press('Enter');
|
||||
}
|
||||
async function expanded(rel) { assert.equal(await row(rel).getAttribute('aria-expanded'), 'true', `${rel} stays expanded`); }
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await row('folder').click(); await row('folder/nested').click(); await row('other').click();
|
||||
await rename('folder/nested/note.md', 'renamed.md'); await row('folder/nested/renamed.md').waitFor();
|
||||
await row('folder/nested/renamed.md').focus(); await page.keyboard.press('Control+z');
|
||||
await row('folder/nested/note.md').waitFor();
|
||||
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
|
||||
await page.keyboard.press('Control+y'); await row('folder/nested/renamed.md').waitFor();
|
||||
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
|
||||
await rename('folder', 'renamed-folder'); await row('renamed-folder/nested/renamed.md').waitFor();
|
||||
await row('renamed-folder').focus(); await page.keyboard.press('Control+z');
|
||||
await row('folder/nested/renamed.md').waitFor();
|
||||
for (const rel of ['folder', 'folder/nested', 'other']) await expanded(rel);
|
||||
await page.keyboard.press('Control+y'); await row('renamed-folder/nested/renamed.md').waitFor();
|
||||
for (const rel of ['renamed-folder', 'renamed-folder/nested', 'other']) await expanded(rel);
|
||||
await paneMenu(); assert.equal(await item('Manage templates…').isVisible(), false);
|
||||
await item('New note').click(); await row('untitled.md').waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get('untitled.md')), '');
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
||||
await item('Daily').click(); await row('Daily.md').waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get('Daily.md')), '# Daily\n\n## Tasks');
|
||||
await paneMenu(); await item('New note').hover(); await item('Manage templates…').click();
|
||||
await page.getByRole('button', { name: 'Close templates', exact: true }).click();
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await setMode(page, mode);
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
||||
await shot(page, `note-menu-${mode}.png`);
|
||||
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
|
||||
}
|
||||
await page.setViewportSize({ width: 600, height: 600 });
|
||||
// The side pane gives way below 800 pixels. The test opens it again.
|
||||
await page.locator('aside.left').waitFor({ state: 'detached' });
|
||||
await page.keyboard.press('Control+Backslash');
|
||||
await page.locator('aside.left').waitFor();
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
||||
await shot(page, 'note-menu-dark-narrow.png');
|
||||
assert.ok(await item('Manage templates…').evaluate(node => node.getBoundingClientRect().right <= innerWidth));
|
||||
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
|
||||
await page.setViewportSize({ width: 1200, height: 850 });
|
||||
await page.evaluate(() => { window.__TEST__.files.delete('.runestone/templates/Daily.md'); window.dispatchEvent(new Event('runestone-templates-changed')); });
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('ArrowRight');
|
||||
assert.equal(await item('Daily').count(), 0);
|
||||
await item('Manage templates…').click();
|
||||
await page.getByRole('button', { name: 'Close templates', exact: true }).click();
|
||||
const creations = await page.evaluate(() => window.__TEST__.calls.filter(call => call.command === 'workspace_create').length);
|
||||
await paneMenu(); await item('New note').focus(); await page.keyboard.press('Enter');
|
||||
await page.waitForFunction(count => window.__TEST__.calls.filter(call => call.command === 'workspace_create').length === count + 1, creations);
|
||||
await page.getByRole('button', { name: 'Source control', exact: true }).waitFor();
|
||||
assert.equal(await page.locator('.header-left').getByRole('button', { name: 'Source control', exact: true }).count(), 1);
|
||||
// Git is a native feature: no plug-in menu lists it, and its graph command is in the command palette.
|
||||
assert.equal(await page.getByRole('button', { name: 'Plug-in views', exact: true }).count(), 0);
|
||||
// The new note keeps the focus in its name field. Move the focus out of it before the palette shortcut.
|
||||
await page.evaluate(() => (document.activeElement instanceof HTMLElement) && document.activeElement.blur());
|
||||
await page.keyboard.press('Control+Shift+P');
|
||||
await page.getByRole('textbox', { name: 'Find a command', exact: true }).fill('Git graph');
|
||||
const graph = page.locator('#command-results .rs-picker-row', { hasText: 'Show Git graph' });
|
||||
await graph.waitFor();
|
||||
assert.match(await graph.innerText(), /Git/);
|
||||
await shot(page, 'real-git-command-dark.png');
|
||||
await page.keyboard.press('Escape');
|
||||
await page.evaluate(async () => {
|
||||
const external = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
external.pluginNavigation.set([{ owner: 'pm-test', id: 'pm', title: 'Board fixture', icon: 'kanban', placement: 'editor', toolbar: true }, { owner: 'git-test', id: 'source', title: 'Source control', icon: 'git', placement: 'sidebar', toolbar: true }]);
|
||||
external.pluginTools.set([{ owner: 'pm-test', id: 'pm', title: 'Board fixture', kind: 'view', surface: 'open' }, { owner: 'git-test', id: 'graph', title: 'Graph view', kind: 'command', surface: 'open', icon: 'git' }]);
|
||||
external.pluginTools.update(items => [...items, { owner: 'runestone.browser', id: 'new-tab', title: 'New browser tab', kind: 'command', surface: 'open' }]);
|
||||
const registry = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/registry.ts').name);
|
||||
registry.pluginHost.get('browser').newTab = async () => { window.__TEST__.browserOpened = true; };
|
||||
});
|
||||
// The app tools are in the left ribbon. Plugin view shortcuts stay out of it in this test (src/lib/layout/PluginRibbon.svelte).
|
||||
await page.locator('.plugin-ribbon').getByRole('button', { name: 'New browser tab', exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.browserOpened), true);
|
||||
assert.equal(await page.locator('.plugin-ribbon .ribbon-tools').getByRole('button', { name: 'Board fixture', exact: true }).count(), 0);
|
||||
assert.equal(await page.locator('.header-left').getByRole('button', { name: 'Source control', exact: true }).count(), 1);
|
||||
assert.equal(await page.locator('.plugin-ribbon .ribbon-tools').getByRole('button', { name: 'Source control', exact: true }).count(), 0);
|
||||
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
|
||||
assert.equal(await page.getByRole('menuitem', { name: /Board fixture/ }).count(), 1);
|
||||
assert.equal(await page.getByRole('menuitem', { name: /New browser tab/ }).count(), 0);
|
||||
await page.getByRole('menuitem', { name: /Graph view/ }).waitFor(); await page.keyboard.press('Escape');
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await setMode(page, mode);
|
||||
await page.getByRole('button', { name: 'Plug-in views', exact: true }).click();
|
||||
await shot(page, `plugin-navigation-${mode}.png`);
|
||||
await page.keyboard.press('Escape');
|
||||
}
|
||||
const token = '00000000-0000-4000-8000-000000000001';
|
||||
const saved = await page.evaluate(token => {
|
||||
const layout = JSON.stringify({ leftOpen: true, rightOpen: true, leftWidth: 280, rightWidth: 260, leftView: 'files' });
|
||||
localStorage.setItem('runestone.workbenchLayout', layout);
|
||||
void window.__TAURI_INTERNALS__.invoke('tab_transfer_offer', { id: token, root: 'C:\\host-todo-test', payload: JSON.stringify({ buffer: { id: 'moved', relPath: 'a.md', name: 'a.md', kind: 'text', contents: '# Transferred', saved: '# Note', chrome: 'Writing', pinned: true } }) });
|
||||
return layout;
|
||||
}, token);
|
||||
const detached = await openPage(context, { timeout: 30000 });
|
||||
await detached.goto(`${smokeUrl}/?tabTransfer=${token}`);
|
||||
await detached.getByRole('tab', { name: /a.md/ }).waitFor();
|
||||
await detached.getByText('# Transferred', { exact: true }).waitFor();
|
||||
assert.equal(await detached.locator('.shell.left-open,.shell.right-open').count(), 0);
|
||||
assert.equal(await detached.getByRole('button', { name: 'Show outline', exact: true }).count(), 0);
|
||||
assert.equal(await detached.evaluate(() => localStorage.getItem('runestone.workbenchLayout')), saved);
|
||||
assert.equal(await detached.getByRole('button', { name: 'Files', exact: true }).count(), 0);
|
||||
await detached.keyboard.press('Control+Backslash');
|
||||
await detached.keyboard.press('Control+Shift+f');
|
||||
assert.equal(await detached.locator('aside.left,aside.right,.plugin-ribbon,.gutter-v').count(), 0);
|
||||
await detached.keyboard.press('Escape');
|
||||
assert.equal(await detached.evaluate(() => localStorage.getItem('runestone.workbenchLayout')), saved);
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await setMode(detached, mode);
|
||||
await detached.setViewportSize({ width: 650, height: 600 });
|
||||
await shot(detached, `detached-${mode}-narrow.png`);
|
||||
}
|
||||
assert.deepEqual([...page.errors, ...detached.errors], []);
|
||||
console.log('Host navigation passed: nested file/folder rename undo/redo, expanded folders, blank New note parent, template submenu, plugin navigation dedup, detached layout isolation.');
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
// File tree selection: Ctrl and Shift ranges across expanded folders, F2 on multiple rows, and Collapse all.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/selection", async ({ page }) => {
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
await mockTauri(page, {
|
||||
commands: test => test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"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",
|
||||
},
|
||||
writeEvents: true,
|
||||
}),
|
||||
});
|
||||
const output = await outputDir("tree/selection");
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
const selected = () => page.locator('[role="treeitem"][aria-selected="true"]').evaluateAll(rows => rows.map(row => row.dataset.treeRel));
|
||||
await page.goto(smokeUrl);
|
||||
await row("notes").waitFor();
|
||||
await row("notes").click();
|
||||
await row("notes/second.md").waitFor();
|
||||
assert.deepEqual(await selected(), ["notes"]);
|
||||
await row("notes/second.md").click({ modifiers: ["Control"] });
|
||||
await row("src").click({ modifiers: ["Control"] });
|
||||
assert.deepEqual(await selected(), ["notes", "notes/second.md", "src"]);
|
||||
assert.equal(await row("src").getAttribute("aria-expanded"), "false");
|
||||
assert.equal(await page.getByRole("tab").count(), 1);
|
||||
assert.equal(await page.getByRole("tab", { name: "New tab", exact: true }).count(), 1);
|
||||
await row("notes").click({ modifiers: ["Control"] });
|
||||
assert.deepEqual(await selected(), ["notes/second.md", "src"]);
|
||||
assert.equal(await row("notes").getAttribute("aria-expanded"), "true");
|
||||
await row("notes/second.md").click({ modifiers: ["Shift"] });
|
||||
assert.deepEqual(await selected(), ["notes", "notes/second.md"]);
|
||||
await row("src").click({ modifiers: ["Shift"] });
|
||||
assert.deepEqual(await selected(), ["notes", "notes/second.md", "notes/welcome.md", "src"]);
|
||||
await page.keyboard.press("F2");
|
||||
assert.equal(await page.locator(".tree .rename").count(), 0);
|
||||
await row("notes/welcome.md").click({ modifiers: ["Shift"] });
|
||||
assert.deepEqual(await selected(), ["notes", "notes/second.md", "notes/welcome.md"]);
|
||||
await row("notes/second.md").click();
|
||||
assert.deepEqual(await selected(), ["notes/second.md"]);
|
||||
await page.getByRole("tab", { name: /second/ }).waitFor();
|
||||
await row("notes/second.md").click({ modifiers: ["Control"] });
|
||||
assert.deepEqual(await selected(), []);
|
||||
await row("src").click({ modifiers: ["Control"] });
|
||||
await row("notes").click({ modifiers: ["Control"] });
|
||||
await row("notes").click({ modifiers: ["Control"] });
|
||||
await page.keyboard.press("F2");
|
||||
assert.equal(await page.locator(".tree .rename").inputValue(), "src");
|
||||
await page.keyboard.press("Escape");
|
||||
await row("notes/second.md").click({ modifiers: ["Shift"] });
|
||||
assert.deepEqual(await selected(), ["notes/second.md", "notes/welcome.md", "src"]);
|
||||
const colors = await page.locator(".tree .row.selected").evaluateAll(rows => rows.map(row => getComputedStyle(row).backgroundColor));
|
||||
assert.equal(new Set(colors).size, 1);
|
||||
await page.screenshot({ path: path.join(output, "tree-selection.png") });
|
||||
await page.getByRole("button", { name: "Collapse all", exact: true }).click();
|
||||
assert.deepEqual(await selected(), ["src"]);
|
||||
await row("notes").click({ modifiers: ["Shift"] });
|
||||
assert.deepEqual(await selected(), ["notes", "src"]);
|
||||
await row("notes").click({ modifiers: ["Control"] });
|
||||
await row("notes").click({ modifiers: ["Shift", "Control"] });
|
||||
assert.deepEqual(await selected(), ["notes", "src"]);
|
||||
});
|
||||
Reference in New Issue
Block a user