feat(web): workbench Outliner matches the desktop Layout geometry

The desktop golden comes from Blender's own laid-out screen data
(tools/web/measure-outliner-desktop.py, blender 5.2.0 LTS, factory
Layout at 1920x1080): right column 339 px, Outliner area 339x189 under
a 26 px header, 20 px rows, 14 px per-level indent (0.7 * UI_UNIT_X).
The workbench derives the right width and the Outliner/timeline split
from those ratios so it reproduces the area at the reference size and
scales elsewhere.

The headed suite grows outliner-metrics-web with +-1 px assertions,
and the runner now materializes inline base64 attachments so the
checker can compare the measured boxes against the golden.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-30 04:21:08 +08:00
parent 721acdad4f
commit 5ce5625f2e
8 changed files with 416 additions and 24 deletions

View File

@@ -1,9 +1,13 @@
import { expect, test, type Page } from "@playwright/test";
import { readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const BASIC_SCENE = path.resolve(HERE, "../../../tests/files/web/basic_scene.blend");
/* Desktop geometry measured from Blender's own Layout screen
* (tools/web/measure-outliner-desktop.py, blender 5.2.0 LTS, factory startup). */
const DESKTOP_METRICS = path.resolve(HERE, "../../../tests/golden/OUTLINER-DESKTOP-METRICS/outliner-metrics.json");
/* Shared entry for the web workbench: open the fixture through the product
* input, wait for the engine to own the project, and expose the native tools
@@ -88,6 +92,46 @@ test.describe("Outliner headed baseline", () => {
await expect.poll(async () => page.locator(`.outliner-tree button[aria-label="隐藏 ${name}"]`).count(), { timeout: 15_000 }).toBe(1);
});
test("[outliner-metrics-web] the workbench Outliner matches the desktop Layout geometry", async ({ page }, testInfo) => {
test.setTimeout(150_000);
await openWorkbench(page);
await expect.poll(async () => page.getByRole("treeitem").count(), { timeout: 20_000 }).toBeGreaterThan(1);
const golden = (JSON.parse(readFileSync(DESKTOP_METRICS, "utf8")) as { outliner: { width: number; height: number; headerHeight: number; rowHeight: number; indentPerLevel: number } }).outliner;
const measured = await page.evaluate(() => {
const rect = (element: Element | null) => {
if (!element) return null;
const box = element.getBoundingClientRect();
return { x: box.x, y: box.y, width: box.width, height: box.height };
};
const area = document.querySelector(".outliner-area");
const header = area?.querySelector(":scope > .editor-header") ?? null;
const rows = Array.from(document.querySelectorAll<HTMLElement>(".outliner-tree .tree-row"));
const paddingLevels = [...new Set(rows.map((row) => Math.round(parseFloat(getComputedStyle(row).paddingLeft))))].sort((a, b) => a - b);
const steps = paddingLevels.slice(1).map((value, index) => value - paddingLevels[index]);
return {
viewport: { width: window.innerWidth, height: window.innerHeight },
outliner: rect(area),
header: rect(header),
rowHeights: rows.map((row) => row.getBoundingClientRect().height),
paddingLevels,
indentPerLevel: steps.length ? Math.min(...steps) : null,
};
});
await testInfo.attach("outliner-metrics-web", { body: JSON.stringify({ golden, measured }, null, 2), contentType: "application/json" });
expect(measured.viewport).toEqual({ width: 1920, height: 1080 });
expect(measured.outliner).not.toBeNull();
expect(measured.header).not.toBeNull();
/* The desktop Layout at 1920x1080: Outliner area 339x189, header 26,
* row 20, indent 14 (UI_TREEVIEW_INDENT = 0.7 * UI_UNIT_X). */
expect(Math.abs(measured.outliner!.width - golden.width)).toBeLessThanOrEqual(1);
expect(Math.abs(measured.outliner!.height - golden.height)).toBeLessThanOrEqual(1);
expect(Math.abs(measured.header!.height - golden.headerHeight)).toBeLessThanOrEqual(1);
expect(measured.rowHeights.length).toBeGreaterThan(0);
for (const height of measured.rowHeights) expect(Math.abs(height - golden.rowHeight)).toBeLessThanOrEqual(1);
expect(measured.indentPerLevel).not.toBeNull();
expect(Math.abs(measured.indentPerLevel! - golden.indentPerLevel)).toBeLessThanOrEqual(1);
});
test("[outliner-mirror-baseline-web] the desktop mirror hands the Outliner to the DOM workspace", async ({ page }) => {
test.setTimeout(120_000);
await page.goto("/");