import { expect, story } from "../../storybook/playwright/story" for (const direction of ["ltr", "rtl"]) { for (const alternate of ["none", "queue", "steer"]) { story(`scrolls overflowing controls beside fixed ${alternate} actions in ${direction}`, async ({ mount, page }) => { const component = await mount("opencode-composer-flow--toolbar-overflow", { args: { alternate }, globals: { direction }, }) const controls = component.locator('[data-slot="composer-controls"]') const actions = component.locator('[data-slot="composer-actions"]') const submit = component.locator('[data-action="composer-submit"]') const add = component.locator('[data-action="composer-attach"]') const agent = controls.getByRole("button", { name: "Choose agent" }) const variant = controls.getByRole("button", { name: "Choose model variant" }) await expect(controls).toHaveCSS("overflow-x", "auto") await expect(controls).toHaveCSS("overscroll-behavior-x", "contain") await expect(controls).toHaveCSS("direction", direction) await expect(controls).toHaveCSS("padding-inline-start", "0px") await expect(controls).toHaveCSS("padding-inline-end", "0px") await expect(component.locator('[data-action="composer-alternate-delivery"]')).toHaveCount( alternate === "none" ? 0 : 1, ) // A late Inter swap resizes the delivery keybind and shifts the toolbar; measure after fonts settle. await page.evaluate(() => document.fonts.ready.then(() => undefined)) for (const width of [1024, 360]) { await page.setViewportSize({ width, height: 720 }) await expect .poll(() => controls.evaluate((element) => element.scrollWidth - element.clientWidth)) .toBeGreaterThan(0) const fixed = await submit.boundingBox() const fixedAdd = await add.boundingBox() const viewport = await controls.boundingBox() const action = await actions.boundingBox() expect(fixed).not.toBeNull() expect(viewport).not.toBeNull() expect(action).not.toBeNull() expect(fixedAdd).not.toBeNull() if (!fixed || !viewport || !action || !fixedAdd) return expect(direction === "ltr" ? fixedAdd.x + fixedAdd.width : viewport.x + viewport.width).toBeCloseTo( direction === "ltr" ? viewport.x - 4 : fixedAdd.x - 4, 1, ) expect(direction === "ltr" ? viewport.x + viewport.width : action.x + action.width).toBeCloseTo( direction === "ltr" ? action.x - 12 : viewport.x - 12, 1, ) await controls.evaluate((element) => { element.scrollLeft = 0 }) await expect(controls).toHaveAttribute("data-overflow-start", "false") await expect(controls).toHaveAttribute("data-overflow-end", "true") await expect(controls).toHaveCSS( "mask-image", `linear-gradient(to ${direction === "ltr" ? "right" : "left"}, rgba(0, 0, 0, 0), rgb(0, 0, 0) 0px, rgb(0, 0, 0) calc(100% - 16px), rgba(0, 0, 0, 0))`, ) const first = await agent.boundingBox() if (!first) throw new Error("Missing agent control") expect( direction === "ltr" ? first.x - viewport.x : viewport.x + viewport.width - first.x - first.width, ).toBeCloseTo(0, 0) await controls.evaluate((element) => { element.scrollLeft = ((getComputedStyle(element).direction === "rtl" ? -1 : 1) * (element.scrollWidth - element.clientWidth)) / 2 }) await expect(controls).toHaveAttribute("data-overflow-start", "true") await expect(controls).toHaveAttribute("data-overflow-end", "true") const scrolled = (await controls.boundingBox())! expect(scrolled.x).toBeCloseTo(viewport.x, 1) expect(scrolled.width).toBeCloseTo(viewport.width, 1) await controls.hover() await page.mouse.wheel(direction === "ltr" ? 1000 : -1000, 0) await expect.poll(() => controls.evaluate((element) => Math.abs(element.scrollLeft))).toBeGreaterThan(0) expect(await submit.boundingBox()).toEqual(fixed) expect(await add.boundingBox()).toEqual(fixedAdd) // The fade disappears at the endpoint instead of reserving padding. await variant.focus() await controls.evaluate((element) => { element.scrollLeft = getComputedStyle(element).direction === "rtl" ? -element.scrollWidth : element.scrollWidth }) await expect(controls).toHaveAttribute("data-overflow-start", "true") await expect(controls).toHaveAttribute("data-overflow-end", "false") const last = await variant.boundingBox() if (!last) throw new Error("Missing variant control") expect( Math.abs(direction === "ltr" ? viewport.x + viewport.width - last.x - last.width : last.x - viewport.x), ).toBeLessThan(1) expect( Math.abs((direction === "ltr" ? action.x - last.x - last.width : last.x - action.x - action.width) - 12), ).toBeLessThan(1) await page.keyboard.press("Enter") // Below the mobile breakpoint the variant picker opens in a bottom drawer instead of a menu. await expect( width < 768 ? page .getByRole("dialog", { name: "Choose model variant", exact: true }) .getByRole("button", { name: "high", exact: true }) : page.getByRole("menuitemradio", { name: "high", exact: true }), ).toBeVisible() await page.keyboard.press("Escape") await expect(variant).toBeFocused() await expect(submit).toBeInViewport() await expect(add).toBeInViewport() await add.click() await expect(page.getByRole("menuitem", { name: "Images and files" })).toBeVisible() await page.keyboard.press("Escape") await expect(add).toBeFocused() expect(await add.boundingBox()).toEqual(fixedAdd) } if (alternate !== "none") { const width = (await controls.boundingBox())!.width await component.getByRole("textbox", { name: "Prompt", exact: true }).fill("") await expect(component.locator('[data-action="composer-alternate-delivery"]')).toHaveCount(0) await expect.poll(async () => (await controls.boundingBox())!.width).toBeGreaterThan(width) } }) } } story("does not mask or pad controls when they fit", async ({ mount }) => { const component = await mount("opencode-composer-flow--model-and-variant") const controls = component.locator('[data-slot="composer-controls"]') await expect(controls).toHaveAttribute("data-overflow-start", "false") await expect(controls).toHaveAttribute("data-overflow-end", "false") await expect(controls).toHaveCSS("mask-image", "none") await expect(controls).toHaveCSS("padding-inline-start", "0px") await expect(controls).toHaveCSS("padding-inline-end", "0px") }) story("grows suggestions while preserving visible timeline context", async ({ mount }) => { const component = await mount("opencode-composer-flow--constrained-command-suggestions") const boundary = component.locator('[data-slot="composer-suggestion-boundary-story"]') const suggestions = component.locator('[data-component="composer-suggestions"]') await expect(suggestions).toHaveCSS("max-height", "166px") await expect(suggestions).toHaveCSS("scroll-padding-bottom", "18px") await expect.poll(() => suggestions.evaluate((element) => element.scrollHeight > element.clientHeight)).toBe(true) await expect .poll(async () => { const menu = await suggestions.boundingBox() const items = await suggestions.locator("[data-suggestion-id]").evaluateAll((elements) => elements.map((element) => { const rect = element.getBoundingClientRect() return { top: rect.top, bottom: rect.bottom } }), ) if (!menu) return false const bottom = menu.y + menu.height return items.some((item) => item.top < bottom && item.bottom > bottom) }) .toBe(true) await boundary.evaluate((element) => { element.style.height = "400px" }) await expect(suggestions).toHaveCSS("max-height", "306px") }) story("ignores a detached suggestion boundary", async ({ mount }) => { const component = await mount("opencode-composer-flow--detached-command-suggestion-boundary") await expect(component.locator('[data-component="composer-suggestions"]')).toHaveCSS("max-height", "306px") }) // ThemeProvider writes resolved token values into a