AuditTrace.test.tsx
1 // Copyright (c) 2026 VPL Solutions. All rights reserved. 2 // Licensed under the MIT License. See LICENSE for details. 3 4 import { describe, it, expect } from 'vitest'; 5 import { render, screen } from '@testing-library/react'; 6 import { AuditTrace } from '../AuditTrace'; 7 import type { StepSummary } from '../../../api/investigation'; 8 9 const SAMPLE_STEPS: StepSummary[] = [ 10 { step_number: 1, agent_role: 'intake', action: 'Classified ticket as data_quality', status_before: 'INTAKE', status_after: 'INTAKE', timestamp: '2026-03-20T14:32:00.000Z', elapsed_ms: 1200 }, 11 { step_number: 2, agent_role: 'machine', action: 'transition INTAKE to RESEARCH', status_before: 'INTAKE', status_after: 'RESEARCH', timestamp: '2026-03-20T14:32:05.000Z', elapsed_ms: 0 }, 12 { step_number: 3, agent_role: 'research', action: 'Queried postgres_payments', status_before: 'RESEARCH', status_after: 'RESEARCH', timestamp: '2026-03-20T14:33:00.000Z', elapsed_ms: 850 }, 13 ]; 14 15 describe('AuditTrace', () => { 16 it('renders empty state when no steps', () => { 17 render(<AuditTrace steps={[]} />); 18 expect(screen.getByText('No audit steps recorded yet.')).toBeInTheDocument(); 19 }); 20 21 it('renders step numbers', () => { 22 render(<AuditTrace steps={SAMPLE_STEPS} />); 23 expect(screen.getByText('1')).toBeInTheDocument(); 24 expect(screen.getByText('2')).toBeInTheDocument(); 25 expect(screen.getByText('3')).toBeInTheDocument(); 26 }); 27 28 it('renders agent role badges and action descriptions', () => { 29 const { container } = render(<AuditTrace steps={SAMPLE_STEPS} />); 30 expect(container.textContent).toContain('Intake'); 31 expect(container.textContent).toContain('Research'); 32 expect(container.textContent).toContain('Classified ticket as data_quality'); 33 expect(container.textContent).toContain('Queried postgres_payments'); 34 }); 35 36 it('renders state transitions', () => { 37 const { container } = render(<AuditTrace steps={SAMPLE_STEPS} />); 38 expect(container.textContent).toContain('INTAKE'); 39 expect(container.textContent).toContain('RESEARCH'); 40 }); 41 42 it('renders elapsed time', () => { 43 const { container } = render(<AuditTrace steps={SAMPLE_STEPS} />); 44 expect(container.textContent).toContain('1.2s'); 45 expect(container.textContent).toContain('850ms'); 46 }); 47 48 it('renders trace integrity footer with step count', () => { 49 const { container } = render(<AuditTrace steps={SAMPLE_STEPS} />); 50 expect(container.textContent).toContain('3 steps recorded'); 51 expect(container.textContent).toContain('all actions audited'); 52 }); 53 });