Skip to content

Commit 62b41fe

Browse files
fix(ui): center the working claw in chat layout (#133682)
* fix(ui): center the working claw optically * fix(ui): center working claw in real chat layout * test(ui): route claw layout proof through node
1 parent 69464f7 commit 62b41fe

7 files changed

Lines changed: 81 additions & 0 deletions

File tree

145 KB
Loading
5.19 KB
Loading
145 KB
Loading
5.28 KB
Loading
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
});

‎ui/src/styles/chat/grouped.css‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ img.chat-avatar.chat-avatar--logo {
783783

784784
/* Keep the working claw on the same left edge as the flat text column. */
785785
.chat-group.assistant .chat-bubble.chat-reading-indicator {
786+
display: inline-flex;
787+
align-items: center;
786788
padding: 10px 0;
787789
}
788790

‎ui/vitest.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const sharedUiTestConfig = {
102102
const nodeDrivenBrowserLayoutTests = [
103103
"src/ui/chat/sidebar-session-picker.browser.test.ts",
104104
"src/pages/chat/chat-responsive.browser.test.ts",
105+
"src/pages/chat/chat-working-indicator.browser.test.ts",
105106
"src/pages/chat/chat-composer-undo-redo.browser.test.ts",
106107
"src/pages/chat/components/chat-swarm-progress.browser.test.ts",
107108
"src/components/form-controls.browser.test.ts",

0 commit comments

Comments
 (0)