import { render, screen } from '@testing-library/react' import ChiefAnalystCard from '@/features/run-detail/components/ChiefAnalystCard' import type { ChiefAnalystReport } from '@/lib/types/agents' // react-to-pdf uses browser APIs not available in Jest — mock it jest.mock('react-to-pdf', () => ({ usePDF: () => ({ toPDF: jest.fn(), targetRef: { current: null } }), })) const mockReport: ChiefAnalystReport = { verdict: 'BUY', catalyst: 'Strong Q4 earnings beat with record margins', execution: 'Enter at market price, stop loss at $180', tail_risk: 'Federal Reserve rate hike could compress multiples', } test('shows pending state when status is pending and report is null', () => { render() expect(screen.getByText(/standing by/i)).toBeInTheDocument() }) test('shows running skeleton when status is running', () => { render() expect(screen.getByTestId('chief-analyst-card')).toBeInTheDocument() }) test('shows verdict when status is done and report is provided', () => { render() expect(screen.getByText('BUY')).toBeInTheDocument() }) test('shows catalyst when done', () => { render() expect(screen.getByText(/Strong Q4 earnings beat/i)).toBeInTheDocument() }) test('shows execution when done', () => { render() expect(screen.getByText(/Enter at market price/i)).toBeInTheDocument() }) test('shows tail_risk when done', () => { render() expect(screen.getByText(/Federal Reserve rate hike/i)).toBeInTheDocument() }) test('shows download button when done', () => { render() expect(screen.getByRole('button', { name: /download/i })).toBeInTheDocument() }) test('shows report-unavailable fallback when done but report is null', () => { render() expect(screen.getByText(/report unavailable/i)).toBeInTheDocument() })