From e7f6fd5e918109ba4c7091f8fa43b33b7222231c Mon Sep 17 00:00:00 2001 From: James Date: Thu, 7 Aug 2025 09:36:36 +0100 Subject: [PATCH] Tidy testing --- .../tools/sanitize/SanitizeSettings.test.tsx | 16 ++++++++-------- .../tools/sanitize/useSanitizeOperation.test.ts | 10 +++++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/tools/sanitize/SanitizeSettings.test.tsx b/frontend/src/components/tools/sanitize/SanitizeSettings.test.tsx index cf8e0c487..055de2466 100644 --- a/frontend/src/components/tools/sanitize/SanitizeSettings.test.tsx +++ b/frontend/src/components/tools/sanitize/SanitizeSettings.test.tsx @@ -59,7 +59,7 @@ describe('SanitizeSettings', () => { const checkboxes = screen.getAllByRole('checkbox'); const parameterValues = Object.values(defaultParameters); - + parameterValues.forEach((value, index) => { if (value) { expect(checkboxes[index]).toBeChecked(); @@ -80,7 +80,7 @@ describe('SanitizeSettings', () => { ); const checkboxes = screen.getAllByRole('checkbox'); - + // Click the first checkbox (removeJavaScript - should toggle from true to false) fireEvent.click(checkboxes[0]); expect(mockOnParameterChange).toHaveBeenCalledWith('removeJavaScript', false); @@ -160,9 +160,9 @@ describe('SanitizeSettings', () => { ); // Verify that translation keys are being called (just check that it was called, not specific order) - expect(mockT).toHaveBeenCalledWith('sanitize.options.title', 'Sanitization Options'); - expect(mockT).toHaveBeenCalledWith('sanitize.options.removeJavaScript', 'Remove JavaScript'); - expect(mockT).toHaveBeenCalledWith('sanitize.options.removeEmbeddedFiles', 'Remove Embedded Files'); + expect(mockT).toHaveBeenCalledWith('sanitize.options.title', expect.any(String)); + expect(mockT).toHaveBeenCalledWith('sanitize.options.removeJavaScript', expect.any(String)); + expect(mockT).toHaveBeenCalledWith('sanitize.options.removeEmbeddedFiles', expect.any(String)); expect(mockT).toHaveBeenCalledWith('sanitize.options.note', expect.any(String)); }); @@ -178,12 +178,12 @@ describe('SanitizeSettings', () => { ); const checkboxes = screen.getAllByRole('checkbox'); - + // Verify checkboxes are disabled checkboxes.forEach(checkbox => { expect(checkbox).toBeDisabled(); }); - + // Try to click a disabled checkbox - this might still fire the event in tests // but we can verify the checkbox state doesn't actually change const firstCheckbox = checkboxes[0] as HTMLInputElement; @@ -191,4 +191,4 @@ describe('SanitizeSettings', () => { fireEvent.click(firstCheckbox); expect(firstCheckbox.checked).toBe(initialChecked); }); -}); \ No newline at end of file +}); diff --git a/frontend/src/hooks/tools/sanitize/useSanitizeOperation.test.ts b/frontend/src/hooks/tools/sanitize/useSanitizeOperation.test.ts index 26c924dcf..f6e267fec 100644 --- a/frontend/src/hooks/tools/sanitize/useSanitizeOperation.test.ts +++ b/frontend/src/hooks/tools/sanitize/useSanitizeOperation.test.ts @@ -32,11 +32,15 @@ vi.mock('../../../contexts/FileContext', () => ({ // Mock fetch const mockFetch = vi.fn(); -globalThis.fetch = mockFetch; +vi.stubGlobal('fetch', mockFetch); // Mock URL.createObjectURL and revokeObjectURL -globalThis.URL.createObjectURL = vi.fn(() => 'mock-blob-url'); -globalThis.URL.revokeObjectURL = vi.fn(); +const mockCreateObjectURL = vi.fn(() => 'mock-blob-url'); +const mockRevokeObjectURL = vi.fn(); +vi.stubGlobal('URL', { + createObjectURL: mockCreateObjectURL, + revokeObjectURL: mockRevokeObjectURL +}); describe('useSanitizeOperation', () => { const mockGenerateSanitizedFileName = (originalFileName?: string): string => {