Files
RuneStone/tests/smoke/layout/titleBar.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

122 lines
8.2 KiB
JavaScript

// The title bar: the workspace button, the left ribbon, readable tabs with a list of all tabs, the drag area, caption buttons, Snap Layouts, and the macOS layout.
import assert from "node:assert/strict";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
const names = ["meeting-notes", "research-plan", "inbox", "field-notes", "weekly-review", "reading-list", "project-ideas", "travel", "budget", "journal", "recipes"];
await runSmoke("layout/titleBar", async ({ browser }) => {
const output = await outputDir("layout/titleBar");
const context = await browser.newContext({ viewport: { width: 1280, height: 720 } });
await mockTauri(context, {
state: { names },
commands: test => ({
...test.workspace({ root: "C:\\Users\\me\\Documents\\Field work", files: Object.fromEntries(test.state.names.map(name => [`notes/${name}.md`, `# ${name}\n\nText.\n`])) }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
"plugin:window|is_maximized": () => false,
window_snap_layouts: () => null,
}),
});
const page = await openPage(context);
async function open(name) {
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill(`${name}.md`);
await page.getByRole("dialog").getByRole("button").filter({ hasText: `${name}.md` }).first().click();
await page.getByRole("tab", { name: `${name}.md`, exact: true, selected: true }).waitFor();
}
const box = locator => locator.evaluate(node => { const rect = node.getBoundingClientRect(); return { x: rect.x, right: rect.right, width: rect.width, height: rect.height, bottom: rect.bottom }; });
await page.goto(smokeUrl);
// The workspace button is the first control of the header. It opens the workspace list below it.
const workspace = page.getByRole("button", { name: "Field work", exact: true });
await workspace.waitFor();
// Auto-save stays off, so the edited tab keeps its unsaved mark.
await page.evaluate(() => window.__TEST__.writeSettings("general", { autosaveEnabled: false, autosaveSeconds: 5 }));
assert.equal(await page.locator("header.header button").first().evaluate(node => node.classList.contains("workspace-button")), true);
await workspace.click();
const picker = page.getByRole("dialog", { name: "Workspaces" });
await picker.waitFor();
assert.ok(await picker.evaluate((node, bottom) => node.getBoundingClientRect().top >= bottom, (await box(workspace)).bottom));
await page.keyboard.press("Escape");
// Help and Settings stay in the left ribbon when the side pane closes.
await page.keyboard.press("Control+\\");
await page.locator("aside.left").waitFor({ state: "detached" });
const ribbon = page.locator(".plugin-ribbon");
await ribbon.getByRole("button", { name: "Help and about (F1)", exact: true }).click();
await page.getByRole("dialog", { name: "Help and about" }).waitFor();
await page.getByRole("button", { name: "Close help", exact: true }).click();
assert.equal(await ribbon.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).isVisible(), true);
assert.equal((await box(ribbon)).width, 44);
await page.keyboard.press("Control+\\");
await page.locator("aside.left").waitFor();
// Tabs keep a readable width and scroll. Fades show hidden tabs, and the list names every tab.
for (const name of names) await open(name);
const widths = await page.locator("header .tab").evaluateAll(tabs => tabs.map(tab => tab.getBoundingClientRect().width));
assert.ok(widths.every(width => width >= 120), JSON.stringify(widths));
const strip = page.locator("header .tabs");
assert.equal(await strip.evaluate(node => node.classList.contains("fade-start")), true);
assert.equal(await strip.evaluate(node => node.classList.contains("fade-end")), false, "The active last tab is in view with its close button");
await page.locator(".cm-content").click();
await page.keyboard.type("Edit ");
// An unsaved tab adds " •" to its name.
await page.getByRole("tab", { name: /^recipes.md/ }).click({ button: "right" });
await page.getByRole("menuitem", { name: "Pin", exact: true }).click();
await page.getByRole("button", { name: "All tabs", exact: true }).click();
const list = page.getByRole("menu", { name: "All tabs", exact: true });
await list.waitFor();
assert.equal(await list.getByRole("menuitemradio").count(), names.length);
const recipes = list.getByRole("menuitemradio", { name: /^recipes\.md/ });
assert.equal(await recipes.getAttribute("aria-checked"), "true");
assert.match(await recipes.innerText(), /Unsaved/);
assert.equal(await recipes.locator("svg").count(), 1, "The pinned tab shows the pin icon");
await page.screenshot({ path: `${output}/all-tabs.png` });
await list.getByRole("menuitemradio", { name: "inbox.md", exact: true }).click();
await page.getByRole("tab", { name: "inbox.md", exact: true, selected: true }).waitFor();
await list.waitFor({ state: "detached" });
assert.equal(await strip.evaluate(node => node.classList.contains("fade-end")), true);
// A fixed drag area follows the tabs. Caption buttons are square and fill the title bar height.
const drag = page.locator(".window-drag-space");
assert.equal(Math.round((await box(drag)).width), 120);
assert.equal(await drag.getAttribute("data-tauri-drag-region"), "");
const captions = await page.locator(".window-controls .icon-btn").evaluateAll(buttons => buttons.map(button => ({ width: button.getBoundingClientRect().width, height: button.getBoundingClientRect().height, radius: getComputedStyle(button).borderRadius })));
const height = (await box(page.locator("header.header"))).height;
assert.deepEqual(captions, Array(3).fill({ width: 46, height, radius: "0px" }));
// Resting on maximize asks the host for Snap Layouts. A short pass does not.
const calls = () => page.evaluate(() => window.__TEST__.calls.filter(call => call.command === "window_snap_layouts").length);
await page.getByRole("button", { name: "Maximize window", exact: true }).hover();
await page.mouse.move(600, 400);
await page.waitForTimeout(700);
assert.equal(await calls(), 0);
await page.getByRole("button", { name: "Maximize window", exact: true }).hover();
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "window_snap_layouts"));
await page.mouse.move(600, 400);
for (const theme of ["dark", "light"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); window.dispatchEvent(new Event("focus")); }, theme);
await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme);
await page.locator("header.header").screenshot({ path: `${output}/header-${theme}.png` });
}
await page.setViewportSize({ width: 880, height: 560 });
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
assert.ok((await box(page.locator(".window-controls"))).right <= 880);
await page.screenshot({ path: `${output}/narrow.png` });
// macOS keeps its native traffic lights: no caption buttons, and room at the start of the title bar.
const mac = await openPage(context);
await mac.addInitScript(() => {
Object.defineProperty(navigator, "platform", { get: () => "MacIntel" });
Object.defineProperty(navigator, "userAgentData", { get: () => ({ platform: "macOS" }) });
});
await mac.goto(smokeUrl);
await mac.getByRole("button", { name: "Field work", exact: true }).waitFor();
assert.equal(await mac.evaluate(() => document.documentElement.dataset.titleBar), "mac");
assert.equal(await mac.locator(".window-controls").count(), 0);
assert.equal(await mac.locator(".header-left").evaluate(node => getComputedStyle(node).paddingLeft), "82px");
assert.match(await mac.getByRole("button", { name: "Settings (⌘,)", exact: true }).getAttribute("aria-label"), /⌘/);
await mac.locator("header.header").screenshot({ path: `${output}/header-mac.png` });
assert.deepEqual([...page.errors, ...mac.errors], []);
console.log("PASS: workspace button, permanent ribbon, readable tabs with fades and a list, fixed drag area, square caption buttons, Snap Layouts request, macOS layout, both themes, narrow window.");
});