import { expect, test, type APIResponse, type Page } from "@playwright/test"; test.use({ viewport: { width: 390, height: 664 }, isMobile: true, hasTouch: true }); async function json(response: APIResponse) { const body = await response.text(); expect(response.ok(), `${response.status()} ${body}`).toBeTruthy(); return JSON.parse(body); } async function swipeUp(page: Page, x: number, y: number) { const session = await page.context().newCDPSession(page); try { await session.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x, y }] }); for (let step = 1; step <= 8; step++) { await session.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x, y: y - step * 18 }] }); } await session.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] }); } finally { await session.detach(); } } for (const surface of ["Chat", "Tasks"]) test(`long mobile approval cards scroll inside ${surface}`, async ({ page, request, browserName }) => { test.skip(browserName !== "chromium", "Uses Chromium touch input, not a programmatic scroll."); test.setTimeout(75_000); const company = await json(await request.post("/api/companies", { data: { name: `Mobile Card Scroll ${surface} ${Date.now()}` } })); const base = `/api/companies/${company.id}`; const experimental = await json(await request.get("/api/instance/settings/experimental")); const preferences = await json(await request.get("/api/workspace-preferences/me")); await page.route("**/api/instance/settings/experimental", route => route.fulfill({ json: { ...experimental, enableAgentChat: true, enableClassicTaskInterface: false }, })); await page.route("**/api/workspace-preferences/me", route => route.fulfill({ json: { ...preferences, coordinatorWorkspaceEnabled: true }, })); const agent = await json(await request.post(`${base}/agents`, { data: { name: "Mobile review agent", adapterType: "process", adapterConfig: { command: "/usr/bin/false" }, runtimeConfig: { heartbeat: { enabled: false, wakeOnDemand: false } }, } })); const issue = surface === "Chat" ? await json(await request.post(`${base}/chats/${agent.id}`, { data: {} })) : await json(await request.post(`${base}/issues`, { data: { title: "Review the task approval on mobile", status: "backlog", } })); const title = "Review the long request"; await json(await request.post(`/api/issues/${issue.id}/interactions`, { data: { kind: "request_confirmation", title, continuationPolicy: "none", payload: { version: 1, prompt: title, acceptLabel: "Approve test request", rejectLabel: "Decline test request", detailsMarkdown: Array.from({ length: 24 }, (_, index) => `Detail ${index + 1}: Check the recorded evidence before making a decision.`).join("\n\n"), }, } })); const route = surface === "Chat" ? `/${company.issuePrefix}/chats/${agent.id}` : `/${company.issuePrefix}/issues/${issue.identifier}`; await page.goto(route); const card = page.getByTestId("task-chat-composer-takeover"); await card.getByText("Details", { exact: true }).tap(); await expect(card.getByText("Detail 24:", { exact: false })).toBeAttached(); const bounds = await card.boundingBox(); expect(bounds).toBeTruthy(); const x = Math.round(bounds!.x + bounds!.width / 2); const y = Math.round(Math.min(bounds!.y + bounds!.height - 24, 550)); const before = await card.evaluate(node => ({ height: node.clientHeight, scrollHeight: node.scrollHeight, top: node.getBoundingClientRect().top, bottom: node.getBoundingClientRect().bottom, viewport: window.visualViewport?.height ?? window.innerHeight, })); expect.soft(before.top, "The expanded card must not start offscreen").toBeGreaterThanOrEqual(0); expect.soft(before.bottom, "The expanded card must fit in the visible viewport").toBeLessThanOrEqual(before.viewport); expect.soft(before.scrollHeight, "Long content must overflow inside the card").toBeGreaterThan(before.height); await swipeUp(page, x, y); await expect.poll(() => card.evaluate(node => node.scrollTop)).toBeGreaterThan(40); for (let i = 0; i < 12; i++) { const more = await card.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop); if (more <= 5) break; await swipeUp(page, x, y); } const action = card.getByRole("button", { name: "Approve test request", exact: true }); await expect(action).toBeInViewport({ ratio: 1 }); const compactHeight = await card.evaluate(node => { const shell = node.closest(".paperclip-app-shell")!; const original = shell.style.getPropertyValue("--mobile-chat-viewport-height"); shell.style.setProperty("--mobile-chat-viewport-height", "420px"); const maxHeight = getComputedStyle(node).maxHeight; shell.style.setProperty("--mobile-chat-viewport-height", original); return maxHeight; }); expect(compactHeight).toBe("210px"); });