Skip to content

Commit

Permalink
feat: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
huiliangShen committed Aug 1, 2024
1 parent f486feb commit 4101c75
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/uploader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 4101c75

Please sign in to comment.