feat(webui): streamline contextual message controls (#5831)
This commit is contained in:
1 parent
99a7ec256f
commit
920efd00b8
24 files changed
+1776
-955
No files matched your search
@@ -76,49 +76,6 @@ function activityMessages(extraReasoning = "", extraTool?: UIMessage): UIMessage
|
||||
return rows;
|
||||
}
|
||||
|
||||
function installAnimationFrameQueue() {
|
||||
const originalRequest = window.requestAnimationFrame;
|
||||
const originalCancel = window.cancelAnimationFrame;
|
||||
const callbacks = new Map<number, FrameRequestCallback>();
|
||||
let nextId = 1;
|
||||
|
||||
window.requestAnimationFrame = ((callback: FrameRequestCallback) => {
|
||||
const id = nextId;
|
||||
nextId += 1;
|
||||
callbacks.set(id, callback);
|
||||
return id;
|
||||
}) as typeof window.requestAnimationFrame;
|
||||
window.cancelAnimationFrame = ((id: number) => {
|
||||
callbacks.delete(id);
|
||||
}) as typeof window.cancelAnimationFrame;
|
||||
|
||||
return {
|
||||
flush() {
|
||||
const pending = Array.from(callbacks.entries());
|
||||
callbacks.clear();
|
||||
for (const [, callback] of pending) callback(0);
|
||||
},
|
||||
restore() {
|
||||
window.requestAnimationFrame = originalRequest;
|
||||
window.cancelAnimationFrame = originalCancel;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function setScrollGeometry(
|
||||
element: HTMLElement,
|
||||
geometry: { scrollHeight: number; clientHeight: number; scrollTop?: number },
|
||||
) {
|
||||
Object.defineProperties(element, {
|
||||
scrollHeight: { configurable: true, value: geometry.scrollHeight },
|
||||
clientHeight: { configurable: true, value: geometry.clientHeight },
|
||||
scrollTop: {
|
||||
configurable: true,
|
||||
value: geometry.scrollTop ?? element.scrollTop,
|
||||
writable: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function installReducedMotion() {
|
||||
const original = window.matchMedia;
|
||||
@@ -219,186 +176,39 @@ describe("AgentActivityCluster", () => {
|
||||
expect(screen.queryByTestId("activity-step")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("jumps to the latest activity when opened", () => {
|
||||
const raf = installAnimationFrameQueue();
|
||||
try {
|
||||
render(
|
||||
<AgentActivityCluster
|
||||
messages={activityMessages()}
|
||||
isTurnStreaming
|
||||
hasBodyBelow={false}
|
||||
/>,
|
||||
);
|
||||
it.each([false, true])("uses one activity layout without nested scrolling (streaming: %s)", (isTurnStreaming) => {
|
||||
const onExpandedChange = vi.fn();
|
||||
const props = {
|
||||
messages: activityMessages(),
|
||||
isTurnStreaming,
|
||||
hasBodyBelow: false,
|
||||
...(isTurnStreaming ? {} : { expanded: true, hideHeader: true }),
|
||||
onExpandedChange,
|
||||
};
|
||||
const view = render(<AgentActivityCluster {...props} />);
|
||||
const header = screen.getByRole("button", { name: /^(Working|Worked)/ });
|
||||
const content = screen.getByTestId("agent-activity-content");
|
||||
|
||||
const scrollport = screen.getByTestId("agent-activity-scroll");
|
||||
setScrollGeometry(scrollport, {
|
||||
scrollHeight: 1000,
|
||||
clientHeight: 120,
|
||||
scrollTop: 0,
|
||||
});
|
||||
expect(header).toHaveClass("h-7", "gap-1.5", "px-1.5");
|
||||
expect(header.querySelector("svg")).toHaveClass("lucide-activity");
|
||||
expect(header).toHaveAttribute("aria-expanded", "true");
|
||||
expect(view.container.querySelector("[data-contextual-activity-guide]")).toBeInTheDocument();
|
||||
expect(content).toHaveClass("ps-6");
|
||||
expect(content).not.toHaveClass("max-h-[180px]");
|
||||
expect(content).not.toHaveClass("overflow-y-auto");
|
||||
expect(screen.queryByTestId("activity-scroll-fade-top")).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId("activity-scroll-fade-bottom")).not.toBeInTheDocument();
|
||||
|
||||
act(() => {
|
||||
raf.flush();
|
||||
});
|
||||
|
||||
expect(scrollport.scrollTop).toBe(880);
|
||||
} finally {
|
||||
raf.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("follows new reasoning and tool activity while the user is at the bottom", () => {
|
||||
const raf = installAnimationFrameQueue();
|
||||
try {
|
||||
const { rerender } = render(
|
||||
<AgentActivityCluster
|
||||
messages={activityMessages()}
|
||||
isTurnStreaming
|
||||
hasBodyBelow={false}
|
||||
/>,
|
||||
);
|
||||
|
||||
const scrollport = screen.getByTestId("agent-activity-scroll");
|
||||
setScrollGeometry(scrollport, {
|
||||
scrollHeight: 1000,
|
||||
clientHeight: 120,
|
||||
scrollTop: 0,
|
||||
});
|
||||
act(() => {
|
||||
raf.flush();
|
||||
});
|
||||
|
||||
rerender(
|
||||
<AgentActivityCluster
|
||||
messages={activityMessages(" with more detail", {
|
||||
id: "t2",
|
||||
role: "tool",
|
||||
kind: "trace",
|
||||
content: "open_browser()",
|
||||
traces: ["open_browser()"],
|
||||
createdAt: 3,
|
||||
})}
|
||||
isTurnStreaming
|
||||
hasBodyBelow={false}
|
||||
/>,
|
||||
);
|
||||
setScrollGeometry(scrollport, {
|
||||
scrollHeight: 1500,
|
||||
clientHeight: 120,
|
||||
scrollTop: scrollport.scrollTop,
|
||||
});
|
||||
|
||||
act(() => {
|
||||
raf.flush();
|
||||
});
|
||||
|
||||
expect(scrollport.scrollTop).toBe(1380);
|
||||
} finally {
|
||||
raf.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("does not pull the user down after they scroll up inside the activity pane", () => {
|
||||
const raf = installAnimationFrameQueue();
|
||||
try {
|
||||
const { rerender } = render(
|
||||
<AgentActivityCluster
|
||||
messages={activityMessages()}
|
||||
isTurnStreaming
|
||||
hasBodyBelow={false}
|
||||
/>,
|
||||
);
|
||||
|
||||
const scrollport = screen.getByTestId("agent-activity-scroll");
|
||||
setScrollGeometry(scrollport, {
|
||||
scrollHeight: 1000,
|
||||
clientHeight: 120,
|
||||
scrollTop: 0,
|
||||
});
|
||||
act(() => {
|
||||
raf.flush();
|
||||
});
|
||||
|
||||
scrollport.scrollTop = 100;
|
||||
fireEvent.scroll(scrollport);
|
||||
|
||||
rerender(
|
||||
<AgentActivityCluster
|
||||
messages={activityMessages(" still streaming")}
|
||||
isTurnStreaming
|
||||
hasBodyBelow={false}
|
||||
/>,
|
||||
);
|
||||
setScrollGeometry(scrollport, {
|
||||
scrollHeight: 1500,
|
||||
clientHeight: 120,
|
||||
scrollTop: scrollport.scrollTop,
|
||||
});
|
||||
|
||||
act(() => {
|
||||
raf.flush();
|
||||
});
|
||||
|
||||
expect(scrollport.scrollTop).toBe(100);
|
||||
} finally {
|
||||
raf.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("feathers only the activity edges with clipped content", () => {
|
||||
const raf = installAnimationFrameQueue();
|
||||
try {
|
||||
render(
|
||||
<AgentActivityCluster
|
||||
messages={activityMessages()}
|
||||
isTurnStreaming
|
||||
hasBodyBelow={false}
|
||||
/>,
|
||||
);
|
||||
|
||||
const scrollport = screen.getByTestId("agent-activity-scroll");
|
||||
setScrollGeometry(scrollport, {
|
||||
scrollHeight: 1000,
|
||||
clientHeight: 120,
|
||||
scrollTop: 0,
|
||||
});
|
||||
|
||||
act(() => {
|
||||
raf.flush();
|
||||
});
|
||||
expect(scrollport).toHaveAttribute("data-fade-top", "true");
|
||||
expect(scrollport).toHaveAttribute("data-fade-bottom", "false");
|
||||
const topFade = screen.getByTestId("activity-scroll-fade-top");
|
||||
expect(scrollport).not.toContainElement(topFade);
|
||||
expect(scrollport).not.toHaveClass("activity-scroll-fade");
|
||||
expect(screen.queryByTestId("activity-scroll-fade-bottom")).not.toBeInTheDocument();
|
||||
|
||||
scrollport.scrollTop = 440;
|
||||
fireEvent.scroll(scrollport);
|
||||
expect(scrollport).toHaveAttribute("data-fade-top", "true");
|
||||
expect(scrollport).toHaveAttribute("data-fade-bottom", "true");
|
||||
expect(screen.getByTestId("activity-scroll-fade-top")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-scroll-fade-bottom")).toBeInTheDocument();
|
||||
|
||||
scrollport.scrollTop = 0;
|
||||
fireEvent.scroll(scrollport);
|
||||
expect(scrollport).toHaveAttribute("data-fade-top", "false");
|
||||
expect(scrollport).toHaveAttribute("data-fade-bottom", "true");
|
||||
expect(screen.queryByTestId("activity-scroll-fade-top")).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-scroll-fade-bottom")).toBeInTheDocument();
|
||||
|
||||
setScrollGeometry(scrollport, {
|
||||
scrollHeight: 100,
|
||||
clientHeight: 120,
|
||||
scrollTop: 0,
|
||||
});
|
||||
fireEvent.scroll(scrollport);
|
||||
expect(scrollport).toHaveAttribute("data-fade-top", "false");
|
||||
expect(scrollport).toHaveAttribute("data-fade-bottom", "false");
|
||||
expect(screen.queryByTestId("activity-scroll-fade-top")).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId("activity-scroll-fade-bottom")).not.toBeInTheDocument();
|
||||
} finally {
|
||||
raf.restore();
|
||||
view.rerender(<AgentActivityCluster {...props} messages={activityMessages(" updated", {
|
||||
id: "next-tool", role: "tool", kind: "trace", content: "open_browser()", createdAt: 3,
|
||||
})} />);
|
||||
expect(screen.getByTestId("agent-activity-content")).toBe(content);
|
||||
expect(content).toHaveTextContent("thinking updated");
|
||||
fireEvent.click(header);
|
||||
if (isTurnStreaming) {
|
||||
expect(screen.queryByTestId("agent-activity-content")).not.toBeInTheDocument();
|
||||
} else {
|
||||
expect(onExpandedChange).toHaveBeenCalledWith(false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -459,7 +269,7 @@ describe("AgentActivityCluster", () => {
|
||||
hasBodyBelow
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByTestId("agent-activity-scroll")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("agent-activity-content")).toBeInTheDocument();
|
||||
|
||||
rerender(
|
||||
<AgentActivityCluster
|
||||
@@ -473,11 +283,11 @@ describe("AgentActivityCluster", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByTestId("agent-activity-scroll")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("agent-activity-content")).toBeInTheDocument();
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(301);
|
||||
});
|
||||
expect(screen.queryByTestId("agent-activity-scroll")).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId("agent-activity-content")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Worked" })).toHaveAttribute(
|
||||
"aria-expanded",
|
||||
"false",
|
||||
@@ -487,31 +297,6 @@ describe("AgentActivityCluster", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps chevron color feedback faster than the drawer rotation", () => {
|
||||
render(
|
||||
<AgentActivityCluster
|
||||
messages={[{
|
||||
id: "r-motion",
|
||||
role: "assistant",
|
||||
content: "",
|
||||
reasoning: "checking motion",
|
||||
createdAt: 1,
|
||||
}]}
|
||||
isTurnStreaming={false}
|
||||
hasBodyBelow
|
||||
/>,
|
||||
);
|
||||
|
||||
const button = screen.getByRole("button", { name: "Worked" });
|
||||
expect(button).toHaveAttribute("data-thread-disclosure");
|
||||
const chevron = button.querySelector("svg");
|
||||
expect(chevron).toBeInTheDocument();
|
||||
expect(chevron).toHaveClass("transition-colors", "duration-200");
|
||||
expect(chevron?.parentElement).toHaveClass(
|
||||
"transition-transform",
|
||||
"[transition-duration:220ms]",
|
||||
);
|
||||
});
|
||||
|
||||
it("uses persisted turn latency for completed history instead of replay timestamps", () => {
|
||||
render(
|
||||
@@ -711,7 +496,7 @@ describe("AgentActivityCluster", () => {
|
||||
const assertIndependentDiff = () => {
|
||||
const diff = screen.getByTestId("file-edit-diff");
|
||||
expect(diff).toBeVisible();
|
||||
expect(diff.closest('[aria-hidden="true"], [inert], [data-testid="agent-activity-scroll"]'))
|
||||
expect(diff.closest('[aria-hidden="true"], [inert], [data-testid="agent-activity-content"]'))
|
||||
.toBeNull();
|
||||
expect(screen.getAllByTestId("activity-file-reference")).toHaveLength(1);
|
||||
};
|
||||
@@ -1140,7 +925,7 @@ describe("AgentActivityCluster", () => {
|
||||
);
|
||||
|
||||
expect(screen.queryByRole("button", { name: /edited app\.tsx/i })).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId("agent-activity-scroll")).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId("agent-activity-content")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("Edited")).toBeInTheDocument();
|
||||
expect(screen.queryByTestId("activity-header-file-reference")).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx");
|
||||
|
||||
@@ -23,4 +23,19 @@ describe("chat translation resources", () => {
|
||||
expect(i18n.t(key), key).not.toBe(key);
|
||||
}
|
||||
});
|
||||
|
||||
it("uses one Chinese work-status vocabulary with and without duration", async () => {
|
||||
const i18n = createInstance();
|
||||
await i18n.init({
|
||||
lng: "zh-CN",
|
||||
fallbackLng: false,
|
||||
resources: { "zh-CN": { translation: zhCN } },
|
||||
});
|
||||
|
||||
expect(i18n.t("message.activityWorkingFor", { duration: "15s" })).toBe("处理中 15s");
|
||||
expect(i18n.t("message.activityWorked")).toBe("已处理");
|
||||
expect(i18n.t("message.activityWorkedFor", { duration: "15s" })).toBe("已处理 15s");
|
||||
expect(i18n.t("message.activityShowFor", { duration: "15s" })).toBe("查看过程 15s");
|
||||
expect(i18n.t("message.activityHide")).toBe("收起过程");
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,11 @@
|
||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { MessageBubble } from "@/components/MessageBubble";
|
||||
import { MessageBlockMenuActions, MessageBubble } from "@/components/MessageBubble";
|
||||
import { ThreadMessages } from "@/components/thread/ThreadMessages";
|
||||
import { setAppLanguage } from "@/i18n";
|
||||
import * as clipboard from "@/lib/clipboard";
|
||||
import { fmtDateTime, formatMessageEndTime } from "@/lib/format";
|
||||
import { formatMessageEndTime } from "@/lib/format";
|
||||
import type {
|
||||
CliAppInfo,
|
||||
McpPresetInfo,
|
||||
@@ -96,49 +97,53 @@ const SLASH_COMMANDS: SlashCommand[] = [
|
||||
},
|
||||
];
|
||||
|
||||
function menuActions(root: ParentNode = document): HTMLElement {
|
||||
const actions = root.querySelector<HTMLElement>("[data-message-block-menu-actions]");
|
||||
expect(actions).not.toBeNull();
|
||||
return actions!;
|
||||
}
|
||||
|
||||
describe("MessageBubble", () => {
|
||||
it.each([false, undefined])("hides normal and legacy source badges (fallback: %s)", (fallback) => {
|
||||
it.each([false, undefined])("keeps normal sources out of the block menu (fallback: %s)", (fallback) => {
|
||||
const message: UIMessage = { id: "primary", role: "assistant", content: "Hello", createdAt: 0,
|
||||
isStreaming: true, responseSources: [{ provider: "openai_codex", model: "gpt", preset: "codex", fallback }] };
|
||||
const { container, rerender } = render(<MessageBubble message={message} />);
|
||||
expect(screen.queryByText("codex")).not.toBeInTheDocument();
|
||||
expect(container.querySelector("[data-assistant-footer]")).toHaveAttribute("data-state", "reserved");
|
||||
rerender(<MessageBubble message={{ ...message, isStreaming: false }} />);
|
||||
expect(screen.queryByText("codex")).not.toBeInTheDocument();
|
||||
responseSources: [{ provider: "openai_codex", model: "gpt", preset: "codex", fallback }] };
|
||||
render(<MessageBlockMenuActions message={message} />);
|
||||
expect(screen.getByRole("button", { name: "Copy" })).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: /fallback/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows only fallback provider logos and preset names while streaming and after completion", () => {
|
||||
it("keeps fallback sources visible live and moves them into the completed block menu", () => {
|
||||
const message: UIMessage = { id: "actual", role: "assistant", content: "Hello", createdAt: 0,
|
||||
isStreaming: true, responseSources: [
|
||||
{ provider: "openai_codex", model: "gpt", preset: "codex", fallback: false },
|
||||
{ provider: "xai", model: "grok-4.5", preset: "grok", fallback: true },
|
||||
] };
|
||||
const { container, rerender } = render(<MessageBubble message={message} />);
|
||||
const { container, rerender } = render(<ThreadMessages messages={[message]} isStreaming />);
|
||||
expect(screen.getByText("grok")).toBeVisible();
|
||||
expect(screen.queryByText("codex")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("grok-4.5")).not.toBeInTheDocument();
|
||||
expect(container.querySelector("[data-assistant-footer]")).toHaveAttribute("data-state", "visible");
|
||||
expect(container.querySelector("img")).toHaveAttribute("alt", "");
|
||||
fireEvent.error(container.querySelector("img")!);
|
||||
expect(screen.getByText("grok")).toBeVisible();
|
||||
rerender(<MessageBubble message={{ ...message, isStreaming: false }} />);
|
||||
expect(screen.getByText("grok")).toBeVisible();
|
||||
rerender(<MessageBubble message={{ ...message, responseSources: undefined }} />);
|
||||
rerender(<ThreadMessages messages={[{ ...message, isStreaming: false }]} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
expect(menuActions()).toContainElement(screen.getByText("grok"));
|
||||
expect(screen.getAllByText("grok")).toHaveLength(1);
|
||||
rerender(<ThreadMessages messages={[{ ...message, isStreaming: false, responseSources: undefined }]} />);
|
||||
expect(screen.queryByText("grok")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("explains fallback on focus and click, with the source directly after the timestamp", async () => {
|
||||
it("explains fallback on focus and click, with the source above static metadata", async () => {
|
||||
await setAppLanguage("zh-CN");
|
||||
const description = "本条回复已切换至备用模型,由 grok 回答。";
|
||||
const { container } = render(<MessageBubble message={{
|
||||
const { container } = render(<MessageBlockMenuActions message={{
|
||||
id: "fallback-info", role: "assistant", content: "你好", createdAt: 1,
|
||||
responseSources: [{ provider: "xai", model: "grok", preset: "grok", fallback: true }],
|
||||
}} />);
|
||||
const trigger = screen.getByRole("button", { name: description });
|
||||
const footer = container.querySelector("[data-assistant-footer]")!;
|
||||
const sourceGroup = footer.querySelector("[data-message-timestamp]")!.nextElementSibling;
|
||||
expect(sourceGroup).toContainElement(trigger);
|
||||
expect(sourceGroup).not.toHaveClass("ml-auto");
|
||||
const actions = menuActions(container);
|
||||
const metadata = actions.querySelector("[data-message-block-metadata]")!;
|
||||
expect(trigger.compareDocumentPosition(metadata) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
fireEvent.focus(trigger);
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent(description);
|
||||
fireEvent.blur(trigger);
|
||||
@@ -157,11 +162,13 @@ describe("MessageBubble", () => {
|
||||
configurable: true,
|
||||
value: { writeText },
|
||||
});
|
||||
render(<MessageBubble message={{
|
||||
const { container } = render(<ThreadMessages messages={[{
|
||||
id: "compact-empty", role: "assistant", content: "Nothing to compact.",
|
||||
compactReply: "empty", createdAt: 1,
|
||||
}} />);
|
||||
}]} />);
|
||||
expect(screen.getByText("无需压缩上下文")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "消息操作" }));
|
||||
expect(container).toHaveTextContent("无需压缩上下文");
|
||||
fireEvent.click(screen.getByRole("button", { name: "复制" }));
|
||||
await waitFor(() => expect(writeText).toHaveBeenCalledWith("无需压缩上下文"));
|
||||
});
|
||||
@@ -202,9 +209,28 @@ describe("MessageBubble", () => {
|
||||
const pill = screen.getByText("hello");
|
||||
|
||||
expect(row).toHaveClass("ml-auto", "flex");
|
||||
expect(row).toHaveAttribute("data-user-text-bubble", "true");
|
||||
expect(pill).toHaveClass("ml-auto", "w-fit", "rounded-floating");
|
||||
expect(screen.getByRole("button", { name: "Copy" })).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Fork" })).not.toBeInTheDocument();
|
||||
expect(pill).toHaveTextContent("hello");
|
||||
});
|
||||
|
||||
it("aligns the context trigger to the first text line only when text leads the user block", () => {
|
||||
const message: UIMessage = {
|
||||
id: "u-alignment", role: "user", content: "first line\nsecond line", createdAt: 0,
|
||||
};
|
||||
const contextMenu = <button data-message-block-menu-trigger>Message actions</button>;
|
||||
const { container, rerender } = render(
|
||||
<MessageBubble message={message} contextMenu={contextMenu} />,
|
||||
);
|
||||
const row = container.firstElementChild!;
|
||||
expect(row).toHaveAttribute("data-user-text-bubble", "true");
|
||||
expect(screen.getByRole("button", { name: "Message actions" }).parentElement).toBe(row);
|
||||
|
||||
rerender(<MessageBubble message={{ ...message, images: [{ name: "image.png" }] }} contextMenu={contextMenu} />);
|
||||
expect(row).not.toHaveAttribute("data-user-text-bubble");
|
||||
|
||||
rerender(<MessageBubble message={{ ...message, content: "> [!QUOTE]\n> excerpt\n\nreply" }} contextMenu={contextMenu} />);
|
||||
expect(row).not.toHaveAttribute("data-user-text-bubble");
|
||||
});
|
||||
|
||||
it("renders cross-session input with its public handle", () => {
|
||||
@@ -368,7 +394,7 @@ describe("MessageBubble", () => {
|
||||
};
|
||||
|
||||
try {
|
||||
render(<MessageBubble message={message} />);
|
||||
render(<MessageBlockMenuActions message={message} />);
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Copy" }));
|
||||
|
||||
@@ -499,7 +525,7 @@ describe("MessageBubble", () => {
|
||||
.toHaveTextContent("Try unknown or blocked-skill and $");
|
||||
});
|
||||
|
||||
it("renders fork control in completed assistant action rows", () => {
|
||||
it("renders fork as a contextual assistant action", () => {
|
||||
const onForkFromHere = vi.fn();
|
||||
const message: UIMessage = {
|
||||
id: "a-fork",
|
||||
@@ -509,16 +535,19 @@ describe("MessageBubble", () => {
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
|
||||
render(<MessageBubble message={message} onForkFromHere={onForkFromHere} />);
|
||||
const { container } = render(
|
||||
<MessageBlockMenuActions message={message} onForkFromHere={onForkFromHere} />,
|
||||
);
|
||||
|
||||
menuActions(container);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Fork" }));
|
||||
expect(onForkFromHere).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("shows the assistant completion time in the former latency slot", async () => {
|
||||
it("keeps assistant completion time in the block menu metadata", () => {
|
||||
const completedAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
||||
const { container } = render(
|
||||
<MessageBubble
|
||||
<MessageBlockMenuActions
|
||||
message={{
|
||||
id: "a-completed-at",
|
||||
role: "assistant",
|
||||
@@ -530,28 +559,35 @@ describe("MessageBubble", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByRole("button", { name: "Copy" })).toBeInTheDocument();
|
||||
const time = container.querySelector("[data-assistant-completed-at]");
|
||||
menuActions(container);
|
||||
const time = document.querySelector("[data-assistant-completed-at]");
|
||||
expect(time).toHaveTextContent(formatMessageEndTime(completedAt));
|
||||
expect(time).toHaveAttribute("dateTime", new Date(completedAt).toISOString());
|
||||
expect(time).not.toHaveAttribute("title");
|
||||
expect(time).toHaveAttribute("tabIndex", "0");
|
||||
expect(time).toHaveClass(
|
||||
"cursor-help",
|
||||
"text-[11px]",
|
||||
"leading-none",
|
||||
"text-muted-foreground/70",
|
||||
"tabular-nums",
|
||||
);
|
||||
expect(time).toHaveClass("tabular-nums");
|
||||
});
|
||||
|
||||
fireEvent.pointerMove(time!);
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent(fmtDateTime(completedAt));
|
||||
it("groups actions above static timestamp metadata", () => {
|
||||
const completedAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
||||
const { container } = render(<MessageBlockMenuActions
|
||||
message={{ id: "a-actions", role: "assistant", content: "Finished answer",
|
||||
completedAt, createdAt: completedAt - 1_000 }}
|
||||
onForkFromHere={vi.fn()}
|
||||
/>);
|
||||
const actions = menuActions(container);
|
||||
const copy = screen.getByRole("button", { name: "Copy" });
|
||||
const fork = screen.getByRole("button", { name: "Fork" });
|
||||
const metadata = actions.querySelector("[data-message-block-metadata]")!;
|
||||
expect(actions.querySelector("[data-message-block-toolbar]")).toContainElement(copy);
|
||||
expect(actions.querySelector("[data-message-block-toolbar]")).toContainElement(fork);
|
||||
expect(metadata).toHaveTextContent(formatMessageEndTime(completedAt));
|
||||
expect(copy.compareDocumentPosition(fork) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(fork.compareDocumentPosition(metadata) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
});
|
||||
|
||||
it("falls back to the assistant creation time when replay has no completion time", () => {
|
||||
const createdAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
||||
const { container } = render(
|
||||
<MessageBubble
|
||||
<MessageBlockMenuActions
|
||||
message={{
|
||||
id: "a-created-at",
|
||||
role: "assistant",
|
||||
@@ -561,17 +597,17 @@ describe("MessageBubble", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
const time = container.querySelector("[data-message-timestamp]");
|
||||
menuActions(container);
|
||||
const time = document.querySelector("[data-message-timestamp]");
|
||||
expect(time).toHaveTextContent(formatMessageEndTime(createdAt));
|
||||
expect(time).toHaveAttribute("dateTime", new Date(createdAt).toISOString());
|
||||
expect(time).not.toHaveAttribute("title");
|
||||
expect(time).not.toHaveAttribute("data-assistant-completed-at");
|
||||
});
|
||||
|
||||
it("renders the creation time for user messages", async () => {
|
||||
it("renders the creation time for user messages", () => {
|
||||
const createdAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
||||
const { container } = render(
|
||||
<MessageBubble
|
||||
<MessageBlockMenuActions
|
||||
message={{
|
||||
id: "u-created-at",
|
||||
role: "user",
|
||||
@@ -585,17 +621,15 @@ describe("MessageBubble", () => {
|
||||
expect(time).toHaveTextContent(formatMessageEndTime(createdAt));
|
||||
expect(time).toHaveAttribute("dateTime", new Date(createdAt).toISOString());
|
||||
expect(time).not.toHaveAttribute("title");
|
||||
expect(time).toHaveAttribute("tabIndex", "0");
|
||||
|
||||
fireEvent.pointerMove(time!);
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent(fmtDateTime(createdAt));
|
||||
expect(time).toHaveProperty("tabIndex", -1);
|
||||
expect(time?.parentElement).toHaveAttribute("data-message-block-metadata");
|
||||
});
|
||||
|
||||
it("does not infer completion time from the assistant creation timestamp", () => {
|
||||
const createdAt = Date.UTC(2026, 6, 25, 12, 34, 0);
|
||||
const latencyMs = 13_000;
|
||||
const { container } = render(
|
||||
<MessageBubble
|
||||
<MessageBlockMenuActions
|
||||
message={{
|
||||
id: "a-replayed-completion",
|
||||
role: "assistant",
|
||||
@@ -606,7 +640,11 @@ describe("MessageBubble", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelector("[data-assistant-completed-at]")).not.toBeInTheDocument();
|
||||
menuActions(container);
|
||||
expect(document.querySelector("[data-assistant-completed-at]")).not.toBeInTheDocument();
|
||||
expect(document.querySelector("[data-message-timestamp]")).toHaveTextContent(
|
||||
formatMessageEndTime(createdAt),
|
||||
);
|
||||
});
|
||||
|
||||
it("renders installed CLI app mentions inside sent user messages", () => {
|
||||
@@ -634,7 +672,7 @@ describe("MessageBubble", () => {
|
||||
expect(screen.getByText(/not @krita/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("places automation metadata after the timestamp and reveals its source on hover", async () => {
|
||||
it("places automation metadata after the timestamp with its source visible", () => {
|
||||
const completedAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
||||
const message: UIMessage = {
|
||||
id: "a-cron",
|
||||
@@ -645,28 +683,15 @@ describe("MessageBubble", () => {
|
||||
createdAt: completedAt - 1_000,
|
||||
};
|
||||
|
||||
const { container } = render(<MessageBubble message={message} />);
|
||||
const { container } = render(<MessageBlockMenuActions message={message} />);
|
||||
|
||||
const footer = container.querySelector("[data-assistant-footer]")!;
|
||||
const timestamp = footer.querySelector("[data-message-timestamp]")!;
|
||||
const trigger = footer.querySelector("[data-automation-trigger]")!;
|
||||
menuActions(container);
|
||||
|
||||
const timestamp = document.querySelector("[data-message-timestamp]")!;
|
||||
const automation = document.querySelector("[data-automation-trigger]")!;
|
||||
expect(timestamp).toHaveTextContent(formatMessageEndTime(completedAt));
|
||||
expect(trigger).toHaveTextContent("Triggered automatically");
|
||||
expect(trigger.previousElementSibling).toBe(timestamp);
|
||||
expect(trigger).toHaveClass(
|
||||
"text-[11px]",
|
||||
"leading-none",
|
||||
"text-muted-foreground/70",
|
||||
"tabular-nums",
|
||||
);
|
||||
expect(trigger.className).not.toMatch(/(?:^|\s)(?:border|bg-)/);
|
||||
expect(trigger.querySelector("svg")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("drink water")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("Time to drink water.")).toBeInTheDocument();
|
||||
|
||||
fireEvent.pointerMove(trigger);
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent("drink water");
|
||||
expect(automation).toHaveTextContent("Triggered automatically · drink water");
|
||||
expect(timestamp.compareDocumentPosition(automation) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
});
|
||||
|
||||
it("renders structured CLI app attachments even without the installed catalog", () => {
|
||||
@@ -751,11 +776,12 @@ describe("MessageBubble", () => {
|
||||
it("copies the original mention identifiers rather than display names", async () => {
|
||||
const copy = vi.spyOn(clipboard, "copyTextToClipboard").mockResolvedValue(true);
|
||||
try {
|
||||
render(<MessageBubble message={{
|
||||
render(<ThreadMessages messages={[{
|
||||
id: "copy-display-name", role: "user", content: "Please use @drawio",
|
||||
cliApps: [{ name: "drawio", display_name: "Draw.io", category: "diagram", entry_point: "drawio" }],
|
||||
}} />);
|
||||
}]} />);
|
||||
expect(screen.getByTestId("message-cli-mention-drawio")).toHaveTextContent("@Draw.io");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Copy", exact: true }));
|
||||
await waitFor(() => expect(copy).toHaveBeenCalledWith("Please use @drawio"));
|
||||
} finally {
|
||||
@@ -800,8 +826,9 @@ describe("MessageBubble", () => {
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
|
||||
render(<MessageBubble message={message} />);
|
||||
const { container } = render(<MessageBlockMenuActions message={message} />);
|
||||
|
||||
menuActions(container);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Copy" }));
|
||||
|
||||
expect(writeText).toHaveBeenCalledWith("I can help with the next step.");
|
||||
@@ -828,14 +855,12 @@ describe("MessageBubble", () => {
|
||||
};
|
||||
|
||||
try {
|
||||
render(<MessageBubble message={message} />);
|
||||
const { container } = render(<MessageBlockMenuActions message={message} />);
|
||||
|
||||
menuActions(container);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Copy" }));
|
||||
|
||||
await waitFor(() => expect(execCommand).toHaveBeenCalledWith("copy"));
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole("button", { name: "Copied" })).toBeInTheDocument(),
|
||||
);
|
||||
} finally {
|
||||
Reflect.deleteProperty(navigator, "clipboard");
|
||||
Reflect.deleteProperty(document, "execCommand");
|
||||
@@ -861,15 +886,13 @@ describe("MessageBubble", () => {
|
||||
};
|
||||
|
||||
try {
|
||||
render(<MessageBubble message={message} />);
|
||||
const { container } = render(<MessageBlockMenuActions message={message} />);
|
||||
|
||||
menuActions(container);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Copy" }));
|
||||
|
||||
expect(writeText).toHaveBeenCalledWith("Rejected clipboard copy.");
|
||||
await waitFor(() => expect(execCommand).toHaveBeenCalledWith("copy"));
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole("button", { name: "Copied" })).toBeInTheDocument(),
|
||||
);
|
||||
} finally {
|
||||
Reflect.deleteProperty(navigator, "clipboard");
|
||||
Reflect.deleteProperty(document, "execCommand");
|
||||
@@ -890,67 +913,36 @@ describe("MessageBubble", () => {
|
||||
expect(screen.queryByRole("button", { name: "Copy" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps assistant footer geometry mounted across stream completion", () => {
|
||||
const streaming: UIMessage = {
|
||||
id: "a-footer-stable",
|
||||
role: "assistant",
|
||||
content: "Stable answer",
|
||||
isStreaming: true,
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
const { container, rerender } = render(<MessageBubble message={streaming} />);
|
||||
|
||||
const reservedFooter = container.querySelector("[data-assistant-footer]");
|
||||
expect(reservedFooter).not.toBeNull();
|
||||
expect(reservedFooter).toHaveAttribute("data-state", "reserved");
|
||||
expect(reservedFooter).toHaveClass("mt-2", "min-h-8", "opacity-0");
|
||||
|
||||
rerender(
|
||||
<MessageBubble
|
||||
message={{
|
||||
...streaming,
|
||||
isStreaming: false,
|
||||
completedAt: Date.now(),
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const visibleFooter = container.querySelector("[data-assistant-footer]");
|
||||
expect(visibleFooter).toBe(reservedFooter);
|
||||
expect(visibleFooter).toHaveAttribute("data-state", "visible");
|
||||
expect(visibleFooter).toHaveClass("mt-2", "min-h-8", "opacity-100");
|
||||
it("keeps the assistant body mounted when its completed block menu becomes available", () => {
|
||||
const message: UIMessage = { id: "a-stable", role: "assistant", content: "Stable answer",
|
||||
isStreaming: true, createdAt: Date.now() };
|
||||
const { container, rerender } = render(<ThreadMessages messages={[message]} isStreaming />);
|
||||
const body = container.querySelector("[data-assistant-message]");
|
||||
expect(body).toHaveClass("relative", "w-full");
|
||||
rerender(<ThreadMessages messages={[{ ...message, isStreaming: false }]} />);
|
||||
expect(container.querySelector("[data-assistant-message]")).toBe(body);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
expect(screen.getByRole("button", { name: "Copy" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("omits footer space when an active answer is no longer the tail", () => {
|
||||
const message: UIMessage = {
|
||||
id: "a-intermediate",
|
||||
role: "assistant",
|
||||
content: "I will keep working.",
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
|
||||
const { container } = render(
|
||||
<MessageBubble
|
||||
message={message}
|
||||
isTurnStreaming
|
||||
isThreadTail={false}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelector("[data-assistant-footer]")).not.toBeInTheDocument();
|
||||
it("makes answer actions available after the containing turn completes", () => {
|
||||
const message: UIMessage = { id: "a-intermediate", role: "assistant",
|
||||
content: "I will keep working.", createdAt: Date.now() };
|
||||
const { rerender } = render(<ThreadMessages messages={[message]} isStreaming />);
|
||||
expect(screen.getByText(message.content)).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: "Message actions" })).not.toBeInTheDocument();
|
||||
rerender(<ThreadMessages messages={[message]} />);
|
||||
expect(screen.getByRole("button", { name: "Message actions" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not show copy when showCopyAction is false", () => {
|
||||
const message: UIMessage = {
|
||||
id: "a-mid",
|
||||
role: "assistant",
|
||||
content: "Mid-turn snippet.",
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
|
||||
render(<MessageBubble message={message} showCopyAction={false} />);
|
||||
|
||||
expect(screen.queryByRole("button", { name: "Copy" })).not.toBeInTheDocument();
|
||||
it("keeps timestamp metadata available for a media-only message", () => {
|
||||
const createdAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
||||
const { container } = render(<MessageBlockMenuActions
|
||||
message={{ id: "a-file", role: "assistant", content: "", createdAt,
|
||||
media: [{ kind: "file", name: "report.csv", url: "/api/media/report.csv" }] }}
|
||||
/>);
|
||||
expect(container.querySelector("time")).toHaveTextContent(formatMessageEndTime(createdAt));
|
||||
expect(container.querySelector("time")).toHaveAttribute("dateTime", new Date(createdAt).toISOString());
|
||||
});
|
||||
|
||||
it("renders trace messages as collapsible tool groups", () => {
|
||||
|
||||
@@ -10,12 +10,7 @@ function renderShell(expanded: boolean) {
|
||||
active={false}
|
||||
expanded={expanded}
|
||||
label="Thought"
|
||||
viewportRef={() => undefined}
|
||||
contentRef={() => undefined}
|
||||
fadeTop={false}
|
||||
fadeBottom={false}
|
||||
onToggle={vi.fn()}
|
||||
onScroll={vi.fn()}
|
||||
>
|
||||
<button type="button">Hidden action</button>
|
||||
</ThinkingReasoningShell>,
|
||||
@@ -23,6 +18,64 @@ function renderShell(expanded: boolean) {
|
||||
}
|
||||
|
||||
describe("ThinkingReasoningShell", () => {
|
||||
it.each([false, true])("shows activity without clipping or edge fades (active: %s)", (active) => {
|
||||
render(
|
||||
<ThinkingReasoningShell
|
||||
active={active}
|
||||
expanded
|
||||
label={active ? "Working" : "Worked"}
|
||||
onToggle={vi.fn()}
|
||||
>
|
||||
{Array.from({ length: 16 }, (_, index) => <div key={index}>Activity {index + 1}</div>)}
|
||||
</ThinkingReasoningShell>
|
||||
);
|
||||
const content = screen.getByTestId("agent-activity-content");
|
||||
expect(content).not.toHaveClass("max-h-[180px]");
|
||||
expect(content).not.toHaveClass("overflow-y-auto");
|
||||
expect(screen.queryByTestId("activity-scroll-fade-top")).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId("activity-scroll-fade-bottom")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("Activity 1")).toBeVisible();
|
||||
expect(screen.getByText("Activity 16")).toBeVisible();
|
||||
});
|
||||
|
||||
it("keeps the same header and content layout when live activity completes", () => {
|
||||
const shell = (active: boolean) => (
|
||||
<ThinkingReasoningShell active={active} expanded label={active ? "Working" : "Worked"}
|
||||
collapseLabel="Collapse activity details" onToggle={vi.fn()}>
|
||||
<p>A processing step</p>
|
||||
</ThinkingReasoningShell>
|
||||
);
|
||||
const view = render(shell(true));
|
||||
const button = screen.getByRole("button", { name: "Working · Collapse activity details" });
|
||||
const content = screen.getByTestId("agent-activity-content");
|
||||
const headerClass = button.className;
|
||||
const contentClass = content.className;
|
||||
expect(button.querySelector("svg")).toHaveClass("lucide-activity");
|
||||
expect(view.container.querySelector("[data-contextual-activity-guide]")).toBeInTheDocument();
|
||||
|
||||
view.rerender(shell(false));
|
||||
|
||||
expect(screen.getByRole("button", { name: "Worked · Collapse activity details" })).toBe(button);
|
||||
expect(button.className).toBe(headerClass);
|
||||
expect(screen.getByTestId("agent-activity-content")).toBe(content);
|
||||
expect(content.className).toBe(contentClass);
|
||||
});
|
||||
|
||||
it("aligns the waiting status with the disclosure shown when details arrive", () => {
|
||||
const shell = (hasDetails: boolean) => (
|
||||
<ThinkingReasoningShell active expanded hasDetails={hasDetails} label="Working"
|
||||
onToggle={vi.fn()}><p>A processing step</p></ThinkingReasoningShell>
|
||||
);
|
||||
const view = render(shell(false));
|
||||
const status = screen.getByRole("status", { name: "Working" });
|
||||
expect(status).toHaveClass("touch-target", "h-7", "px-1.5");
|
||||
expect(status.querySelector("svg")).toHaveClass("lucide-activity");
|
||||
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
||||
|
||||
view.rerender(shell(true));
|
||||
expect(screen.getByRole("button", { name: "Working" })).toHaveClass(...status.classList);
|
||||
});
|
||||
|
||||
it("mounts details on first expansion and preserves their state across folding", () => {
|
||||
const mounted = vi.fn();
|
||||
function Details() {
|
||||
@@ -31,8 +84,7 @@ describe("ThinkingReasoningShell", () => {
|
||||
}
|
||||
const shell = (expanded: boolean) => (
|
||||
<ThinkingReasoningShell active={false} expanded={expanded} label="Thought"
|
||||
viewportRef={null} contentRef={null} fadeTop={false} fadeBottom={false}
|
||||
onToggle={() => {}} onScroll={() => {}}><Details /></ThinkingReasoningShell>
|
||||
onToggle={() => {}}><Details /></ThinkingReasoningShell>
|
||||
);
|
||||
const view = render(shell(false));
|
||||
expect(mounted).toHaveBeenCalledTimes(0);
|
||||
@@ -46,7 +98,7 @@ describe("ThinkingReasoningShell", () => {
|
||||
it("makes collapsed descendants inert as well as visually hidden", () => {
|
||||
const { rerender } = renderShell(false);
|
||||
const disclosure = screen.getByRole("button", { name: "Thought" });
|
||||
const collapsible = disclosure.nextElementSibling;
|
||||
const collapsible = disclosure.parentElement?.nextElementSibling;
|
||||
|
||||
expect(collapsible).toHaveAttribute("inert");
|
||||
expect(collapsible).toHaveAttribute("aria-hidden", "true");
|
||||
@@ -56,18 +108,14 @@ describe("ThinkingReasoningShell", () => {
|
||||
active={false}
|
||||
expanded
|
||||
label="Thought"
|
||||
viewportRef={() => undefined}
|
||||
contentRef={() => undefined}
|
||||
fadeTop={false}
|
||||
fadeBottom={false}
|
||||
onToggle={vi.fn()}
|
||||
onScroll={vi.fn()}
|
||||
>
|
||||
<button type="button">Hidden action</button>
|
||||
</ThinkingReasoningShell>,
|
||||
);
|
||||
|
||||
expect(disclosure.nextElementSibling).not.toHaveAttribute("inert");
|
||||
expect(disclosure.nextElementSibling).toHaveAttribute("aria-hidden", "false");
|
||||
const expandedCollapsible = disclosure.parentElement?.nextElementSibling;
|
||||
expect(expandedCollapsible).not.toHaveAttribute("inert");
|
||||
expect(expandedCollapsible).toHaveAttribute("aria-hidden", "false");
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
@@ -16,6 +16,41 @@ afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
function openAssistantBlockMenu(root: ParentNode = document): HTMLElement {
|
||||
const row = root.querySelector("[data-assistant-message]")?.closest<HTMLElement>("[data-thread-display-unit]");
|
||||
expect(row).toBeTruthy();
|
||||
return openMessageBlockMenu(row!).trigger;
|
||||
}
|
||||
|
||||
function assistantActionCounts(root: ParentNode = document) {
|
||||
const counts = { copy: 0, fork: 0 };
|
||||
for (const body of root.querySelectorAll("[data-assistant-message]")) {
|
||||
const row = body.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
if (!row.querySelector("[data-message-block-menu-trigger]")) continue;
|
||||
const { menu } = openMessageBlockMenu(row);
|
||||
counts.copy += within(menu).queryAllByRole("button", { name: "Copy", exact: true }).length;
|
||||
counts.fork += within(menu).queryAllByRole("button", { name: "Fork", exact: true }).length;
|
||||
fireEvent.keyDown(menu, { key: "Escape" });
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
function openMessageBlockMenu(root: ParentNode): {
|
||||
trigger: HTMLElement;
|
||||
menu: HTMLElement;
|
||||
} {
|
||||
const trigger = root.querySelector<HTMLElement>("[data-message-block-menu-trigger]");
|
||||
expect(trigger).not.toBeNull();
|
||||
if (trigger?.getAttribute("aria-expanded") === "false") {
|
||||
fireEvent.click(trigger);
|
||||
}
|
||||
const menu = document.querySelector<HTMLElement>(
|
||||
'[data-message-block-menu][data-state="open"]',
|
||||
);
|
||||
expect(menu).not.toBeNull();
|
||||
return { trigger: trigger!, menu: menu! };
|
||||
}
|
||||
|
||||
describe("ThreadMessages", () => {
|
||||
it.each([0, -13_000, -14_000, -15_000, 15_000])(
|
||||
"keeps the optimistic timer through acknowledgement and output with %i ms server clock skew",
|
||||
@@ -74,7 +109,7 @@ describe("ThreadMessages", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByRole("button", { name: "Working for 1s" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /^Working for 1s/ })).toBeInTheDocument();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -362,11 +397,27 @@ describe("ThreadMessages", () => {
|
||||
.toBeTruthy();
|
||||
|
||||
rerender(<ThreadMessages messages={messages} isStreaming={false} activeTurnId={null} />);
|
||||
const firstRow = firstAnswer.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const finalRow = finalAnswer.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const firstActions = firstRow.querySelector<HTMLElement>("[data-message-block-menu-trigger]")!;
|
||||
const finalActions = finalRow.querySelector<HTMLElement>("[data-message-block-menu-trigger]")!;
|
||||
expect(firstRow).toContainElement(firstActions);
|
||||
expect(finalRow).toContainElement(finalActions);
|
||||
expect(firstActions).not.toBe(finalActions);
|
||||
expect(firstRow).toHaveClass("message-context-hit-area");
|
||||
expect(finalRow).toHaveClass("message-context-hit-area");
|
||||
expect(finalActions).toHaveClass("absolute", "-start-[var(--message-block-trigger-offset)]", "top-0");
|
||||
expect(finalActions.querySelector("[data-message-block-menu-highlight]")).toHaveClass(
|
||||
"h-4",
|
||||
"w-7",
|
||||
"rounded-full",
|
||||
);
|
||||
expect(screen.queryByRole("button", { name: /worked/i })).not.toBeInTheDocument();
|
||||
fireEvent.click(finalActions);
|
||||
const completedActivity = screen.getByRole("button", { name: /worked/i });
|
||||
expect(firstAnswer.compareDocumentPosition(completedActivity) & Node.DOCUMENT_POSITION_FOLLOWING)
|
||||
.toBeTruthy();
|
||||
expect(completedActivity.compareDocumentPosition(finalAnswer) & Node.DOCUMENT_POSITION_FOLLOWING)
|
||||
.toBeTruthy();
|
||||
expect(completedActivity).toHaveClass("min-h-[var(--message-block-control-size)]");
|
||||
expect(completedActivity).toHaveAttribute("aria-expanded", "false");
|
||||
expect(document.querySelectorAll("[data-block-context-rail]")).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("ignores a completed empty answer frame without splitting contiguous activity", () => {
|
||||
@@ -467,16 +518,20 @@ describe("ThreadMessages", () => {
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
|
||||
const activityShells = screen.getAllByRole("button", { name: /worked/i });
|
||||
const ok = screen.getByText("ok");
|
||||
const final = screen.getByText("finished");
|
||||
expect(activityShells).toHaveLength(2);
|
||||
expect(activityShells[0].compareDocumentPosition(ok) & Node.DOCUMENT_POSITION_FOLLOWING)
|
||||
.toBeTruthy();
|
||||
expect(ok.compareDocumentPosition(activityShells[1]) & Node.DOCUMENT_POSITION_FOLLOWING)
|
||||
.toBeTruthy();
|
||||
expect(activityShells[1].compareDocumentPosition(final) & Node.DOCUMENT_POSITION_FOLLOWING)
|
||||
expect(ok.compareDocumentPosition(final) & Node.DOCUMENT_POSITION_FOLLOWING)
|
||||
.toBeTruthy();
|
||||
const okRow = ok.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const finalRow = final.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
openMessageBlockMenu(okRow);
|
||||
expect(screen.getByRole("button", { name: /^worked/i })).toBeInTheDocument();
|
||||
const { menu } = openMessageBlockMenu(finalRow);
|
||||
const finalActivity = menu.querySelector<HTMLElement>("[data-message-block-activity-action]")!;
|
||||
expect(finalActivity).toBeInTheDocument();
|
||||
fireEvent.click(finalActivity);
|
||||
expect(screen.getByTestId("agent-activity-content")).toHaveTextContent("Completed First");
|
||||
expect(screen.getByTestId("agent-activity-content")).toHaveTextContent("Completed Second");
|
||||
});
|
||||
|
||||
it("keeps empty frame source counts on the nearest visible unit", () => {
|
||||
@@ -568,7 +623,7 @@ describe("ThreadMessages", () => {
|
||||
expect(removeAllRanges).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("groups consecutive reasoning and tool rows into one timeline before the answer", () => {
|
||||
it("keeps one completed activity row above the final answer", async () => {
|
||||
const messages: UIMessage[] = [
|
||||
{
|
||||
id: "r1",
|
||||
@@ -577,7 +632,7 @@ describe("ThreadMessages", () => {
|
||||
reasoning: "thinking",
|
||||
reasoningStreaming: false,
|
||||
isStreaming: true,
|
||||
createdAt: Date.now(),
|
||||
createdAt: 1_000,
|
||||
},
|
||||
{
|
||||
id: "t1",
|
||||
@@ -585,7 +640,7 @@ describe("ThreadMessages", () => {
|
||||
kind: "trace",
|
||||
content: "search()",
|
||||
traces: ["search()"],
|
||||
createdAt: Date.now(),
|
||||
createdAt: 2_000,
|
||||
},
|
||||
{
|
||||
id: "r2",
|
||||
@@ -594,13 +649,14 @@ describe("ThreadMessages", () => {
|
||||
reasoning: "more thinking",
|
||||
reasoningStreaming: false,
|
||||
isStreaming: true,
|
||||
createdAt: Date.now(),
|
||||
createdAt: 3_000,
|
||||
},
|
||||
{
|
||||
id: "a1",
|
||||
role: "assistant",
|
||||
content: "final answer",
|
||||
createdAt: Date.now(),
|
||||
latencyMs: 16_000,
|
||||
createdAt: 4_000,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -611,7 +667,381 @@ describe("ThreadMessages", () => {
|
||||
|
||||
expect(rows).toHaveLength(2);
|
||||
expect(rows[0]).not.toHaveClass("mt-2", "mt-4", "mt-5");
|
||||
expect(rows[1]).toHaveClass("mt-4");
|
||||
expect(rows[1]).not.toHaveClass("mt-4");
|
||||
const answerRow = screen.getByText("final answer")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const { trigger, menu } = openMessageBlockMenu(answerRow);
|
||||
const disclosure = screen.getByRole("button", { name: "Worked for 16s" });
|
||||
expect(menu).toHaveFocus();
|
||||
expect(menu.querySelector("[data-message-block-copy-action]")).not.toHaveFocus();
|
||||
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
|
||||
expect(disclosure).toHaveAttribute("aria-expanded", "false");
|
||||
expect(disclosure).toHaveAttribute("aria-controls");
|
||||
expect(disclosure).toHaveAttribute("data-message-block-activity-action", "true");
|
||||
expect(disclosure).toHaveClass("min-h-[var(--message-block-control-size)]", "group", "hover:text-foreground");
|
||||
expect(disclosure).not.toHaveClass("hover:bg-muted/60");
|
||||
expect(menu.querySelector("[data-message-block-copy-action]")).toHaveClass(
|
||||
"rounded-control",
|
||||
"h-[var(--message-block-control-size)]",
|
||||
"w-[var(--message-block-action-width)]",
|
||||
);
|
||||
expect(menu.querySelector("[data-message-block-copy-action]")).not.toHaveClass("touch-target");
|
||||
expect(disclosure.querySelector("[data-message-block-activity-icon]")).toHaveClass(
|
||||
"h-[var(--message-block-control-size)]",
|
||||
"w-[var(--message-block-action-width)]",
|
||||
"rounded-control",
|
||||
"group-hover:bg-muted/70",
|
||||
);
|
||||
expect(disclosure.querySelector("svg")).toBeInTheDocument();
|
||||
const toolbar = menu.querySelector("[data-message-block-toolbar]");
|
||||
expect(toolbar).toHaveClass("flex", "flex-wrap", "items-center");
|
||||
expect(toolbar).not.toHaveClass("flex-col");
|
||||
expect(toolbar).toContainElement(menu.querySelector("[data-message-block-copy-action]"));
|
||||
expect(toolbar).toContainElement(disclosure);
|
||||
const timestamp = menu.querySelector<HTMLElement>("[data-message-timestamp]")!;
|
||||
expect(timestamp).toBeInTheDocument();
|
||||
expect(timestamp).toHaveClass("min-h-[var(--message-block-control-size)]");
|
||||
expect(timestamp.parentElement).toHaveClass("border-t", "text-muted-foreground/45");
|
||||
expect(toolbar).not.toContainElement(timestamp);
|
||||
expect(timestamp).not.toHaveAttribute("tabindex");
|
||||
expect(timestamp.querySelector("svg")).not.toBeInTheDocument();
|
||||
expect(disclosure.compareDocumentPosition(timestamp) & Node.DOCUMENT_POSITION_FOLLOWING)
|
||||
.toBeTruthy();
|
||||
expect(menu).toHaveClass("w-max", "max-w-64", "bg-popover", "rounded-floating", "overflow-y-auto");
|
||||
expect(menu).not.toHaveClass("min-w-[8.5rem]", "bg-popover/95", "rounded-xl");
|
||||
const menuButtons = Array.from(menu.querySelectorAll("button"));
|
||||
expect(menuButtons.length).toBeGreaterThan(1);
|
||||
for (const button of menuButtons) {
|
||||
expect(button.className).toMatch(/(?:min-)?h-\[var\(--message-block-control-size\)\]/);
|
||||
}
|
||||
expect(rows[0].compareDocumentPosition(rows[1]) & Node.DOCUMENT_POSITION_FOLLOWING)
|
||||
.toBeTruthy();
|
||||
|
||||
fireEvent.click(disclosure);
|
||||
|
||||
expect(trigger).toHaveAttribute("aria-expanded", "false");
|
||||
expect(answerRow.querySelector("[data-contextual-activity]")?.parentElement?.parentElement)
|
||||
.toHaveClass("mb-2");
|
||||
expect(screen.getByTestId("agent-activity-content")).toBeInTheDocument();
|
||||
const collapse = screen.getByRole("button", { name: /Collapse activity details/ });
|
||||
expect(collapse).toHaveAttribute("data-contextual-activity-collapse", "true");
|
||||
expect(collapse.querySelectorAll("svg")).toHaveLength(1);
|
||||
const guide = answerRow.querySelector("[data-contextual-activity-guide]");
|
||||
expect(guide).toBeInTheDocument();
|
||||
expect(guide).toHaveClass("start-[13px]");
|
||||
expect(screen.getByTestId("agent-activity-content")).toHaveClass("ps-6");
|
||||
await waitFor(() => expect(collapse).toHaveFocus());
|
||||
fireEvent.click(collapse);
|
||||
|
||||
expect(answerRow.querySelector("[data-contextual-activity]")?.parentElement?.parentElement)
|
||||
.not.toHaveClass("mb-2");
|
||||
expect(screen.queryByTestId("agent-activity-content")).not.toBeInTheDocument();
|
||||
expect(answerRow.querySelector("[data-contextual-activity-guide]"))
|
||||
.not.toBeInTheDocument();
|
||||
await waitFor(() => expect(trigger).toHaveFocus());
|
||||
});
|
||||
|
||||
it("activates only the hovered visual message block within one logical turn", () => {
|
||||
const messages: UIMessage[] = [
|
||||
{
|
||||
id: "user",
|
||||
role: "user",
|
||||
content: "prompt",
|
||||
createdAt: 500,
|
||||
},
|
||||
{
|
||||
id: "tool-a",
|
||||
role: "tool",
|
||||
kind: "trace",
|
||||
content: "first command",
|
||||
traces: ["first command"],
|
||||
createdAt: 1_000,
|
||||
},
|
||||
{
|
||||
id: "answer-a",
|
||||
role: "assistant",
|
||||
content: "first answer",
|
||||
createdAt: 2_000,
|
||||
},
|
||||
{
|
||||
id: "tool-b",
|
||||
role: "tool",
|
||||
kind: "trace",
|
||||
content: "second command",
|
||||
traces: ["second command"],
|
||||
createdAt: 3_000,
|
||||
},
|
||||
{
|
||||
id: "answer-b",
|
||||
role: "assistant",
|
||||
content: "second answer",
|
||||
createdAt: 4_000,
|
||||
},
|
||||
];
|
||||
|
||||
const { container } = render(
|
||||
<ThreadMessages messages={messages} isStreaming={false} />,
|
||||
);
|
||||
const activityA = container.querySelector<HTMLElement>(
|
||||
'[data-thread-display-unit="activity-tool-a"]',
|
||||
)!;
|
||||
const answerA = screen.getByText("first answer")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const activityB = container.querySelector<HTMLElement>(
|
||||
'[data-thread-display-unit="activity-tool-b"]',
|
||||
)!;
|
||||
const answerB = screen.getByText("second answer")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
|
||||
expect(activityA).not.toHaveAttribute("data-message-context-block");
|
||||
expect(activityB).not.toHaveAttribute("data-message-context-block");
|
||||
expect(answerA.dataset.messageContextBlock).toBeTruthy();
|
||||
expect(answerB.dataset.messageContextBlock).toBeTruthy();
|
||||
expect(answerA.dataset.messageContextBlock)
|
||||
.not.toBe(answerB.dataset.messageContextBlock);
|
||||
expect(answerA.querySelector("[data-contextual-activity]")).toBeInTheDocument();
|
||||
expect(answerB.querySelector("[data-contextual-activity]")).toBeInTheDocument();
|
||||
expect(answerA).toHaveClass("message-context-hit-area", "relative");
|
||||
expect(answerB).toHaveClass("message-context-hit-area", "relative");
|
||||
|
||||
fireEvent.pointerEnter(answerA, { pointerType: "mouse" });
|
||||
expect(answerA).toHaveAttribute("data-context-block-active", "true");
|
||||
expect(answerB).not.toHaveAttribute("data-context-block-active");
|
||||
|
||||
fireEvent.pointerEnter(answerB, { pointerType: "mouse" });
|
||||
expect(answerA).not.toHaveAttribute("data-context-block-active");
|
||||
expect(answerB).toHaveAttribute("data-context-block-active", "true");
|
||||
|
||||
const answerBTrigger = answerB.querySelector<HTMLElement>("[data-message-block-menu-trigger]")!;
|
||||
expect(answerBTrigger).toHaveClass(
|
||||
"-start-[var(--message-block-trigger-offset)]",
|
||||
"h-[var(--message-block-control-size)]",
|
||||
"w-[var(--message-block-control-size)]",
|
||||
);
|
||||
fireEvent.pointerLeave(answerB, {
|
||||
pointerType: "mouse",
|
||||
relatedTarget: answerBTrigger,
|
||||
});
|
||||
expect(answerB).toHaveAttribute("data-context-block-active", "true");
|
||||
fireEvent.pointerLeave(answerB, { pointerType: "mouse" });
|
||||
expect(answerB).not.toHaveAttribute("data-context-block-active");
|
||||
|
||||
fireEvent.focus(answerA.querySelector<HTMLElement>("[data-message-block-menu-trigger]")!);
|
||||
expect(answerA).toHaveAttribute("data-context-block-active", "true");
|
||||
fireEvent.focus(answerBTrigger);
|
||||
expect(answerA).not.toHaveAttribute("data-context-block-active");
|
||||
expect(answerB).toHaveAttribute("data-context-block-active", "true");
|
||||
});
|
||||
|
||||
it("uses one active visual block across user and assistant messages", () => {
|
||||
const messages: UIMessage[] = [
|
||||
{ id: "user-a", role: "user", content: "first prompt", createdAt: 500 },
|
||||
{ id: "answer-a", role: "assistant", content: "first answer", createdAt: 1_000 },
|
||||
{ id: "user-b", role: "user", content: "second prompt", createdAt: 1_500 },
|
||||
];
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
const userA = screen.getByText("first prompt")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const answerA = screen.getByText("first answer")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const userB = screen.getByText("second prompt")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
|
||||
expect(userA.dataset.messageContextBlock).toBeTruthy();
|
||||
expect(userB.dataset.messageContextBlock).toBeTruthy();
|
||||
expect(userA.dataset.messageContextBlock).not.toBe(answerA.dataset.messageContextBlock);
|
||||
expect(userB.dataset.messageContextBlock).not.toBe(answerA.dataset.messageContextBlock);
|
||||
expect(userA.querySelector("[data-message-block-menu-trigger]")).toBeInTheDocument();
|
||||
expect(userB.querySelector("[data-message-block-menu-trigger]")).toBeInTheDocument();
|
||||
|
||||
fireEvent.pointerEnter(userA, { pointerType: "mouse" });
|
||||
expect(userA).toHaveAttribute("data-context-block-active", "true");
|
||||
expect(answerA).not.toHaveAttribute("data-context-block-active");
|
||||
|
||||
fireEvent.pointerEnter(answerA, { pointerType: "mouse" });
|
||||
expect(userA).not.toHaveAttribute("data-context-block-active");
|
||||
expect(answerA).toHaveAttribute("data-context-block-active", "true");
|
||||
|
||||
fireEvent.pointerEnter(userB, { pointerType: "mouse" });
|
||||
expect(answerA).not.toHaveAttribute("data-context-block-active");
|
||||
expect(userB).toHaveAttribute("data-context-block-active", "true");
|
||||
|
||||
const { menu: userMenu } = openMessageBlockMenu(userA);
|
||||
expect(userMenu.querySelector("[data-message-block-copy-action]")).toBeInTheDocument();
|
||||
expect(userMenu.querySelector("[data-message-block-fork-action]")).not.toBeInTheDocument();
|
||||
fireEvent.focus(userA.querySelector<HTMLElement>("[data-message-block-menu-trigger]")!);
|
||||
expect(userA).toHaveAttribute("data-context-block-active", "true");
|
||||
expect(userB).not.toHaveAttribute("data-context-block-active");
|
||||
});
|
||||
|
||||
it("closes an open block menu after the pointer leaves its block and panel", async () => {
|
||||
const messages: UIMessage[] = [
|
||||
{ id: "user-a", role: "user", content: "first prompt", createdAt: 500 },
|
||||
{ id: "answer-a", role: "assistant", content: "first answer", createdAt: 1_000 },
|
||||
{ id: "user-b", role: "user", content: "second prompt", createdAt: 1_500 },
|
||||
];
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
const userA = screen.getByText("first prompt")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const userB = screen.getByText("second prompt")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
|
||||
fireEvent.pointerEnter(userA, { pointerType: "mouse" });
|
||||
const { menu } = openMessageBlockMenu(userA);
|
||||
expect(menu).toHaveAttribute(
|
||||
"data-message-context-menu-block",
|
||||
userA.dataset.messageContextBlock,
|
||||
);
|
||||
|
||||
fireEvent.pointerLeave(userA, {
|
||||
pointerType: "mouse",
|
||||
relatedTarget: menu,
|
||||
});
|
||||
expect(menu).toHaveAttribute("data-state", "open");
|
||||
expect(userA).toHaveAttribute("data-context-block-active", "true");
|
||||
|
||||
fireEvent.pointerLeave(menu, {
|
||||
pointerType: "mouse",
|
||||
relatedTarget: userB,
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('[data-message-block-menu][data-state="open"]'))
|
||||
.not.toBeInTheDocument();
|
||||
});
|
||||
expect(userA).not.toHaveAttribute("data-context-block-active");
|
||||
expect(userB).toHaveAttribute("data-context-block-active", "true");
|
||||
|
||||
fireEvent.pointerEnter(userA, { pointerType: "mouse" });
|
||||
openMessageBlockMenu(userA);
|
||||
fireEvent.pointerEnter(userB, { pointerType: "mouse" });
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('[data-message-block-menu][data-state="open"]'))
|
||||
.not.toBeInTheDocument();
|
||||
});
|
||||
expect(userB).toHaveAttribute("data-context-block-active", "true");
|
||||
});
|
||||
|
||||
it("clears completed block controls when the pointer enters an ungrouped message", () => {
|
||||
const messages: UIMessage[] = [
|
||||
{ id: "user-a", role: "user", content: "first prompt", createdAt: 500 },
|
||||
{
|
||||
id: "tool-a",
|
||||
role: "tool",
|
||||
kind: "trace",
|
||||
content: "first command",
|
||||
traces: ["first command"],
|
||||
createdAt: 1_000,
|
||||
},
|
||||
{ id: "answer-a", role: "assistant", content: "first answer", createdAt: 2_000 },
|
||||
{ id: "user-b", role: "user", content: "current prompt", createdAt: 3_000 },
|
||||
{
|
||||
id: "answer-b",
|
||||
role: "assistant",
|
||||
content: "current answer",
|
||||
isStreaming: true,
|
||||
createdAt: 4_000,
|
||||
},
|
||||
];
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming activeTurnId={null} />);
|
||||
const completedAnswer = screen.getByText("first answer")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const currentAnswer = screen.getByText("current answer")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
|
||||
fireEvent.pointerEnter(completedAnswer, { pointerType: "mouse" });
|
||||
expect(completedAnswer).toHaveAttribute("data-context-block-active", "true");
|
||||
|
||||
fireEvent.pointerEnter(currentAnswer, { pointerType: "mouse" });
|
||||
expect(completedAnswer).not.toHaveAttribute("data-context-block-active");
|
||||
});
|
||||
|
||||
it("keeps only the last tapped message block controls active on touch", () => {
|
||||
const messages: UIMessage[] = [
|
||||
{ id: "user-a", role: "user", content: "first prompt", createdAt: 500 },
|
||||
{ id: "answer-a", role: "assistant", content: "first answer", createdAt: 1_000 },
|
||||
{ id: "user-b", role: "user", content: "second prompt", createdAt: 1_500 },
|
||||
{ id: "answer-b", role: "assistant", content: "second answer", createdAt: 2_000 },
|
||||
];
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
const answerA = screen.getByText("first answer")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const answerB = screen.getByText("second answer")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
|
||||
fireEvent.pointerDown(answerA, { pointerType: "touch" });
|
||||
fireEvent.pointerLeave(answerA, { pointerType: "touch" });
|
||||
expect(answerA).toHaveAttribute("data-context-block-active", "true");
|
||||
|
||||
fireEvent.pointerDown(answerB, { pointerType: "touch" });
|
||||
expect(answerA).not.toHaveAttribute("data-context-block-active");
|
||||
expect(answerB).toHaveAttribute("data-context-block-active", "true");
|
||||
});
|
||||
|
||||
it.each(["mouse", "touch"])("preserves the %s block when previous controls lose focus", (pointerType) => {
|
||||
render(<ThreadMessages messages={[
|
||||
{ id: "user", role: "user", content: "prompt", createdAt: 1 },
|
||||
{ id: "answer", role: "assistant", content: "answer", createdAt: 2 },
|
||||
]} />);
|
||||
const user = screen.getByText("prompt").closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const answer = screen.getByText("answer").closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const trigger = user.querySelector<HTMLElement>("[data-message-block-menu-trigger]")!;
|
||||
fireEvent.focus(trigger);
|
||||
if (pointerType === "touch") {
|
||||
openMessageBlockMenu(user);
|
||||
fireEvent.pointerDown(answer, { pointerType });
|
||||
} else {
|
||||
fireEvent.pointerEnter(answer, { pointerType });
|
||||
fireEvent.pointerDown(answer, { pointerType });
|
||||
}
|
||||
fireEvent.blur(trigger, { relatedTarget: document.body });
|
||||
|
||||
expect(answer).toHaveAttribute("data-context-block-active", "true");
|
||||
expect(user).not.toHaveAttribute("data-context-block-active");
|
||||
expect(document.querySelector('[data-message-block-menu][data-state="open"]')).toBeNull();
|
||||
});
|
||||
|
||||
it("closes the block menu with Escape from a focused copy action", async () => {
|
||||
render(<ThreadMessages messages={[
|
||||
{ id: "answer", role: "assistant", content: "answer", createdAt: 2 },
|
||||
]} />);
|
||||
const answer = screen.getByText("answer").closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const { menu, trigger } = openMessageBlockMenu(answer);
|
||||
const copy = menu.querySelector<HTMLElement>("[data-message-block-copy-action]")!;
|
||||
act(() => copy.focus());
|
||||
expect(copy).toHaveFocus();
|
||||
fireEvent.keyDown(copy, { key: "Escape" });
|
||||
await waitFor(() => expect(menu).not.toBeInTheDocument());
|
||||
expect(trigger).toHaveAttribute("aria-expanded", "false");
|
||||
});
|
||||
|
||||
it("clears keyboard context when focus leaves and no pointer owns a block", () => {
|
||||
render(<ThreadMessages messages={[
|
||||
{ id: "answer", role: "assistant", content: "answer", createdAt: 2 },
|
||||
]} />);
|
||||
const answer = screen.getByText("answer").closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const trigger = answer.querySelector<HTMLElement>("[data-message-block-menu-trigger]")!;
|
||||
fireEvent.focus(trigger);
|
||||
expect(answer).toHaveAttribute("data-context-block-active", "true");
|
||||
fireEvent.blur(trigger, { relatedTarget: document.body });
|
||||
expect(answer).not.toHaveAttribute("data-context-block-active");
|
||||
});
|
||||
|
||||
it.each(["cron", "local_trigger", "trigger"])("preserves %s provenance as static menu metadata", (kind) => {
|
||||
render(<ThreadMessages messages={[
|
||||
{ id: "answer", role: "assistant", content: "automated answer", createdAt: 2,
|
||||
source: { kind, label: "Review schedule" } },
|
||||
]} />);
|
||||
const answer = screen.getByText("automated answer").closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const { menu } = openMessageBlockMenu(answer);
|
||||
const metadata = menu.querySelector<HTMLElement>("[data-message-block-metadata]")!;
|
||||
expect(metadata).toHaveTextContent("Triggered automatically · Review schedule");
|
||||
expect(metadata.querySelector("time[datetime]")).toBeInTheDocument();
|
||||
expect(metadata.querySelector("button, svg, [tabindex]")).toBeNull();
|
||||
expect(metadata).toBe(menu.querySelector("[data-message-block-menu-actions]")?.lastElementChild);
|
||||
});
|
||||
|
||||
it("renders a fork boundary divider after the copied history", () => {
|
||||
@@ -1018,9 +1448,15 @@ describe("ThreadMessages", () => {
|
||||
expect(units[1].message).not.toHaveProperty("reasoning");
|
||||
}
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
const { container } = render(
|
||||
<ThreadMessages messages={messages} isStreaming={false} />,
|
||||
);
|
||||
expect(screen.queryByRole("button", { name: /^thinking$/i })).not.toBeInTheDocument();
|
||||
expect(screen.getByText("Worked for 9s")).toBeInTheDocument();
|
||||
openAssistantBlockMenu(container);
|
||||
const disclosure = screen.getByRole("button", { name: "Worked for 9s" });
|
||||
expect(disclosure).toHaveAttribute("aria-expanded", "false");
|
||||
fireEvent.click(disclosure);
|
||||
expect(screen.getByTestId("agent-activity-content")).toBeInTheDocument();
|
||||
expect(screen.getByText("final answer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -1056,9 +1492,14 @@ describe("ThreadMessages", () => {
|
||||
|
||||
expect(units[0].type === "activity" ? units[0].turnLatencyMs : undefined).toBe(20_000);
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
expect(screen.getByText("Worked for 20s")).toBeInTheDocument();
|
||||
expect(screen.queryByText("Worked for 3s")).not.toBeInTheDocument();
|
||||
const { container } = render(
|
||||
<ThreadMessages messages={messages} isStreaming={false} />,
|
||||
);
|
||||
openAssistantBlockMenu(container);
|
||||
expect(screen.getByRole("button", { name: "Worked for 20s" }))
|
||||
.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Worked for 3s" }))
|
||||
.not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps a streamed answer outside late activity when the prompt snapshot is absent", () => {
|
||||
@@ -1112,7 +1553,7 @@ describe("ThreadMessages", () => {
|
||||
expect(answer.compareDocumentPosition(liveActivity) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
});
|
||||
|
||||
it("keeps late activity after a completed assistant answer", () => {
|
||||
it("summarizes late activity above the completed assistant answer", () => {
|
||||
const messages: UIMessage[] = [
|
||||
{
|
||||
id: "r1",
|
||||
@@ -1156,12 +1597,13 @@ describe("ThreadMessages", () => {
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
|
||||
const answer = screen.getByText("Hong Kong is hot today.");
|
||||
openMessageBlockMenu(answer.closest<HTMLElement>("[data-thread-display-unit]")!);
|
||||
const laterActivity = screen.getAllByRole("button", { name: /worked/i }).at(-1);
|
||||
expect(laterActivity).toBeTruthy();
|
||||
expect(answer.compareDocumentPosition(laterActivity!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(laterActivity).toHaveAttribute("data-message-block-activity-action", "true");
|
||||
});
|
||||
|
||||
it("keeps completed web-search activity on both sides of an answer", () => {
|
||||
it("folds completed web-search activity into one row above the answer", () => {
|
||||
const messages: UIMessage[] = [
|
||||
{
|
||||
id: "user",
|
||||
@@ -1197,11 +1639,11 @@ describe("ThreadMessages", () => {
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
|
||||
const activities = screen.getAllByRole("button", { name: /worked/i });
|
||||
const answer = screen.getByText("知道,IEM Cologne Major 2026 今天开打了。");
|
||||
expect(activities).toHaveLength(2);
|
||||
expect(activities[0].compareDocumentPosition(answer) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(answer.compareDocumentPosition(activities[1]) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
openMessageBlockMenu(answer.closest<HTMLElement>("[data-thread-display-unit]")!);
|
||||
const activities = screen.getAllByRole("button", { name: /worked/i });
|
||||
expect(activities).toHaveLength(1);
|
||||
expect(activities[0]).toHaveAttribute("data-message-block-activity-action", "true");
|
||||
});
|
||||
|
||||
it("preserves a completed prior turn's order while the next turn is streaming", () => {
|
||||
@@ -1376,10 +1818,15 @@ describe("ThreadMessages", () => {
|
||||
},
|
||||
];
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
const { container } = render(
|
||||
<ThreadMessages messages={messages} isStreaming={false} />,
|
||||
);
|
||||
|
||||
expect(screen.getByText("Worked for 15s")).toBeInTheDocument();
|
||||
expect(screen.queryByText("Worked for 0s")).not.toBeInTheDocument();
|
||||
openAssistantBlockMenu(container);
|
||||
expect(screen.getByRole("button", { name: "Worked for 15s" }))
|
||||
.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Worked for 0s" }))
|
||||
.not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps answer slices on either side of activity in generation order", () => {
|
||||
@@ -1431,8 +1878,7 @@ describe("ThreadMessages", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getAllByRole("button", { name: "Copy" })).toHaveLength(2);
|
||||
expect(screen.getAllByRole("button", { name: "Fork" })).toHaveLength(1);
|
||||
expect(assistantActionCounts(document)).toEqual({ copy: 2, fork: 1 });
|
||||
expect(screen.getByText("starting…").closest("[data-testid='activity-model-message']")).toBeNull();
|
||||
expect(screen.getByText("final reply").closest("[data-testid='activity-model-message']")).toBeNull();
|
||||
});
|
||||
@@ -1489,6 +1935,10 @@ describe("ThreadMessages", () => {
|
||||
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
expect(screen.getByText("result.csv")).toBeInTheDocument();
|
||||
const ownerRow = screen.getByText("result.csv")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
openAssistantBlockMenu(ownerRow);
|
||||
expect(screen.getByRole("button", { name: "Worked" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("hides current turn actions until turn_end", () => {
|
||||
@@ -1530,18 +1980,17 @@ describe("ThreadMessages", () => {
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
const finalAnswer = screen.getByText("second answer slice")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
expect(firstAnswer.querySelector("[data-assistant-footer]")).not.toBeInTheDocument();
|
||||
expect(finalAnswer.querySelector("[data-assistant-footer]"))
|
||||
.toHaveAttribute("data-state", "reserved");
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]')).toHaveLength(1);
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(1);
|
||||
expect(firstAnswer.querySelector("[data-message-block-menu-trigger]"))
|
||||
.not.toBeInTheDocument();
|
||||
expect(finalAnswer.querySelector("[data-message-block-menu-trigger]"))
|
||||
.not.toBeInTheDocument();
|
||||
expect(assistantActionCounts(container)).toEqual({ copy: 1, fork: 1 });
|
||||
|
||||
rerender(<ThreadMessages {...props} isStreaming={false} activeTurnId={null} />);
|
||||
|
||||
expect(firstAnswer.querySelector("[data-assistant-footer]"))
|
||||
.toHaveAttribute("data-state", "visible");
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]')).toHaveLength(3);
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(2);
|
||||
expect(firstAnswer.querySelector("[data-message-block-menu-trigger]"))
|
||||
.toBeInTheDocument();
|
||||
expect(assistantActionCounts(container)).toEqual({ copy: 3, fork: 2 });
|
||||
});
|
||||
|
||||
it("keeps active turn actions hidden across guidance and failed user rows", () => {
|
||||
@@ -1570,8 +2019,7 @@ describe("ThreadMessages", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]')).toHaveLength(1);
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(1);
|
||||
expect(assistantActionCounts(container)).toEqual({ copy: 1, fork: 1 });
|
||||
});
|
||||
|
||||
it("only hides the active assistant-only automation turn", () => {
|
||||
@@ -1593,8 +2041,7 @@ describe("ThreadMessages", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]')).toHaveLength(1);
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(0);
|
||||
expect(assistantActionCounts(container)).toEqual({ copy: 1, fork: 0 });
|
||||
});
|
||||
|
||||
it("falls back to the latest user boundary for untagged active slices", () => {
|
||||
@@ -1610,10 +2057,7 @@ describe("ThreadMessages", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelector('[data-assistant-footer] [aria-label="Copy"]'))
|
||||
.not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-assistant-footer] [aria-label="Fork"]'))
|
||||
.not.toBeInTheDocument();
|
||||
expect(assistantActionCounts(container)).toEqual({ copy: 0, fork: 0 });
|
||||
});
|
||||
|
||||
it("falls back to the latest user boundary while the active turn id is pending", () => {
|
||||
@@ -1631,10 +2075,7 @@ describe("ThreadMessages", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]'))
|
||||
.toHaveLength(1);
|
||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]'))
|
||||
.toHaveLength(1);
|
||||
expect(assistantActionCounts(container)).toEqual({ copy: 1, fork: 1 });
|
||||
});
|
||||
|
||||
it("projects adjacent assistant text slices into one answer", () => {
|
||||
@@ -1642,8 +2083,10 @@ describe("ThreadMessages", () => {
|
||||
{ id: "a1", role: "assistant", content: "part one", createdAt: 1 },
|
||||
{ id: "a2", role: "assistant", content: "part two", createdAt: 2 },
|
||||
];
|
||||
render(<ThreadMessages messages={messages} isStreaming={false} />);
|
||||
expect(screen.getAllByRole("button", { name: "Copy" })).toHaveLength(1);
|
||||
const { container } = render(
|
||||
<ThreadMessages messages={messages} isStreaming={false} />,
|
||||
);
|
||||
expect(assistantActionCounts(container).copy).toBe(1);
|
||||
expect(screen.getByText("part one")).toBeInTheDocument();
|
||||
expect(screen.getByText("part two")).toBeInTheDocument();
|
||||
});
|
||||
@@ -1672,7 +2115,10 @@ describe("ThreadMessages", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getAllByRole("button", { name: "Fork" }).at(-1)!);
|
||||
const answerRow = screen.getByText("answer two")
|
||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
openMessageBlockMenu(answerRow);
|
||||
fireEvent.click(document.querySelector("[data-message-block-fork-action]")!);
|
||||
expect(onForkFromMessage).toHaveBeenCalledWith(2);
|
||||
});
|
||||
|
||||
|
||||
@@ -22,6 +22,13 @@ import { canonicalThreadPayload } from "./thread-test-payload";
|
||||
const HERO_GREETING_PATTERN =
|
||||
/What should we work on\?|Where should we start\?|What are we building today\?|What should we tackle together\?/;
|
||||
|
||||
async function openMessageActions(text: string): Promise<HTMLElement> {
|
||||
const message = await screen.findByText(text);
|
||||
const block = message.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||
fireEvent.click(within(block).getByRole("button", { name: "Message actions" }));
|
||||
return screen.findByRole("dialog", { name: "Message actions" });
|
||||
}
|
||||
|
||||
function makeClient() {
|
||||
const errorHandlers = new Set<(err: StreamError) => void>();
|
||||
const statusHandlers = new Set<(status: ConnectionStatus) => void>();
|
||||
@@ -532,7 +539,8 @@ describe("ThreadShell", () => {
|
||||
/>,
|
||||
));
|
||||
|
||||
const activity = await screen.findByRole("button", { name: /Worked/ });
|
||||
const menu = await openMessageActions("done");
|
||||
const activity = within(menu).getByRole("button", { name: /Worked/ });
|
||||
fireEvent.click(activity);
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent(
|
||||
"Full activity details could not be loaded.",
|
||||
@@ -544,9 +552,9 @@ describe("ThreadShell", () => {
|
||||
await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument());
|
||||
await waitFor(() => expect(document.body).toHaveTextContent("echo full"));
|
||||
|
||||
const resolvedActivity = screen.getByRole("button", { name: /Worked/ });
|
||||
fireEvent.click(resolvedActivity);
|
||||
fireEvent.click(resolvedActivity);
|
||||
fireEvent.click(screen.getByRole("button", { name: /Collapse activity details/ }));
|
||||
const reopenedMenu = await openMessageActions("done");
|
||||
fireEvent.click(within(reopenedMenu).getByRole("button", { name: /Worked/ }));
|
||||
await act(async () => Promise.resolve());
|
||||
expect(detailCalls).toBe(2);
|
||||
});
|
||||
@@ -584,7 +592,7 @@ describe("ThreadShell", () => {
|
||||
/>,
|
||||
);
|
||||
const { rerender } = render(view("trace-failure-a"));
|
||||
fireEvent.click(await screen.findByRole("button", { name: /Worked/ }));
|
||||
fireEvent.click(within(await openMessageActions("done-a")).getByRole("button", { name: /Worked/ }));
|
||||
|
||||
rerender(view("trace-failure-b"));
|
||||
await screen.findByText("done-b");
|
||||
@@ -624,7 +632,7 @@ describe("ThreadShell", () => {
|
||||
/>,
|
||||
);
|
||||
const { rerender } = render(view("visible-failure-a"));
|
||||
fireEvent.click(await screen.findByRole("button", { name: /Worked/ }));
|
||||
fireEvent.click(within(await openMessageActions("failed-a")).getByRole("button", { name: /Worked/ }));
|
||||
expect(await screen.findByRole("alert")).toBeInTheDocument();
|
||||
|
||||
rerender(view("visible-failure-b"));
|
||||
@@ -873,7 +881,8 @@ describe("ThreadShell", () => {
|
||||
/>,
|
||||
));
|
||||
|
||||
await waitFor(() => expect(screen.getAllByRole("button", { name: "Copy" })).toHaveLength(1));
|
||||
const oldMenu = await openMessageActions("old automation");
|
||||
expect(within(oldMenu).getByRole("button", { name: "Copy" })).toBeInTheDocument();
|
||||
const turnId = "turn-automation";
|
||||
const startedAt = Date.now() / 1000;
|
||||
act(() => client._emitChat("assistant-only-actions", {
|
||||
@@ -883,7 +892,7 @@ describe("ThreadShell", () => {
|
||||
started_at: startedAt,
|
||||
turn_id: turnId,
|
||||
}));
|
||||
expect(screen.getAllByRole("button", { name: "Copy" })).toHaveLength(1);
|
||||
expect(screen.getAllByRole("button", { name: "Message actions" })).toHaveLength(1);
|
||||
|
||||
act(() => client._emitChat("assistant-only-actions", {
|
||||
event: "message",
|
||||
@@ -892,14 +901,18 @@ describe("ThreadShell", () => {
|
||||
turn_id: turnId,
|
||||
}));
|
||||
await waitFor(() => expect(screen.getByText("new automation")).toBeInTheDocument());
|
||||
expect(screen.getAllByRole("button", { name: "Copy" })).toHaveLength(1);
|
||||
expect(screen.getAllByRole("button", { name: "Message actions" })).toHaveLength(1);
|
||||
expect(screen.getByText("new automation").closest("[data-thread-display-unit]"))
|
||||
.not.toHaveAttribute("data-message-context-block");
|
||||
|
||||
act(() => client._emitChat("assistant-only-actions", {
|
||||
event: "turn_end",
|
||||
chat_id: "assistant-only-actions",
|
||||
turn_id: turnId,
|
||||
}));
|
||||
await waitFor(() => expect(screen.getAllByRole("button", { name: "Copy" })).toHaveLength(2));
|
||||
await waitFor(() => expect(screen.getAllByRole("button", { name: "Message actions" })).toHaveLength(2));
|
||||
const newMenu = await openMessageActions("new automation");
|
||||
expect(within(newMenu).getByRole("button", { name: "Copy" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not navigate away when clicking the chat title", async () => {
|
||||
@@ -1177,6 +1190,7 @@ describe("ThreadShell", () => {
|
||||
).not.toHaveAttribute("data-fallback");
|
||||
});
|
||||
expect(screen.getByText("Default")).toBeInTheDocument();
|
||||
await openMessageActions("Reply from the actual provider");
|
||||
expect(await screen.findByText("backup")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -2060,10 +2074,8 @@ describe("ThreadShell", () => {
|
||||
),
|
||||
);
|
||||
|
||||
const targetText = await screen.findByText("answer 100");
|
||||
fireEvent.click(within(targetText.closest(".w-full") as HTMLElement).getByRole("button", {
|
||||
name: "Fork",
|
||||
}));
|
||||
const menu = await openMessageActions("answer 100");
|
||||
fireEvent.click(within(menu).getByRole("button", { name: "Fork" }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(onForkChat).toHaveBeenCalledWith("long-chat", 101),
|
||||
|
||||
@@ -266,6 +266,27 @@ describe("ThreadViewport", () => {
|
||||
expect(takeUserControl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("yields scroll control before expanding activity from a portaled message menu", () => {
|
||||
const takeUserControl = vi.spyOn(ThreadMotionCoordinator.prototype, "takeUserControl");
|
||||
render(
|
||||
<ThreadViewport
|
||||
messages={[
|
||||
{ id: "reasoning", role: "assistant", content: "", reasoning: "A completed thought", createdAt: 1 },
|
||||
{ id: "answer", role: "assistant", content: "Finished answer", createdAt: 2 },
|
||||
]}
|
||||
isStreaming={false}
|
||||
composer={<div>composer</div>}
|
||||
/>,
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Message actions" }));
|
||||
const disclosure = screen.getByRole("button", { name: "Worked" });
|
||||
expect(screen.getByTestId("thread-message-region")).not.toContainElement(disclosure);
|
||||
takeUserControl.mockClear();
|
||||
fireEvent.click(disclosure);
|
||||
expect(takeUserControl).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByRole("button", { name: /Collapse activity details/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("top-aligns short threads in the message rendering area", () => {
|
||||
render(
|
||||
<ThreadViewport
|
||||
@@ -305,12 +326,16 @@ describe("ThreadViewport", () => {
|
||||
expect(screen.getByTestId("thread-message-region")).toHaveClass("min-w-0");
|
||||
});
|
||||
|
||||
it("uses the shared content-column width for conversation messages", () => {
|
||||
it("keeps message hit rows full width and constrains content inside each row", () => {
|
||||
render(<ThreadViewport messages={messages} isStreaming={false} composer={<div>composer</div>} />);
|
||||
|
||||
expect(screen.getByTestId("thread-message-region").firstElementChild).toHaveClass(
|
||||
"mx-auto", "w-full", "max-w-[var(--content-column-width)]",
|
||||
);
|
||||
const region = screen.getByTestId("thread-message-region");
|
||||
expect(region.firstElementChild).toHaveClass("w-full");
|
||||
expect(region.firstElementChild).not.toHaveClass("max-w-[var(--content-column-width)]");
|
||||
expect(region.parentElement).not.toHaveClass("max-w-[64rem]");
|
||||
const rows = region.querySelectorAll("[data-thread-display-unit]");
|
||||
expect(rows.length).toBeGreaterThan(0);
|
||||
for (const row of rows) expect(row).toHaveClass("thread-message-row");
|
||||
});
|
||||
|
||||
it("top-aligns a short active turn while the agent is responding", () => {
|
||||
|
||||
Reference in new issue
Block a user