feat(web): port the pi2-web-ui-design v0.1.1 UI
Sync the React console with the v0.1.1 prototype (20 CHGs): Quiet Workbench
shell, Chat IA v3, tool-family rendering, and the mobile page pill.
Shell / tokens (CHG-01/04/15/20):
- tokens.css rewritten from the prototype (three-layer light/dark/system),
`--tabbar-h` removed, new faint/border-subtle/surface-1-2/fs-*/dur-*/reading-max
- 56px icon-only nav rail/sidebar (44x44 hit targets, CSS tooltips, active is a
solid primary fill, no left bar), 52px topbar, merged preferences menu,
⌘K/Cmd-K palette
- `<600` gets a topbar page pill + page sheet; the bottom tabbar is gone
Pages (CHG-01): workspaces becomes a card grid with whole-card links and a
320px recent-activity column; status gets four metric tiles + a zero-primary
layout; connect gets a two-column hero, one primary per state and a collapsed
manual form.
Chat IA v3 (CHG-02/10-14/16-19): two columns, single-workspace tree with a
workspace switch, single-line rows with attention, body-level row popover,
session tray (todo/tasks) replacing the right panel, context ring moved into a
composer telemetry line, right-aligned user messages, queued messages as one
stream entity plus a composer status bar, and an in-place subagent child view.
Tool rendering (CHG-05/06/09): new `features/chat/tools` module — one row per
call, DTO adapter for the daemon's block shape, 11 kind families, state
semantics ("one state, one meaning"), 44px touch targets and the diff row
contrast fix.
i18n: 729 keys per language (zh/en parity checked), 0 unresolved keys.
Verification: web typecheck + 297 vitest + vite build green, root typecheck
green, `scripts/smoke.sh` green, and a new visual harness
(`scripts/ui-mock-server.mjs` + `scripts/ui-shots.mjs`, docs/ui-parity.md)
shoots 4 pages x 3 viewports x 2 themes = 24 screenshots clean with
overflow/console/primary/tabbar assertions. `scripts/e2e/ui-e2e.mjs` selectors
are updated to the new DOM; that suite still needs a real pi + nvim to run.
This commit is contained in:
1 parent
a8425a51b6
commit
88e73c7737
98 files changed
+17676
-2871
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { Composer } from "@/features/chat/composer";
|
||||
import { Composer, type ComposerProps } from "@/features/chat/composer";
|
||||
import { setLanguage } from "@/lib/i18n";
|
||||
import { sessionFixture } from "./chat-fixtures";
|
||||
|
||||
@@ -16,7 +16,7 @@ const MODELS = [
|
||||
},
|
||||
];
|
||||
|
||||
function renderComposer(session = sessionFixture()) {
|
||||
function renderComposer(session = sessionFixture(), overrides: Partial<ComposerProps> = {}) {
|
||||
const onSend = vi.fn();
|
||||
const onAbort = vi.fn();
|
||||
const onRemoveQueue = vi.fn();
|
||||
@@ -34,6 +34,7 @@ function renderComposer(session = sessionFixture()) {
|
||||
onSetSteer={onSetSteer}
|
||||
onSetModel={onSetModel}
|
||||
onSetThinking={onSetThinking}
|
||||
{...overrides}
|
||||
/>,
|
||||
);
|
||||
return { ...utils, onSend, onAbort, onRemoveQueue, onSetSteer, onSetModel, onSetThinking };
|
||||
@@ -43,12 +44,23 @@ describe("composer", () => {
|
||||
it("exposes the stable Playwright selectors", () => {
|
||||
renderComposer(sessionFixture({ status: "busy" }));
|
||||
expect(screen.getByTestId("composer-input")).toHaveClass("composer__ta");
|
||||
expect(screen.getByTestId("composer-send")).toHaveClass("composer__send");
|
||||
expect(screen.getByTestId("composer-abort")).toBeInTheDocument();
|
||||
// Busy: the single slot is the abort button, so `composer-send` is absent.
|
||||
expect(screen.queryByTestId("composer-send")).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId("composer-abort")).toHaveClass("composer__send");
|
||||
expect(screen.getByTestId("composer-model")).toHaveAttribute("aria-label", "Model");
|
||||
expect(screen.getByTestId("composer-thinking")).toHaveAttribute("aria-label", "Thinking level");
|
||||
});
|
||||
|
||||
it("keeps one circular send slot while the session is idle", () => {
|
||||
renderComposer(sessionFixture({ status: "idle" }));
|
||||
const send = screen.getByTestId("composer-send");
|
||||
expect(send).toHaveClass("composer__send");
|
||||
expect(send).not.toHaveClass("is-busy");
|
||||
expect(screen.queryByTestId("composer-abort")).not.toBeInTheDocument();
|
||||
// The text label is screen-reader only; the button itself is an icon.
|
||||
expect(screen.getByRole("button", { name: "Send" })).toBe(send);
|
||||
});
|
||||
|
||||
it("sends on Enter and keeps Shift+Enter for a newline", () => {
|
||||
const { onSend } = renderComposer(sessionFixture({ status: "idle" }));
|
||||
const textarea = screen.getByTestId("composer-input");
|
||||
@@ -71,36 +83,129 @@ describe("composer", () => {
|
||||
expect(onSend).toHaveBeenCalledWith("next step", [], "follow_up");
|
||||
});
|
||||
|
||||
it("keeps send for follow-ups and adds steer + abort while the session is busy", () => {
|
||||
const session = sessionFixture({ status: "busy" });
|
||||
const { onAbort, onSend } = renderComposer(session);
|
||||
it("turns the send slot into a single red abort circle while busy", () => {
|
||||
const { onAbort } = renderComposer(sessionFixture({ status: "busy" }));
|
||||
|
||||
fireEvent.change(screen.getByTestId("composer-input"), { target: { value: "queue me" } });
|
||||
fireEvent.click(screen.getByTestId("composer-send"));
|
||||
expect(onSend).toHaveBeenLastCalledWith("queue me", [], "follow_up");
|
||||
// No separate steer / abort text buttons any more (CHG-2026-10-26-16).
|
||||
expect(screen.queryByTestId("composer-steer")).not.toBeInTheDocument();
|
||||
const abort = screen.getByTestId("composer-abort");
|
||||
expect(abort).toHaveClass("composer__send");
|
||||
expect(abort).toHaveClass("is-busy");
|
||||
expect(screen.queryAllByTestId("composer-send")).toHaveLength(0);
|
||||
|
||||
fireEvent.change(screen.getByTestId("composer-input"), { target: { value: "interrupt" } });
|
||||
fireEvent.click(screen.getByTestId("composer-steer"));
|
||||
expect(onSend).toHaveBeenLastCalledWith("interrupt", [], "steer");
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Abort" }));
|
||||
fireEvent.click(abort);
|
||||
expect(onAbort).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("renders queue chips with the session-wide steer toggle and remove", () => {
|
||||
it("never renders queue bodies, per-item steer toggles or delete buttons", () => {
|
||||
const session = sessionFixture({
|
||||
status: "idle",
|
||||
queue: [
|
||||
{ id: "q1", text: "later please", steer: false },
|
||||
{ id: "q2", text: "and this one", steer: true },
|
||||
],
|
||||
});
|
||||
renderComposer(session);
|
||||
|
||||
expect(screen.queryByText("later please")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("and this one")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("checkbox")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Remove queued message" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("reports counts in a role=status bar, not the message text", () => {
|
||||
const session = sessionFixture({
|
||||
status: "busy",
|
||||
queue: [
|
||||
{ id: "q1", text: "later please", steer: false },
|
||||
{ id: "q2", text: "and this one", steer: true },
|
||||
],
|
||||
});
|
||||
renderComposer(session);
|
||||
|
||||
const bar = screen.getByTestId("composer-queue");
|
||||
expect(bar).toHaveAttribute("role", "status");
|
||||
expect(bar).toHaveAttribute("aria-live", "polite");
|
||||
expect(bar).not.toHaveClass("is-empty");
|
||||
expect(bar).toHaveTextContent(/2 pending/);
|
||||
expect(bar).toHaveTextContent(/1 inserting now/);
|
||||
// "inserting now" supersedes the after-turn hint.
|
||||
expect(bar).not.toHaveTextContent(/Sends after this turn/);
|
||||
});
|
||||
|
||||
it("falls back to the after-turn hint and hides the bar when the queue is empty", () => {
|
||||
const session = sessionFixture({
|
||||
status: "busy",
|
||||
queue: [{ id: "q1", text: "later please", steer: false }],
|
||||
});
|
||||
const { onRemoveQueue, onSetSteer } = renderComposer(session);
|
||||
const { rerender } = renderComposer(session);
|
||||
expect(screen.getByTestId("composer-queue")).toHaveTextContent(/1 pending/);
|
||||
expect(screen.getByTestId("composer-queue")).toHaveTextContent(/Sends after this turn/);
|
||||
|
||||
expect(screen.getByText("later please")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("checkbox", { name: "Steer" }));
|
||||
// Steering is a session-wide mode, so the toggle carries no queue id.
|
||||
expect(onSetSteer).toHaveBeenCalledWith(true);
|
||||
rerender(
|
||||
<Composer
|
||||
session={sessionFixture({ status: "busy", queue: [] })}
|
||||
models={MODELS}
|
||||
connected
|
||||
onSend={vi.fn()}
|
||||
onAbort={vi.fn()}
|
||||
onRemoveQueue={vi.fn()}
|
||||
onSetSteer={vi.fn()}
|
||||
onSetModel={vi.fn()}
|
||||
onSetThinking={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
const empty = screen.getByTestId("composer-queue");
|
||||
expect(empty).toHaveClass("is-empty");
|
||||
expect(empty).toHaveTextContent(/0 pending/);
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Remove queued message" }));
|
||||
expect(onRemoveQueue).toHaveBeenCalledWith("q1");
|
||||
it("counts the optimistic send until the queue projects it, and honours queuedCount", () => {
|
||||
const sending = { text: "first prompt" };
|
||||
const { unmount } = renderComposer(sessionFixture({ status: "busy", queue: [] }), { sending });
|
||||
expect(screen.getByTestId("composer-queue")).toHaveTextContent(/1 pending/);
|
||||
// The body of the optimistic message never shows up in the composer.
|
||||
expect(screen.queryByText("first prompt")).not.toBeInTheDocument();
|
||||
unmount();
|
||||
|
||||
renderComposer(
|
||||
sessionFixture({
|
||||
status: "busy",
|
||||
queue: [{ id: "q1", text: "later please", steer: false }],
|
||||
}),
|
||||
{ sending, queuedCount: 7 },
|
||||
);
|
||||
expect(screen.getByTestId("composer-queue")).toHaveTextContent(/7 pending/);
|
||||
});
|
||||
|
||||
it("clears the queue through onClearQueue", () => {
|
||||
const session = sessionFixture({
|
||||
status: "busy",
|
||||
queue: [
|
||||
{ id: "q1", text: "later please", steer: false },
|
||||
{ id: "q2", text: "and this one", steer: false },
|
||||
],
|
||||
});
|
||||
const onClearQueue = vi.fn();
|
||||
const { onRemoveQueue } = renderComposer(session, { onClearQueue });
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Clear queue" }));
|
||||
expect(onClearQueue).toHaveBeenCalledTimes(1);
|
||||
expect(onRemoveQueue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("falls back to per-item removal when no bulk clear is wired", () => {
|
||||
const session = sessionFixture({
|
||||
status: "busy",
|
||||
queue: [
|
||||
{ id: "q1", text: "later please", steer: false },
|
||||
{ id: "q2", text: "and this one", steer: false },
|
||||
],
|
||||
});
|
||||
const { onRemoveQueue } = renderComposer(session);
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Clear queue" }));
|
||||
expect(onRemoveQueue.mock.calls.map(([id]) => id)).toEqual(["q1", "q2"]);
|
||||
});
|
||||
|
||||
it("drops the mock-era demo copy from the attachment dialog", () => {
|
||||
|
||||
Reference in new issue
Block a user