Files
RuneStone/tests/smoke/workspace/openAndCreate.smoke.mjs
T
Knotty Wyvern ebacdb8164 Add the command palette, Write formatting keys, and platform labels
Phase 5-2.

- Ctrl+Shift+P opens the command palette: every workbench command with
  its shortcut, then the plugin commands (UI-048).
- In Write, Ctrl+B, Ctrl+I, Ctrl+Shift+X, and Ctrl+Shift+H format the
  selection, and Ctrl+K inserts a Markdown link. The Format menu shows
  these shortcuts.
- Ctrl+\ toggles the side pane. It matches the physical key on every
  keyboard layout. Ctrl+B now belongs to Write.
- Help lists every shortcut in groups, open by default. The list comes
  from the command table.
- src/lib/ui/shortcuts.ts writes shortcut labels for the platform:
  Ctrl+Shift+P on Windows and Linux, and the macOS symbols on a Mac.
  The catalog uses placeholders, so no translation contains "Ctrl".
- 19 new catalog rows, and 10 rows converted to placeholders, in
  French, Japanese, and Simplified Chinese.
- Docs: UI-048, the user guide keyboard tables, and a label rule in
  ui-design.md.

New tests: layout/commands, tests/unit/ui/shortcuts.spec.ts, and new
cases in workbenchKeys.spec.ts. Tests that read the old labels or
pressed Ctrl+B for the side pane now use the new names and Ctrl+\.

The smoke harness raises the resource timing buffer to 5000 entries.
The new modules pushed the CodeMirror language module past the
default 250 entries, so editor/markdownPaste could not find its URL.
2026-10-28 19:10:25 -07:00

135 lines
8.6 KiB
JavaScript

// Workspace menu: recent history, opening and creating workspaces in new windows, cancellation, errors, keyboard use, removal, and the empty state.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("workspace/openAndCreate", async ({ page }) => {
const output = await outputDir("workspace/openAndCreate");
// Unknown commands return null, as the original mock did.
await mockTauri(page, {
strict: false,
commands: test => {
let current = "D:\\Notes";
let recent = ["D:\\Writing\\Notes", current, "D:\\Missing"];
let picked = null;
let contents = "Original note";
const windows = [];
Object.assign(test, { windows, pick: path => picked = path, clear: () => recent = [], reorder: () => recent = ["D:\\Writing\\Notes", current, "D:\\Missing"] });
return {
workspace_last_path: () => current,
workspace_recent: () => recent,
workspace_forget: args => { recent = recent.filter(path => path !== args.path); return recent; },
workspace_list: args => args.rel ? [] : [{ name: "note.txt", rel_path: "note.txt", kind: "file" }],
workspace_read: args => { if (args.rel === "note.txt") return contents; throw "File not found"; },
workspace_write: args => { contents = args.contents; },
"plugin:dialog|open": () => picked,
"plugin:dialog|message": () => "Cancel",
workspace_new: args => {
if (args.name === "Existing") throw "A file or folder with that name already exists.";
const root = args.parent + "\\" + args.name;
recent = [root, ...recent]; windows.push(root);
},
workspace_open_window: args => {
if (args.path.endsWith("Missing")) throw "folder does not exist";
windows.push(args.path);
recent = [args.path, ...recent.filter(p => p !== args.path)];
},
workspace_open: args => {
if (args.path.endsWith("Missing")) throw "folder does not exist";
current = args.path; recent = [current, ...recent.filter(p => p !== current)];
return { root: current, name: current.split("\\").pop(), watch_mode: "native" };
},
};
},
});
await page.goto(smokeUrl);
await page.locator(".ws").filter({ hasText: "Notes" }).waitFor();
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill("note.txt");
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.txt" }).first().click();
await page.locator(".source-editor .cm-content").waitFor();
await page.evaluate(async () => {
window.__EditorView = (await import("/node_modules/@codemirror/view/dist/index.js")).EditorView;
const view = window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "My pending edit" } });
});
const trigger = page.getByRole("button", { name: "Open folder", exact: true });
const menu = page.getByRole("dialog", { name: "Workspaces", exact: true });
await page.evaluate(() => window.__TEST__.reorder());
await trigger.click();
await menu.getByText("D:\\Writing\\Notes", { exact: true }).waitFor();
await page.mouse.move(1000, 50);
assert.equal(await menu.locator('.workspace-row').first().evaluate(node => node === document.activeElement), false, "Pointer opening does not force focus onto a different workspace");
assert.equal(await menu.locator('.workspace-row').first().evaluate(node => getComputedStyle(node).backgroundColor), "rgba(0, 0, 0, 0)", "The first workspace has no stuck highlight");
assert.equal(await menu.locator('[aria-current="true"]').count(), 1);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "plugin:dialog|open").length), 0);
await page.screenshot({ path: path.join(output, "workspaces-menu.png") });
const opened = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length);
await menu.getByRole("button").filter({ hasText: "Current" }).click();
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length), opened);
await page.keyboard.press("Control+o");
await menu.getByRole("button").filter({ hasText: "Missing" }).click();
await menu.getByRole("alert").filter({ hasText: "folder does not exist" }).waitFor();
await menu.getByRole("button", { name: "Open another folder…" }).click();
assert(await menu.isVisible(), "Cancelling folder picker keeps history available");
await menu.getByRole("button").filter({ hasText: "D:\\Writing\\Notes" }).click();
await menu.waitFor({ state: "hidden" });
assert.equal(await page.locator(".ws").textContent(), "Notes");
assert.deepEqual(await page.evaluate(() => window.__TEST__.windows), ["D:\\Writing\\Notes"]);
await trigger.click();
await page.evaluate(() => window.__TEST__.pick("D:\\Other"));
await menu.getByRole("button", { name: "Open another folder…" }).click();
await menu.waitFor({ state: "hidden" });
assert.equal(await page.locator(".ws").textContent(), "Notes");
await trigger.click();
await menu.getByRole("button", { name: "New workspace…" }).click();
const dialog = page.getByRole("dialog", { name: "New workspace", exact: true });
assert(await dialog.getByRole("button", { name: "Create workspace", exact: true }).isDisabled());
await dialog.getByLabel("Workspace name").fill("Existing");
await page.evaluate(() => window.__TEST__.pick("D:\\Projects"));
await dialog.getByRole("button", { name: "Browse…" }).click();
await dialog.getByRole("button", { name: "Create workspace", exact: true }).click();
await dialog.getByRole("alert").filter({ hasText: "already exists" }).waitFor();
await dialog.getByLabel("Workspace name").fill("Fresh notes");
await page.screenshot({ path: path.join(output, "workspaces-create.png") });
await dialog.getByRole("button", { name: "Create workspace", exact: true }).click();
await dialog.waitFor({ state: "hidden" });
assert.equal(await page.locator(".ws").textContent(), "Notes");
assert.deepEqual(await page.evaluate(() => window.__TEST__.windows), ["D:\\Writing\\Notes", "D:\\Other", "D:\\Projects\\Fresh notes"]);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length), opened);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "plugin:dialog|message").length), 0);
assert.equal(await page.evaluate(() => window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString()), "My pending edit");
assert(await page.getByRole("tab", { name: /note\.txt/ }).isVisible());
await trigger.click();
await page.keyboard.press("End");
assert.equal(await page.locator(":focus").textContent(), " Open another folder…");
await page.keyboard.press("Escape");
await menu.waitFor({ state: "hidden" });
for (const theme of ['light', 'dark']) {
await page.evaluate(async mode => {
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
applyAppearance({ theme: 'default', mode });
}, theme);
await page.setViewportSize({ width: theme === 'light' ? 1100 : 380, height: 800 });
await trigger.click();
await menu.getByRole('button', { name: 'Remove D:\\Missing from recent workspaces', exact: true }).focus();
await page.screenshot({ path: path.join(output, `workspaces-remove-${theme}.png`) });
if (theme === 'dark') {
await page.keyboard.press('Enter');
await menu.getByText('D:\\Missing', { exact: true }).waitFor({ state: 'detached' });
assert.equal(await page.locator('.ws').textContent(), 'Notes', 'History removal does not close the current workspace');
await page.keyboard.press('Escape');
await trigger.click();
assert.equal(await menu.getByText('D:\\Missing', { exact: true }).count(), 0, 'Removed paths stay absent after reopening');
}
await page.keyboard.press('Escape');
}
await page.setViewportSize({ width: 1100, height: 800 });
await page.evaluate(() => window.__TEST__.clear());
await trigger.click();
await menu.getByText("No recent workspaces yet.").waitFor();
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
await menu.waitFor({ state: "hidden" });
console.log("Workspace smoke passed: history, opening and creating in new windows, original workspace preserved, cancellation, errors, keyboard and empty state.");
}, { viewport: { width: 1100, height: 800 }, timeout: 30000 });