|
| 1 | +// Control UI tests cover the working claw's optical alignment. |
| 2 | +import { chromium, type Browser } from "playwright"; |
| 3 | +import { afterAll, beforeAll, describe, expect, it } from "vitest"; |
| 4 | +import { readStyleSheet } from "../../../../test/helpers/ui-style-fixtures.js"; |
| 5 | +import { |
| 6 | + canRunPlaywrightChromium, |
| 7 | + resolvePlaywrightChromiumExecutablePath, |
| 8 | +} from "../../test-helpers/control-ui-e2e.ts"; |
| 9 | + |
| 10 | +const chromiumExecutablePath = resolvePlaywrightChromiumExecutablePath(chromium.executablePath()); |
| 11 | +const describeBrowser = canRunPlaywrightChromium(chromiumExecutablePath) ? describe : describe.skip; |
| 12 | + |
| 13 | +const claw = ` |
| 14 | + <svg viewBox="0 0 24 24"> |
| 15 | + <path d="M8.2 10 A5.2 5.2 0 1 0 8.2 20.4 A5.2 5.2 0 0 0 8.2 10 Z M10.2 20 C14.5 20.8 19 18.6 22.3 13.2 C21 12.9 19.7 12.7 18.4 12.8 L17.5 14.6 L16 12.9 L14.3 14.5 L13.5 13 L11.5 14.2 Z"></path> |
| 16 | + <path class="claw-icon__jaw" d="M5.6 12.2 C5.2 5.6 10.4 1.4 15.6 2 C19.4 2.6 21.8 5.2 22.6 8.2 C20.9 7.7 19.2 7.6 17.6 7.9 L16.9 6.3 L15.2 8.5 C13.6 9.4 12.2 10.9 11.6 12.4 L6.8 13 Z"></path> |
| 17 | + </svg>`; |
| 18 | + |
| 19 | +describeBrowser("working claw browser layout", () => { |
| 20 | + let browser: Browser; |
| 21 | + |
| 22 | + beforeAll(async () => { |
| 23 | + browser = await chromium.launch({ executablePath: chromiumExecutablePath, headless: true }); |
| 24 | + }); |
| 25 | + |
| 26 | + afterAll(async () => { |
| 27 | + await browser?.close(); |
| 28 | + }); |
| 29 | + |
| 30 | + it("centers the claw when grouped chat styles load after the indicator styles", async () => { |
| 31 | + const page = await browser.newPage({ viewport: { width: 640, height: 240 } }); |
| 32 | + try { |
| 33 | + const css = [ |
| 34 | + "ui/src/styles/base.css", |
| 35 | + "ui/src/styles/components.css", |
| 36 | + "ui/src/styles/chat/tool-cards.css", |
| 37 | + // Production code splitting can attach grouped chat CSS after the |
| 38 | + // indicator chunk. The centering invariant must not depend on order. |
| 39 | + "ui/src/styles/chat/grouped.css", |
| 40 | + ] |
| 41 | + .map((file) => readStyleSheet(file)) |
| 42 | + .join("\n"); |
| 43 | + await page.setContent(`<!doctype html><html><head><style>${css}</style></head><body> |
| 44 | + <div class="chat-group assistant chat-group--working"> |
| 45 | + <div class="chat-working-indicator"> |
| 46 | + <div class="chat-bubble chat-reading-indicator">${claw}</div> |
| 47 | + <span class="chat-working-indicator__status"> |
| 48 | + <span class="chat-working-indicator__elapsed">8s</span><span>·</span><span>72 tokens</span> |
| 49 | + </span> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + </body></html>`); |
| 53 | + |
| 54 | + const geometry = await page.evaluate(() => { |
| 55 | + const center = (selector: string) => { |
| 56 | + const bounds = document.querySelector(selector)!.getBoundingClientRect(); |
| 57 | + return bounds.top + bounds.height / 2; |
| 58 | + }; |
| 59 | + const svg = document.querySelector<SVGElement>(".chat-reading-indicator svg")!; |
| 60 | + return { |
| 61 | + display: getComputedStyle(document.querySelector(".chat-reading-indicator")!).display, |
| 62 | + layoutCenter: center(".chat-reading-indicator"), |
| 63 | + paintedCenter: center(".chat-reading-indicator svg"), |
| 64 | + statusCenter: center(".chat-working-indicator__status"), |
| 65 | + translate: getComputedStyle(svg).translate, |
| 66 | + }; |
| 67 | + }); |
| 68 | + |
| 69 | + // As a flex item, inline-flex is blockified to flex in computed style. |
| 70 | + expect(geometry.display).toBe("flex"); |
| 71 | + expect(geometry.layoutCenter).toBeCloseTo(geometry.statusCenter, 3); |
| 72 | + expect(geometry.paintedCenter).toBeCloseTo(geometry.statusCenter, 3); |
| 73 | + expect(geometry.translate).toBe("none"); |
| 74 | + } finally { |
| 75 | + await page.close(); |
| 76 | + } |
| 77 | + }); |
| 78 | +}); |
0 commit comments