diff --git a/packages/app/component-tests/composer.spec.ts b/packages/app/component-tests/composer.spec.ts index 60be7bfd751..31fe09c2fc4 100644 --- a/packages/app/component-tests/composer.spec.ts +++ b/packages/app/component-tests/composer.spec.ts @@ -1,16 +1,139 @@ import { expect, story } from "../../storybook/playwright/story" -story("raises the docked composer only in dark mode", async ({ mount, page }) => { - const component = await mount("opencode-composer-flow--empty-draft") - const composer = component.locator('[data-component="composer"]') +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, + ) - await page.locator("html").evaluate((root) => root.setAttribute("data-color-scheme", "light")) - await expect(composer).toHaveCSS("background-color", "rgb(255, 255, 255)") + 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 page.locator("html").evaluate((root) => root.setAttribute("data-color-scheme", "dark")) - await expect(composer).toHaveCSS("background-color", "rgb(36, 36, 36)") + 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") + await expect(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") + 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") }) +// ThemeProvider writes resolved token values into a