|
| 1 | +import { expect, test } from "@playwright/test" |
| 2 | +import { fixture, pageMessages } from "../performance/timeline/session-timeline-stress.fixture" |
| 3 | +import { installStressSessionTabs, stressSessionHref } from "../performance/timeline/timeline-test-helpers" |
| 4 | +import { mockOpenCodeServer } from "../utils/mock-server" |
| 5 | + |
| 6 | +for (const position of ["top", "bottom"] as const) { |
| 7 | + test(`mobile session tabs switch views and keep the terminal cached with ${position} navigation`, async ({ |
| 8 | + page, |
| 9 | + }) => { |
| 10 | + await page.setViewportSize({ width: 390, height: 844 }) |
| 11 | + await mockOpenCodeServer(page, { |
| 12 | + directory: fixture.directory, |
| 13 | + project: fixture.project, |
| 14 | + sessions: fixture.sessions, |
| 15 | + provider: fixture.provider, |
| 16 | + pageMessages, |
| 17 | + fileList: () => [], |
| 18 | + }) |
| 19 | + await installStressSessionTabs(page) |
| 20 | + await page.addInitScript( |
| 21 | + (position) => |
| 22 | + localStorage.setItem("settings.v3", JSON.stringify({ general: { mobileTitlebarPosition: position } })), |
| 23 | + position, |
| 24 | + ) |
| 25 | + await page.route("**/api/pty*", (route) => |
| 26 | + route.fulfill({ |
| 27 | + json: { |
| 28 | + location: { directory: fixture.directory, project: { id: fixture.project.id, directory: fixture.directory } }, |
| 29 | + data: { |
| 30 | + id: "pty_mobile_views", |
| 31 | + title: "Terminal 1", |
| 32 | + command: "sh", |
| 33 | + args: [], |
| 34 | + cwd: fixture.directory, |
| 35 | + status: "running", |
| 36 | + pid: 1, |
| 37 | + }, |
| 38 | + }, |
| 39 | + }), |
| 40 | + ) |
| 41 | + await page.routeWebSocket("**/api/pty/pty_mobile_views/connect", () => undefined) |
| 42 | + await page.route("**/api/pty/pty_mobile_views/connect-token*", (route) => |
| 43 | + route.fulfill({ |
| 44 | + json: { |
| 45 | + location: { directory: fixture.directory, project: { id: fixture.project.id, directory: fixture.directory } }, |
| 46 | + data: { ticket: "e2e-ticket", expires_in: 60 }, |
| 47 | + }, |
| 48 | + }), |
| 49 | + ) |
| 50 | + await page.goto(stressSessionHref(fixture.targetID)) |
| 51 | + |
| 52 | + const tabs = page.getByRole("tablist", { name: "Session view", exact: true }) |
| 53 | + const navigation = page.locator('[data-slot="session-mobile-view-navigation"]') |
| 54 | + const more = navigation.getByRole("button", { name: "More options", exact: true }) |
| 55 | + const picker = tabs.getByRole("tab", { selected: true }) |
| 56 | + const message = page.locator( |
| 57 | + `[data-timeline-row="UserMessage"][data-message-id="${fixture.expected.targetMessageIDs.at(-1)}"]`, |
| 58 | + ) |
| 59 | + const composer = page.getByRole("textbox", { name: "Prompt", exact: true }) |
| 60 | + await expect(picker).toHaveText("Session") |
| 61 | + await expect(message).toBeVisible() |
| 62 | + await expect(composer).toBeVisible() |
| 63 | + await expect(tabs.getByRole("tab")).toHaveText(["Session", "Changes", "Files", "Terminal"]) |
| 64 | + await expect(tabs).toHaveCSS("padding-left", "0px") |
| 65 | + await expect(tabs).toHaveCSS("padding-right", "0px") |
| 66 | + await expect |
| 67 | + .poll(async () => { |
| 68 | + const bounds = await navigation.boundingBox() |
| 69 | + return !!bounds && bounds.x >= 8 && bounds.x <= 9 && bounds.width >= 372 && bounds.width <= 374 |
| 70 | + }) |
| 71 | + .toBe(true) |
| 72 | + await expect |
| 73 | + .poll(async () => { |
| 74 | + const bar = await tabs.boundingBox() |
| 75 | + const input = await composer.boundingBox() |
| 76 | + return ( |
| 77 | + !!bar && !!input && (position === "bottom" ? bar.y >= input.y + input.height : bar.y + bar.height <= input.y) |
| 78 | + ) |
| 79 | + }) |
| 80 | + .toBe(true) |
| 81 | + await expect(page.locator("[data-session-title]")).toHaveCount(0) |
| 82 | + await expect(page.locator('[data-slot="mobile-tabs-trigger"]')).toContainText(fixture.expected.targetTitle) |
| 83 | + await page.getByRole("button", { name: "Tabs", exact: true }).click() |
| 84 | + const drawer = page.getByRole("dialog", { name: "Tabs", exact: true }) |
| 85 | + await expect(drawer).toHaveAttribute("data-open", "") |
| 86 | + await expect(drawer).not.toHaveAttribute("data-transitioning") |
| 87 | + await expect(drawer.getByRole("button", { name: "Settings", exact: true })).toBeInViewport() |
| 88 | + await drawer.getByRole("button", { name: "Settings", exact: true }).click() |
| 89 | + await expect(page.getByTestId("settings-screen")).toBeVisible() |
| 90 | + await page.getByRole("button", { name: "Back to app", exact: true }).click() |
| 91 | + await page.getByRole("button", { name: "Tabs", exact: true }).click() |
| 92 | + await expect(drawer).not.toHaveAttribute("data-transitioning") |
| 93 | + await expect(drawer.getByRole("button", { name: "Settings", exact: true })).toBeInViewport() |
| 94 | + await page.keyboard.press("Escape") |
| 95 | + await expect(drawer).toBeHidden() |
| 96 | + |
| 97 | + await more.click() |
| 98 | + await page.getByRole("menuitem", { name: "Usage", exact: true }).click() |
| 99 | + await expect(picker).toHaveCount(0) |
| 100 | + await expect(page.getByText("Total Cost", { exact: true })).toBeVisible() |
| 101 | + await expect(composer).toBeHidden() |
| 102 | + |
| 103 | + await more.click() |
| 104 | + await page.getByRole("menuitem", { name: "Status", exact: true }).click() |
| 105 | + const status = page.getByRole("dialog", { name: "Status", exact: true }) |
| 106 | + await expect(status.getByRole("tab", { name: "MCP", exact: true })).toBeVisible() |
| 107 | + await status.getByRole("tab", { name: "Plugins", exact: true }).click() |
| 108 | + await expect(status.getByText("opencode.json", { exact: true })).toBeVisible() |
| 109 | + await status.getByRole("button", { name: "Close", exact: true }).click() |
| 110 | + await expect(status).toBeHidden() |
| 111 | + await expect(more).toBeFocused() |
| 112 | + |
| 113 | + await more.click() |
| 114 | + await page.getByRole("menuitem", { name: "Session details", exact: true }).click() |
| 115 | + const details = page.getByRole("dialog", { name: "Session details", exact: true }) |
| 116 | + await expect(details.getByText(fixture.project.name, { exact: true })).toBeVisible() |
| 117 | + await expect(details.getByRole("button", { name: "No changes", exact: true })).toBeVisible() |
| 118 | + await details.getByRole("button", { name: "Close", exact: true }).click() |
| 119 | + await expect(details).toBeHidden() |
| 120 | + await expect(more).toBeFocused() |
| 121 | + await more.click() |
| 122 | + await page.getByRole("menuitem", { name: "Session details", exact: true }).click() |
| 123 | + await expect(details.getByRole("button", { name: "No changes", exact: true })).toBeVisible() |
| 124 | + await expect(details).not.toHaveAttribute("data-transitioning") |
| 125 | + await page.keyboard.press("Escape") |
| 126 | + await expect(details).toBeHidden() |
| 127 | + await expect(more).toBeFocused() |
| 128 | + await more.click() |
| 129 | + await page.getByRole("menuitem", { name: "Session details", exact: true }).click() |
| 130 | + await details.getByRole("button", { name: "No changes", exact: true }).click() |
| 131 | + await expect(details).toBeHidden() |
| 132 | + await expect(picker).toHaveText("Changes") |
| 133 | + await expect(page.getByText("No uncommitted changes yet", { exact: true })).toBeVisible() |
| 134 | + await expect(page.locator('[data-slot="session-review-header"]')).toHaveCSS("height", "40px") |
| 135 | + await expect(page.locator('[data-slot="session-review-header"]')).toHaveCSS("padding-left", "8px") |
| 136 | + await expect(composer).toBeHidden() |
| 137 | + |
| 138 | + await tabs.getByRole("tab", { name: "Files", exact: true }).click() |
| 139 | + await expect(picker).toHaveText("Files") |
| 140 | + await expect(page.getByRole("combobox", { name: "Filter files", exact: true })).toBeVisible() |
| 141 | + await expect(composer).toBeHidden() |
| 142 | + |
| 143 | + await tabs.getByRole("tab", { name: "Terminal", exact: true }).click() |
| 144 | + const panel = page.locator("#terminal-panel") |
| 145 | + await expect(panel).toHaveAttribute("data-opened", "true") |
| 146 | + await expect(panel.getByRole("tab", { name: /Terminal 1/ })).toBeVisible() |
| 147 | + await expect(panel.locator('[data-component="terminal"]')).toBeVisible() |
| 148 | + await expect(panel.locator("textarea")).toBeEditable() |
| 149 | + await expect(panel).toHaveCount(1) |
| 150 | + await panel.evaluate((element) => element.setAttribute("data-cache-probe", "original")) |
| 151 | + await expect(composer).toBeHidden() |
| 152 | + |
| 153 | + await tabs.getByRole("tab", { name: "Session", exact: true }).click() |
| 154 | + await expect(message).toBeVisible() |
| 155 | + await expect(panel).toBeHidden() |
| 156 | + await expect(panel).toHaveAttribute("inert", "") |
| 157 | + await expect(panel).toHaveAttribute("data-cache-probe", "original") |
| 158 | + |
| 159 | + await page.keyboard.press("Control+Backquote") |
| 160 | + await expect(picker).toHaveText("Terminal") |
| 161 | + await expect(panel).toBeVisible() |
| 162 | + await expect(panel).toHaveAttribute("data-cache-probe", "original") |
| 163 | + await page.keyboard.press("Control+Backquote") |
| 164 | + await expect(picker).toHaveText("Session") |
| 165 | + |
| 166 | + await page.keyboard.press("Control+Backquote") |
| 167 | + await expect(picker).toHaveText("Terminal") |
| 168 | + await panel.getByRole("button", { name: "Close terminal", exact: true }).click() |
| 169 | + await expect(picker).toHaveText("Session") |
| 170 | + await expect(panel).toBeHidden() |
| 171 | + |
| 172 | + await more.click() |
| 173 | + await page.getByRole("menuitem", { name: "Usage", exact: true }).click() |
| 174 | + await expect(page.getByText("Total Cost", { exact: true })).toBeVisible() |
| 175 | + await page.goto(stressSessionHref(fixture.sourceID)) |
| 176 | + await expect(picker).toHaveText("Session") |
| 177 | + await expect(page.locator('[data-slot="mobile-tabs-trigger"]')).toContainText(fixture.expected.sourceTitle) |
| 178 | + |
| 179 | + await page.setViewportSize({ width: 1280, height: 900 }) |
| 180 | + await expect(picker).toBeHidden() |
| 181 | + await expect(page.locator("[data-session-title]")).toBeVisible() |
| 182 | + }) |
| 183 | +} |
0 commit comments