feat(webui): refresh the empty chat welcome (#6650)

* feat(webui): refresh the empty chat welcome

* fix(webui): keep empty chat accessible in split panes

* chore(webui): remove unused fixture test id
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-13 17:12:18 +08:00
1 parent 90d69e7a11
commit 6a24b17629
26 files changed
+283 -205

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ for (const theme of ["light", "dark"]) {
await expect(surface).toBeVisible();
const input = page.getByRole("textbox", { name: "Message input" });
await input.blur();
await page.getByTestId("hero-greeting").click();
await page.getByTestId("thread-empty-region").click();
const rest = await surface.evaluate(element => getComputedStyle(element).boxShadow);
const bounds = await surface.boundingBox();
const footer = await page.locator(".thread-composer-footer").boundingBox();
+11 -2
View File
@@ -1,5 +1,6 @@
import { useState } from "react";
import { ThreadShell } from "@/components/thread/ThreadShell";
import { PaneWorkbench } from "@/components/workbench/PaneWorkbench";
import type { WorkspaceScopePayload } from "@/lib/types";
import { StartupSkeleton } from "@/components/StartupSkeleton";
import { settings } from "@/dev/gallery/settings";
@@ -18,11 +19,19 @@ export function NewChatSkeletonFixture() {
{params.has("loading") ? <StartupSkeleton sidebarExpanded={sidebarExpanded} sidebarWidth={sidebarWidth} /> : <>
<aside className="hidden shrink-0 bg-sidebar lg:block" style={{ width: sidebarExpanded ? sidebarWidth : 56 }} />
<main className="thread-workspace relative flex min-w-0 flex-1 flex-col overflow-hidden">
<ThreadShell session={null} title="nanobot" onToggleSidebar={noop} theme={dark ? "dark" : "light"}
{params.has("split") ? <PaneWorkbench
panes={[{ key: "one", title: "One" }, { key: "two", title: "Two" }, { key: "three", title: "Three" }]}
activePaneKey="one" layout="columns" showLayoutControl={false} onActivatePane={noop} onAddPane={noop}
onLayoutChange={noop} onPaneOrderChange={noop}
renderPane={(_pane, context) => <ThreadShell session={null} title="nanobot" onToggleSidebar={noop}
headerPortalTarget={context.headerPortalTarget} headerActive={context.active}
composerPortalTarget={context.composerPortalTarget} composerActive={context.active} settingsSnapshot={settings}
navigationFrame={context.navigationFrame} multiplePanes={context.multiplePanes} emptyComposerVariant="thread" />}
/> : <ThreadShell session={null} title="nanobot" onToggleSidebar={noop} theme={dark ? "dark" : "light"}
hideSidebarToggleForHostChrome onTemporaryChatEnabledChange={noop} settingsSnapshot={settings}
workspaceScope={workspaceScope}
workspaceDefaultScope={{ project_path: "/workspace", access_mode: "full" }}
workspaceControls={{ can_change_project: true, can_browse_directories: true }} onWorkspaceScopeChange={setWorkspaceScope} />
workspaceControls={{ can_change_project: true, can_browse_directories: true }} onWorkspaceScopeChange={setWorkspaceScope} />}
</main>
</>}
</div>;
+81 -6
View File
@@ -25,9 +25,8 @@ function sameBox(actual: Awaited<ReturnType<typeof box>>, expected: typeof actua
for (const c of cases) for (const locale of ["en", "zh-CN"]) {
test.describe(`${c.name} ${locale} new chat`, () => {
test.use({ viewport: { width: c.width, height: c.height }, hasTouch: c.touch, reducedMotion: "reduce" });
test("aligns the document skeleton with the real welcome, composer and header", async ({ page }) => {
test("aligns the document skeleton with the real composer and header", async ({ page }) => {
await page.addInitScript((language) => {
Math.random = () => 0;
localStorage.setItem("nanobot.locale", language);
}, locale);
await page.route("**/api/commands", (route) => route.fulfill({ json: { commands: [] } }));
@@ -42,12 +41,22 @@ for (const c of cases) for (const locale of ["en", "zh-CN"]) {
return { x, y, width, height };
})),
composer: await box(page.locator(".thread-composer-surface")),
mark: await box(page.getByTestId("thread-welcome-mark")),
input: await box(page.locator(".thread-composer-input")),
footer: await box(page.locator(".thread-composer-footer")),
greeting: await box(page.getByTestId("hero-greeting")),
workspaceRow: await box(page.locator(".thread-composer-meta")),
workspaceControl: await box(page.locator(".thread-composer-workspace")),
};
await expect(page.getByTestId("thread-empty-region").getByRole("heading", {
level: 1, name: locale === "en" ? "New topic" : "新建话题",
})).toHaveClass("sr-only");
await expect(page.getByTestId("thread-welcome-mark").locator(".thread-welcome-mark__focus")).toHaveCSS("mask-image", /nanobot_mark_outline\.svg/);
await expect(page.getByTestId("thread-welcome-mark").locator(".thread-welcome-mark__fill")).toHaveCSS("background-image", /nanobot_mark\.svg/);
await expect(page.getByTestId("thread-welcome-mark").locator(".thread-welcome-mark__fill")).toHaveCSS("filter", "grayscale(1)");
expect(Math.abs(loaded.mark.x + loaded.mark.width / 2 - loaded.composer.x - loaded.composer.width / 2)).toBeLessThanOrEqual(1);
expect(loaded.mark.y).toBeLessThan(loaded.composer.y);
expect(loaded.mark.y + loaded.mark.height).toBeGreaterThan(loaded.composer.y);
await expect(page.getByTestId("thread-welcome-mark")).toHaveCSS("pointer-events", "none");
await page.goto(`${url}&loading`);
sameBox(await box(page.locator(".startup-chat-header")), loaded.header);
sameBox(await box(page.locator(".startup-composer-surface")), loaded.composer);
@@ -58,11 +67,77 @@ for (const c of cases) for (const locale of ["en", "zh-CN"]) {
const controls = page.locator(".startup-header-menu:visible, .startup-header-actions > div");
await expect(controls).toHaveCount(loaded.controls.length);
for (let i = 0; i < loaded.controls.length; i++) sameBox(await box(controls.nth(i)), loaded.controls[i]);
const greeting = await box(page.locator(".startup-welcome-line"));
if (c.width < 640) expect(Math.abs(greeting.y + greeting.height / 2 - loaded.greeting.y - loaded.greeting.height / 2)).toBeLessThanOrEqual(1);
else expect(Math.abs(greeting.y + greeting.height - loaded.greeting.y - loaded.greeting.height)).toBeLessThanOrEqual(1);
expect(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth)).toBe(false);
await expect(page.getByRole("status")).toHaveText("Loading nanobot…");
});
});
}
test("keeps the welcome marks proportional and inside split panes as the window resizes", async ({ page }) => {
await page.setViewportSize({ width: 1100, height: 936 });
await page.route("**/api/commands", (route) => route.fulfill({ json: { commands: [] } }));
await page.goto("/browser/fixture.html?case=new-chat-skeleton&split");
const panes = page.locator(".workbench-pane");
await expect(panes).toHaveCount(3);
for (const width of [1100, 946]) {
await page.setViewportSize({ width, height: 936 });
for (const pane of await panes.all()) {
const region = await box(pane.getByTestId("thread-empty-region"));
const mark = await box(pane.getByTestId("thread-welcome-mark"));
expect(mark.x).toBeGreaterThanOrEqual(region.x - 0.1);
expect(mark.x + mark.width).toBeLessThanOrEqual(region.x + region.width + 0.1);
expect(mark.width / mark.height).toBeCloseTo(783 / 742, 2);
}
}
});
test("draws the nose bridge and the original cheek lines", async ({ page }) => {
await page.route("**/api/commands", (route) => route.fulfill({ json: { commands: [] } }));
await page.goto("/browser/fixture.html?case=new-chat-skeleton");
await expect(page.getByTestId("thread-welcome-mark")).toBeVisible();
const pixels = await page.evaluate(async () => {
const image = new Image();
image.src = "/brand/nanobot_mark_outline.svg";
await image.decode();
const canvas = document.createElement("canvas");
canvas.width = 783;
canvas.height = 742;
const context = canvas.getContext("2d")!;
context.drawImage(image, 0, 0);
return [[379, 200], [379, 400], [379, 650], [80, 497], [680, 497]]
.map(([x, y]) => context.getImageData(x + 12, y + 12, 1, 1).data[3]);
});
expect(pixels[0]).toBe(0);
expect(pixels[1]).toBeGreaterThan(0);
expect(pixels[2]).toBe(0);
expect(pixels[3]).toBeGreaterThan(0);
expect(pixels[4]).toBeGreaterThan(0);
});
for (const reducedMotion of ["no-preference", "reduce"] as const) {
test.describe(`welcome mark with ${reducedMotion} motion`, () => {
test.use({ reducedMotion });
test("reveals the outline near the pointer and hides the focus when the window loses focus", async ({ page }) => {
await page.route("**/api/commands", (route) => route.fulfill({ json: { commands: [] } }));
await page.goto("/browser/fixture.html?case=new-chat-skeleton");
const mark = page.getByTestId("thread-welcome-mark");
const bounds = await box(mark);
const focus = mark.locator(".thread-welcome-mark__focus");
const position = () => mark.evaluate((element) => ({
x: Number.parseFloat(element.style.getPropertyValue("--mark-x")),
y: Number.parseFloat(element.style.getPropertyValue("--mark-y")),
}));
await page.mouse.move(bounds.x + 40, bounds.y + 50);
await expect.poll(async () => Math.abs((await position()).x - 40)).toBeLessThan(1);
await expect(focus).toHaveCSS("opacity", "1");
await page.mouse.move(bounds.x + bounds.width - 40, bounds.y + 70);
await expect.poll(async () => Math.abs((await position()).x - (bounds.width - 40))).toBeLessThan(1);
expect(Math.abs((await position()).y - 70)).toBeLessThan(1);
await page.evaluate(() => window.dispatchEvent(new Event("blur")));
await expect(focus).toHaveCSS("opacity", "0");
});
});
}
+1 -1
View File
@@ -23,7 +23,7 @@ export function ThemeToggleFixture() {
</div>
<div className="workbench-body">
<section data-theme-surface className="workbench-pane flex flex-col gap-8 bg-background">
<h1 data-testid="hero-greeting" data-theme-ink className="text-center text-4xl text-foreground">Where should we start?</h1>
<h1 data-theme-ink className="text-center text-4xl text-foreground">Theme preview</h1>
<ThreadComposer variant="hero" onSend={() => {}} />
</section>
</div>
+2 -2
View File
@@ -70,7 +70,7 @@ test("pointer selection after keyboard entry does not restore keyboard focus", a
test("pointer dismissal outside a keyboard-opened menu does not refocus the trigger", async ({ page }) => {
const trigger = page.locator(".thread-composer-access");
await openWithKeyboard(page, trigger);
const greeting = (await page.getByTestId("hero-greeting").boundingBox())!;
await page.mouse.click(greeting.x + 8, greeting.y + 8);
const mark = (await page.getByTestId("thread-welcome-mark").boundingBox())!;
await page.mouse.click(mark.x + 8, mark.y + 8);
await expectPointerDismissal(page, trigger);
});