Files
RuneStone/tests/smoke/layout/panesAndSettings.smoke.mjs
T
Knotty Wyvern 0fdc991b2e Give way in narrow windows and use one icon for each action
Phase 5-6.

- Side panes give way when the window becomes narrow: the outline
  below 1100 pixels, the side pane below 800 pixels. They come back
  when the window grows. A pane that the user opens in a narrow window
  stays open, and the saved layout keeps the wide-window choice.
- One function has one icon. The SDK icon set gets duplicate, template,
  and tab. The reveal action has one label for each platform (Show in
  Explorer, Show in Finder, Show in file manager).
- The file menu follows one order: open, clipboard, organize, show and
  copy path, history, then Delete and Delete permanently in the error
  color after a separator. The tree copies paths through a Copy path
  submenu, as the tab menu does.
- The tree uses the shared chevron. Search hits come in groups by file,
  with counts and marked matches. Bookmarks show the name, the folder,
  and a remove button.
- All boolean settings use one switch design (src/lib/ui/switch.css).
  Browser settings apply at once, and the Save button is gone. The
  Settings window opens with the focus on its search.
- Targets of at least 24 pixels: the tab close button, outline rows,
  switches, and the settings search.
- Catalog rows in French, Japanese, and Simplified Chinese.
- Docs: UI-052, ui-design.md, and the user guide.

Tests: the new layout/panesAndSettings. Tests that closed or opened
panes by hand around narrow windows now rely on the new behavior, or
wait for the panes to give way before they reopen one. Tests that read
the old menu labels or the browser Save button use the new ones.
2026-10-28 21:31:36 -07:00

113 lines
8.0 KiB
JavaScript

// Layout, icons, and Settings: side panes that give way, one file menu order with a danger Delete, tree chevrons,
// grouped search hits, readable bookmarks, 24-pixel targets, one switch design, and the first focus in Settings.
import assert from "node:assert/strict";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("layout/panesAndSettings", async ({ browser }) => {
const output = await outputDir("layout/panesAndSettings");
const context = await browser.newContext({ viewport: { width: 1280, height: 760 } });
await mockTauri(context, {
commands: test => ({
...test.workspace({
root: "C:\\panes",
files: {
"alpha.md": "# Alpha\n\nThe river runs past the river mill.\n",
"notes/beta.md": "# Beta\n\nA river note.\n\nAnother river line.\n",
"notes/gamma.md": "# Gamma\n\nNo match here.\n",
".runestone/marks.json": JSON.stringify({ pins: [], bookmarks: ["notes/beta.md", "alpha.md"], order: {} }),
},
}),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
"plugin:window|is_maximized": () => false,
}),
});
const page = await openPage(context);
await page.goto(smokeUrl);
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
await row("alpha.md").waitFor();
await row("alpha.md").click();
await page.getByRole("tab", { name: "alpha.md", exact: true, selected: true }).waitFor();
// Side panes give way in narrow windows and come back when the window grows. The saved layout keeps the wide choice.
const panes = () => page.evaluate(() => ({ left: !!document.querySelector("aside.left"), right: !!document.querySelector("aside.right") }));
assert.deepEqual(await panes(), { left: true, right: true });
await page.setViewportSize({ width: 1000, height: 760 });
await page.waitForFunction(() => !document.querySelector("aside.right"));
assert.deepEqual(await panes(), { left: true, right: false });
await page.setViewportSize({ width: 760, height: 760 });
await page.waitForFunction(() => !document.querySelector("aside.left"));
const layout = () => page.evaluate(() => JSON.parse(localStorage.getItem("runestone.workbenchLayout") ?? "{}"));
assert.equal((await layout()).leftOpen, true);
assert.equal((await layout()).rightOpen, true);
// A pane that the user opens in a narrow window stays open.
await page.getByRole("button", { name: "Show outline", exact: true }).click();
await page.locator("aside.right").waitFor();
await page.screenshot({ path: `${output}/narrow-760.png` });
await page.setViewportSize({ width: 1280, height: 760 });
await page.waitForFunction(() => !!document.querySelector("aside.left") && !!document.querySelector("aside.right"));
// The file menu: open, clipboard, organize, show and copy path, history, then Delete in the error color.
await row("alpha.md").click({ button: "right" });
const menu = page.getByRole("menu", { name: "File actions", exact: true });
await menu.waitFor();
const labels = await menu.locator(":scope > button, :scope > hr").evaluateAll(nodes => nodes.map(node => node.tagName === "HR" ? "|" : node.querySelector(".action-label").textContent));
assert.deepEqual(labels, ["Open in new tab", "Open in default app", "Open in terminal", "|", "Cut", "Copy", "Paste", "Make a copy", "|",
"Rename", "Remove bookmark", "Pin", "Save as template", "|", "Show in Explorer", "Copy path", "|", "Undo file move", "Redo file move", "|", "Delete", "Delete permanently"]);
const error = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "var(--rs-error)"; document.body.append(probe); const color = getComputedStyle(probe).color; probe.remove(); return color; });
assert.equal(await menu.getByRole("menuitem", { name: "Delete", exact: true }).evaluate(node => getComputedStyle(node).color), error);
// Each function has one icon: duplicate, template, and tab differ from copy.
const icon = name => menu.getByRole("menuitem", { name, exact: true }).locator("svg").first().evaluate(node => node.innerHTML);
const copy = await icon("Copy");
for (const name of ["Make a copy", "Save as template", "Open in new tab"]) assert.notEqual(await icon(name), copy, name);
await page.screenshot({ path: `${output}/file-menu.png` });
await page.keyboard.press("Escape");
// Folders use the shared chevron. It turns when the folder opens.
const chevron = row("notes").locator(".twist svg");
assert.equal(await chevron.count(), 1);
assert.equal(await chevron.evaluate(node => getComputedStyle(node).transform), "none");
await row("notes").click();
await page.waitForFunction(() => getComputedStyle(document.querySelector('[data-tree-rel="notes"] .twist svg')).transform !== "none");
// Search hits come in groups by file, with a count and marked matches.
await page.getByRole("button", { name: "Search", exact: true }).click();
await page.getByPlaceholder("Search files and notes").fill("river");
await page.keyboard.press("Enter");
await page.getByRole("status").filter({ hasText: "3 results in 2 files" }).waitFor();
const groups = await page.locator(".results > .file").evaluateAll(nodes => nodes.map(node => [node.querySelector(".name").textContent, node.querySelector(".count").textContent]));
assert.deepEqual(groups, [["alpha.md", "1"], ["beta.md", "2"]]);
assert.equal(await page.locator(".results > .file").first().locator("mark").count(), 2);
assert.equal(await page.locator(".results mark").first().textContent(), "river");
await page.screenshot({ path: `${output}/search.png` });
await page.locator(".results button").filter({ hasText: "Another river line." }).click();
await page.getByRole("tab", { name: "beta.md", exact: true, selected: true }).waitFor();
// Bookmarks show the file name, its folder, and a remove button.
await page.getByRole("button", { name: "Bookmarks", exact: true }).click();
const bookmark = page.locator(".pane li").filter({ hasText: "beta.md" });
assert.equal(await bookmark.locator(".folder").textContent(), "notes");
await page.screenshot({ path: `${output}/bookmarks.png` });
await bookmark.getByRole("button", { name: "Remove bookmark: beta.md", exact: true }).click();
await bookmark.waitFor({ state: "detached" });
// Targets are at least 24 pixels.
const close = await page.getByRole("button", { name: "Close beta.md", exact: true }).boundingBox();
assert.ok(close.width >= 24 && close.height >= 24, JSON.stringify(close));
const outlineRows = await page.locator("aside.right li button").evaluateAll(nodes => nodes.map(node => node.getBoundingClientRect().height));
assert.ok(outlineRows.length && outlineRows.every(height => height >= 24), JSON.stringify(outlineRows));
// Settings: the first focus is on the search, and every switch has one design.
const settings = await openPage(context);
await settings.goto(smokeUrl + "/?settingsWindow=true");
await settings.getByRole("textbox", { name: "Search settings", exact: true }).waitFor();
await settings.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "Search settings");
await settings.getByRole("button", { name: "General", exact: true }).click();
const switches = await settings.getByRole("switch").evaluateAll(nodes => nodes.map(node => { const rect = node.getBoundingClientRect(); return `${node.className.split(" ")[0]} ${Math.round(rect.width)}x${Math.round(rect.height)}`; }));
assert.ok(switches.length >= 4 && switches.every(item => item === "rs-switch 40x24"), JSON.stringify(switches));
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
assert.equal(await settings.getByRole("switch", { name: "Transparent surfaces", exact: true }).evaluate(node => node.className.split(" ")[0]), "rs-switch");
await settings.screenshot({ path: `${output}/settings-appearance.png` });
assert.deepEqual([...page.errors, ...settings.errors], []);
console.log("PASS: panes give way, file menu order and icons, danger Delete, tree chevrons, grouped search, bookmarks, 24-pixel targets, one switch design, Settings first focus.");
});