import { expect, test } from "@playwright/test" for (const theme of ["light", "dark"] as const) { for (const width of [360, 1440]) { test(`composer controls align and remain actionable at ${width}px in ${theme}`, async ({ page }) => { await page.setViewportSize({ width, height: 800 }) await page.emulateMedia({ colorScheme: theme }) await page.goto("/e2e/paas/index.html?ux") await page.evaluate((mode) => { document.documentElement.style.colorScheme = mode document.documentElement.setAttribute("data-color-scheme", mode) }, theme) await page.getByLabel("API Key", { exact: true }).fill("controls-layout") await page.getByRole("button", { name: "连接平台", exact: true }).click() const topbarAlignment = await page .locator(".paas-topbar-chat-actions .paas-icon-action, .paas-topbar-chat-actions .paas-more-actions > summary") .evaluateAll((elements) => { const centers = elements .filter((element) => element.getClientRects().length) .map((element) => { const box = element.getBoundingClientRect() return box.y + box.height / 2 }) return Math.max(...centers) - Math.min(...centers) }) expect(topbarAlignment).toBeLessThanOrEqual(1) const upload = page.getByRole("button", { name: "添加文件", exact: true }) const role = page.getByRole("button", { name: "选择执行角色", exact: true }) const submit = page.getByRole("button", { name: "发送消息", exact: true }) for (const control of [upload, role, submit]) await expect(control).toBeInViewport() const boxes = await Promise.all([upload, submit].map((control) => control.boundingBox())) const centers = boxes.map((box) => box!.y + box!.height / 2) expect(Math.max(...centers) - Math.min(...centers)).toBeLessThanOrEqual(1) expect(boxes[0]!.x + boxes[0]!.width).toBeLessThan(boxes[1]!.x) expect((await role.boundingBox())!.y).toBeLessThan((await page.locator(".paas-composer").boundingBox())!.y) if (width > 600) { const scope = page.locator(".paas-task-scope > summary") const controls = await Promise.all([role, scope].map((control) => control.boundingBox())) expect( Math.abs(controls[0]!.y + controls[0]!.height / 2 - controls[1]!.y - controls[1]!.height / 2), ).toBeLessThanOrEqual(1) await scope.click() await expect .poll(async () => { const expanded = await Promise.all([role, scope].map((control) => control.boundingBox())) return Math.abs(expanded[0]!.y + expanded[0]!.height / 2 - expanded[1]!.y - expanded[1]!.height / 2) }) .toBeLessThanOrEqual(1) await scope.click() } await role.focus() await page.keyboard.press("Enter") await expect(page.getByRole("listbox", { name: "执行角色" })).toBeVisible() await page.keyboard.press("Escape") await expect(role).toBeFocused() expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width) await page.screenshot({ path: `/private/tmp/desktop-outcome-controls-${theme}-${width}.png` }) if (width < 1100) await page.getByRole("button", { name: "打开导航", exact: true }).click() const archiveFits = await page.locator(".paas-archive-toggle").evaluate((element) => { const box = element.getBoundingClientRect() const parent = element.closest(".paas-nav-history")!.getBoundingClientRect() return box.top >= parent.top && box.bottom <= parent.bottom }) expect(archiveFits).toBe(true) const project = page.getByLabel("切换项目", { exact: true }) await expect(project).toBeVisible() const spacing = await project.evaluate((element) => { const style = getComputedStyle(element) return { padding: Number.parseFloat(style.paddingRight), image: style.backgroundImage, position: style.backgroundPosition, } }) expect(spacing.padding).toBeGreaterThanOrEqual(32) expect(spacing.image).not.toBe("none") expect(spacing.position).toContain("12px") await page.getByRole("button", { name: "项目设置", exact: true }).click() const bind = page.getByRole("button", { name: "添加工作文件夹", exact: true }) await expect(bind).toBeVisible() const appearance = await bind.evaluate((element) => { const style = getComputedStyle(element) const hint = element.previousElementSibling! return { border: Number.parseFloat(style.borderTopWidth), height: element.getBoundingClientRect().height, gap: element.getBoundingClientRect().top - hint.getBoundingClientRect().bottom, } }) expect(appearance.border).toBeGreaterThanOrEqual(1) expect(appearance.height).toBeGreaterThanOrEqual(32) expect(appearance.gap).toBeGreaterThanOrEqual(6) await bind.click() await expect(page.getByRole("dialog")).toContainText("D:/Research/optics") await page.getByRole("button", { name: "完成", exact: true }).click() if (await page.locator(".paas-nav-backdrop").isVisible()) await page.keyboard.press("Escape") await expect( page.locator(".paas-composer-context").getByText("D:/Research/optics", { exact: true }), ).toBeVisible() }) } }