-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathSubAgentPanel.test.tsx
More file actions
85 lines (76 loc) · 2.66 KB
/
Copy pathSubAgentPanel.test.tsx
File metadata and controls
85 lines (76 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from 'vitest';
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { I18nProvider } from '../../../i18n';
import type { ACPToolCall } from '../../../adapters/types';
import { formatTimestamp } from '../../MessageTimestamp';
// SubAgentPanel pulls in ToolGroup, which imports App only for
// CompactModeContext; loading the real App module would drag the whole
// application graph into this unit test.
vi.mock('../../../App', async () => {
const { createContext } = await import('react');
return { CompactModeContext: createContext(false) };
});
const { SubAgentPanel } = await import('./SubAgentPanel');
(
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;
const mounted: Array<{ root: Root; container: HTMLElement }> = [];
afterEach(() => {
for (const { root, container } of mounted.splice(0)) {
act(() => root.unmount());
container.remove();
}
});
function renderPanel(tool: ACPToolCall): HTMLElement {
const container = document.createElement('div');
document.body.appendChild(container);
const root = createRoot(container);
act(() => {
root.render(
<I18nProvider language="en">
<SubAgentPanel tool={tool} defaultExpanded inline hideHeader />
</I18nProvider>,
);
});
mounted.push({ root, container });
return container;
}
function makeAgentWithSubTool(subTool: ACPToolCall): ACPToolCall {
return {
callId: 'agent-1',
toolName: 'Task',
status: 'completed',
args: { description: 'demo agent' },
subTools: [subTool],
};
}
describe('SubAgentPanel sub-tool timestamps', () => {
it('renders each sub-tool start time, like the main transcript rows', () => {
// A past date so formatTimestamp always renders the dated form; the
// expectation is derived from the same formatter, so it matches
// regardless of the test machine's clock or timezone.
const startTime = new Date('2020-01-02T03:04:05').getTime();
const container = renderPanel(
makeAgentWithSubTool({
callId: 'sub-1',
toolName: 'Read',
status: 'completed',
startTime,
}),
);
expect(container.textContent).toContain(formatTimestamp(startTime));
});
it('renders a sub-tool without a start time unchanged (no time shown)', () => {
const reference = new Date('2020-01-02T03:04:05').getTime();
const container = renderPanel(
makeAgentWithSubTool({
callId: 'sub-1',
toolName: 'Read',
status: 'completed',
}),
);
expect(container.textContent).not.toContain(formatTimestamp(reference));
});
});