From c878a5a860ab2f08ecf7180234983680a518405c Mon Sep 17 00:00:00 2001 From: perf3ct Date: Wed, 2 Jul 2025 00:18:21 +0000 Subject: [PATCH] fix(tests): resolve broken frontend tests due to retry functionality --- .../src/components/RetryRecommendations.tsx | 8 ++++---- ...umentManagementPage.runtime-errors.test.tsx | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/RetryRecommendations.tsx b/frontend/src/components/RetryRecommendations.tsx index 5950c96..6f230d9 100644 --- a/frontend/src/components/RetryRecommendations.tsx +++ b/frontend/src/components/RetryRecommendations.tsx @@ -92,7 +92,7 @@ export const RetryRecommendations: React.FC = ({ return `${percentage}% (Low)`; }; - if (loading && recommendations.length === 0) { + if (loading && (!recommendations || recommendations.length === 0)) { return ( @@ -138,7 +138,7 @@ export const RetryRecommendations: React.FC = ({ )} - {recommendations.length === 0 && !loading ? ( + {(!recommendations || recommendations.length === 0) && !loading ? ( No retry recommendations available. This usually means: @@ -151,7 +151,7 @@ export const RetryRecommendations: React.FC = ({ ) : ( - {recommendations.map((recommendation, index) => ( + {(recommendations || []).map((recommendation, index) => ( @@ -236,7 +236,7 @@ export const RetryRecommendations: React.FC = ({ )} - {loading && recommendations.length > 0 && ( + {loading && recommendations && recommendations.length > 0 && ( )} diff --git a/frontend/src/pages/__tests__/DocumentManagementPage.runtime-errors.test.tsx b/frontend/src/pages/__tests__/DocumentManagementPage.runtime-errors.test.tsx index 754cc1c..4203137 100644 --- a/frontend/src/pages/__tests__/DocumentManagementPage.runtime-errors.test.tsx +++ b/frontend/src/pages/__tests__/DocumentManagementPage.runtime-errors.test.tsx @@ -14,6 +14,9 @@ const mockDocumentService = { deleteLowConfidence: vi.fn(), deleteFailedOcr: vi.fn(), downloadFile: vi.fn(), + getRetryRecommendations: vi.fn(), + getRetryStats: vi.fn(), + getDocumentRetryHistory: vi.fn(), }; const mockQueueService = { @@ -23,6 +26,7 @@ const mockQueueService = { const mockApi = { get: vi.fn(), delete: vi.fn(), + bulkRetryOcr: vi.fn(), }; // Mock API with comprehensive responses @@ -51,6 +55,20 @@ describe('DocumentManagementPage - Runtime Error Prevention', () => { mockDocumentService.getFailedOcrDocuments.mockClear(); mockDocumentService.getDuplicates.mockClear(); mockQueueService.requeueFailed.mockClear(); + + // Setup default mock returns for retry functionality + mockDocumentService.getRetryRecommendations.mockResolvedValue({ + data: { recommendations: [], total_recommendations: 0 } + }); + mockDocumentService.getRetryStats.mockResolvedValue({ + data: { failure_reasons: [], file_types: [], total_failed: 0 } + }); + mockDocumentService.getDocumentRetryHistory.mockResolvedValue({ + data: { document_id: 'test', retry_history: [], total_retries: 0 } + }); + mockApi.bulkRetryOcr.mockResolvedValue({ + data: { success: true, queued_count: 0, matched_count: 0, documents: [] } + }); }); describe('OCR Confidence Display - Null Safety', () => {