Files
RuneStone/tests/smoke/layout/outline.smoke.mjs
T
2026-11-16 04:21:21 -07:00

104 lines
5.4 KiB
JavaScript

// Sidebar layout persistence: the hidden outline, resized sidebars, the navigation view, and collapsed backlinks survive layout changes, tab changes, reloads, and reopened windows.
import assert from "node:assert/strict";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("layout/outline", async ({ browser }) => {
const output = await outputDir("layout/outline");
// Pages share one context, so a reopened window keeps the saved layout.
const context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
// Unknown commands return null, as the original mock did.
await mockTauri(context, {
strict: false,
commands: test => ({
...test.workspace({ root: "D:\\LayoutTest", files: { "note.md": "# Layout test\n\nA note.\n", "data.txt": "Plain text.\n" } }),
plugins_snapshot: () => ({ root: "D:\\LayoutTest\\plugins", plugins: [] }),
}),
});
const errors = [];
let page;
async function ready() { await page.getByRole("button", { name: /^(Hide|Show) outline$/ }).waitFor(); }
async function reopen() {
if (page) { errors.push(...page.errors); await page.close(); }
page = await openPage(context, { timeout: 5000 });
await page.goto(smokeUrl);
await ready();
}
async function resize(index, x) {
const box = await page.locator(".gutter-v").nth(index).boundingBox();
await page.mouse.move(box.x + box.width / 2, box.y + 60);
await page.mouse.down();
await page.mouse.move(x, box.y + 60);
await page.mouse.up();
}
async function widths() {
return page.locator(".shell").evaluate(element => [element.style.getPropertyValue("--left"), element.style.getPropertyValue("--right")]);
}
async function quickOpen(name) {
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).click();
await page.locator(`[role="tab"][data-path="${name}"][aria-selected="true"]`).waitFor();
}
await reopen();
await page.getByText("LayoutTest", { exact: true }).waitFor();
await quickOpen("note.md");
await page.locator(".cm-content").waitFor();
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
await page.keyboard.press("Control+e");
await page.locator(".source-editor .cm-content").waitFor();
assert.equal(await page.locator(".right").count(), 0);
await page.keyboard.press("Control+e");
await page.locator(".cm-content").waitFor();
assert.equal(await page.locator(".right").count(), 0);
console.log("PASS: hidden outline stays hidden across Writer and Source changes");
await page.reload();
await page.getByRole("button", { name: "Show outline", exact: true }).waitFor();
assert.equal(await page.locator(".right").count(), 0);
await reopen();
await page.getByRole("button", { name: "Show outline", exact: true }).waitFor();
console.log("PASS: hidden outline survives reload and window reopen");
await page.getByRole("button", { name: "Show outline", exact: true }).click();
// The left ribbon is 44 pixels wide, so the gutter at 374 gives a 330-pixel side pane.
await resize(0, 374);
await resize(1, 970);
const resized = await widths();
assert.deepEqual(resized, ["330px", "310px"]);
await page.getByRole("button", { name: "Bookmarks", exact: true }).click();
await reopen();
assert.deepEqual(await widths(), resized);
assert.equal(await page.getByRole("button", { name: "Bookmarks", exact: true }).getAttribute("aria-pressed"), "true");
await page.getByRole("button", { name: "Hide outline", exact: true }).waitFor();
console.log("PASS: resized sidebars and chosen navigation view survive reopen");
await page.getByRole("button", { name: "Bookmarks", exact: true }).click();
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
await reopen();
assert.equal(await page.locator(".left, .right").count(), 0);
await page.keyboard.press("Control+Backslash");
assert.equal(await page.getByRole("button", { name: "Bookmarks", exact: true }).getAttribute("aria-pressed"), "true");
await page.getByRole("button", { name: "Show outline", exact: true }).click();
assert.deepEqual(await widths(), resized);
console.log("PASS: collapsed sidebars retain their sizes and navigation view");
// Card e81770bc: collapsed backlinks stay collapsed while a tab without backlinks is active, and after a window reopen.
const backlinks = () => page.getByRole("button", { name: /^Backlinks \d+$/ });
await quickOpen("note.md");
await backlinks().click();
assert.equal(await backlinks().getAttribute("aria-expanded"), "false");
await quickOpen("data.txt");
await backlinks().waitFor({ state: "detached" });
await quickOpen("note.md");
assert.equal(await backlinks().getAttribute("aria-expanded"), "false");
await page.screenshot({ path: `${output}/backlinks-collapsed-after-tab-change.png` });
await reopen();
await quickOpen("note.md");
assert.equal(await backlinks().getAttribute("aria-expanded"), "false");
await backlinks().click();
assert.equal(await backlinks().getAttribute("aria-expanded"), "true");
assert.equal(await page.evaluate(() => JSON.parse(localStorage.getItem("runestone.workbenchLayout")).backlinksOpen), true);
console.log("PASS: collapsed backlinks survive a tab change and a window reopen");
errors.push(...page.errors);
assert.deepEqual(errors, []);
});