fix(tests): resolve broken frontend tests due to retry functionality

This commit is contained in:
perf3ct 2025-07-02 00:18:21 +00:00
parent 4279823268
commit 9004633d68
2 changed files with 22 additions and 4 deletions

View File

@ -92,7 +92,7 @@ export const RetryRecommendations: React.FC<RetryRecommendationsProps> = ({
return `${percentage}% (Low)`;
};
if (loading && recommendations.length === 0) {
if (loading && (!recommendations || recommendations.length === 0)) {
return (
<Card>
<CardContent>
@ -138,7 +138,7 @@ export const RetryRecommendations: React.FC<RetryRecommendationsProps> = ({
</Alert>
)}
{recommendations.length === 0 && !loading ? (
{(!recommendations || recommendations.length === 0) && !loading ? (
<Alert severity="info">
<Typography variant="body2">
No retry recommendations available. This usually means:
@ -151,7 +151,7 @@ export const RetryRecommendations: React.FC<RetryRecommendationsProps> = ({
</Alert>
) : (
<Stack spacing={2}>
{recommendations.map((recommendation, index) => (
{(recommendations || []).map((recommendation, index) => (
<Card key={recommendation.reason} variant="outlined">
<CardContent>
<Box display="flex" justifyContent="space-between" alignItems="flex-start" mb={1}>
@ -236,7 +236,7 @@ export const RetryRecommendations: React.FC<RetryRecommendationsProps> = ({
</Stack>
)}
{loading && recommendations.length > 0 && (
{loading && recommendations && recommendations.length > 0 && (
<LinearProgress sx={{ mt: 2 }} />
)}
</CardContent>

View File

@ -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', () => {