fix autoUpdateProgress percent and add test case

This commit is contained in:
afc163 2018-05-22 15:36:25 +08:00 committed by 偏右
parent 77301c378f
commit 89ed0dcb35
3 changed files with 39 additions and 2 deletions

View File

@ -79,7 +79,7 @@ export default class Upload extends React.Component<UploadProps, UploadState> {
this.progressTimer = setInterval(() => {
curPercent = getPercent(curPercent);
this.onProgress({
percent: curPercent,
percent: curPercent * 100,
}, file);
}, 200);
}

View File

@ -86,6 +86,43 @@ describe('Upload', () => {
});
});
it('should increase percent automaticly when call autoUpdateProgress in IE', (done) => {
let uploadInstance;
let lastPercent = -1;
const props = {
action: 'http://jsonplaceholder.typicode.com/posts/',
onChange: ({ file }) => {
if (file.percent === 0 && file.status === 'uploading') {
// manually call it
uploadInstance.autoUpdateProgress(0, file);
}
if (file.status === 'uploading') {
expect(file.percent).toBeGreaterThan(lastPercent);
lastPercent = file.percent;
}
if (file.status === 'done' || file.status === 'error') {
done();
}
},
};
const wrapper = mount(
<Upload {...props}>
<button>upload</button>
</Upload>
);
wrapper.find('input').simulate('change', {
target: {
files: [
{ file: 'foo.png' },
],
},
});
uploadInstance = wrapper.instance();
});
it('should not stop upload when return value of beforeUpload is not false', (done) => {
const data = jest.fn();
const props = {

View File

@ -39,7 +39,7 @@ export function genPercentAdd() {
if (k < 0.001) {
k = 0.001;
}
return start * 100;
return start;
};
}