diff --git a/packages/react/src/components/FileUploader/FileUploader-test.js b/packages/react/src/components/FileUploader/FileUploader-test.js index b5ef7ed38c97..367dc88e217a 100644 --- a/packages/react/src/components/FileUploader/FileUploader-test.js +++ b/packages/react/src/components/FileUploader/FileUploader-test.js @@ -255,8 +255,20 @@ describe('FileUploader', () => { }); describe('FileUploaderDropContainer', () => { - const dropContainer = ; - const mountWrapper = mount(dropContainer); + let onAddFiles; + let dropContainer; + let mountWrapper; + + beforeEach(() => { + onAddFiles = jest.fn(); + dropContainer = ( + + ); + mountWrapper = mount(dropContainer); + }); describe('Renders as expected with default props', () => { it('renders with given className', () => { @@ -293,6 +305,24 @@ describe('FileUploaderDropContainer', () => { expect(evt.target.value).toEqual(null); }); + + it('should call `onAddFiles` when a file is selected', () => { + const fileFoo = new File(['foo'], 'foo.txt', { type: 'text/plain' }); + const fileBar = new File(['bar'], 'bar.txt', { type: 'text/plain' }); + const mockFiles = [fileFoo, fileBar]; + const input = mountWrapper.find(`.${prefix}--file-input`); + const evt = { target: { files: mockFiles } }; + input.simulate('change', evt); + expect(onAddFiles).toHaveBeenCalledTimes(1); + expect(onAddFiles).toHaveBeenCalledWith( + expect.objectContaining({ + target: { + files: [fileFoo, fileBar], + }, + }), + { addedFiles: [fileFoo, fileBar] } + ); + }); }); describe('Unique id props', () => { diff --git a/packages/react/src/components/FileUploader/FileUploaderDropContainer.js b/packages/react/src/components/FileUploader/FileUploaderDropContainer.js index 22c0b2b25921..17410bb84b9d 100644 --- a/packages/react/src/components/FileUploader/FileUploaderDropContainer.js +++ b/packages/react/src/components/FileUploader/FileUploaderDropContainer.js @@ -43,8 +43,8 @@ export default function FileUploaderDropContainer(props) { * @param {Event} evt - Event object, used to get the list of files added */ const validateFiles = evt => { - const transferredFiles = [...evt.dataTransfer.files]; if (evt.type === 'drop') { + const transferredFiles = [...evt.dataTransfer.files]; if (!accept.length) { return transferredFiles; }