Skip to content

Commit

Permalink
fix: still keep order when upload fails (ant-design#10794)
Browse files Browse the repository at this point in the history
  • Loading branch information
picodoth authored Jun 6, 2018
1 parent 6602df1 commit e1ba74e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default class Upload extends React.Component<UploadProps, UploadState> {
if (result === false) {
this.onChange({
file,
fileList: uniqBy(fileList.map(fileToObject).concat(this.state.fileList), (item: UploadFile) => item.uid),
fileList: uniqBy(this.state.fileList.concat(fileList.map(fileToObject)), (item: UploadFile) => item.uid),
});
return false;
} else if (result && (result as PromiseLike<any>).then) {
Expand Down
8 changes: 7 additions & 1 deletion components/upload/__tests__/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,22 @@ describe('Upload', () => {
});

it('should not stop upload when return value of beforeUpload is false', (done) => {
const fileList = [{
uid: 'bar',
name: 'bar.png',
}];
const mockFile = new File(['foo'], 'foo.png', {
type: 'image/png',
});
const data = jest.fn();
const props = {
action: 'http://upload.com',
fileList,
beforeUpload: () => false,
data,
onChange: ({ file }) => {
onChange: ({ file, fileList: updatedFileList }) => {
expect(file instanceof File).toBe(true);
expect(updatedFileList.map(f => f.name)).toEqual(['bar.png', 'foo.png']);
expect(data).not.toBeCalled();
done();
},
Expand Down

0 comments on commit e1ba74e

Please sign in to comment.