test(e2e): cover pane resize, persistence, and edge cases

Four spec files under apps/web/e2e/tests/layout/ exercise the runtime
cap and pinned-defaults persistence end-to-end via dockview's `.dv-sash`
drag handles and `window.__dockviewApi__`:

- pane-resize-right: drag past the old 450px cap, viewport-shrink
  re-clamp, reload + cross-env propagation of preferred width.
- pane-resize-sidebar: same coverage for the sidebar including
  toggle-off/on width retention.
- pane-persistence-tablet: localStorage round-trip for the tablet
  layout keys (`task-layout-tablet-v1`, `task-layout-right-v2`).
- pane-resize-edge-cases: double-click smoke, rapid drags +
  beforeunload flush, maximize round-trip, sash off-viewport, resize
  with sidebar hidden.

Adds e2e/helpers/dockview-resize.ts for the shared drag + width
read-out helpers.
This commit is contained in:
José Almeida
2026-05-22 00:49:40 +01:00
parent f3cfcae463
commit c906d53ed9
5 changed files with 656 additions and 0 deletions
+109
View File
@@ -0,0 +1,109 @@
import { expect, type Page } from "@playwright/test";
/** Bounding-box info Playwright returns. Re-declared to avoid pulling the
* full Locator type just for one shape. */
type Box = { x: number; y: number; width: number; height: number };
/** Read the live pixel width of a dockview group containing a given panel. */
export async function getDockviewGroupWidth(page: Page, panelId: string): Promise<number> {
return page.evaluate((id) => {
type Group = { width: number };
type Panel = { group: Group };
type Api = { getPanel: (id: string) => Panel | undefined };
const api = (window as unknown as { __dockviewApi__?: Api }).__dockviewApi__;
if (!api) throw new Error("dockview api not exposed");
const pnl = api.getPanel(id);
if (!pnl) throw new Error(`panel ${id} not found`);
return pnl.group.width;
}, panelId);
}
/** Read the live pixel width of a dockview group by group ID. */
export async function getDockviewGroupWidthById(page: Page, groupId: string): Promise<number> {
return page.evaluate((id) => {
type Group = { id: string; width: number };
type Api = { groups: Group[] };
const api = (window as unknown as { __dockviewApi__?: Api }).__dockviewApi__;
if (!api) throw new Error("dockview api not exposed");
const g = api.groups.find((grp) => grp.id === id);
if (!g) throw new Error(`group ${id} not found`);
return g.width;
}, groupId);
}
async function sashBoxAt(page: Page, index: number): Promise<Box> {
const sashes = page.locator(".dv-sash");
const count = await sashes.count();
if (count === 0) throw new Error("no .dv-sash elements found");
if (index >= count) {
throw new Error(`sash index ${index} out of range (${count} sashes)`);
}
const box = await sashes.nth(index).boundingBox();
if (!box) throw new Error(`sash ${index} has no bounding box`);
return box;
}
/**
* Drag a horizontal-direction sash (between two columns) by deltaX pixels.
* sashIndex is the dockview sash order (0 = left-most). Uses many small mouse
* moves so dockview's drag listener fires through-out the drag, mirroring real
* user motion.
*/
export async function dragHorizontalSash(
page: Page,
sashIndex: number,
deltaX: number,
steps = 20,
): Promise<void> {
const box = await sashBoxAt(page, sashIndex);
const cx = box.x + box.width / 2;
const cy = box.y + box.height / 2;
await page.mouse.move(cx, cy);
await page.mouse.down();
await page.mouse.move(cx + deltaX, cy, { steps });
await page.mouse.up();
// Give the debounced layout-save 350ms to fire so subsequent reload assertions
// see the new width.
await page.waitForTimeout(400);
}
/**
* Return the index of the sash bordering the sidebar / right column.
* - sidebar sash: between groups[0] and groups[1] (= sash 0)
* - right sash: between groups[N-2] and groups[N-1] (= last sash)
*/
export async function getColumnSashIndex(page: Page, column: "sidebar" | "right"): Promise<number> {
if (column === "sidebar") return 0;
return page.evaluate(() => {
return document.querySelectorAll(".dv-sash").length - 1;
});
}
/** Pre-populate the pinned-defaults sessionStorage slot before navigation so
* the dockview store seeds with the desired widths on first build. */
export async function setPinnedDefaultsViaStorage(
page: Page,
defaults: { sidebar?: number; right?: number },
): Promise<void> {
await page.evaluate((d) => {
window.sessionStorage.setItem("kandev.dockview.pinned-defaults", JSON.stringify(d));
}, defaults);
}
/** Read the pinned-defaults sessionStorage slot. */
export async function readPinnedDefaultsFromStorage(
page: Page,
): Promise<{ sidebar?: number; right?: number }> {
return page.evaluate(() => {
const raw = window.sessionStorage.getItem("kandev.dockview.pinned-defaults");
return raw ? (JSON.parse(raw) as { sidebar?: number; right?: number }) : {};
});
}
/** Expect a width to be approximately equal (±slack px) to a target. */
export function expectApproxWidth(actual: number, target: number, slack = 8): void {
expect(
Math.abs(actual - target) <= slack,
`width ${actual} not within ±${slack} of target ${target}`,
).toBe(true);
}
@@ -0,0 +1,107 @@
import { type Page } from "@playwright/test";
import { test, expect } from "../../fixtures/test-base";
import type { SeedData } from "../../fixtures/test-base";
import type { ApiClient } from "../../helpers/api-client";
import { SessionPage } from "../../pages/session-page";
const TABLET_VIEWPORT = { width: 1024, height: 800 };
async function openTabletTask(
page: Page,
apiClient: ApiClient,
seedData: SeedData,
title: string,
): Promise<SessionPage> {
await page.setViewportSize(TABLET_VIEWPORT);
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
title,
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
await page.goto(`/t/${task.id}`);
const session = new SessionPage(page);
await session.waitForLoad();
await expect(page.getByTestId("tablet-task-layout")).toBeVisible({ timeout: 10_000 });
return session;
}
async function readStoredLayout(page: Page, id: string): Promise<unknown | null> {
return page.evaluate((key) => {
const raw = window.localStorage.getItem(key);
return raw ? JSON.parse(raw) : null;
}, id);
}
test.describe("Tablet pane persistence", () => {
test("tablet left/right split persists to localStorage", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openTabletTask(testPage, apiClient, seedData, "Tablet persist");
// Drive the resize-panels library directly by overwriting the stored
// layout — the underlying drag handle is a complex pointer-events target
// that's flaky to grab in headless. The stored layout drives the next
// render; this test verifies the round-trip persistence contract.
await testPage.evaluate(() => {
window.localStorage.setItem("task-layout-tablet-v1", JSON.stringify({ left: 70, right: 30 }));
});
await testPage.reload();
await session.waitForLoad();
const stored = (await readStoredLayout(testPage, "task-layout-tablet-v1")) as Record<
string,
number
>;
expect(stored.left).toBe(70);
expect(stored.right).toBe(30);
});
test("invalid stored layout falls back to default", async ({ testPage, apiClient, seedData }) => {
await testPage.setViewportSize(TABLET_VIEWPORT);
await testPage.goto("/");
await testPage.evaluate(() => {
window.localStorage.setItem("task-layout-tablet-v1", '{"left":2}');
});
const session = await openTabletTask(testPage, apiClient, seedData, "Tablet fallback");
await expect(testPage.getByTestId("tablet-task-layout")).toBeVisible();
// Default layout still renders both panels — the broken stored layout
// is rejected by `isLayoutValid` (panel "right" is missing) and the
// base layout takes over.
const tabletLayout = testPage.getByTestId("tablet-task-layout");
await expect(tabletLayout).toBeVisible();
void session;
});
test("tablet right-panel top/bottom shrinks below the old 30% floor", async ({
testPage,
apiClient,
seedData,
}) => {
await openTabletTask(testPage, apiClient, seedData, "Tablet top shrink");
// The right-panel internal split now allows minSize=15. Round-trip via
// localStorage: write a 20/80 layout (below the old 30% floor), reload,
// assert the layout was accepted (would have been rejected before).
await testPage.evaluate(() => {
window.localStorage.setItem("task-layout-right-v2", JSON.stringify({ top: 20, bottom: 80 }));
});
await testPage.reload();
await expect(testPage.getByTestId("tablet-task-layout")).toBeVisible({ timeout: 10_000 });
const stored = (await readStoredLayout(testPage, "task-layout-right-v2")) as Record<
string,
number
>;
expect(stored.top).toBe(20);
expect(stored.bottom).toBe(80);
});
});
@@ -0,0 +1,151 @@
import { type Page } from "@playwright/test";
import { test, expect } from "../../fixtures/test-base";
import type { SeedData } from "../../fixtures/test-base";
import type { ApiClient } from "../../helpers/api-client";
import { SessionPage } from "../../pages/session-page";
import {
dragHorizontalSash,
expectApproxWidth,
getColumnSashIndex,
getDockviewGroupWidth,
} from "../../helpers/dockview-resize";
const WIDE_VIEWPORT = { width: 1600, height: 900 };
async function openWideTask(
page: Page,
apiClient: ApiClient,
seedData: SeedData,
title: string,
): Promise<SessionPage> {
await page.setViewportSize(WIDE_VIEWPORT);
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
title,
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
await page.goto(`/t/${task.id}`);
const session = new SessionPage(page);
await session.waitForLoad();
await session.waitForDockviewReady();
return session;
}
test.describe("Pane resize edge cases", () => {
test("double-click on sidebar sash does not crash dockview", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openWideTask(testPage, apiClient, seedData, "Edge dblclick");
const sashIdx = await getColumnSashIndex(testPage, "sidebar");
const sash = testPage.locator(".dv-sash").nth(sashIdx);
await sash.dblclick();
await session.expectLayoutHealthy();
});
test("rapid drags persist the final value across reload", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openWideTask(testPage, apiClient, seedData, "Edge rapid drag");
const sashIdx = await getColumnSashIndex(testPage, "right");
// Five quick drags, each shifting +60px left from the current position.
for (let i = 0; i < 5; i++) {
await dragHorizontalSash(testPage, sashIdx, -60, 5);
}
const finalWidth = await getDockviewGroupWidth(testPage, "files");
await testPage.reload();
await session.waitForLoad();
await session.waitForDockviewReady();
const afterReload = await getDockviewGroupWidth(testPage, "files");
expectApproxWidth(afterReload, finalWidth, 15);
});
test("resize during maximize does not corrupt the pre-maximize width", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openWideTask(testPage, apiClient, seedData, "Edge maximize");
const sashIdx = await getColumnSashIndex(testPage, "right");
await dragHorizontalSash(testPage, sashIdx, -250);
const before = await getDockviewGroupWidth(testPage, "files");
// Maximize the files group, then exit. The pre-maximize layout is the
// source of truth; the new cap should not have squashed it.
await testPage.evaluate(() => {
type Group = { id: string; panels: { id: string }[] };
type Api = { groups: Group[] };
const fileWindow = window as unknown as {
__dockviewApi__?: Api;
__testMaximize__?: (gid: string) => void;
};
const api = fileWindow.__dockviewApi__;
if (!api) return;
const group = api.groups.find((g) => g.panels.some((p) => p.id === "files"));
if (!group) return;
// Use the store action via the keyboard shortcut path is brittle; just
// call the API's own maximize for the smoke check.
type GroupApi = { maximize: () => void };
type ApiWithMax = { groups: (Group & { api: GroupApi })[] };
const apiMax = fileWindow.__dockviewApi__ as unknown as ApiWithMax;
const matching = apiMax.groups.find((g) => g.panels.some((p) => p.id === "files"));
matching?.api.maximize();
});
await testPage.waitForTimeout(150);
await testPage.evaluate(() => {
type GroupApi = { exitMaximized: () => void };
type Group = { id: string; panels: { id: string }[]; api: GroupApi };
type Api = { groups: Group[] };
const api = (window as unknown as { __dockviewApi__?: Api }).__dockviewApi__;
const matching = api?.groups.find((g) => g.panels.some((p) => p.id === "files"));
matching?.api.exitMaximized();
});
await session.waitForDockviewReady();
const after = await getDockviewGroupWidth(testPage, "files");
expectApproxWidth(after, before, 30);
});
test("drag past viewport edge clamps at the runtime cap", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Edge past-viewport");
const sashIdx = await getColumnSashIndex(testPage, "right");
await dragHorizontalSash(testPage, sashIdx, -5000);
const cap = Math.round(WIDE_VIEWPORT.width * 0.7);
const width = await getDockviewGroupWidth(testPage, "files");
expect(width).toBeLessThanOrEqual(cap + 10);
expect(width).toBeGreaterThan(0);
});
test("resize after sidebar hidden does not throw", async ({ testPage, apiClient, seedData }) => {
const session = await openWideTask(testPage, apiClient, seedData, "Edge sidebar hidden");
const errors: string[] = [];
testPage.on("pageerror", (err) => errors.push(err.message));
await testPage.locator("body").click({ position: { x: 5, y: 5 } });
const mod = process.platform === "darwin" ? "Meta" : "Control";
await testPage.keyboard.press(`${mod}+b`);
await testPage.waitForTimeout(200);
// The right sash is now between center and right (sash index 0 since
// sidebar is gone).
const sashIdx = await getColumnSashIndex(testPage, "right");
await dragHorizontalSash(testPage, sashIdx, -200);
await session.expectLayoutHealthy();
expect(errors).toEqual([]);
});
});
@@ -0,0 +1,146 @@
import { type Page } from "@playwright/test";
import { test, expect } from "../../fixtures/test-base";
import type { SeedData } from "../../fixtures/test-base";
import type { ApiClient } from "../../helpers/api-client";
import { SessionPage } from "../../pages/session-page";
import {
dragHorizontalSash,
expectApproxWidth,
getColumnSashIndex,
getDockviewGroupWidth,
readPinnedDefaultsFromStorage,
} from "../../helpers/dockview-resize";
const WIDE_VIEWPORT = { width: 1600, height: 900 };
async function openWideTask(
page: Page,
apiClient: ApiClient,
seedData: SeedData,
title: string,
): Promise<SessionPage> {
await page.setViewportSize(WIDE_VIEWPORT);
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
title,
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
await page.goto(`/t/${task.id}`);
const session = new SessionPage(page);
await session.waitForLoad();
await session.waitForDockviewReady();
return session;
}
test.describe("Right pane resize — viewport-proportional cap", () => {
test("resizes past the old 450px hard cap", async ({ testPage, apiClient, seedData }) => {
await openWideTask(testPage, apiClient, seedData, "Right resize past old cap");
const sashIdx = await getColumnSashIndex(testPage, "right");
await dragHorizontalSash(testPage, sashIdx, -350);
const width = await getDockviewGroupWidth(testPage, "files");
expect(width).toBeGreaterThan(600);
});
test("respects the viewport-proportional cap (max(800, vw*0.7))", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Right cap respect");
const sashIdx = await getColumnSashIndex(testPage, "right");
// Drag aggressively left — dockview should clamp at vw*0.7 = 1120.
await dragHorizontalSash(testPage, sashIdx, -2000);
const width = await getDockviewGroupWidth(testPage, "files");
const cap = Math.round(WIDE_VIEWPORT.width * 0.7);
expect(width).toBeLessThanOrEqual(cap + 10);
});
test("user width survives reload (sessionStorage round-trip)", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openWideTask(testPage, apiClient, seedData, "Right resize reload");
const sashIdx = await getColumnSashIndex(testPage, "right");
await dragHorizontalSash(testPage, sashIdx, -250);
const before = await getDockviewGroupWidth(testPage, "files");
await testPage.reload();
await session.waitForLoad();
await session.waitForDockviewReady();
const after = await getDockviewGroupWidth(testPage, "files");
expectApproxWidth(after, before, 10);
});
test("user width persists into sessionStorage pinned-defaults slot", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Right pinned defaults");
const sashIdx = await getColumnSashIndex(testPage, "right");
await dragHorizontalSash(testPage, sashIdx, -300);
const live = await getDockviewGroupWidth(testPage, "files");
const defaults = await readPinnedDefaultsFromStorage(testPage);
expect(defaults.right).toBeDefined();
expectApproxWidth(defaults.right ?? 0, live, 12);
});
test("new task adopts user's preferred right width", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openWideTask(testPage, apiClient, seedData, "Right propagate A");
const sashIdx = await getColumnSashIndex(testPage, "right");
await dragHorizontalSash(testPage, sashIdx, -280);
const widthA = await getDockviewGroupWidth(testPage, "files");
void session;
const taskB = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"Right propagate B",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
await testPage.goto(`/t/${taskB.id}`);
const sessionB = new SessionPage(testPage);
await sessionB.waitForLoad();
await sessionB.waitForDockviewReady();
const widthB = await getDockviewGroupWidth(testPage, "files");
expectApproxWidth(widthB, widthA, 20);
});
test("viewport shrink re-clamps an over-cap pinned width", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Right viewport shrink");
const sashIdx = await getColumnSashIndex(testPage, "right");
await dragHorizontalSash(testPage, sashIdx, -400);
const wideWidth = await getDockviewGroupWidth(testPage, "files");
expect(wideWidth).toBeGreaterThan(700);
await testPage.setViewportSize({ width: 1100, height: 800 });
// Allow ResizeObserver tick + applyDynamicConstraints to fire.
await testPage.waitForTimeout(250);
const newCap = Math.max(800, Math.round(1100 * 0.7));
const narrowWidth = await getDockviewGroupWidth(testPage, "files");
expect(narrowWidth).toBeLessThanOrEqual(newCap + 10);
});
});
@@ -0,0 +1,143 @@
import { type Page } from "@playwright/test";
import { test, expect } from "../../fixtures/test-base";
import type { SeedData } from "../../fixtures/test-base";
import type { ApiClient } from "../../helpers/api-client";
import { SessionPage } from "../../pages/session-page";
import {
dragHorizontalSash,
expectApproxWidth,
getColumnSashIndex,
getDockviewGroupWidth,
} from "../../helpers/dockview-resize";
const WIDE_VIEWPORT = { width: 1600, height: 900 };
async function openWideTask(
page: Page,
apiClient: ApiClient,
seedData: SeedData,
title: string,
): Promise<SessionPage> {
await page.setViewportSize(WIDE_VIEWPORT);
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
title,
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
await page.goto(`/t/${task.id}`);
const session = new SessionPage(page);
await session.waitForLoad();
await session.waitForDockviewReady();
return session;
}
test.describe("Sidebar resize — viewport-proportional cap", () => {
test("resizes past the old 350px hard cap", async ({ testPage, apiClient, seedData }) => {
await openWideTask(testPage, apiClient, seedData, "Sidebar past cap");
const sashIdx = await getColumnSashIndex(testPage, "sidebar");
await dragHorizontalSash(testPage, sashIdx, +250);
const width = await getDockviewGroupWidth(testPage, "sidebar");
expect(width).toBeGreaterThan(450);
});
test("respects the viewport-proportional cap on narrower screens", async ({
testPage,
apiClient,
seedData,
}) => {
await testPage.setViewportSize({ width: 1200, height: 800 });
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"Sidebar cap narrow",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
await testPage.goto(`/t/${task.id}`);
const session = new SessionPage(testPage);
await session.waitForLoad();
await session.waitForDockviewReady();
const sashIdx = await getColumnSashIndex(testPage, "sidebar");
await dragHorizontalSash(testPage, sashIdx, +2000);
const width = await getDockviewGroupWidth(testPage, "sidebar");
expect(width).toBeLessThanOrEqual(Math.max(800, Math.round(1200 * 0.7)) + 10);
});
test("user width survives reload", async ({ testPage, apiClient, seedData }) => {
const session = await openWideTask(testPage, apiClient, seedData, "Sidebar reload");
const sashIdx = await getColumnSashIndex(testPage, "sidebar");
await dragHorizontalSash(testPage, sashIdx, +180);
const before = await getDockviewGroupWidth(testPage, "sidebar");
await testPage.reload();
await session.waitForLoad();
await session.waitForDockviewReady();
const after = await getDockviewGroupWidth(testPage, "sidebar");
expectApproxWidth(after, before, 10);
});
test("user width propagates to brand-new task envs", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openWideTask(testPage, apiClient, seedData, "Sidebar propagate A");
const sashIdx = await getColumnSashIndex(testPage, "sidebar");
await dragHorizontalSash(testPage, sashIdx, +200);
const widthA = await getDockviewGroupWidth(testPage, "sidebar");
void session;
const taskB = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"Sidebar propagate B",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
await testPage.goto(`/t/${taskB.id}`);
const sessionB = new SessionPage(testPage);
await sessionB.waitForLoad();
await sessionB.waitForDockviewReady();
const widthB = await getDockviewGroupWidth(testPage, "sidebar");
expectApproxWidth(widthB, widthA, 20);
});
test("toggle sidebar off+on preserves the last user width", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openWideTask(testPage, apiClient, seedData, "Sidebar toggle");
const sashIdx = await getColumnSashIndex(testPage, "sidebar");
await dragHorizontalSash(testPage, sashIdx, +160);
const before = await getDockviewGroupWidth(testPage, "sidebar");
// TOGGLE_SIDEBAR shortcut (Ctrl/Cmd+B). Move focus out of any input first.
await testPage.locator("body").click({ position: { x: 5, y: 5 } });
const mod = process.platform === "darwin" ? "Meta" : "Control";
await testPage.keyboard.press(`${mod}+b`);
await testPage.waitForTimeout(200);
await testPage.keyboard.press(`${mod}+b`);
await session.waitForDockviewReady();
const after = await getDockviewGroupWidth(testPage, "sidebar");
expectApproxWidth(after, before, 20);
});
});