feat(webui): stabilize session transitions and goal presentation
Keep the composer stable during interruptible session changes. Move active and blocked goals into the header with localized gallery previews, and preserve focus when overlays close. Include the reviewed navigation, layout and accessibility fixes.
This commit is contained in:
1 parent
e65bec9a6e
commit
ce3f36983d
58 files changed
+1874
-453
No files matched your search
@@ -926,13 +926,13 @@ describe("App layout", () => {
|
||||
expect(await screen.findByText(firstMessage)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("creates a new temporary chat from the hero each time", async () => {
|
||||
it.each([false, true])("closes the active temporary chat without losing its replacement (pending capture=%s)", async (pendingCapture) => {
|
||||
const { unmount } = render(<App />);
|
||||
|
||||
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
|
||||
const sidebar = screen.getByRole("navigation", { name: "Sidebar navigation" });
|
||||
expect(within(sidebar).queryByRole("button", { name: "Temporary chat" })).not.toBeInTheDocument();
|
||||
const firstToggle = screen.getByRole("button", { name: "Temporary chat" });
|
||||
const firstToggle = await screen.findByRole("button", { name: "Temporary chat" });
|
||||
expect(firstToggle).toHaveAttribute("aria-pressed", "false");
|
||||
fireEvent.click(firstToggle);
|
||||
expect(firstToggle).toHaveAttribute("aria-pressed", "true");
|
||||
@@ -974,36 +974,66 @@ describe("App layout", () => {
|
||||
name: "second private message",
|
||||
})).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(within(sidebar).getByRole("button", {
|
||||
name: "first private message",
|
||||
}));
|
||||
await waitFor(() => expect(window.location.hash).toBe(firstHash));
|
||||
expect(within(screen.getByTestId("thread-header")).getByText(
|
||||
"first private message",
|
||||
)).toBeInTheDocument();
|
||||
await waitFor(() => expect(document.title).toBe("first private message"));
|
||||
expect(screen.queryByRole("button", { name: "Temporary chat" })).not.toBeInTheDocument();
|
||||
// Native capture delays the update callback, so React can run the route
|
||||
// cleanup effect before it. Do not replace transitionSession with a sync mock.
|
||||
const descriptor = Object.getOwnPropertyDescriptor(document, "startViewTransition");
|
||||
const captures: (() => void)[] = [];
|
||||
const capture = vi.fn((update: () => void) => {
|
||||
const finished = new Promise<void>((resolve) => {
|
||||
captures.push(() => { update(); resolve(); });
|
||||
});
|
||||
return { ready: finished, finished, skipTransition: vi.fn() };
|
||||
});
|
||||
const completeCaptures = async () => {
|
||||
while (captures.length) await act(async () => { captures.shift()!(); });
|
||||
};
|
||||
Object.defineProperty(document, "startViewTransition", { configurable: true, value: capture });
|
||||
try {
|
||||
fireEvent.click(within(sidebar).getByRole("button", {
|
||||
name: "first private message",
|
||||
}));
|
||||
expect(capture).toHaveBeenCalledTimes(1);
|
||||
expect(window.location.hash).toBe(secondHash);
|
||||
await completeCaptures();
|
||||
await waitFor(() => expect(window.location.hash).toBe(firstHash));
|
||||
expect(within(screen.getByTestId("thread-header")).getByText(
|
||||
"first private message",
|
||||
)).toBeInTheDocument();
|
||||
await waitFor(() => expect(document.title).toBe("first private message"));
|
||||
expect(screen.queryByRole("button", { name: "Temporary chat" })).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(within(sidebar).getByRole("button", {
|
||||
name: "Close temporary chat: first private message",
|
||||
}));
|
||||
await waitFor(() => expect(window.location.hash).toBe(secondHash));
|
||||
expect(within(sidebar).queryByRole("button", {
|
||||
name: "first private message",
|
||||
})).not.toBeInTheDocument();
|
||||
expect(within(sidebar).getByRole("button", {
|
||||
name: "second private message",
|
||||
})).toBeInTheDocument();
|
||||
expect(discardTemporaryChatSpy).toHaveBeenCalledTimes(1);
|
||||
if (pendingCapture) {
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: "second private message" }));
|
||||
expect(window.location.hash).toBe(firstHash);
|
||||
expect(captures).toHaveLength(1);
|
||||
}
|
||||
fireEvent.click(within(sidebar).getByRole("button", {
|
||||
name: "Close temporary chat: first private message",
|
||||
}));
|
||||
await completeCaptures();
|
||||
await waitFor(() => expect(window.location.hash).toBe(secondHash));
|
||||
expect(within(screen.getByTestId("thread-header")).getByText("second private message")).toBeInTheDocument();
|
||||
expect(within(sidebar).queryByRole("button", {
|
||||
name: "first private message",
|
||||
})).not.toBeInTheDocument();
|
||||
expect(within(sidebar).getByRole("button", {
|
||||
name: "second private message",
|
||||
})).toBeInTheDocument();
|
||||
expect(discardTemporaryChatSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
unmount();
|
||||
await waitFor(() => expect(discardTemporaryChatSpy).toHaveBeenCalledTimes(2));
|
||||
const discardedChatIds = discardTemporaryChatSpy.mock.calls.map(([chatId]) => chatId);
|
||||
expect(new Set(discardedChatIds).size).toBe(2);
|
||||
expect(discardedChatIds).toEqual([
|
||||
"00000000-0000-4000-8000-000000000001",
|
||||
"00000000-0000-4000-8000-000000000002",
|
||||
]);
|
||||
unmount();
|
||||
await waitFor(() => expect(discardTemporaryChatSpy).toHaveBeenCalledTimes(2));
|
||||
const discardedChatIds = discardTemporaryChatSpy.mock.calls.map(([chatId]) => chatId);
|
||||
expect(new Set(discardedChatIds).size).toBe(2);
|
||||
expect(discardedChatIds).toEqual([
|
||||
"00000000-0000-4000-8000-000000000001",
|
||||
"00000000-0000-4000-8000-000000000002",
|
||||
]);
|
||||
} finally {
|
||||
await completeCaptures();
|
||||
if (descriptor) Object.defineProperty(document, "startViewTransition", descriptor);
|
||||
else Reflect.deleteProperty(document, "startViewTransition");
|
||||
}
|
||||
});
|
||||
|
||||
it("shows the temporary-chat control only on the new-topic hero", async () => {
|
||||
@@ -3927,6 +3957,43 @@ describe("App layout", () => {
|
||||
expect(screen.queryByRole("menuitem", { name: "Move to" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each([false, true])("animates replaced threads rather than focusing a visible pane (mobile=%s)", async mobile => {
|
||||
vi.stubGlobal("matchMedia", vi.fn((query: string) => ({
|
||||
matches: mobile && query.includes("max-width: 767px"), media: query, onchange: null,
|
||||
addListener: vi.fn(), removeListener: vi.fn(), addEventListener: vi.fn(), removeEventListener: vi.fn(), dispatchEvent: vi.fn(),
|
||||
})));
|
||||
mockSessions = ["alpha", "child", "other"].map(chatId => ({
|
||||
key: `websocket:${chatId}`, channel: "websocket", chatId,
|
||||
createdAt: null, updatedAt: null, title: `${chatId} topic`, preview: "",
|
||||
}));
|
||||
window.history.replaceState(null, "", "/#/chat/websocket%3Aalpha");
|
||||
mockFetchRoutes({ "/api/webui/sidebar-state": { workbench: { version: 1, tabs: {
|
||||
"tab:alpha": { explicit: true, title: "Group", paneKeys: ["websocket:alpha", "websocket:child"], layout: "columns" },
|
||||
} } } });
|
||||
render(<App />);
|
||||
await act(async () => { await import("@/components/thread/ThreadShell"); });
|
||||
await screen.findByTestId("workbench-pane-websocket:alpha");
|
||||
const sidebar = screen.getByRole("navigation", { name: "Sidebar navigation" });
|
||||
await within(sidebar).findByRole("button", { name: "Group: Group" });
|
||||
const descriptor = Object.getOwnPropertyDescriptor(document, "startViewTransition");
|
||||
const capture = vi.fn((update: () => void) => {
|
||||
update();
|
||||
return { ready: Promise.resolve(), finished: Promise.resolve(), skipTransition: vi.fn() };
|
||||
});
|
||||
Object.defineProperty(document, "startViewTransition", { configurable: true, value: capture });
|
||||
try {
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: "child topic" }));
|
||||
await waitFor(() => expect(screen.getByTestId("workbench-pane-websocket:child")).toHaveAttribute("data-active", "true"));
|
||||
expect(capture).toHaveBeenCalledTimes(mobile ? 1 : 0);
|
||||
fireEvent.click(within(sidebar).getByRole("button", { name: "other topic" }));
|
||||
await screen.findByTestId("workbench-pane-websocket:other");
|
||||
expect(capture).toHaveBeenCalledTimes(mobile ? 2 : 1);
|
||||
} finally {
|
||||
if (descriptor) Object.defineProperty(document, "startViewTransition", descriptor);
|
||||
else Reflect.deleteProperty(document, "startViewTransition");
|
||||
}
|
||||
});
|
||||
|
||||
it("materializes a singleton tab without linking it to another pane", async () => {
|
||||
mockSessions = [
|
||||
{
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { GoalIsland } from "@/components/thread/GoalIsland";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import { ThreadHeader } from "@/components/thread/ThreadHeader";
|
||||
|
||||
const goal = { active: true, ui_summary: "Ship the release", objective: "Verify the full release checklist." };
|
||||
|
||||
function Conversation({ blocked = false }: { blocked?: boolean }) {
|
||||
return <>
|
||||
<ThreadHeader title="Release planning" onToggleSidebar={vi.fn()} theme="light" onToggleTheme={vi.fn()}
|
||||
goal={<GoalIsland goal={{ ...goal, active: !blocked, status: blocked ? "blocked" : "active", ...(blocked ? { recap: "Waiting for approval." } : {}) }} />} />
|
||||
<ThreadComposer onSend={vi.fn()} persistDraft={false} goalState={goal} />
|
||||
</>;
|
||||
}
|
||||
|
||||
describe("GoalIsland", () => {
|
||||
it("shows the summary and complete objective, dismissing through Escape and outside input without losing its draft", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Conversation />);
|
||||
const input = screen.getByRole("textbox", { name: "Message input" });
|
||||
await user.type(input, "Keep my draft");
|
||||
const trigger = screen.getByRole("button", { name: "Show full goal" });
|
||||
await user.click(trigger);
|
||||
const dialog = await screen.findByRole("dialog", { name: "Goal" });
|
||||
expect(dialog).toHaveTextContent(goal.ui_summary);
|
||||
expect(dialog).toHaveTextContent(goal.objective);
|
||||
expect(trigger).toHaveAttribute("aria-expanded", "true");
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(input).toHaveFocus();
|
||||
await user.click(trigger);
|
||||
await user.click(input);
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(input).toHaveValue("Keep my draft");
|
||||
expect(input).toHaveFocus();
|
||||
});
|
||||
|
||||
it("returns keyboard-opened details to their trigger on Escape", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Conversation />);
|
||||
await user.click(screen.getByRole("textbox", { name: "Message input" }));
|
||||
const trigger = screen.getByRole("button", { name: "Show full goal" });
|
||||
trigger.focus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(screen.getByRole("dialog", { name: "Goal" })).toBeVisible();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(trigger).toHaveFocus();
|
||||
});
|
||||
|
||||
it("updates the active goal to blocked with the gateway recap while keeping the expanded view", async () => {
|
||||
const user = userEvent.setup();
|
||||
const { rerender } = render(<Conversation />);
|
||||
await user.click(screen.getByRole("button", { name: "Show full goal" }));
|
||||
expect(screen.getByRole("heading", { name: goal.ui_summary })).toBeVisible();
|
||||
rerender(<Conversation blocked />);
|
||||
const dialog = screen.getByRole("dialog");
|
||||
expect(dialog).toHaveTextContent("Blocked");
|
||||
expect(dialog).toHaveTextContent(/Waiting for approval\..*Verify the full release checklist\./);
|
||||
});
|
||||
});
|
||||
@@ -185,3 +185,42 @@ describe("ModelPresetBadge selected preset tooltip", () => {
|
||||
await waitFor(() => expect(screen.queryByRole("tooltip")).not.toBeInTheDocument());
|
||||
});
|
||||
});
|
||||
|
||||
describe("ModelPresetBadge dismissal focus", () => {
|
||||
it("does not request composer focus for an outside click", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onRequestComposerFocus = vi.fn();
|
||||
render(<><ModelPresetBadge label="zhipu" modelPreset="zhipu" modelPresets={presets}
|
||||
onPresetChange={vi.fn()} onRequestComposerFocus={onRequestComposerFocus} isHero /><input aria-label="Other field" /></>);
|
||||
await user.click(screen.getByRole("button", { name: "zhipu" }));
|
||||
const outside = screen.getByRole("textbox", { name: "Other field" });
|
||||
await user.click(outside);
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(outside).toHaveFocus();
|
||||
expect(onRequestComposerFocus).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns keyboard Escape to the picker rather than requesting composer focus", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onRequestComposerFocus = vi.fn();
|
||||
render(<ModelPresetBadge label="zhipu" modelPreset="zhipu" modelPresets={presets}
|
||||
onPresetChange={vi.fn()} onRequestComposerFocus={onRequestComposerFocus} isHero />);
|
||||
const trigger = screen.getByRole("button", { name: "zhipu" });
|
||||
await user.tab();
|
||||
await user.keyboard("{Enter}{Escape}");
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
expect(onRequestComposerFocus).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("requests composer focus once after a picker selection closes", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onRequestComposerFocus = vi.fn();
|
||||
render(<ModelPresetBadge label="zhipu" modelPreset="zhipu" modelPresets={presets}
|
||||
onPresetChange={vi.fn()} onRequestComposerFocus={onRequestComposerFocus} isHero />);
|
||||
await user.click(screen.getByRole("button", { name: "zhipu" }));
|
||||
await user.click(screen.getByRole("option", { name: "codex" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(onRequestComposerFocus).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import { useRef } from "react";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, beforeEach, expect, it } from "vitest";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { useOverlayEscapeFocus } from "@/hooks/useOverlayEscapeFocus";
|
||||
import { mockBrowserFocus } from "./browser-focus";
|
||||
|
||||
let restoreBrowserFocus: () => void;
|
||||
beforeEach(() => { restoreBrowserFocus = mockBrowserFocus(); });
|
||||
afterEach(() => restoreBrowserFocus());
|
||||
|
||||
function FocusFixture({ override = false }: { override?: boolean }) {
|
||||
const escapeFocus = useOverlayEscapeFocus();
|
||||
const destination = useRef<HTMLInputElement>(null);
|
||||
return <>
|
||||
<input aria-label="Editing field" />
|
||||
<Popover><PopoverTrigger asChild><button {...escapeFocus.triggerProps}>Open information</button></PopoverTrigger>
|
||||
<PopoverContent {...escapeFocus.contentProps} onCloseAutoFocus={(event) => {
|
||||
if (override) { event.preventDefault(); destination.current?.focus(); }
|
||||
escapeFocus.contentProps.onCloseAutoFocus(event);
|
||||
}}><input aria-label="Popover field" /></PopoverContent>
|
||||
</Popover>
|
||||
<input ref={destination} aria-label="Destination field" />
|
||||
</>;
|
||||
}
|
||||
|
||||
it("returns pointer-open / Escape to the interrupted editing field", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<FocusFixture />);
|
||||
const editor = screen.getByRole("textbox", { name: "Editing field" });
|
||||
await user.click(editor);
|
||||
await user.click(screen.getByRole("button", { name: "Open information" }));
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(editor).toHaveFocus());
|
||||
});
|
||||
|
||||
it("returns keyboard-open / Escape to the trigger", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<FocusFixture />);
|
||||
await user.tab();
|
||||
await user.tab();
|
||||
const trigger = screen.getByRole("button", { name: "Open information" });
|
||||
expect(trigger).toHaveFocus();
|
||||
await user.keyboard("{Enter}{Escape}");
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
});
|
||||
|
||||
it("leaves outside-click focus with the clicked field", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<FocusFixture />);
|
||||
await user.click(screen.getByRole("textbox", { name: "Editing field" }));
|
||||
await user.click(screen.getByRole("button", { name: "Open information" }));
|
||||
const destination = screen.getByRole("textbox", { name: "Destination field" });
|
||||
await user.click(destination);
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(destination).toHaveFocus();
|
||||
});
|
||||
|
||||
it("honors a caller's explicit close-focus handoff", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<FocusFixture override />);
|
||||
await user.click(screen.getByRole("textbox", { name: "Editing field" }));
|
||||
await user.click(screen.getByRole("button", { name: "Open information" }));
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(screen.getByRole("textbox", { name: "Destination field" })).toHaveFocus());
|
||||
});
|
||||
@@ -79,3 +79,16 @@ it("keeps an unknown recovered time blank while the prompt remains navigable", a
|
||||
await user.click(prompt);
|
||||
expect(onJumpToPrompt).toHaveBeenCalledWith("undated");
|
||||
});
|
||||
|
||||
it("returns shortcut-opened search to the interrupted editor", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<><input aria-label="Draft" /><PromptNavigator messages={[
|
||||
{ id: "one", role: "user", content: "alpha", createdAt: 1 },
|
||||
]} onJumpToPrompt={vi.fn()} /></>);
|
||||
const editor = screen.getByRole("textbox", { name: "Draft" });
|
||||
await user.click(editor);
|
||||
await user.keyboard("{Control>}f{/Control}");
|
||||
await waitFor(() => expect(screen.getByRole("textbox", { name: "Search messages" })).toHaveFocus());
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(editor).toHaveFocus());
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
|
||||
import { finishSessionTransition, transitionSession } from "@/components/thread/session-transition";
|
||||
|
||||
const nativeTransition = Object.getOwnPropertyDescriptor(document, "startViewTransition");
|
||||
|
||||
afterEach(() => {
|
||||
transitionSession(() => {}, false);
|
||||
vi.restoreAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
if (nativeTransition) Object.defineProperty(document, "startViewTransition", nativeTransition);
|
||||
else Reflect.deleteProperty(document, "startViewTransition");
|
||||
delete document.documentElement.dataset.themeSnapshot;
|
||||
});
|
||||
|
||||
function nativeCaptures() {
|
||||
const captures: { update: () => void; finish: () => void; skipTransition: ReturnType<typeof vi.fn> }[] = [];
|
||||
const start = vi.fn((update: () => void) => {
|
||||
let finish!: () => void;
|
||||
const finished = new Promise<void>(resolve => { finish = resolve; });
|
||||
const capture = { update, finish, skipTransition: vi.fn() };
|
||||
captures.push(capture);
|
||||
return { ready: Promise.resolve(), finished, skipTransition: capture.skipTransition };
|
||||
});
|
||||
vi.stubGlobal("matchMedia", () => ({ matches: false }));
|
||||
Object.defineProperty(document, "startViewTransition", { configurable: true, value: start });
|
||||
return { captures, start };
|
||||
}
|
||||
|
||||
it("commits only the latest navigation when native captures are interrupted", async () => {
|
||||
const { captures } = nativeCaptures();
|
||||
const old = vi.fn();
|
||||
const latest = vi.fn();
|
||||
transitionSession(old);
|
||||
transitionSession(latest);
|
||||
expect(captures[0].skipTransition).toHaveBeenCalledOnce();
|
||||
captures[0].update();
|
||||
captures[1].update();
|
||||
expect(old).not.toHaveBeenCalled();
|
||||
expect(latest).toHaveBeenCalledOnce();
|
||||
captures[0].finish();
|
||||
await Promise.resolve();
|
||||
expect(document.documentElement).toHaveAttribute("data-session-transition");
|
||||
captures[1].finish();
|
||||
await Promise.resolve();
|
||||
expect(document.documentElement).not.toHaveAttribute("data-session-transition");
|
||||
});
|
||||
|
||||
it("leaving chat invalidates a pending session capture", () => {
|
||||
const { captures } = nativeCaptures();
|
||||
const stale = vi.fn();
|
||||
const settings = vi.fn();
|
||||
transitionSession(stale);
|
||||
transitionSession(settings, false);
|
||||
captures[0].update();
|
||||
expect(settings).toHaveBeenCalledOnce();
|
||||
expect(stale).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each(["reduced-motion", "theme-snapshot", "no-native-capture"])("navigates immediately with %s", mode => {
|
||||
const { start } = nativeCaptures();
|
||||
if (mode === "reduced-motion") vi.stubGlobal("matchMedia", () => ({ matches: true }));
|
||||
if (mode === "theme-snapshot") document.documentElement.dataset.themeSnapshot = "";
|
||||
if (mode === "no-native-capture") Object.defineProperty(document, "startViewTransition", { configurable: true, value: undefined });
|
||||
const update = vi.fn();
|
||||
transitionSession(update);
|
||||
expect(update).toHaveBeenCalledOnce();
|
||||
expect(start).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("finishes an accepted navigation before handing snapshots to the theme toggle", () => {
|
||||
const { captures } = nativeCaptures();
|
||||
const update = vi.fn();
|
||||
transitionSession(update);
|
||||
finishSessionTransition();
|
||||
expect(update).toHaveBeenCalledOnce();
|
||||
expect(captures[0].skipTransition).toHaveBeenCalledOnce();
|
||||
expect(document.documentElement).not.toHaveAttribute("data-session-transition");
|
||||
captures[0].update();
|
||||
expect(update).toHaveBeenCalledOnce();
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useState } from "react";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { expect, it } from "vitest";
|
||||
import { SettingsFeature } from "@/components/settings/shared/SettingsFeature";
|
||||
|
||||
function FeatureFixture({ saveOnClose = false }: { saveOnClose?: boolean }) {
|
||||
const [enabled, setEnabled] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
return <SettingsFeature title="Example feature" enabled={enabled} disabled={saving}
|
||||
onChange={setEnabled} onClose={() => { if (saveOnClose) setSaving(true); }}>
|
||||
<p>Configuration</p>
|
||||
</SettingsFeature>;
|
||||
}
|
||||
|
||||
it.each(["title", "configure", "toggle"] as const)("returns Escape to the actual %s opener", async (opener) => {
|
||||
const user = userEvent.setup();
|
||||
render(<FeatureFixture />);
|
||||
const trigger = opener === "toggle" ? screen.getByRole("switch", { name: "Example feature" })
|
||||
: screen.getByRole("button", { name: opener === "title" ? "Example feature" : "Configure" });
|
||||
await user.click(trigger);
|
||||
await screen.findByRole("dialog");
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
});
|
||||
|
||||
it("returns Escape to Configure when saving disables the opening switch", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<FeatureFixture saveOnClose />);
|
||||
const toggle = screen.getByRole("switch", { name: "Example feature" });
|
||||
toggle.focus();
|
||||
await user.keyboard(" ");
|
||||
await screen.findByRole("dialog");
|
||||
expect(toggle).toBeChecked();
|
||||
await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(toggle).toBeDisabled();
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Configure" })).toHaveFocus());
|
||||
});
|
||||
@@ -1697,87 +1697,6 @@ describe("ThreadComposer", () => {
|
||||
});
|
||||
|
||||
|
||||
it("closes the sustained goal through its existing drawer", () => {
|
||||
const { container, rerender } = render(
|
||||
<ThreadComposer
|
||||
onSend={vi.fn()}
|
||||
placeholder="Type your message..."
|
||||
goalState={{
|
||||
active: true,
|
||||
objective: "Ship the release",
|
||||
ui_summary: "Preparing release",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const drawer = container.querySelector("[data-composer-status-drawer]");
|
||||
expect(drawer).not.toBeNull();
|
||||
expect(drawer).toHaveAttribute("data-state", "open");
|
||||
expect(drawer).not.toHaveAttribute("aria-hidden");
|
||||
const status = screen.getByRole("status");
|
||||
expect(status).toHaveClass("composer-status-drawer-content");
|
||||
|
||||
rerender(
|
||||
<ThreadComposer
|
||||
onSend={vi.fn()}
|
||||
placeholder="Type your message..."
|
||||
goalState={{ active: false }}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelector("[data-composer-status-drawer]")).toBe(drawer);
|
||||
expect(drawer).toHaveAttribute("data-state", "closed");
|
||||
expect(drawer).toHaveAttribute("aria-hidden", "true");
|
||||
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
||||
expect(drawer?.querySelector('[role="status"]')).toBe(status);
|
||||
|
||||
fireEvent.transitionEnd(drawer as Element, { propertyName: "grid-template-rows" });
|
||||
expect(container.querySelector("[data-composer-status-drawer]")).toBeNull();
|
||||
});
|
||||
|
||||
it("shows full goal content and dismisses it without losing the composer draft", async () => {
|
||||
const user = userEvent.setup();
|
||||
const longObjective =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789GoalTail";
|
||||
render(
|
||||
<ThreadComposer
|
||||
onSend={vi.fn()}
|
||||
persistDraft={false}
|
||||
placeholder="Type your message..."
|
||||
goalState={{
|
||||
active: true,
|
||||
objective: longObjective,
|
||||
ui_summary: "Short summary for strip",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const input = screen.getByRole("textbox", { name: "Message input" });
|
||||
const trigger = screen.getByRole("button", { name: "Show full goal" });
|
||||
await user.type(input, "Keep my draft");
|
||||
await user.click(trigger);
|
||||
|
||||
const dialog = await screen.findByRole("dialog", { name: "Goal" });
|
||||
expect(dialog).toHaveTextContent("Short summary for strip");
|
||||
expect(dialog).toHaveTextContent(longObjective);
|
||||
expect(trigger).toHaveAttribute("aria-expanded", "true");
|
||||
|
||||
await user.click(trigger);
|
||||
expect(screen.queryByRole("dialog", { name: "Goal" })).not.toBeInTheDocument();
|
||||
expect(trigger).toHaveAttribute("aria-expanded", "false");
|
||||
|
||||
await user.click(trigger);
|
||||
expect(await screen.findByRole("dialog", { name: "Goal" })).toBeVisible();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByRole("dialog", { name: "Goal" })).not.toBeInTheDocument();
|
||||
|
||||
await user.click(trigger);
|
||||
expect(await screen.findByRole("dialog", { name: "Goal" })).toBeVisible();
|
||||
await user.click(input);
|
||||
expect(screen.queryByRole("dialog", { name: "Goal" })).not.toBeInTheDocument();
|
||||
expect(input).toHaveValue("Keep my draft");
|
||||
});
|
||||
|
||||
it("opens a slash command palette and inserts the selected command", () => {
|
||||
const onSend = vi.fn();
|
||||
render(
|
||||
|
||||
@@ -24,9 +24,12 @@ describe("Workspace project picker", () => {
|
||||
it.each(["pointer", "keyboard"])("restores the opening focus context after %s entry and Escape", async (entry) => {
|
||||
const user = userEvent.setup();
|
||||
const onChange = vi.fn();
|
||||
render(<WorkspaceProjectPicker scope={scope} defaultScope={scope} controls={catalog.controls} onBrowseDirectories={vi.fn().mockResolvedValue(directory)} onChange={onChange} />);
|
||||
render(<><input aria-label="Draft" /><WorkspaceProjectPicker scope={scope} defaultScope={scope} controls={catalog.controls} onBrowseDirectories={vi.fn().mockResolvedValue(directory)} onChange={onChange} /></>);
|
||||
const trigger = screen.getByRole("button", { name: "Switch directory" });
|
||||
if (entry === "pointer") await user.click(trigger);
|
||||
if (entry === "pointer") {
|
||||
await user.click(screen.getByRole("textbox", { name: "Draft" }));
|
||||
await user.click(trigger);
|
||||
}
|
||||
else {
|
||||
act(() => trigger.focus());
|
||||
await user.keyboard("{Enter}");
|
||||
@@ -37,7 +40,7 @@ describe("Workspace project picker", () => {
|
||||
// FocusScope restores focus in a task after its exit cleanup.
|
||||
await act(() => new Promise(resolve => setTimeout(resolve, 0)));
|
||||
if (entry === "keyboard") expect(trigger).toHaveFocus();
|
||||
else expect(trigger).not.toHaveFocus();
|
||||
else expect(screen.getByRole("textbox", { name: "Draft" })).toHaveFocus();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user