Files
RuneStone/tests/smoke/workspace/openAndCreate.smoke.mjs
T
Knotty Wyvern c8cf56b224 Keep global actions visible and follow each platform's title bar
Phase 5-4.

- The workspace button sits at the left end of the header. It shows
  the workspace name and opens the workspace list below it.
- The left ribbon is always present: plugin views at the top, Help and
  Settings at the bottom. The left pane footer is gone.
- Tabs keep 120 pixels and scroll. Fades show tabs out of view, and a
  list button names all tabs, with pinned and unsaved marks. The
  active tab now scrolls into view with its close button.
- A drag area of 120 pixels follows the tabs. In a narrow header, the
  tabs shrink first, and the drag area keeps at least 48 pixels.
- Caption buttons are square, 46 pixels wide, and full height. When the
  pointer rests on maximize, the new window_snap_layouts command opens
  Snap Layouts with Win+Z for the focused window.
- macOS keeps its native traffic lights: tauri.macos.conf.json and the
  runtime window builders use an overlay title bar. Title bars leave
  --rs-titlebar-inset-start free for the traffic lights.
- 3 new catalog rows and 1 removed row, in French, Japanese, and
  Simplified Chinese.
- Docs: UI-050, the user guide, and ui-design.md.

Tests: the new layout/titleBar. Tests that used the left pane footer,
the rounded caption buttons, the 600-pixel theme editor pane, or a
ribbon of no width now follow the new layout.
2026-10-28 20:21:20 -07:00

136 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" } });
});
// The workspace button at the left of the header names the workspace (src/lib/layout/WorkbenchHeader.svelte).
const trigger = page.locator(".workspace-button");
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 });