Merge branch 'master' of github.com:ant-design/ant-design

This commit is contained in:
愚道 2018-04-28 11:10:54 +08:00
commit 8b64882562
4 changed files with 10 additions and 11 deletions

View File

@ -195,7 +195,7 @@ export default class Upload extends React.Component<UploadProps, UploadState> {
const result = this.props.beforeUpload(file, fileList);
if (result === false) {
this.onChange({
file: fileToObject(file),
file,
fileList: uniqBy(fileList.map(fileToObject).concat(this.state.fileList), (item: UploadFile) => item.uid),
});
return false;

View File

@ -54,13 +54,17 @@ describe('Upload', () => {
});
});
it('should not stop upload when return value of beforeUpload is not false', (done) => {
it('should not stop upload when return value of beforeUpload is false', (done) => {
const mockFile = new File(['foo'], 'foo.png', {
type: 'image/png',
});
const data = jest.fn();
const props = {
action: 'http://upload.com',
beforeUpload: () => false,
data,
onChange: () => {
onChange: ({ file }) => {
expect(file instanceof File).toBe(true);
expect(data).not.toBeCalled();
done();
},
@ -75,7 +79,7 @@ describe('Upload', () => {
wrapper.find('input').simulate('change', {
target: {
files: [
{ file: 'foo.png' },
mockFile,
],
},
});

View File

@ -16,7 +16,7 @@ export interface UploadFile {
name: string;
filename?: string;
lastModified?: number;
lastModifiedDate?: Date;
lastModrcFlieifiedDate?: Date;
url?: string;
status?: UploadFileStatus;
percent?: number;

View File

@ -8,13 +8,8 @@ export function T() {
// via coping a new Object
export function fileToObject(file: RcFile): UploadFile {
return {
lastModified: file.lastModified,
lastModifiedDate: file.lastModifiedDate,
name: file.name,
size: file.size,
type: file.type,
...file,
percent: 0,
uid: file.uid,
originFileObj: file,
} as UploadFile;
}