diff --git a/tests/e2e/mobile-card-scroll.spec.ts b/tests/e2e/mobile-card-scroll.spec.ts new file mode 100644 index 00000000000..7351839458f --- /dev/null +++ b/tests/e2e/mobile-card-scroll.spec.ts @@ -0,0 +1,92 @@ +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"); +}); diff --git a/ui/src/components/task-chat/TaskChatComposer.tsx b/ui/src/components/task-chat/TaskChatComposer.tsx index 82dcc3ee4db..da16718ccdf 100644 --- a/ui/src/components/task-chat/TaskChatComposer.tsx +++ b/ui/src/components/task-chat/TaskChatComposer.tsx @@ -1322,7 +1322,8 @@ export function TaskChatComposer({ className={cn( "relative rounded-xl border border-border bg-card p-(--sz-18px) shadow-sm", onWelcomeChoicesRevealed && (revealChoices ? "tc-onboarding-choices" : "invisible"), - mobile ? "overflow-visible" : "max-h-(--tc-interaction-card-max-h) overflow-y-auto scrollbar-auto-hide", + "overflow-y-auto scrollbar-auto-hide", + mobile ? "max-h-(--tc-mobile-interaction-card-max-h) overscroll-y-contain" : "max-h-(--tc-interaction-card-max-h)", )} ref={takeoverElement} inert={Boolean(onWelcomeChoicesRevealed) && !revealChoices} diff --git a/ui/src/index.css b/ui/src/index.css index 6d6aabf1c9f..08d30c29cd0 100644 --- a/ui/src/index.css +++ b/ui/src/index.css @@ -549,6 +549,7 @@ --artifact-play-scrim: rgba(0, 0, 0, 0.55); --artifact-hover-ease: 300ms cubic-bezier(0.3, 0, 0.1, 1); --tc-interaction-card-max-h: 50dvh; + --tc-mobile-interaction-card-max-h: var(--tc-interaction-card-max-h); /* About 3.5 queued rows, and less on short windows so the conversation stays visible. */ --tc-queued-list-max-h: min(calc(var(--spacing) * 40), 28dvh); --shadow-task-composer: 0 2px 8px -2px color-mix(in oklab, var(--foreground) 7%, transparent), @@ -979,6 +980,10 @@ select:where(:not([multiple]):not(.appearance-none)):where(:not([size]), [size=" transition: bottom var(--mobile-nav-motion-duration, var(--motion-mobile-nav-enter)) var(--mobile-nav-motion-ease, var(--motion-ease-out-expo)); } +.paperclip-app-shell { + --tc-mobile-interaction-card-max-h: calc(var(--mobile-chat-viewport-height) * 0.5); +} + html:has(.paperclip-app-shell:is([data-mobile="true"], [data-keyboard-open="true"]) [data-task-chat-shell]), html:has(.paperclip-app-shell:is([data-mobile="true"], [data-keyboard-open="true"]) [data-task-chat-shell]) body, html:has(.paperclip-app-shell[data-keyboard-open="true"] [data-classic-task-shell]),