Files
RuneStone/tests/smoke/layout/titleBar.smoke.mjs
T
Knotty Wyvern 0ab7fe0c64 Use the free header space for tabs
The drag area after the tabs kept 120 pixels. The tabs shrank and
scrolled first, so the 120 pixels stayed empty while tabs were out of
view.

- The drag area fills the free space after the + button. When the tabs
  need more room, they use all space up to a drag area of 48 pixels.
  Then they scroll.
- UI-062 records the rule change, and the interface design guide holds
  the new rule.

The titleBar smoke test checks the drag area with one tab and with 11
tabs. Card 7f1d29d6.
2026-11-03 00:23:17 -07:00

145 lines
10 KiB
JavaScript

// The title bar and the side pane: the bottom bar with the workspace switcher, Help, and Settings, the ribbon fallback, 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 bar at the bottom of the side pane holds the workspace switcher, Help, and Settings, as in Obsidian.
// The switcher opens the workspace list above 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 }));
const footer = page.locator("aside.left .left-footer");
assert.equal(await footer.locator(".workspace-button").count(), 1);
assert.equal(await footer.getByRole("button", { name: "Help and about (F1)", exact: true }).count(), 1);
assert.equal(await footer.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).count(), 1);
assert.equal(await page.locator("header.header .workspace-button").count(), 0);
// The header right keeps only Save, the outline toggle, and the window controls. The other tools are in the left ribbon.
assert.deepEqual(await page.locator(".header-right").getByRole("button").evaluateAll(nodes => nodes.map(node => node.getAttribute("aria-label"))),
["Save", "Hide outline", "Minimize window", "Maximize window", "Close window"]);
const ribbon = page.locator(".plugin-ribbon");
assert.equal(await ribbon.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).count(), 0, "The ribbon has no second copy while the pane is open");
await workspace.click();
const picker = page.getByRole("dialog", { name: "Workspaces" });
await picker.waitFor();
assert.ok(await picker.evaluate((node, top) => node.getBoundingClientRect().bottom <= top, (await workspace.boundingBox()).y));
await page.screenshot({ path: `${output}/bottom-bar.png` });
await page.keyboard.press("Escape");
// While the side pane is closed, the workspace switcher, Help, and Settings move to the bottom of the ribbon.
await page.keyboard.press("Control+\\");
await page.locator("aside.left").waitFor({ state: "detached" });
const ribbonSwitcher = ribbon.getByRole("button", { name: "Open folder (Ctrl+O)", exact: true });
await ribbonSwitcher.click();
await picker.waitFor();
const switcherBox = await ribbonSwitcher.boundingBox(), pickerBox = await picker.boundingBox();
assert.ok(pickerBox.y + pickerBox.height <= switcherBox.y + 1 && pickerBox.x < 100, JSON.stringify({ switcherBox, pickerBox }));
await page.screenshot({ path: `${output}/ribbon-fallback.png` });
await page.keyboard.press("Escape");
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();
// With few tabs, the drag area fills the free space after the + button.
const drag = page.locator(".window-drag-space");
await open(names[0]);
const center = await box(page.locator(".header-center")), free = await box(drag);
assert.ok(free.width > 400 && Math.abs(free.right - center.right) <= 1, JSON.stringify({ center, free }));
// Tabs keep a readable width and scroll. Fades show hidden tabs, and the list names every tab.
for (const name of names.slice(1)) 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);
// When the tabs scroll, they use all space up to a drag area of 48 pixels. Caption buttons are square and fill the title bar height.
assert.equal(Math.round((await box(drag)).width), 48);
assert.ok(Math.abs((await box(drag)).right - (await box(page.locator(".header-center"))).right) <= 1);
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: bottom bar of the side pane, ribbon fallback, readable tabs with fades and a list, tabs that fill the header up to the drag area, square caption buttons, Snap Layouts request, macOS layout, both themes, narrow window.");
});