diff --git a/tests/uploader.spec.tsx b/tests/uploader.spec.tsx index ba3e47d..8850f54 100644 --- a/tests/uploader.spec.tsx +++ b/tests/uploader.spec.tsx @@ -37,12 +37,45 @@ const makeFileSystemEntry = item => { return ret; }; +const makeFileSystemEntryAsync = item => { + const isDirectory = Array.isArray(item.children); + const ret = { + isDirectory, + isFile: !isDirectory, + file: handle => { + handle(new Item(item.name)); + }, + createReader: () => { + let first = true; + return { + async readEntries(handle) { + await sleep(100); + + if (!first) { + return handle([]); + } + + first = false; + return handle(item.children.map(makeFileSystemEntry)); + }, + }; + }, + }; + return ret; +}; + const makeDataTransferItem = item => { return { webkitGetAsEntry: () => makeFileSystemEntry(item), }; }; +const makeDataTransferItemAsync = item => { + return { + webkitGetAsEntry: () => makeFileSystemEntryAsync(item), + }; +}; + describe('uploader', () => { let requests; let xhr; @@ -462,6 +495,46 @@ describe('uploader', () => { }, 100); }); + it('dragging and dropping files to upload through asynchronous file reading is run normal', done => { + const input = uploader.container.querySelector('input')!; + + const files = { + name: 'foo', + children: [ + { + name: 'bar', + children: [ + { + name: '1.png', + }, + { + name: '2.png', + }, + { + name: 'rc', + children: [ + { + name: '5.webp', + }, + { + name: '4.webp', + }, + ], + }, + ], + }, + ], + }; + fireEvent.drop(input, { dataTransfer: { items: [makeDataTransferItemAsync(files)] } }); + const mockStart = jest.fn(); + handlers.onStart = mockStart; + + setTimeout(() => { + expect(mockStart.mock.calls.length).toBe(2); + done(); + }, 500); + }); + it('unaccepted type files to upload will not trigger onStart when select directory', done => { const input = uploader.container.querySelector('input')!; const files = [