feat(web): adjustable workspace partitions, floating areas and uncluttered panels
- Add workspace-layout.tsx: three draggable separators (viewport/right column, viewport/timeline, outliner/properties) with pointer, arrow-key and double-click reset, remembered in one shared localStorage record. - Areas can pop out of the grid into floating windows from the area menu; the same section is only re-positioned, so the WebGL canvas and editor state survive. Title-bar drag, corner resize, dock button and grid placeholder. - Viewport overlays (N-panel, tool shelf, shading/navigation cluster) are draggable inside the viewport, with reset and a 视图 menu entry to reopen them. - Remove overlap: the docked quick toolbar gets its own grid band, the area switcher moves into the header (and only fades in over headerless areas), properties controls wrap when the column narrows, the N-panel stops growing to 714px, and the 901-1280px media query no longer freezes the right column at 290px over the draggable variable. - New spec wbv2-workspace-layout-production with evidence in tests/golden/WEB-WORKSPACE-LAYOUT-20261123 (NOT_CLAIMED); status doc records the local regressions, the A/B that pinned them and the online walk at 1440x900 and 1280x800 on release 20261124-workinf_blender_wasm-2c8449f42. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
220
web/tests/e2e/wbv2-workspace-layout-production.spec.ts
Normal file
220
web/tests/e2e/wbv2-workspace-layout-production.spec.ts
Normal file
@@ -0,0 +1,220 @@
|
||||
import { expect, test, type Locator, type Page } from "@playwright/test";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { observeNative } from "../fixtures/native-ui-workflow";
|
||||
|
||||
/* Wide enough that the responsive 290px column does not apply. */
|
||||
test.use({ viewport: { width: 1600, height: 1000 } });
|
||||
|
||||
const root = path.resolve(import.meta.dirname, "../../..");
|
||||
const outputDir = path.join(root, "tests/golden/WEB-WORKSPACE-LAYOUT-20261123");
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
|
||||
const LAYOUT_KEY = "web-blender.workspace-layout.v1";
|
||||
const OFFSET_KEY = "web-blender.panel-offsets.v1";
|
||||
|
||||
async function storedLayout(page: Page): Promise<{ splits?: Record<string, number>; floating?: Record<string, unknown> }> {
|
||||
return page.evaluate((key) => {
|
||||
try { return JSON.parse(window.localStorage.getItem(key) ?? "{}"); }
|
||||
catch { return {}; }
|
||||
}, LAYOUT_KEY);
|
||||
}
|
||||
|
||||
async function panelOffset(page: Page, id: string): Promise<{ x: number; y: number } | null> {
|
||||
return page.evaluate(([key, panelId]) => {
|
||||
try {
|
||||
const map = JSON.parse(window.localStorage.getItem(key as string) ?? "{}") as Record<string, { x: number; y: number }>;
|
||||
return map[panelId as string] ?? null;
|
||||
}
|
||||
catch { return null; }
|
||||
}, [OFFSET_KEY, id] as const);
|
||||
}
|
||||
|
||||
function rectOf(locator: Locator): Promise<{ x: number; y: number; width: number; height: number }> {
|
||||
return locator.evaluate((element) => {
|
||||
const rect = element.getBoundingClientRect();
|
||||
return { x: rect.x, y: rect.y, width: rect.width, height: rect.height };
|
||||
});
|
||||
}
|
||||
|
||||
/** Drag `handle` by (dx, dy) with real pointer input. */
|
||||
async function dragBy(page: Page, handle: Locator, dx: number, dy: number): Promise<void> {
|
||||
const box = await handle.boundingBox();
|
||||
expect(box, "drag handle must be laid out").toBeTruthy();
|
||||
/* Start on the grip itself: the handles also hold small buttons. */
|
||||
const startX = box!.x + Math.min(6, box!.width / 2);
|
||||
const startY = box!.y + box!.height / 2;
|
||||
await page.mouse.move(startX, startY);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(startX + dx / 2, startY + dy / 2, { steps: 4 });
|
||||
await page.mouse.move(startX + dx, startY + dy, { steps: 4 });
|
||||
await page.mouse.up();
|
||||
}
|
||||
|
||||
async function openScene(page: Page): Promise<void> {
|
||||
await observeNative(page);
|
||||
await page.goto("/?ui=web");
|
||||
await page.getByTestId("blend-file-input").setInputFiles(path.join(root, "tests/files/web/basic_scene.blend"));
|
||||
await expect(page.getByTestId("engine-status")).toContainText(/SceneIR r\d+/, { timeout: 120_000 });
|
||||
}
|
||||
|
||||
test("partition splitters resize, persist and reset the workspace areas", async ({ page }) => {
|
||||
test.setTimeout(240_000);
|
||||
await openScene(page);
|
||||
|
||||
const viewport = page.locator(".viewport-area").first();
|
||||
const properties = page.locator(".area-frame.properties-area").first();
|
||||
const timeline = page.locator(".timeline-area").first();
|
||||
const rightSplitter = page.locator('.workspace-splitter[data-splitter="right"]');
|
||||
const timelineSplitter = page.locator('.workspace-splitter[data-splitter="timeline"]');
|
||||
await expect(rightSplitter).toBeVisible({ timeout: 60_000 });
|
||||
await expect(timelineSplitter).toBeVisible();
|
||||
|
||||
const before = { viewport: await rectOf(viewport), properties: await rectOf(properties), timeline: await rectOf(timeline) };
|
||||
expect(before.properties.width).toBeCloseTo(320, 0);
|
||||
|
||||
/* Right column: widen the properties area by dragging the bar left. */
|
||||
await dragBy(page, rightSplitter, -120, 0);
|
||||
await expect.poll(async () => (await storedLayout(page)).splits?.rightWidth ?? 0, { timeout: 10_000 }).toBeGreaterThan(400);
|
||||
const widened = await rectOf(properties);
|
||||
expect(widened.width).toBeGreaterThan(before.properties.width + 100);
|
||||
expect((await rectOf(viewport)).width).toBeLessThan(before.viewport.width - 100);
|
||||
|
||||
/* Timeline: taller by dragging up. */
|
||||
await dragBy(page, timelineSplitter, 0, -40);
|
||||
await expect.poll(async () => (await storedLayout(page)).splits?.timelineHeight ?? 0, { timeout: 10_000 }).toBeGreaterThan(120);
|
||||
const taller = await rectOf(timeline);
|
||||
expect(taller.height).toBeGreaterThan(before.timeline.height + 30);
|
||||
|
||||
/* The size is a browser preference: it survives a reload. */
|
||||
const layout = await storedLayout(page);
|
||||
await page.reload();
|
||||
/* The unsaved test scene is not restored, but the layout preference is: the
|
||||
* right column must come back at the dragged width. */
|
||||
await expect(page.locator(".area-frame.properties-area").first()).toBeVisible({ timeout: 120_000 });
|
||||
const reloaded = await rectOf(page.locator(".area-frame.properties-area").first());
|
||||
expect(reloaded.width).toBeCloseTo(widened.width, 0);
|
||||
expect((await storedLayout(page)).splits?.rightWidth).toBe(layout.splits?.rightWidth);
|
||||
|
||||
/* Keyboard nudge and double-click reset both return to the built-in sizes. */
|
||||
await page.locator('.workspace-splitter[data-splitter="right"]').focus();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await expect.poll(async () => (await storedLayout(page)).splits?.rightWidth ?? 0, { timeout: 10_000 }).toBe(layout.splits!.rightWidth! - 16);
|
||||
await page.locator('.workspace-splitter[data-splitter="right"]').dblclick();
|
||||
await expect.poll(async () => (await storedLayout(page)).splits?.rightWidth ?? 0, { timeout: 10_000 }).toBe(320);
|
||||
await expect.poll(async () => (await rectOf(page.locator(".area-frame.properties-area").first())).width, { timeout: 10_000 }).toBeCloseTo(before.properties.width, 0);
|
||||
|
||||
fs.writeFileSync(path.join(outputDir, "splits.json"), JSON.stringify({
|
||||
schemaVersion: 1, browser: "chromium", storage: "OPFS",
|
||||
workflow: "/?ui=web + basic_scene.blend -> drag right/timeline splitters -> reload -> ArrowRight -> double-click reset",
|
||||
before, widened, taller, reloaded, splits: (await storedLayout(page)).splits ?? null,
|
||||
status: "PASS", acceptance: "NOT_CLAIMED",
|
||||
}, null, 2));
|
||||
});
|
||||
|
||||
test("an area pops out as a floating window and docks back", async ({ page }) => {
|
||||
test.setTimeout(240_000);
|
||||
await openScene(page);
|
||||
|
||||
const properties = page.locator(".area-frame.properties-area").first();
|
||||
const placeholder = page.locator(".area-dock-placeholder");
|
||||
await expect(placeholder).toHaveCount(0);
|
||||
|
||||
await properties.locator(".editor-header .desktop-menu-trigger > button").first().click();
|
||||
await page.getByRole("menuitem", { name: "浮动为独立窗口" }).click();
|
||||
await expect(properties).toHaveAttribute("data-floating", "true", { timeout: 10_000 });
|
||||
const floating = await properties.evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
const rect = element.getBoundingClientRect();
|
||||
return { position: style.position, rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height } };
|
||||
});
|
||||
expect(floating.position).toBe("fixed");
|
||||
await expect(placeholder).toBeVisible();
|
||||
expect((await storedLayout(page)).floating?.["properties-area"]).toBeTruthy();
|
||||
|
||||
/* Drag the title bar: the window moves and the new rect is remembered. */
|
||||
await dragBy(page, properties.locator(".editor-header"), 140, 80);
|
||||
const moved = await rectOf(properties);
|
||||
expect(moved.x).toBeGreaterThan(floating.rect.x + 100);
|
||||
expect(moved.y).toBeGreaterThan(floating.rect.y + 50);
|
||||
|
||||
/* The viewport keeps rendering while an area floats over the grid. */
|
||||
await page.screenshot({ path: path.join(outputDir, "floating-properties.png") });
|
||||
await expect(page.getByTestId("engine-status")).toContainText(/SceneIR r\d+/, { timeout: 30_000 });
|
||||
|
||||
await properties.getByLabel("停靠回布局").click();
|
||||
await expect(page.locator(".area-frame.properties-area").first()).not.toHaveAttribute("data-floating", "true");
|
||||
await expect(placeholder).toHaveCount(0);
|
||||
await expect.poll(async () => Object.keys((await storedLayout(page)).floating ?? {}).length, { timeout: 10_000 }).toBe(0);
|
||||
|
||||
fs.writeFileSync(path.join(outputDir, "floating-area.json"), JSON.stringify({
|
||||
schemaVersion: 1, browser: "chromium", storage: "OPFS",
|
||||
workflow: "properties area menu -> 浮动为独立窗口 -> drag title bar -> dock",
|
||||
floating, moved, status: "PASS", acceptance: "NOT_CLAIMED",
|
||||
}, null, 2));
|
||||
});
|
||||
|
||||
test("viewport overlays move out of the model and stay inside the viewport", async ({ page }) => {
|
||||
test.setTimeout(240_000);
|
||||
const errors: string[] = [];
|
||||
page.on("pageerror", (error) => errors.push(String(error)));
|
||||
await openScene(page);
|
||||
|
||||
const viewport = page.locator(".viewport-placeholder").first();
|
||||
const viewportRect = await rectOf(viewport);
|
||||
|
||||
/* N-panel: drag by its grip, then close it with the new × button. */
|
||||
const sidebar = page.locator(".viewport-sidebar").first();
|
||||
await expect(sidebar).toBeVisible({ timeout: 60_000 });
|
||||
await dragBy(page, sidebar.locator(".viewport-sidebar-grip"), 60, 60);
|
||||
await expect.poll(async () => (await panelOffset(page, "viewport-n-panel"))?.x ?? 0, { timeout: 10_000 }).not.toBe(0);
|
||||
const movedSidebar = await rectOf(sidebar);
|
||||
expect(movedSidebar.x).toBeGreaterThanOrEqual(viewportRect.x - 1);
|
||||
expect(movedSidebar.y).toBeGreaterThanOrEqual(viewportRect.y - 1);
|
||||
expect(movedSidebar.x + movedSidebar.width).toBeLessThanOrEqual(viewportRect.x + viewportRect.width + 1);
|
||||
expect(movedSidebar.y + movedSidebar.height).toBeLessThanOrEqual(viewportRect.y + viewportRect.height + 1);
|
||||
/* The N-panel stays a column; it used to grow to ~714px and hide the model. */
|
||||
expect(movedSidebar.width).toBeLessThanOrEqual(424);
|
||||
|
||||
await sidebar.getByLabel("关闭侧栏").click();
|
||||
await expect(viewport).toHaveAttribute("data-side-panel", "closed", { timeout: 10_000 });
|
||||
/* 视图 → 侧栏 is the reopen path (the N shortcut only fires from the canvas). */
|
||||
await page.getByRole("button", { name: "视图", exact: true }).click();
|
||||
await page.getByRole("menuitem", { name: "侧栏" }).click();
|
||||
await expect(viewport).toHaveAttribute("data-side-panel", "open", { timeout: 10_000 });
|
||||
await page.getByLabel("复位侧栏位置").click();
|
||||
await expect.poll(async () => (await panelOffset(page, "viewport-n-panel"))?.x ?? -1, { timeout: 10_000 }).toBe(0);
|
||||
|
||||
/* Shading + navigation cluster: one draggable group, no overlapping columns. */
|
||||
const quick = page.locator(".viewport-quick-tools").first();
|
||||
await expect(quick).toBeVisible();
|
||||
const shading = await rectOf(page.locator(".viewport-shading-tools").first());
|
||||
const navigation = await rectOf(page.locator(".viewport-navigation-tools").first());
|
||||
expect(navigation.y).toBeGreaterThanOrEqual(shading.y + shading.height - 1);
|
||||
await dragBy(page, quick.locator(".viewport-quick-tools-handle"), -120, 40);
|
||||
await expect.poll(async () => (await panelOffset(page, "viewport-quick-tools"))?.x ?? 0, { timeout: 10_000 }).not.toBe(0);
|
||||
const movedQuick = await rectOf(quick);
|
||||
expect(movedQuick.x).toBeLessThan(viewportRect.x + viewportRect.width);
|
||||
|
||||
/* Tool shelf: 视图 → 工具架 opens it, its header drags it off the model. */
|
||||
await page.getByRole("button", { name: "视图", exact: true }).click();
|
||||
await page.getByRole("menuitem", { name: "工具架" }).click();
|
||||
const shelf = page.locator(".viewport-tool-shelf").first();
|
||||
await expect(shelf).toBeVisible({ timeout: 30_000 });
|
||||
await dragBy(page, shelf.locator("header").first(), 40, 30);
|
||||
await expect.poll(async () => (await panelOffset(page, "viewport-tool-shelf"))?.x ?? 0, { timeout: 10_000 }).not.toBe(0);
|
||||
|
||||
expect(errors).toEqual([]);
|
||||
|
||||
fs.writeFileSync(path.join(outputDir, "viewport-overlays.json"), JSON.stringify({
|
||||
schemaVersion: 1, browser: "chromium", storage: "OPFS",
|
||||
workflow: "drag N-panel -> close/reopen with N -> reset -> drag quick tools -> T shelf -> drag header",
|
||||
viewportRect, movedSidebar, movedQuick, shading, navigation,
|
||||
offsets: {
|
||||
sidebar: await panelOffset(page, "viewport-n-panel"),
|
||||
quick: await panelOffset(page, "viewport-quick-tools"),
|
||||
shelf: await panelOffset(page, "viewport-tool-shelf"),
|
||||
},
|
||||
pageErrors: errors, status: "PASS", acceptance: "NOT_CLAIMED",
|
||||
}, null, 2));
|
||||
});
|
||||
Reference in New Issue
Block a user