|
1 | 1 | import { expect, story } from "../../storybook/playwright/story" |
2 | 2 |
|
| 3 | +story("cycles full prompts with plain arrows without opening the picker", async ({ mount, page }) => { |
| 4 | + const component = await mount("opencode-composer-flow--prompt-history") |
| 5 | + const input = component.getByRole("textbox", { name: "Prompt", exact: true }) |
| 6 | + const options = component.getByRole("option") |
| 7 | + const composer = component.locator('[data-component="composer"]') |
| 8 | + const content = component.locator('[data-slot="composer-content"]') |
| 9 | + await page.evaluate(() => document.fonts.ready.then(() => undefined)) |
| 10 | + const height = await composer.evaluate((element) => element.getBoundingClientRect().height) |
| 11 | + |
| 12 | + await input.press("ArrowUp") |
| 13 | + await expect(input).toHaveText("Explain the latest changes") |
| 14 | + await expect(input).toBeFocused() |
| 15 | + await expect(options).toHaveCount(0) |
| 16 | + await expect(content).toHaveCSS("mask-image", "none") |
| 17 | + await input.press("ArrowUp") |
| 18 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 19 | + await expect(component.getByRole("img", { name: "layout.png", exact: true })).toBeVisible() |
| 20 | + await expect(component.getByText("Keep the search separate from the draft", { exact: true })).toBeVisible() |
| 21 | + await expect |
| 22 | + .poll(() => composer.evaluate((element) => element.getBoundingClientRect().height)) |
| 23 | + .toBeGreaterThan(height) |
| 24 | + await expect(options).toHaveCount(0) |
| 25 | + await input.press("ArrowUp") |
| 26 | + await expect(input).toHaveText("Run the focused tests") |
| 27 | + await input.press("ArrowUp") |
| 28 | + await expect(input).toHaveText("Run the focused tests") |
| 29 | + await input.press("ArrowDown") |
| 30 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 31 | + await input.press("ArrowDown") |
| 32 | + await expect(input).toHaveText("Explain the latest changes") |
| 33 | + await input.press("ArrowDown") |
| 34 | + await expect(input).toBeEmpty() |
| 35 | + await expect(composer).toHaveCSS("height", `${height}px`) |
| 36 | + |
| 37 | + // A new cycle saves and restores an empty-text draft's attachments and comments. |
| 38 | + await input.press("ArrowUp") |
| 39 | + await input.press("ArrowUp") |
| 40 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 41 | + await input.fill("") |
| 42 | + await input.press("ArrowUp") |
| 43 | + await expect(input).toHaveText("Explain the latest changes") |
| 44 | + await expect(component.getByRole("img", { name: "layout.png", exact: true })).toHaveCount(0) |
| 45 | + await input.press("ArrowDown") |
| 46 | + await expect(input).toBeEmpty() |
| 47 | + await expect(component.getByRole("img", { name: "layout.png", exact: true })).toBeVisible() |
| 48 | + await expect(component.getByText("Keep the search separate from the draft", { exact: true })).toBeVisible() |
| 49 | + |
| 50 | + await input.press("ArrowUp") |
| 51 | + await input.press("ArrowUp") |
| 52 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 53 | + await input.press("ArrowRight") |
| 54 | + await input.press("Shift+ArrowUp") |
| 55 | + await expect(options).toHaveCount(0) |
| 56 | + await expect.poll(() => input.evaluate(() => window.getSelection()?.toString())).toBe("R") |
| 57 | + await input.press("ArrowRight") |
| 58 | + await input.pressSequentially("!") |
| 59 | + await expect(input).toHaveText("R!eview the composer layout\nKeep keyboard navigation accessible") |
| 60 | + await input.press("ArrowUp") |
| 61 | + await expect(input).toHaveText("R!eview the composer layout\nKeep keyboard navigation accessible") |
| 62 | + |
| 63 | + await input.fill("") |
| 64 | + await input.press("ArrowUp") |
| 65 | + await expect(input).toHaveText("Explain the latest changes") |
| 66 | + await input.press("Enter") |
| 67 | + await expect(input).toBeEmpty() |
| 68 | + await expect(component.getByRole("status")).toHaveText("Submitted: Explain the latest changes") |
| 69 | + await input.press("ArrowUp") |
| 70 | + await expect(input).toHaveText("Explain the latest changes") |
| 71 | + await expect(options).toHaveCount(0) |
| 72 | + |
| 73 | + await input.fill("!") |
| 74 | + await expect(input).toBeEmpty() |
| 75 | + await input.press("ArrowUp") |
| 76 | + await expect(input).toHaveText("bun typecheck") |
| 77 | + await expect(options).toHaveCount(0) |
| 78 | + await input.press("ArrowDown") |
| 79 | + await expect(input).toBeEmpty() |
| 80 | + await input.press("ArrowUp") |
| 81 | + await input.press("Enter") |
| 82 | + await expect(component.getByRole("status")).toHaveText("Submitted: bun typecheck") |
| 83 | +}) |
| 84 | + |
| 85 | +story( |
| 86 | + "previews history in the composer, accepts without sending, and cancels back to the original draft", |
| 87 | + async ({ mount, page }) => { |
| 88 | + const component = await mount("opencode-composer-flow--prompt-history") |
| 89 | + const input = component.getByRole("textbox", { name: "Prompt", exact: true }) |
| 90 | + const search = component.getByRole("combobox", { name: "Prompt history", exact: true }) |
| 91 | + const options = component.getByRole("option") |
| 92 | + const composer = component.locator('[data-component="composer"]') |
| 93 | + const content = component.locator('[data-slot="composer-content"]') |
| 94 | + const viewport = component.locator('[data-component="composer-scroll"] > .scroll-view__viewport') |
| 95 | + await page.evaluate(() => document.fonts.ready.then(() => undefined)) |
| 96 | + const height = await composer.evaluate((element) => element.getBoundingClientRect().height) |
| 97 | + |
| 98 | + await input.press("Shift+ArrowUp") |
| 99 | + await expect(input).toBeFocused() |
| 100 | + await expect(search).toHaveCount(0) |
| 101 | + await expect(input).toHaveText("Explain the latest changes") |
| 102 | + await expect(composer).toHaveCSS("height", `${height}px`) |
| 103 | + const menu = await component.locator('[data-component="composer-suggestions"]').boundingBox() |
| 104 | + |
| 105 | + if (!menu) throw new Error("Missing history menu") |
| 106 | + await expect(options).toHaveText([ |
| 107 | + "Run the focused tests", |
| 108 | + "Review the composer layout Keep keyboard navigation accessible", |
| 109 | + "Explain the latest changes", |
| 110 | + ]) |
| 111 | + await expect(component.getByRole("option", { selected: true })).toHaveText("Explain the latest changes") |
| 112 | + await input.press("ArrowUp") |
| 113 | + await expect(component.getByRole("option", { selected: true })).toHaveText( |
| 114 | + "Review the composer layout Keep keyboard navigation accessible", |
| 115 | + ) |
| 116 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 117 | + await expect(composer).toHaveCSS("height", `${height}px`) |
| 118 | + await expect |
| 119 | + .poll(() => component.locator('[data-slot="composer-content"]').evaluate((element) => element.scrollTop)) |
| 120 | + .toBeGreaterThan(0) |
| 121 | + await expect(input).toBeInViewport() |
| 122 | + await expect |
| 123 | + .poll(() => |
| 124 | + input.evaluate( |
| 125 | + (element) => |
| 126 | + element.getBoundingClientRect().top - |
| 127 | + element.closest('[data-slot="composer-content"]')!.getBoundingClientRect().top, |
| 128 | + ), |
| 129 | + ) |
| 130 | + .toBe(0) |
| 131 | + await expect(content).not.toHaveCSS("mask-image", "none") |
| 132 | + await expect(viewport).toHaveCSS("mask-image", "none") |
| 133 | + await expect(content).toHaveCSS("--composer-fade-bottom", "16px") |
| 134 | + await content.evaluate((element) => { |
| 135 | + element.scrollTop = element.scrollHeight |
| 136 | + }) |
| 137 | + await expect(content).toHaveCSS("--composer-fade-bottom", "0px") |
| 138 | + await expect |
| 139 | + .poll(async () => (await component.locator('[data-component="composer-suggestions"]').boundingBox())?.y) |
| 140 | + .toBe(menu.y) |
| 141 | + await expect(component.getByRole("img", { name: "layout.png", exact: true })).toBeVisible() |
| 142 | + await expect(component.getByText("Keep the search separate from the draft", { exact: true })).toBeVisible() |
| 143 | + await input.press("ArrowUp") |
| 144 | + await expect(input).toHaveText("Run the focused tests") |
| 145 | + await expect(composer).toHaveCSS("height", `${height}px`) |
| 146 | + await input.press("ArrowUp") |
| 147 | + await expect(input).toHaveText("Run the focused tests") |
| 148 | + await input.press("ArrowDown") |
| 149 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 150 | + await input.press("ControlOrMeta+f") |
| 151 | + await expect(search).toBeFocused() |
| 152 | + await search.fill("ACCESSIBLE") |
| 153 | + await expect(composer).toHaveCSS("height", `${height}px`) |
| 154 | + await search.press("Escape") |
| 155 | + await expect(input).toBeFocused() |
| 156 | + await expect(composer).toHaveCSS("height", `${height}px`) |
| 157 | + await expect |
| 158 | + .poll(() => |
| 159 | + component |
| 160 | + .locator('[data-slot="composer-content"]') |
| 161 | + .evaluate((element) => element.scrollHeight > element.clientHeight), |
| 162 | + ) |
| 163 | + .toBe(true) |
| 164 | + await input.press("Enter") |
| 165 | + await expect(options).toHaveCount(0) |
| 166 | + await expect(content).toHaveCSS("mask-image", "none") |
| 167 | + await expect(viewport).not.toHaveCSS("mask-image", "none") |
| 168 | + await expect(content).toHaveCSS("--composer-fade-bottom", "0px") |
| 169 | + await expect(input).toBeFocused() |
| 170 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 171 | + await expect(component.getByRole("status")).toHaveText("Ready") |
| 172 | + await expect |
| 173 | + .poll(() => composer.evaluate((element) => element.getBoundingClientRect().height)) |
| 174 | + .toBeGreaterThan(height) |
| 175 | + |
| 176 | + // History must not intercept navigation in a populated multiline editor. |
| 177 | + await input.press("ControlOrMeta+Home") |
| 178 | + await input.press("ArrowUp") |
| 179 | + await expect(search).toHaveCount(0) |
| 180 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 181 | + |
| 182 | + // An empty-text draft can still have attachments and comments. Previewing must not lose them on cancel. |
| 183 | + await input.fill("") |
| 184 | + const restoredHeight = await composer.evaluate((element) => element.getBoundingClientRect().height) |
| 185 | + await input.press("Shift+ArrowUp") |
| 186 | + await expect(input).toHaveText("Explain the latest changes") |
| 187 | + await expect(component.getByRole("img", { name: "layout.png", exact: true })).toHaveCount(0) |
| 188 | + await expect(composer).toHaveCSS("height", `${restoredHeight}px`) |
| 189 | + await input.press("Escape") |
| 190 | + await expect(options).toHaveCount(0) |
| 191 | + await expect(input).toBeFocused() |
| 192 | + await expect(input).toBeEmpty() |
| 193 | + await expect(composer).toHaveCSS("height", `${restoredHeight}px`) |
| 194 | + await expect(component.getByRole("img", { name: "layout.png", exact: true })).toBeVisible() |
| 195 | + await expect(component.getByText("Keep the search separate from the draft", { exact: true })).toBeVisible() |
| 196 | + }, |
| 197 | +) |
| 198 | + |
| 199 | +story("searches history on demand, returns to browsing, and keeps shell history separate", async ({ mount, page }) => { |
| 200 | + const component = await mount("opencode-composer-flow--prompt-history") |
| 201 | + const input = component.getByRole("textbox", { name: "Prompt", exact: true }) |
| 202 | + const search = component.getByRole("combobox", { name: "Prompt history", exact: true }) |
| 203 | + |
| 204 | + await input.press("Shift+ArrowUp") |
| 205 | + await input.press("ControlOrMeta+f") |
| 206 | + await expect(search).toBeFocused() |
| 207 | + await search.fill("ACCESSIBLE") |
| 208 | + await expect(component.getByRole("option")).toHaveCount(1) |
| 209 | + await expect(input).toHaveText("Review the composer layout\nKeep keyboard navigation accessible") |
| 210 | + await expect(search).toBeFocused() |
| 211 | + await search.press("Escape") |
| 212 | + await expect(search).toHaveCount(0) |
| 213 | + await expect(input).toBeFocused() |
| 214 | + await expect(component.getByRole("option")).toHaveCount(3) |
| 215 | + await input.press("Escape") |
| 216 | + await expect(component.getByRole("option")).toHaveCount(0) |
| 217 | + await expect(input).toBeEmpty() |
| 218 | + |
| 219 | + await input.press("Shift+ArrowUp") |
| 220 | + await component.getByRole("button", { name: /^Search/ }).click() |
| 221 | + await expect(search).toBeFocused() |
| 222 | + await search.fill("no matching prompt") |
| 223 | + await expect(component.getByRole("option")).toHaveCount(0) |
| 224 | + await expect(component.getByText("No matching items", { exact: true })).toBeVisible() |
| 225 | + await search.press("ArrowUp") |
| 226 | + await search.press("Enter") |
| 227 | + await expect(search).toHaveValue("no matching prompt") |
| 228 | + await expect(input).toHaveText("Explain the latest changes") |
| 229 | + await search.fill("tests") |
| 230 | + await expect(input).toHaveText("Run the focused tests") |
| 231 | + await expect(search).toBeFocused() |
| 232 | + await search.press("Enter") |
| 233 | + await expect(search).toHaveCount(0) |
| 234 | + await expect(input).toBeFocused() |
| 235 | + await expect(component.getByRole("status")).toHaveText("Ready") |
| 236 | + |
| 237 | + await input.fill("") |
| 238 | + await input.press("Shift+ArrowUp") |
| 239 | + await component.getByRole("option", { name: "Run the focused tests", exact: true }).click() |
| 240 | + await expect(input).toHaveText("Run the focused tests") |
| 241 | + await expect(input).toBeFocused() |
| 242 | + await expect(component.getByRole("status")).toHaveText("Ready") |
| 243 | + |
| 244 | + await page.mouse.move(0, 0) |
| 245 | + await input.fill("") |
| 246 | + await input.press("Shift+ArrowUp") |
| 247 | + await expect(input).toHaveText("Explain the latest changes") |
| 248 | + await expect(component.getByRole("option")).toHaveCount(3) |
| 249 | + await expect(input).toBeFocused() |
| 250 | + await input.press("Shift+Digit1") |
| 251 | + await expect(component.getByRole("option")).toHaveCount(0) |
| 252 | + await expect(input).toHaveText("Explain the latest changes!") |
| 253 | + |
| 254 | + await input.fill("!") |
| 255 | + await expect(input).toBeEmpty() |
| 256 | + await input.press("Shift+ArrowUp") |
| 257 | + await expect(input).toHaveText("bun typecheck") |
| 258 | + await expect(component.getByRole("option")).toHaveText(["bun typecheck"]) |
| 259 | + await input.press("Escape") |
| 260 | + await expect(input).toBeFocused() |
| 261 | + await expect(input).toBeEmpty() |
| 262 | + await input.press("Shift+ArrowUp") |
| 263 | + await input.press("Enter") |
| 264 | + await expect(input).toHaveText("bun typecheck") |
| 265 | + await expect(component.getByRole("status")).toHaveText("Ready") |
| 266 | +}) |
| 267 | + |
| 268 | +story("pins history search above the scrolling prompts", async ({ mount }) => { |
| 269 | + const component = await mount("opencode-composer-flow--prompt-history", { args: { many: true } }) |
| 270 | + const input = component.getByRole("textbox", { name: "Prompt", exact: true }) |
| 271 | + await input.press("Shift+ArrowUp") |
| 272 | + const menu = component.locator('[data-component="composer-suggestions"]') |
| 273 | + const search = menu.getByRole("button", { name: /^Search/ }) |
| 274 | + const viewport = menu.getByRole("region", { name: "scrollable content" }) |
| 275 | + await expect.poll(() => viewport.evaluate((element) => element.scrollHeight > element.clientHeight)).toBe(true) |
| 276 | + |
| 277 | + const clippedTop = () => |
| 278 | + viewport.evaluate((element) => { |
| 279 | + const top = element.getBoundingClientRect().top |
| 280 | + |
| 281 | + return Array.from(element.querySelectorAll('[role="option"]')).some((row) => { |
| 282 | + const rect = row.getBoundingClientRect() |
| 283 | + |
| 284 | + return rect.top < top && rect.bottom > top |
| 285 | + }) |
| 286 | + }) |
| 287 | + |
| 288 | + await expect.poll(clippedTop).toBe(false) |
| 289 | + |
| 290 | + for (let index = 0; index < 12; index++) await input.press("ArrowUp") |
| 291 | + await expect(menu.getByRole("option", { selected: true })).toBeInViewport({ ratio: 1 }) |
| 292 | + await expect.poll(clippedTop).toBe(false) |
| 293 | + await expect.poll(async () => (await search.boundingBox())!.y - (await viewport.boundingBox())!.y).toBeLessThan(0) |
| 294 | + const top = (await search.boundingBox())!.y |
| 295 | + |
| 296 | + await viewport.evaluate((element) => { |
| 297 | + element.scrollTop = 0 |
| 298 | + }) |
| 299 | + await expect(search).toBeInViewport() |
| 300 | + expect((await search.boundingBox())!.y).toBe(top) |
| 301 | + await viewport.evaluate((element) => { |
| 302 | + element.scrollTop = element.scrollHeight |
| 303 | + }) |
| 304 | + await expect(search).toBeInViewport() |
| 305 | + expect((await search.boundingBox())!.y).toBe(top) |
| 306 | +}) |
| 307 | + |
3 | 308 | for (const direction of ["ltr", "rtl"]) { |
4 | 309 | for (const alternate of ["none", "queue", "steer"]) { |
5 | 310 | story(`scrolls overflowing controls beside fixed ${alternate} actions in ${direction}`, async ({ mount, page }) => { |
|
0 commit comments