import { render, screen } from '@testing-library/react' import * as React from 'react' import ResultPanel from './result' vi.mock('@/app/components/workflow/nodes/_base/components/editor/code-editor', () => ({ default: ({ title, value }: { title: React.ReactNode, value: string | object }) => (
{title}
{JSON.stringify(value)}
), })) vi.mock('@/app/components/workflow/run/status', () => ({ default: ({ status, time, tokens, error }: { status: string, time?: number, tokens?: number, error?: string }) => (
{status} {time} {tokens} {error}
), })) vi.mock('@/hooks/use-timestamp', () => ({ default: () => ({ formatTime: vi.fn((ts, _format) => `formatted-${ts}`), }), })) const mockProps = { status: 'succeeded', elapsed_time: 1.23456, total_tokens: 150, error: '', inputs: { query: 'input' }, outputs: { answer: 'output' }, created_by: 'User Name', created_at: '2023-01-01T00:00:00Z', agentMode: 'function_call', tools: ['tool1', 'tool2'], iterations: 3, } describe('ResultPanel', () => { it('should render status panel and code editors', () => { render() expect(screen.getByTestId('status-panel')).toBeInTheDocument() const editors = screen.getAllByTestId('code-editor') expect(editors).toHaveLength(2) expect(screen.getByText('INPUT')).toBeInTheDocument() expect(screen.getByText('OUTPUT')).toBeInTheDocument() expect(screen.getByText(JSON.stringify(mockProps.inputs))).toBeInTheDocument() expect(screen.getByText(JSON.stringify(mockProps.outputs))).toBeInTheDocument() }) it('should display correct metadata', () => { render() expect(screen.getByText('User Name')).toBeInTheDocument() expect(screen.getByText('1.235s')).toBeInTheDocument() // toFixed(3) expect(screen.getByText('150 Tokens')).toBeInTheDocument() expect(screen.getByText('appDebug.agent.agentModeType.functionCall')).toBeInTheDocument() expect(screen.getByText('tool1, tool2')).toBeInTheDocument() expect(screen.getByText('3')).toBeInTheDocument() // Check formatted time expect(screen.getByText(/formatted-/)).toBeInTheDocument() }) it('should handle missing created_by and tools', () => { render() expect(screen.getByText('N/A')).toBeInTheDocument() expect(screen.getByText('Null')).toBeInTheDocument() }) it('should display ReACT mode correctly', () => { render() expect(screen.getByText('appDebug.agent.agentModeType.ReACT')).toBeInTheDocument() }) })