|
| 1 | +/** |
| 2 | + * Journey: the chat on a phone. |
| 3 | + * |
| 4 | + * A conversation scrolls up and down, never sideways. Content that genuinely |
| 5 | + * needs the width — a code block, a table, a JSON dump — scrolls inside its |
| 6 | + * own box; the thread itself stays put. Both checks drive the real surface at |
| 7 | + * phone width and try to pan it, so a layout regression that widens a turn |
| 8 | + * fails here rather than on someone's phone. |
| 9 | + */ |
| 10 | + |
| 11 | +import { test, expect, FIXTURES } from "./fixtures"; |
| 12 | +import { ChatPage } from "./pages"; |
| 13 | + |
| 14 | +test.use({ viewport: { width: 390, height: 844 }, hasTouch: true }); |
| 15 | + |
| 16 | +/** What a real answer puts in a turn: an unbreakable URL, a wide table, a long command. */ |
| 17 | +const WIDE_MARKDOWN = [ |
| 18 | + "https://example.com/a/very/long/path/that/never/breaks/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 19 | + "", |
| 20 | + "| column one | column two | column three | column four | column five | column six |", |
| 21 | + "| --- | --- | --- | --- | --- | --- |", |
| 22 | + "| aaaaaaaaaa | bbbbbbbbbb | cccccccccc | dddddddddd | eeeeeeeeee | ffffffffff |", |
| 23 | + "", |
| 24 | + "```sh", |
| 25 | + "docker run --rm -it --name nodetool --network host -e NODETOOL_API_URL=https://api.example.com/v1/endpoint ghcr.io/example/nodetool:latest", |
| 26 | + "```" |
| 27 | +].join("\\n"); |
| 28 | + |
| 29 | +/** Text in the seeded assistant turn this suite rewrites into `WIDE_MARKDOWN`. */ |
| 30 | +const SEEDED_TAIL = "That night, they dreamed together."; |
| 31 | + |
| 32 | +/** Try to pan `selector` right; report where it actually ended up. */ |
| 33 | +async function pan(page: import("@playwright/test").Page, selector: string) { |
| 34 | + return page.evaluate((sel) => { |
| 35 | + const el = document.querySelector(sel) as HTMLElement | null; |
| 36 | + if (!el) { |
| 37 | + throw new Error(`no element for ${sel}`); |
| 38 | + } |
| 39 | + el.scrollLeft = 500; |
| 40 | + return { |
| 41 | + scrollLeft: el.scrollLeft, |
| 42 | + scrollWidth: el.scrollWidth, |
| 43 | + clientWidth: el.clientWidth |
| 44 | + }; |
| 45 | + }, selector); |
| 46 | +} |
| 47 | + |
| 48 | +test.describe("Chat on a phone", () => { |
| 49 | + test("a turn wider than the column does not pan the conversation", async ({ |
| 50 | + page |
| 51 | + }) => { |
| 52 | + // The fixture backend has no model configured, so the wide turn is |
| 53 | + // injected into the seeded history rather than sent. |
| 54 | + await page.route("**/trpc/**", async (route) => { |
| 55 | + const response = await route.fetch(); |
| 56 | + const body = await response.text(); |
| 57 | + return route.fulfill({ |
| 58 | + response, |
| 59 | + body: body.includes(SEEDED_TAIL) |
| 60 | + ? body.replace(SEEDED_TAIL, WIDE_MARKDOWN) |
| 61 | + : body |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + const chat = new ChatPage(page); |
| 66 | + await page.goto(`/chat/${FIXTURES.thread}`, { |
| 67 | + waitUntil: "domcontentloaded" |
| 68 | + }); |
| 69 | + await chat.waitForMessage("column three"); |
| 70 | + // The fenced block is the last thing in the injected turn — once it is on |
| 71 | + // screen the turn has finished laying out and the widths are stable. |
| 72 | + await page |
| 73 | + .locator(".code-block-content") |
| 74 | + .waitFor({ state: "visible", timeout: 30_000 }); |
| 75 | + |
| 76 | + const thread = await pan(page, ".scrollable-message-wrapper"); |
| 77 | + expect(thread.scrollLeft, "the conversation panned sideways").toBe(0); |
| 78 | + expect(thread.scrollWidth).toBeLessThanOrEqual(thread.clientWidth); |
| 79 | + |
| 80 | + // The code block keeps its own horizontal scroll — locking the thread |
| 81 | + // must not make wide content unreachable. |
| 82 | + const code = await pan(page, ".code-block-content"); |
| 83 | + expect(code.scrollWidth).toBeGreaterThan(code.clientWidth); |
| 84 | + expect(code.scrollLeft).toBeGreaterThan(0); |
| 85 | + }); |
| 86 | + |
| 87 | + // 320px is the narrowest phone still in use; the longest opener chip is |
| 88 | + // wider than the column there, which is where the screen used to pan. |
| 89 | + test("the welcome screen does not pan sideways", async ({ page }) => { |
| 90 | + await page.setViewportSize({ width: 320, height: 780 }); |
| 91 | + await page.goto("/chat/thread-mobile-welcome", { |
| 92 | + waitUntil: "domcontentloaded" |
| 93 | + }); |
| 94 | + const welcome = page.locator(".chat-welcome"); |
| 95 | + await welcome.waitFor({ state: "visible", timeout: 30_000 }); |
| 96 | + |
| 97 | + const screen = await pan(page, ".chat-welcome"); |
| 98 | + expect(screen.scrollLeft, "the welcome screen panned sideways").toBe(0); |
| 99 | + expect(screen.scrollWidth).toBeLessThanOrEqual(screen.clientWidth); |
| 100 | + }); |
| 101 | +}); |
0 commit comments