mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 11:40:04 +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);
|
||||
if (result === false) {
|
||||
this.onChange({
|
||||
file: fileToObject(file),
|
||||
file,
|
||||
fileList: uniqBy(fileList.map(fileToObject).concat(this.state.fileList), (item: UploadFile) => item.uid),
|
||||
});
|
||||
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 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,
|
||||
],
|
||||
},
|
||||
});
|
||||
|
@ -16,7 +16,7 @@ export interface UploadFile {
|
||||
name: string;
|
||||
filename?: string;
|
||||
lastModified?: number;
|
||||
lastModifiedDate?: Date;
|
||||
lastModrcFlieifiedDate?: Date;
|
||||
url?: string;
|
||||
status?: UploadFileStatus;
|
||||
percent?: number;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user