Skip to content

Commit

Permalink
fix(FileUploaderDropContainer): fix NPE selecting file
Browse files Browse the repository at this point in the history
Fixes #4899.
  • Loading branch information
asudoh committed Dec 23, 2019
1 parent bbee3c4 commit 89c7a24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion packages/react/src/components/FileUploader/FileUploader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ describe('FileUploader', () => {
});

describe('FileUploaderDropContainer', () => {
const dropContainer = <FileUploaderDropContainer className="extra-class" />;
const onAddFiles = jest.fn();
const dropContainer = (
<FileUploaderDropContainer
className="extra-class"
onAddFiles={onAddFiles}
/>
);
const mountWrapper = mount(dropContainer);

describe('Renders as expected with default props', () => {
Expand Down Expand Up @@ -293,6 +299,20 @@ describe('FileUploaderDropContainer', () => {

expect(evt.target.value).toEqual(null);
});

it('does the right thing', () => {
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.mock.calls[0][0].target.files).toEqual([
fileFoo,
fileBar,
]);
});
});

describe('Unique id props', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 89c7a24

Please sign in to comment.