mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
Merge branch 'master' of github.com:ant-design/ant-design
This commit is contained in:
commit
8b64882562
@ -195,7 +195,7 @@ export default class Upload extends React.Component<UploadProps, UploadState> {
|
|||||||
const result = this.props.beforeUpload(file, fileList);
|
const result = this.props.beforeUpload(file, fileList);
|
||||||
if (result === false) {
|
if (result === false) {
|
||||||
this.onChange({
|
this.onChange({
|
||||||
file: fileToObject(file),
|
file,
|
||||||
fileList: uniqBy(fileList.map(fileToObject).concat(this.state.fileList), (item: UploadFile) => item.uid),
|
fileList: uniqBy(fileList.map(fileToObject).concat(this.state.fileList), (item: UploadFile) => item.uid),
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
@ -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 data = jest.fn();
|
||||||
const props = {
|
const props = {
|
||||||
action: 'http://upload.com',
|
action: 'http://upload.com',
|
||||||
beforeUpload: () => false,
|
beforeUpload: () => false,
|
||||||
data,
|
data,
|
||||||
onChange: () => {
|
onChange: ({ file }) => {
|
||||||
|
expect(file instanceof File).toBe(true);
|
||||||
expect(data).not.toBeCalled();
|
expect(data).not.toBeCalled();
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
@ -75,7 +79,7 @@ describe('Upload', () => {
|
|||||||
wrapper.find('input').simulate('change', {
|
wrapper.find('input').simulate('change', {
|
||||||
target: {
|
target: {
|
||||||
files: [
|
files: [
|
||||||
{ file: 'foo.png' },
|
mockFile,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -16,7 +16,7 @@ export interface UploadFile {
|
|||||||
name: string;
|
name: string;
|
||||||
filename?: string;
|
filename?: string;
|
||||||
lastModified?: number;
|
lastModified?: number;
|
||||||
lastModifiedDate?: Date;
|
lastModrcFlieifiedDate?: Date;
|
||||||
url?: string;
|
url?: string;
|
||||||
status?: UploadFileStatus;
|
status?: UploadFileStatus;
|
||||||
percent?: number;
|
percent?: number;
|
||||||
|
@ -8,13 +8,8 @@ export function T() {
|
|||||||
// via coping a new Object
|
// via coping a new Object
|
||||||
export function fileToObject(file: RcFile): UploadFile {
|
export function fileToObject(file: RcFile): UploadFile {
|
||||||
return {
|
return {
|
||||||
lastModified: file.lastModified,
|
...file,
|
||||||
lastModifiedDate: file.lastModifiedDate,
|
|
||||||
name: file.name,
|
|
||||||
size: file.size,
|
|
||||||
type: file.type,
|
|
||||||
percent: 0,
|
percent: 0,
|
||||||
uid: file.uid,
|
|
||||||
originFileObj: file,
|
originFileObj: file,
|
||||||
} as UploadFile;
|
} as UploadFile;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user