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.
33 lines
1.9 KiB
TypeScript
33 lines
1.9 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { DEFAULT_WORKBENCH_LAYOUT, WORKBENCH_LAYOUT_KEY, parseWorkbenchLayout, saveWorkbenchLayout } from "../../../src/lib/workspace/workbenchLayout.ts";
|
|
|
|
test("missing and damaged layouts use defaults", () => {
|
|
for (const raw of [null, "{broken", "null", "[]", "42", '"text"']) {
|
|
assert.deepEqual(parseWorkbenchLayout(raw), DEFAULT_WORKBENCH_LAYOUT);
|
|
}
|
|
});
|
|
|
|
test("invalid layout fields do not discard valid collapsed states", () => {
|
|
for (const leftWidth of [0, -1, 159, 481, "260", null]) {
|
|
assert.deepEqual(parseWorkbenchLayout(JSON.stringify({ leftOpen: false, rightOpen: false, leftWidth, rightWidth: 320, leftView: "unknown", backlinksOpen: "false" })), {
|
|
...DEFAULT_WORKBENCH_LAYOUT, leftOpen: false, rightOpen: false, rightWidth: 320,
|
|
});
|
|
}
|
|
assert.deepEqual(parseWorkbenchLayout('{"leftOpen":"false","rightOpen":0}'), DEFAULT_WORKBENCH_LAYOUT);
|
|
// A layout from an older version has no backlinks field. The section starts expanded.
|
|
assert.equal(parseWorkbenchLayout('{"leftOpen":false}').backlinksOpen, true);
|
|
});
|
|
|
|
test("layout survives storage round trips with hidden panels, all navigation views, and collapsed backlinks", () => {
|
|
const store = new Map<string, string>();
|
|
for (const leftView of ["files", "search", "bookmarks"] as const) {
|
|
for (const [leftWidth, backlinksOpen] of [[160, false], [321.5, true], [480, false]] as const) {
|
|
const layout = { leftOpen: false, rightOpen: false, leftWidth, rightWidth: 400, leftView, backlinksOpen };
|
|
saveWorkbenchLayout({ setItem: (key, value) => { store.set(key, value); } }, layout);
|
|
assert.deepEqual(parseWorkbenchLayout(store.get(WORKBENCH_LAYOUT_KEY)!), layout);
|
|
}
|
|
}
|
|
assert.throws(() => saveWorkbenchLayout({ setItem: () => { throw new Error("Storage unavailable"); } }, { ...DEFAULT_WORKBENCH_LAYOUT }), /Storage unavailable/);
|
|
});
|