Files
tutti/packages/agent/gui/agent-gui/agentGuiNode/view/AgentGUIConversationRailClock.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

97 lines
2.7 KiB
TypeScript

import { act, render, screen } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { AgentGUIConversationSummary } from "../model/agentGuiConversationModel";
import { AgentGUIConversationRailRelativeTime } from "./AgentGUIConversationRailClock";
describe("AgentGUIConversationRailRelativeTime", () => {
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(1_000_000);
});
afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
});
it("uses one timer and updates only relative-time consumers", () => {
const setIntervalSpy = vi.spyOn(window, "setInterval");
let rowRenderCount = 0;
function StableRow({ item }: { item: AgentGUIConversationSummary }) {
rowRenderCount += 1;
return (
<div>
<span>{item.title}</span>
<AgentGUIConversationRailRelativeTime
item={item}
labels={RELATIVE_TIME_LABELS}
/>
</div>
);
}
const { unmount } = render(
<>
<StableRow item={createConversation("session-1")} />
<StableRow item={createConversation("session-2")} />
</>
);
expect(rowRenderCount).toBe(2);
expect(
setIntervalSpy.mock.calls.filter((call) => call[1] === 60_000)
).toHaveLength(1);
expect(screen.getAllByText("just now")).toHaveLength(2);
act(() => {
vi.advanceTimersByTime(60_000);
});
expect(rowRenderCount).toBe(2);
expect(screen.getAllByText("1 minute")).toHaveLength(2);
unmount();
expect(vi.getTimerCount()).toBe(0);
});
it("does not subscribe to the minute clock when Activity hides timestamps", () => {
const setIntervalSpy = vi.spyOn(window, "setInterval");
const { unmount } = render(
<AgentGUIConversationRailRelativeTime
hideTime
item={createConversation("session-1")}
labels={RELATIVE_TIME_LABELS}
/>
);
expect(
setIntervalSpy.mock.calls.filter((call) => call[1] === 60_000)
).toHaveLength(0);
unmount();
expect(vi.getTimerCount()).toBe(0);
});
});
function createConversation(id: string): AgentGUIConversationSummary {
return {
cwd: "/workspace",
id,
provider: "codex",
status: "ready",
title: id,
updatedAtUnixMs: 1_000_000
};
}
const RELATIVE_TIME_LABELS = {
relativeTimeDays: (value: number) => `${value} days`,
relativeTimeHours: (value: number) => `${value} hours`,
relativeTimeJustNow: "just now",
relativeTimeMinutes: (value: number) =>
`${value} ${value === 1 ? "minute" : "minutes"}`,
relativeTimeMonths: (value: number) => `${value} months`,
relativeTimeYears: (value: number) => `${value} years`
};