Files
RuneStone/tests/smoke/workspace/openAndCreate.smoke.mjs
T
Knotty Wyvern 69f90df571 Move the smoke tests onto the shared harness
Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri
IPC mock, the in-memory workspace, and output folders, instead of its
own copy. The tests keep their interactions and assertions. Mock
handlers that the app never calls are gone.

- Split the four mixed regression scripts into 18 feature tests.
- Update tests that broke when the app changed on purpose. Each update
  cites the app source that shows the new behavior.
- Mark two real app defects with @known-issue: the settings window
  controls are 1px shorter than the main window controls, and plugin
  tabs cannot be reordered by dragging without a workspace.
- Merge three palette unit tests into one table-driven test.
- The native tests load Playwright through the harness and read
  NATIVE_CDP_URL, with their old variable names as fallbacks.
- A failed smoke test saves a screenshot and prints the console errors.
- The runner runs failed tests once more, alone, and reports a test
  that then passes as flaky.

Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78
passed.
2026-10-27 20:58:55 -07:00

134 lines
8.4 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(".monaco-editor textarea").waitFor();
await page.evaluate(async () => {
window.__MONACO__ = (await import("/src/lib/editor/monacoEnv.ts")).monaco;
window.__MONACO__.editor.getEditors().find(e => e.getDomNode()?.isConnected).setValue("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.__MONACO__.editor.getEditors().find(e => e.getDomNode()?.isConnected)?.getValue()), "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 });