1 import { act, renderHook } from '@testing-library/react-hooks';
3 import { TransferState } from '../../../components/TransferManager/transfer';
4 import { mockGlobalFile, testFile } from '../../../utils/test/file';
5 import type { UploadFileList } from '../interface';
6 import type { FileUpload, FolderUpload } from './interface';
7 import useUploadQueue from './useUploadQueue';
9 describe("useUploadQueue' attributes", () => {
10 const mockLogCallback = jest.fn();
15 fileUploads: FileUpload[];
16 folderUploads: FolderUpload[];
17 allUploads: (FileUpload | FolderUpload)[];
18 add: (shareId: string, parentId: string, fileList: UploadFileList) => void;
24 const { result } = renderHook(() => useUploadQueue(mockLogCallback));
28 it('returns empty queue', () => {
29 expect(hook.current.hasUploads).toBe(false);
30 expect(hook.current.fileUploads).toMatchObject([]);
31 expect(hook.current.folderUploads).toMatchObject([]);
32 expect(hook.current.allUploads).toMatchObject([]);
35 it('returns folder only', () => {
37 hook.current.add('shareId', 'parentId', [{ path: [], folder: 'folder' }]);
40 const expectedFolder = {
41 // We don't check ID and startDate.
44 state: TransferState.Pending,
55 expect(hook.current.hasUploads).toBe(true);
56 expect(hook.current.fileUploads).toMatchObject([]);
57 expect(hook.current.folderUploads).toMatchObject([expectedFolder]);
58 expect(hook.current.allUploads).toMatchObject([expectedFolder]);
61 it('returns file only', () => {
62 const file = testFile('file.txt');
63 const dsStore = testFile('.DS_Store');
65 hook.current.add('shareId', 'parentId', [
67 { path: [], file: dsStore }, // .DS_Store files are ignored.
71 const expectedFile = {
72 // We don't check ID and startDate.
75 state: TransferState.Pending,
84 expect(hook.current.hasUploads).toBe(true);
85 expect(hook.current.fileUploads).toMatchObject([expectedFile]);
86 expect(hook.current.folderUploads).toMatchObject([]);
87 expect(hook.current.allUploads).toMatchObject([expectedFile]);
90 it('returns both files and folders', () => {
91 const file = testFile('file.txt');
93 hook.current.add('shareId', 'parentId', [
94 { path: [], folder: 'folder' },
95 { path: ['folder'], file },
99 expect(hook.current.hasUploads).toBe(true);
100 expect(hook.current.fileUploads).toMatchObject([
102 state: TransferState.Initializing,
106 expect(hook.current.folderUploads).toMatchObject([
108 state: TransferState.Pending,
109 parentId: 'parentId',
110 files: [{ meta: { filename: 'file.txt' } }],
113 expect(hook.current.allUploads.length).toBe(2);