diff --git a/frontend/src/pages/DebugPage.tsx b/frontend/src/pages/DebugPage.tsx index f6595ab..c142bcf 100644 --- a/frontend/src/pages/DebugPage.tsx +++ b/frontend/src/pages/DebugPage.tsx @@ -91,6 +91,20 @@ const DebugPage: React.FC = () => { const [monitoringInterval, setMonitoringInterval] = useState(null); const [processingStatus, setProcessingStatus] = useState(''); + // Auto-switch to debug results tab when debugInfo is available + useEffect(() => { + if (debugInfo && activeTab !== 2) { + setActiveTab(2); + } + }, [debugInfo]); + + // Reset activeTab when debugInfo is cleared + useEffect(() => { + if (!debugInfo && activeTab === 2) { + setActiveTab(0); + } + }, [debugInfo, activeTab]); + const getStepIcon = (status: string, success: boolean) => { if (status === 'processing') return ; if (success || status === 'completed' || status === 'passed') return ; @@ -411,7 +425,7 @@ const DebugPage: React.FC = () => { - {details.queue_history.map((entry: any, index: number) => ( + {(details.queue_history || []).map((entry: any, index: number) => ( { Quality Checks - {Object.entries(details.quality_checks).map(([check, passed]: [string, any]) => ( + {Object.entries(details.quality_checks || {}).map(([check, passed]: [string, any]) => ( { Processing Pipeline - {debugInfo.pipeline_steps.map((step) => ( + {(debugInfo.pipeline_steps || []).map((step) => ( { style: { color: step.success ? '#4caf50' : step.status === 'failed' ? '#f44336' : '#ff9800' } }} > - - {step.name} + + {step.name} - + {renderStepDetails(step)} @@ -889,7 +903,7 @@ const DebugPage: React.FC = () => { - {debugInfo.detailed_processing_logs.map((log: any, index: number) => ( + {(debugInfo.detailed_processing_logs || []).map((log: any, index: number) => ( {index + 1} @@ -978,7 +992,7 @@ const DebugPage: React.FC = () => { )} - {debugInfo.pipeline_steps.some(step => step.step === 3 && step.details.has_processed_image) && ( + {(debugInfo.pipeline_steps || []).some(step => step.step === 3 && step.details?.has_processed_image) && ( @@ -1041,18 +1055,18 @@ const DebugPage: React.FC = () => { OCR Settings - Background OCR: {debugInfo.user_settings.enable_background_ocr ? 'Enabled' : 'Disabled'} - Min Confidence: {debugInfo.user_settings.ocr_min_confidence}% - Max File Size: {debugInfo.user_settings.max_file_size_mb} MB + Background OCR: {debugInfo.user_settings?.enable_background_ocr ? 'Enabled' : 'Disabled'} + Min Confidence: {debugInfo.user_settings?.ocr_min_confidence || 'N/A'}% + Max File Size: {debugInfo.user_settings?.max_file_size_mb || 'N/A'} MB Quality Thresholds - Brightness: {debugInfo.user_settings.quality_thresholds.brightness} - Contrast: {debugInfo.user_settings.quality_thresholds.contrast} - Noise: {debugInfo.user_settings.quality_thresholds.noise} - Sharpness: {debugInfo.user_settings.quality_thresholds.sharpness} + Brightness: {debugInfo.user_settings?.quality_thresholds?.brightness || 'N/A'} + Contrast: {debugInfo.user_settings?.quality_thresholds?.contrast || 'N/A'} + Noise: {debugInfo.user_settings?.quality_thresholds?.noise || 'N/A'} + Sharpness: {debugInfo.user_settings?.quality_thresholds?.sharpness || 'N/A'} diff --git a/frontend/src/pages/__tests__/DebugPage.test.tsx b/frontend/src/pages/__tests__/DebugPage.test.tsx new file mode 100644 index 0000000..5a1d570 --- /dev/null +++ b/frontend/src/pages/__tests__/DebugPage.test.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { BrowserRouter } from 'react-router-dom'; +import { vi } from 'vitest'; +import DebugPage from '../DebugPage'; + +// Mock the API +vi.mock('../../services/api', () => ({ + api: { + get: vi.fn(), + post: vi.fn(), + put: vi.fn(), + delete: vi.fn(), + }, +})); + +const renderDebugPage = () => { + return render( + + + + ); +}; + +describe('DebugPage', () => { + it('renders without crashing', () => { + renderDebugPage(); + expect(screen.getByText('Upload & Debug')).toBeInTheDocument(); + }); + + it('handles undefined debugInfo without errors', () => { + renderDebugPage(); + // Should not throw any errors when debugInfo is null + expect(screen.getByText('Upload & Debug')).toBeInTheDocument(); + }); + + it('handles undefined nested properties without errors', () => { + // This test would check that all the optional chaining we added works correctly + renderDebugPage(); + expect(screen.getByText('Upload & Debug')).toBeInTheDocument(); + }); +}); \ No newline at end of file