Files
tutti/packages/agent/gui/agent-gui/agentGuiNode/view/useAgentGUITimelineTransition.spec.tsx
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

133 lines
3.9 KiB
TypeScript

import { act, renderHook } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { AgentConversationVM } from "../../../shared/agentConversation/contracts/agentConversationVM";
import {
AGENT_GUI_TIMELINE_SKELETON_DELAY_MS,
useAgentGUITimelineTransition
} from "./useAgentGUITimelineTransition";
afterEach(() => {
vi.useRealTimers();
});
describe("useAgentGUITimelineTransition", () => {
it("keeps the previous timeline without flashing a skeleton for a fast load", () => {
vi.useFakeTimers();
let renderCount = 0;
const conversationA = conversation("conversation-a");
const conversationB = conversation("conversation-b");
const { result, rerender } = renderHook(
(input: TimelineTransitionInput) => {
renderCount += 1;
return useAgentGUITimelineTransition(input);
},
{
initialProps: {
activeConversationId: "conversation-a",
availability: "ready",
conversation: conversationA
} as TimelineTransitionInput
}
);
rerender({
activeConversationId: "conversation-b",
availability: "loading",
conversation: null
});
expect(result.current.conversation).toBe(conversationA);
expect(result.current.showTimelineSkeleton).toBe(false);
expect(result.current.timelineConversationId).toBe("conversation-a");
act(() => {
vi.advanceTimersByTime(AGENT_GUI_TIMELINE_SKELETON_DELAY_MS - 1);
});
rerender({
activeConversationId: "conversation-b",
availability: "ready",
conversation: conversationB
});
expect(result.current.conversation).toBe(conversationB);
expect(result.current.showTimelineSkeleton).toBe(false);
expect(result.current.timelineConversationId).toBe("conversation-b");
expect(renderCount).toBe(3);
});
it("reveals the conversation skeleton after 300ms", () => {
vi.useFakeTimers();
const conversationA = conversation("conversation-a");
const { result, rerender } = renderHook(
(input: TimelineTransitionInput) => useAgentGUITimelineTransition(input),
{
initialProps: {
activeConversationId: "conversation-a",
availability: "ready",
conversation: conversationA
} as TimelineTransitionInput
}
);
rerender({
activeConversationId: "conversation-b",
availability: "loading",
conversation: null
});
act(() => {
vi.advanceTimersByTime(AGENT_GUI_TIMELINE_SKELETON_DELAY_MS);
});
expect(result.current.showTimelineSkeleton).toBe(true);
expect(result.current.timelineConversationId).toBe("conversation-b");
});
it("does not reveal a stale skeleton after a rapid second selection", () => {
vi.useFakeTimers();
const conversationA = conversation("conversation-a");
const { result, rerender } = renderHook(
(input: TimelineTransitionInput) => useAgentGUITimelineTransition(input),
{
initialProps: {
activeConversationId: "conversation-a",
availability: "ready",
conversation: conversationA
} as TimelineTransitionInput
}
);
rerender({
activeConversationId: "conversation-b",
availability: "loading",
conversation: null
});
act(() => {
vi.advanceTimersByTime(200);
});
rerender({
activeConversationId: "conversation-c",
availability: "loading",
conversation: null
});
act(() => {
vi.advanceTimersByTime(100);
});
expect(result.current.showTimelineSkeleton).toBe(false);
act(() => {
vi.advanceTimersByTime(200);
});
expect(result.current.showTimelineSkeleton).toBe(true);
});
});
function conversation(id: string): AgentConversationVM {
return {
id,
rows: [{ id: `${id}-row`, kind: "processing" }]
} as unknown as AgentConversationVM;
}
type TimelineTransitionInput = Parameters<
typeof useAgentGUITimelineTransition
>[0];