Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/modules/pdf-forge/store/usePdfStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import { usePdfStore } from './usePdfStore';
import { usePdfStore, toBlob } from './usePdfStore';

// Mock pdf-lib
vi.mock('pdf-lib', () => {
Expand Down Expand Up @@ -52,6 +52,26 @@ describe('usePdfStore', () => {
vi.restoreAllMocks();
});

describe('toBlob', () => {
it('should convert a Uint8Array to a Blob with application/pdf type', () => {
const data = new Uint8Array([1, 2, 3, 4]);
const blob = toBlob(data);

expect(blob).toBeInstanceOf(Blob);
expect(blob.type).toBe('application/pdf');
expect(blob.size).toBe(4);
});

it('should handle an empty Uint8Array correctly', () => {
const emptyData = new Uint8Array([]);
const blob = toBlob(emptyData);

expect(blob).toBeInstanceOf(Blob);
expect(blob.type).toBe('application/pdf');
expect(blob.size).toBe(0);
});
});

it('should have initial state', () => {
const state = usePdfStore.getState();
expect(state.task.operation).toBe('merge');
Expand Down
2 changes: 1 addition & 1 deletion src/modules/pdf-forge/store/usePdfStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function loadPdfPages(file: File): Promise<PdfPage[]> {
}));
}

function toBlob(data: Uint8Array): Blob {
export function toBlob(data: Uint8Array): Blob {
return new Blob([data.buffer as ArrayBuffer], { type: 'application/pdf' });
}

Expand Down