Keep the collapsed Backlinks section after a tab change
The Backlinks section expanded again when the user left a tab and came back. The section lost its state when it closed with its tab. - The workbench layout keeps the state in `backlinksOpen` and saves it with the other layout values. - The user guide describes the control. The outline smoke test and the workbenchLayout unit test check the state. Card e81770bc.
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
// Sidebar layout persistence: the hidden outline, resized sidebars, and the navigation view survive layout changes, reloads, and reopened windows.
|
||||
// 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, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
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" } }),
|
||||
...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: [] }),
|
||||
}),
|
||||
});
|
||||
@@ -32,11 +33,15 @@ await runSmoke("layout/outline", async ({ browser }) => {
|
||||
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 page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("note.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.md" }).click();
|
||||
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");
|
||||
@@ -75,6 +80,24 @@ await runSmoke("layout/outline", async ({ browser }) => {
|
||||
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, []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user