mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-22 04:09:22 +00:00
Fix unit tests
This commit is contained in:
parent
e378e27c60
commit
d44ba30a30
@ -358,6 +358,9 @@ export const useConvertOperation = (): ConvertOperationHook => {
|
|||||||
setDownloadFilename(convertedFile.name);
|
setDownloadFilename(convertedFile.name);
|
||||||
setStatus(t("downloadComplete"));
|
setStatus(t("downloadComplete"));
|
||||||
|
|
||||||
|
// Update local files state for hook consumers
|
||||||
|
setFiles([convertedFile]);
|
||||||
|
|
||||||
await addFiles([convertedFile]);
|
await addFiles([convertedFile]);
|
||||||
markOperationApplied(fileId, operationId);
|
markOperationApplied(fileId, operationId);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -23,13 +23,31 @@ import axios from 'axios';
|
|||||||
vi.mock('axios');
|
vi.mock('axios');
|
||||||
const mockedAxios = vi.mocked(axios);
|
const mockedAxios = vi.mocked(axios);
|
||||||
|
|
||||||
// Mock utility modules
|
// Mock only essential services that are actually called by the tests
|
||||||
vi.mock('../../utils/thumbnailUtils', () => ({
|
vi.mock('../../services/fileStorage', () => ({
|
||||||
generateThumbnailForFile: vi.fn().mockResolvedValue('data:image/png;base64,fake-thumbnail')
|
fileStorage: {
|
||||||
|
init: vi.fn().mockResolvedValue(undefined),
|
||||||
|
storeFile: vi.fn().mockImplementation((file, thumbnail) => {
|
||||||
|
return Promise.resolve({
|
||||||
|
id: `mock-id-${file.name}`,
|
||||||
|
name: file.name,
|
||||||
|
size: file.size,
|
||||||
|
type: file.type,
|
||||||
|
lastModified: file.lastModified,
|
||||||
|
thumbnail: thumbnail
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
getAllFileMetadata: vi.fn().mockResolvedValue([]),
|
||||||
|
cleanup: vi.fn().mockResolvedValue(undefined)
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('../../utils/api', () => ({
|
vi.mock('../../services/thumbnailGenerationService', () => ({
|
||||||
makeApiUrl: vi.fn((path: string) => `/api/v1${path}`)
|
thumbnailGenerationService: {
|
||||||
|
generateThumbnail: vi.fn().mockResolvedValue('data:image/png;base64,fake-thumbnail'),
|
||||||
|
cleanup: vi.fn(),
|
||||||
|
destroy: vi.fn()
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Create realistic test files
|
// Create realistic test files
|
||||||
@ -194,7 +212,14 @@ describe('Convert Tool Integration Tests', () => {
|
|||||||
|
|
||||||
test('should correctly map image conversion parameters to API call', async () => {
|
test('should correctly map image conversion parameters to API call', async () => {
|
||||||
const mockBlob = new Blob(['fake-data'], { type: 'image/jpeg' });
|
const mockBlob = new Blob(['fake-data'], { type: 'image/jpeg' });
|
||||||
mockedAxios.post.mockResolvedValueOnce({ data: mockBlob });
|
mockedAxios.post.mockResolvedValueOnce({
|
||||||
|
data: mockBlob,
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'content-type': 'image/jpeg',
|
||||||
|
'content-disposition': 'attachment; filename="test_converted.jpg"'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const { result } = renderHook(() => useConvertOperation(), {
|
const { result } = renderHook(() => useConvertOperation(), {
|
||||||
wrapper: TestWrapper
|
wrapper: TestWrapper
|
||||||
@ -472,7 +497,14 @@ describe('Convert Tool Integration Tests', () => {
|
|||||||
|
|
||||||
test('should record operation in FileContext', async () => {
|
test('should record operation in FileContext', async () => {
|
||||||
const mockBlob = new Blob(['fake-data'], { type: 'image/png' });
|
const mockBlob = new Blob(['fake-data'], { type: 'image/png' });
|
||||||
mockedAxios.post.mockResolvedValueOnce({ data: mockBlob });
|
mockedAxios.post.mockResolvedValueOnce({
|
||||||
|
data: mockBlob,
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'content-type': 'image/png',
|
||||||
|
'content-disposition': 'attachment; filename="test_converted.png"'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const { result } = renderHook(() => useConvertOperation(), {
|
const { result } = renderHook(() => useConvertOperation(), {
|
||||||
wrapper: TestWrapper
|
wrapper: TestWrapper
|
||||||
@ -506,7 +538,14 @@ describe('Convert Tool Integration Tests', () => {
|
|||||||
|
|
||||||
test('should clean up blob URLs on reset', async () => {
|
test('should clean up blob URLs on reset', async () => {
|
||||||
const mockBlob = new Blob(['fake-data'], { type: 'image/png' });
|
const mockBlob = new Blob(['fake-data'], { type: 'image/png' });
|
||||||
mockedAxios.post.mockResolvedValueOnce({ data: mockBlob });
|
mockedAxios.post.mockResolvedValueOnce({
|
||||||
|
data: mockBlob,
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'content-type': 'image/png',
|
||||||
|
'content-disposition': 'attachment; filename="test_converted.png"'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const { result } = renderHook(() => useConvertOperation(), {
|
const { result } = renderHook(() => useConvertOperation(), {
|
||||||
wrapper: TestWrapper
|
wrapper: TestWrapper
|
||||||
|
@ -18,9 +18,31 @@ import { detectFileExtension } from '../../utils/fileUtils';
|
|||||||
vi.mock('axios');
|
vi.mock('axios');
|
||||||
const mockedAxios = vi.mocked(axios);
|
const mockedAxios = vi.mocked(axios);
|
||||||
|
|
||||||
// Mock utility modules
|
// Mock only essential services that are actually called by the tests
|
||||||
vi.mock('../../utils/thumbnailUtils', () => ({
|
vi.mock('../../services/fileStorage', () => ({
|
||||||
generateThumbnailForFile: vi.fn().mockResolvedValue('data:image/png;base64,fake-thumbnail')
|
fileStorage: {
|
||||||
|
init: vi.fn().mockResolvedValue(undefined),
|
||||||
|
storeFile: vi.fn().mockImplementation((file, thumbnail) => {
|
||||||
|
return Promise.resolve({
|
||||||
|
id: `mock-id-${file.name}`,
|
||||||
|
name: file.name,
|
||||||
|
size: file.size,
|
||||||
|
type: file.type,
|
||||||
|
lastModified: file.lastModified,
|
||||||
|
thumbnail: thumbnail
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
getAllFileMetadata: vi.fn().mockResolvedValue([]),
|
||||||
|
cleanup: vi.fn().mockResolvedValue(undefined)
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock('../../services/thumbnailGenerationService', () => ({
|
||||||
|
thumbnailGenerationService: {
|
||||||
|
generateThumbnail: vi.fn().mockResolvedValue('data:image/png;base64,fake-thumbnail'),
|
||||||
|
cleanup: vi.fn(),
|
||||||
|
destroy: vi.fn()
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user