Files
kandev/apps/web/e2e/tests/layout/pane-resize-right.spec.ts
T
João Salavisa b12336f7a5 test(e2e): replace the layout specs' unconditional sleeps with causal waits (#2648)
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-14 00:12:18 +01:00

289 lines
12 KiB
TypeScript

import { test, expect } from "../../fixtures/test-base";
import { computeRightMaxPx } from "../../../lib/state/layout-manager/caps";
import { TERMINAL_DEFAULT_ID } from "../../../lib/state/layout-manager/constants";
import {
WIDE_VIEWPORT,
openWideTask,
expectApproxWidth,
getDockviewGroupWidth,
getDockviewContainerWidth,
resizeColumnViaSplitview,
waitForDockviewViewportResize,
} from "../../helpers/dockview-resize";
import { KanbanPage } from "../../pages/kanban-page";
import { SessionPage } from "../../pages/session-page";
test.describe("Right pane resize — container-proportional cap", () => {
test("opens with a narrower default width on a laptop viewport", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Laptop default right width", {
width: 1280,
height: 900,
});
const initialWidth = await getDockviewGroupWidth(testPage, "files");
// 1280px minus the 320px app sidebar leaves a 960px task workbench.
// The default right pane should use 30% of that space, rather than the
// prior one-third proportion, leaving more room for the central task view.
expectApproxWidth(initialWidth, 288, 12);
});
test("recomputes automatic width across monitor changes and restores the large-screen ratio", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Responsive right width", {
width: 2200,
height: 900,
});
const largeWidth = await getDockviewGroupWidth(testPage, "files");
expectApproxWidth(largeWidth, 450, 12);
const wideContainer = await getDockviewContainerWidth(testPage);
await testPage.setViewportSize({ width: 1280, height: 900 });
await waitForDockviewViewportResize(testPage, wideContainer);
const laptopWidth = await getDockviewGroupWidth(testPage, "files");
expectApproxWidth(laptopWidth, 288, 12);
const laptopContainer = await getDockviewContainerWidth(testPage);
await testPage.setViewportSize({ width: 2200, height: 900 });
await waitForDockviewViewportResize(testPage, laptopContainer);
expectApproxWidth(await getDockviewGroupWidth(testPage, "files"), largeWidth, 12);
});
test("preserves a manual width while switching between monitor sizes", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Manual right width across monitors", {
width: 2200,
height: 900,
});
const manualWidth = await resizeColumnViaSplitview(testPage, "right", 360);
expectApproxWidth(manualWidth, 360, 12);
// The assertion is that this width does *not* move, so there is nothing to
// poll for: the expected value is already there. Waiting for the container
// to take the new viewport is what gives a regression somewhere to happen,
// since the recompute that could clobber the manual width runs in that same
// layout pass.
const wideContainer = await getDockviewContainerWidth(testPage);
await testPage.setViewportSize({ width: 1280, height: 900 });
await waitForDockviewViewportResize(testPage, wideContainer);
expectApproxWidth(await getDockviewGroupWidth(testPage, "files"), manualWidth, 12);
const laptopContainer = await getDockviewContainerWidth(testPage);
await testPage.setViewportSize({ width: 2200, height: 900 });
await waitForDockviewViewportResize(testPage, laptopContainer);
expectApproxWidth(await getDockviewGroupWidth(testPage, "files"), manualWidth, 12);
});
test("resizes past the old 450px hard cap", async ({ testPage, apiClient, seedData }) => {
await openWideTask(testPage, apiClient, seedData, "Right resize past old cap");
const actual = await resizeColumnViaSplitview(testPage, "right", 700);
expect(actual).toBeGreaterThan(600);
});
test("respects the container cap and center comfort width", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Right cap respect");
const actual = await resizeColumnViaSplitview(testPage, "right", 5000);
const dockviewBox = await testPage.locator(".dv-dockview").boundingBox();
expect(dockviewBox).not.toBeNull();
const availableWidth = dockviewBox?.width ?? 0;
const sidebarWidth = await getDockviewGroupWidth(testPage, "sidebar").catch(() => 0);
const cap = computeRightMaxPx(availableWidth, sidebarWidth);
expect(actual).toBeLessThanOrEqual(cap + 10);
});
test("user width survives reload (localStorage dockview-layout-v3 round-trip)", async ({
testPage,
apiClient,
seedData,
}) => {
const session = await openWideTask(testPage, apiClient, seedData, "Right resize reload");
const before = await resizeColumnViaSplitview(testPage, "right", 600);
await testPage.reload();
await session.waitForLoad();
await session.waitForDockviewReady();
const after = await getDockviewGroupWidth(testPage, "files");
expectApproxWidth(after, before, 12);
});
test("initial restore reconciles a stale saved grid width without a manual resize", async ({
testPage,
apiClient,
seedData,
}) => {
await testPage.setViewportSize({ width: 2200, height: 900 });
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"Right stale grid restore",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
if (!task.session_id) throw new Error("created task did not return a session_id");
await testPage.goto(`/t/${task.id}`);
const session = new SessionPage(testPage);
await session.waitForLoad();
await session.waitForDockviewReady();
expect(await resizeColumnViaSplitview(testPage, "right", 900)).toBeGreaterThan(800);
const staleLayout = await testPage.evaluate((sessionId) => {
type StoreWindow = Window & {
__KANDEV_E2E_STORE__?: {
getState: () => { environmentIdBySessionId: Record<string, string> };
};
};
const store = (window as StoreWindow).__KANDEV_E2E_STORE__;
const envId = store?.getState().environmentIdBySessionId[sessionId];
if (!envId) throw new Error("environment id not hydrated");
const key = `kandev.dockview.env-layout-v3.${envId}`;
const raw = window.sessionStorage.getItem(key);
if (!raw) throw new Error("env layout was not persisted");
const layout = JSON.parse(raw);
const columns = layout.grid?.root?.data;
if (!Array.isArray(columns) || columns.length < 2) {
throw new Error("saved layout does not contain center and right columns");
}
layout.grid.width = 1900;
columns[0].size = 1000;
columns[columns.length - 1].size = 900;
return { key, json: JSON.stringify(layout) };
}, task.session_id);
await testPage.addInitScript(({ key, json }) => {
window.sessionStorage.setItem(key, json);
}, staleLayout);
await testPage.setViewportSize({ width: 1540, height: 900 });
await testPage.reload();
await session.waitForLoad();
await session.waitForDockviewReady();
const dockviewBox = await testPage.locator(".dv-dockview").boundingBox();
expect(dockviewBox).not.toBeNull();
const rightWidth = await getDockviewGroupWidth(testPage, "files");
const terminalWidth = await getDockviewGroupWidth(testPage, TERMINAL_DEFAULT_ID);
const centerWidth = await getDockviewGroupWidth(testPage, `session:${task.session_id}`);
const cap = computeRightMaxPx(dockviewBox?.width ?? 0);
expect(rightWidth).toBeLessThanOrEqual(cap + 10);
expectApproxWidth(terminalWidth, rightWidth, 10);
// Allow 2px of rendering tolerance around the 480px center comfort reserve.
expect(centerWidth).toBeGreaterThanOrEqual(478);
});
test("viewport shrink re-clamps an over-cap pinned width", async ({
testPage,
apiClient,
seedData,
}) => {
await openWideTask(testPage, apiClient, seedData, "Right viewport shrink");
const wideWidth = await resizeColumnViaSplitview(testPage, "right", 900);
expect(wideWidth).toBeGreaterThan(700);
// Do not call the resize helper here: it reapplies constraints and would
// mask a failure to update them automatically on viewport changes. Wait for
// the container instead, which is where the pinned-target enforcement runs.
const wideContainer = await getDockviewContainerWidth(testPage);
await testPage.setViewportSize({ width: 1100, height: 800 });
await waitForDockviewViewportResize(testPage, wideContainer);
const dockviewBox = await testPage.locator(".dv-dockview").boundingBox();
expect(dockviewBox).not.toBeNull();
const narrowWidth = await getDockviewGroupWidth(testPage, "files");
const sidebarWidth = await getDockviewGroupWidth(testPage, "sidebar").catch(() => 0);
const newCap = computeRightMaxPx(dockviewBox?.width ?? 0, sidebarWidth);
expect(narrowWidth).toBeLessThanOrEqual(newCap + 10);
});
});
test.describe("Right pane width — per-task isolation", () => {
test("a narrow resize in Task A does not leak into Task B", async ({
testPage,
apiClient,
seedData,
}) => {
test.setTimeout(120_000);
await testPage.setViewportSize(WIDE_VIEWPORT);
// Two tasks, same default layout. Each gets its own env id and its own
// persisted dockview layout in sessionStorage.
await apiClient.createTaskWithAgent(
seedData.workspaceId,
"Right Width Task A",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
const taskB = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"Right Width Task B",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
},
);
const kanban = new KanbanPage(testPage);
await kanban.goto();
await kanban.taskCardByTitle("Right Width Task A").click();
await expect(testPage).toHaveURL(/\/t\//, { timeout: 15_000 });
const session = new SessionPage(testPage);
await session.waitForLoad();
await session.waitForDockviewReady();
// Resize Task A's right column to a deliberately narrow width. The default
// is ~450 on a 1600px viewport, so 240 is unambiguously a user override.
const narrowedA = await resizeColumnViaSplitview(testPage, "right", 240);
expect(narrowedA).toBeLessThan(300);
// Switch to Task B (no prior resize, default width). Regression: a stale
// global "right" pinned target from Task A's drag used to leak through
// captureRightTarget / enforcePinnedTargets after fromJSON, snapping
// Task B's right column to Task A's narrow width — and the next
// debounced persist would overwrite Task B's saved layout with the
// narrow width, making the leak sticky.
await session.clickTaskInSidebar("Right Width Task B");
await expect(testPage).toHaveURL((url) => url.pathname.includes(taskB.id), {
timeout: 15_000,
});
await expect(testPage.locator(".dv-dockview")).toBeVisible({ timeout: 15_000 });
// Poll rather than sleep-then-read: the width is Task A's narrow value
// until fromJSON + fixups-capture + enforcePinnedTargets have run, so this
// still fails if the leak comes back. Sampled every frame through a real
// switch, the width makes exactly one move (240 -> 384 at ~180ms) and then
// holds for the next 5.8s, so there is no transient correct value for the
// poll to latch onto early.
await expect
.poll(() => getDockviewGroupWidth(testPage, "files"), {
timeout: 10_000,
message: `Task B right width should be the default (>350), not Task A's narrow ${narrowedA}`,
})
.toBeGreaterThan(350);
});
});