Outliner: react-accessible-treeview's controlled expandedIds sync expands a node together with its parent, then the next pass treats that extra parent id as removed from the controlled set and collapses the whole branch. Reproduced as a collapsed tree after ch11 -> ch12 (scene rows complete in React, one collapsed row in the DOM). Keep OUTLINER_ROOT_ID in the controlled set so both passes agree, and drop the rows-digest memo that regressed the normal path. Also arm a bounded post-open OUTLINER_REFRESH loop so the tree settles on rows of the newly opened Main instead of the previous one. Tests: web/playwright.deployed.config.ts + web/tests/deployed walk the 31 manual chapters and the 31 capability rows headed against a deployed origin, and tools/web/run-deployed-functional-tests.mjs preflights, runs and reports. --local serves the production bundle from web/dist on loopback with the same COOP/COEP/CORP/CSP headers, so a case costs compile time instead of a 300 MB download: full local suite 60/60 in 10.3 min, also 60/60 against the deployed release. Report dirs are resolved absolute and [ch28a]-style tags map to their chapter. Area layout: split from the clamped source rect and keep the area switcher inside a narrow header. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
84 lines
4.5 KiB
JavaScript
84 lines
4.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
import ts from "typescript";
|
|
|
|
const repoRoot = path.resolve(import.meta.dirname, "../../..");
|
|
const sourcePath = path.join(repoRoot, "web/protocol/area-layout.ts");
|
|
const transpiled = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 },
|
|
fileName: sourcePath,
|
|
reportDiagnostics: true,
|
|
});
|
|
assert.deepEqual(transpiled.diagnostics, []);
|
|
const moduleUrl = "data:text/javascript;base64," + Buffer.from(transpiled.outputText).toString("base64");
|
|
const { applyAreaOperation, findAreaNeighbor, measureAreaRects } = await import(moduleUrl);
|
|
|
|
function area(id, x, y, width, height, editor = "3D Viewport") {
|
|
return { id, editor, regions: [], rect: { x, y, width, height }, maximized: false, contentKey: id };
|
|
}
|
|
function workspace(areas) {
|
|
return { id: "Layout", name: "Layout", areas, activeAreaId: areas[0].id, revision: 0 };
|
|
}
|
|
|
|
test("split creates a new generic area inside the active rect", () => {
|
|
const state = workspace([area("viewport", 0, 0, 1, 1)]);
|
|
const next = applyAreaOperation(state, { type: "SPLIT_AREA", areaId: "viewport", direction: "VERTICAL", factor: 0.5 });
|
|
assert.equal(next.areas.length, 2);
|
|
assert.equal(next.areas[0].rect.width, 0.5);
|
|
assert.equal(next.areas[1].rect.x, 0.5);
|
|
assert.equal(next.areas[1].contentKey, null);
|
|
assert.equal(next.areas[1].editor, "3D Viewport");
|
|
});
|
|
|
|
test("split starts from the clamped rect of an out-of-bounds restored area", () => {
|
|
/* A workspace restored from storage can carry a rect saved before the bounds
|
|
* clamp (probe: a 5th split area landed at x=1599 on a 1600px window). The
|
|
* split must clamp the source first instead of propagating it. A zero-width
|
|
* rect is not the case here: clampRect lifts it to AREA_MIN_WIDTH and the
|
|
* split then correctly refuses a second child below that minimum. */
|
|
const state = workspace([area("viewport", 1.2, 0, 0.6, 1)]);
|
|
const next = applyAreaOperation(state, { type: "SPLIT_AREA", areaId: "viewport", direction: "VERTICAL", factor: 0.5 });
|
|
assert.equal(next.areas.length, 2);
|
|
for (const item of next.areas) {
|
|
const { x, y, width, height } = item.rect;
|
|
assert.ok(x >= 0 && y >= 0 && width >= 0 && height >= 0, `${item.id} rect must be non-negative`);
|
|
assert.ok(x + width <= 1.0001 && y + height <= 1.0001, `${item.id} rect must stay inside the normalized grid`);
|
|
}
|
|
});
|
|
|
|
test("neighbor lookup uses perpendicular overlap and join unions rects", () => {
|
|
const state = workspace([area("left", 0, 0, 0.5, 1), area("right", 0.5, 0, 0.5, 1, "Properties")]);
|
|
assert.equal(findAreaNeighbor(state.areas, "right", "LEFT")?.id, "left");
|
|
const next = applyAreaOperation(state, { type: "JOIN_AREA", areaId: "right", targetAreaId: "left" });
|
|
assert.equal(next.areas.length, 1);
|
|
assert.deepEqual(next.areas[0].rect, { x: 0, y: 0, width: 1, height: 1 });
|
|
assert.equal(next.areas[0].editor, "Properties");
|
|
});
|
|
|
|
test("swap exchanges editors but keeps slot identity", () => {
|
|
const state = workspace([area("left", 0, 0, 0.5, 1), area("right", 0.5, 0, 0.5, 1, "Properties")]);
|
|
const next = applyAreaOperation(state, { type: "SWAP_AREAS", areaId: "left", targetAreaId: "right" });
|
|
assert.equal(next.areas.find((item) => item.id === "left")?.editor, "Properties");
|
|
assert.equal(next.areas.find((item) => item.id === "right")?.editor, "3D Viewport");
|
|
assert.equal(next.areas.find((item) => item.id === "left")?.contentKey, "left");
|
|
});
|
|
|
|
test("close keeps at least one area and maximize toggles", () => {
|
|
const state = workspace([area("viewport", 0, 0, 1, 1)]);
|
|
assert.equal(applyAreaOperation(state, { type: "CLOSE_AREA", areaId: "viewport" }).areas.length, 1);
|
|
const maximized = applyAreaOperation(state, { type: "TOGGLE_MAXIMIZE_AREA", areaId: "viewport" });
|
|
assert.equal(maximized.areas[0].maximized, true);
|
|
assert.equal(applyAreaOperation(maximized, { type: "TOGGLE_MAXIMIZE_AREA", areaId: "viewport" }).areas[0].maximized, false);
|
|
});
|
|
|
|
test("DOM rect measurement converts to bottom-left normalized Blender rects", () => {
|
|
const rect = (left, top, width, height) => ({ left, top, width, height, right: left + width, bottom: top + height });
|
|
const rects = measureAreaRects([{ id: "viewport", editor: "3D Viewport", contentKey: "viewport", rect: rect(100, 50, 800, 600) }], rect(100, 50, 1000, 800));
|
|
assert.equal(rects[0].rect.x, 0);
|
|
assert.equal(rects[0].rect.width, 0.8);
|
|
assert.equal(rects[0].rect.height, 0.75);
|
|
assert.equal(rects[0].rect.y, 0.25);
|
|
});
|