|
| 1 | +import { describe, it, expect, vi } from 'vitest'; |
| 2 | +import { render, screen } from '../_helpers/render'; |
| 3 | +import { Turn } from '@/canvas/Turn'; |
| 4 | +import type { ToolCall } from '@/api/types'; |
| 5 | + |
| 6 | +const tools: ToolCall[] = []; |
| 7 | + |
| 8 | +describe('<Turn>', () => { |
| 9 | + it('renders byline with agent name + timestamp', () => { |
| 10 | + render( |
| 11 | + <Turn |
| 12 | + agent="intake" timestamp="2026-05-15T14:16:32Z" elapsedMs={2200} |
| 13 | + body="Triage observed elevated p99 latency on payments-svc." |
| 14 | + confidence={0.92} model="gpt" durationMs={1230} turn={1} |
| 15 | + toolCalls={tools} |
| 16 | + active={false} |
| 17 | + onSelectTool={() => {}} |
| 18 | + />, |
| 19 | + ); |
| 20 | + expect(screen.getByText('intake')).toBeInTheDocument(); |
| 21 | + expect(screen.getByText(/14:16:32/)).toBeInTheDocument(); |
| 22 | + expect(screen.getByText(/Triage observed/)).toBeInTheDocument(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('renders elapsed delta in mono when provided', () => { |
| 26 | + render( |
| 27 | + <Turn |
| 28 | + agent="x" timestamp="2026-05-15T14:16:32Z" elapsedMs={2200} |
| 29 | + body="x" confidence={null} model="x" durationMs={0} turn={1} |
| 30 | + toolCalls={tools} active={false} |
| 31 | + onSelectTool={() => {}} |
| 32 | + />, |
| 33 | + ); |
| 34 | + expect(screen.getByText(/\+2\.2s/)).toBeInTheDocument(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('marks active turn with data-active="true" and shows typing cursor in body', () => { |
| 38 | + const { container } = render( |
| 39 | + <Turn |
| 40 | + agent="investigate" timestamp="2026-05-15T14:17:30Z" elapsedMs={null} |
| 41 | + body="Reading deploy diff..." confidence={null} model="x" durationMs={0} turn={2} |
| 42 | + toolCalls={tools} active={true} |
| 43 | + onSelectTool={() => {}} |
| 44 | + />, |
| 45 | + ); |
| 46 | + expect(container.firstChild).toHaveAttribute('data-active', 'true'); |
| 47 | + expect(container.querySelector('[data-typing-cursor]')).not.toBeNull(); |
| 48 | + }); |
| 49 | + |
| 50 | + it('non-active turn omits typing cursor', () => { |
| 51 | + const { container } = render( |
| 52 | + <Turn |
| 53 | + agent="x" timestamp="2026-05-15T14:16:00Z" elapsedMs={0} |
| 54 | + body="done" confidence={null} model="x" durationMs={0} turn={1} |
| 55 | + toolCalls={tools} active={false} |
| 56 | + onSelectTool={() => {}} |
| 57 | + />, |
| 58 | + ); |
| 59 | + expect(container.querySelector('[data-typing-cursor]')).toBeNull(); |
| 60 | + expect(container.firstChild).toHaveAttribute('data-active', 'false'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('passes toolCalls through to Sidenote and renders them', () => { |
| 64 | + const tc: ToolCall = { |
| 65 | + agent: 'x', tool: 'obs:get_logs', args: {}, result: null, |
| 66 | + ts: '2026-05-15T14:16:50Z', risk: 'low', |
| 67 | + status: 'executed', approver: null, approved_at: null, approval_rationale: null, |
| 68 | + }; |
| 69 | + render( |
| 70 | + <Turn |
| 71 | + agent="x" timestamp="2026-05-15T14:16:32Z" elapsedMs={0} |
| 72 | + body="x" confidence={null} model="x" durationMs={0} turn={1} |
| 73 | + toolCalls={[tc]} active={false} |
| 74 | + onSelectTool={() => {}} |
| 75 | + />, |
| 76 | + ); |
| 77 | + expect(screen.getByText('obs:get_logs')).toBeInTheDocument(); |
| 78 | + }); |
| 79 | + |
| 80 | + it('forwards onSelectTool to Sidenote', () => { |
| 81 | + const onSelectTool = vi.fn(); |
| 82 | + const tc: ToolCall = { |
| 83 | + agent: 'x', tool: 'obs:get_logs', args: {}, result: null, |
| 84 | + ts: 'x', risk: null, status: 'executed', |
| 85 | + approver: null, approved_at: null, approval_rationale: null, |
| 86 | + }; |
| 87 | + render( |
| 88 | + <Turn |
| 89 | + agent="x" timestamp="2026-05-15T14:16:32Z" elapsedMs={0} |
| 90 | + body="x" confidence={null} model="x" durationMs={0} turn={1} |
| 91 | + toolCalls={[tc]} active={false} |
| 92 | + onSelectTool={onSelectTool} |
| 93 | + />, |
| 94 | + ); |
| 95 | + screen.getByText('obs:get_logs').closest('[data-tool-card]')!.dispatchEvent( |
| 96 | + new MouseEvent('click', { bubbles: true }), |
| 97 | + ); |
| 98 | + expect(onSelectTool).toHaveBeenCalledWith(tc); |
| 99 | + }); |
| 100 | +}); |
0 commit comments