|
@ -1,6 +1,7 @@ |
|
|
import React from 'react'; |
|
|
import React from 'react'; |
|
|
import { mount } from 'enzyme'; |
|
|
import { mount } from 'enzyme'; |
|
|
import Upload from '..'; |
|
|
import Upload from '..'; |
|
|
|
|
|
import { errorRequest, successRequest } from './requests'; |
|
|
|
|
|
|
|
|
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout)); |
|
|
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout)); |
|
|
|
|
|
|
|
@ -62,23 +63,47 @@ describe('Upload List', () => { |
|
|
|
|
|
|
|
|
it('should be uploading when upload a file', (done) => { |
|
|
it('should be uploading when upload a file', (done) => { |
|
|
let wrapper; |
|
|
let wrapper; |
|
|
let finished; |
|
|
|
|
|
const onChange = ({ file }) => { |
|
|
const onChange = ({ file }) => { |
|
|
if (finished) { |
|
|
|
|
|
done(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (file.status === 'uploading') { |
|
|
if (file.status === 'uploading') { |
|
|
expect(wrapper.render()).toMatchSnapshot(); |
|
|
expect(wrapper.render()).toMatchSnapshot(); |
|
|
} |
|
|
} |
|
|
if (file.status === 'error') { |
|
|
if (file.status === 'done') { |
|
|
|
|
|
expect(wrapper.render()).toMatchSnapshot(); |
|
|
|
|
|
done(); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
wrapper = mount( |
|
|
|
|
|
<Upload |
|
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/" |
|
|
|
|
|
onChange={onChange} |
|
|
|
|
|
customRequest={successRequest} |
|
|
|
|
|
> |
|
|
|
|
|
<button>upload</button> |
|
|
|
|
|
</Upload> |
|
|
|
|
|
); |
|
|
|
|
|
wrapper.find('input').simulate('change', { |
|
|
|
|
|
target: { |
|
|
|
|
|
files: [ |
|
|
|
|
|
{ filename: 'foo.png' }, |
|
|
|
|
|
], |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handle error', (done) => { |
|
|
|
|
|
let wrapper; |
|
|
|
|
|
const onChange = ({ file }) => { |
|
|
|
|
|
if (file.status !== 'uploading') { |
|
|
expect(wrapper.render()).toMatchSnapshot(); |
|
|
expect(wrapper.render()).toMatchSnapshot(); |
|
|
finished = true; |
|
|
|
|
|
done(); |
|
|
done(); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
wrapper = mount( |
|
|
wrapper = mount( |
|
|
<Upload action="http://jsonplaceholder.typicode.com/posts/" onChange={onChange}> |
|
|
<Upload |
|
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/" |
|
|
|
|
|
onChange={onChange} |
|
|
|
|
|
customRequest={errorRequest} |
|
|
|
|
|
> |
|
|
<button>upload</button> |
|
|
<button>upload</button> |
|
|
</Upload> |
|
|
</Upload> |
|
|
); |
|
|
); |
|
|