mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-13 13:06:09 +08:00
Mock requests
This commit is contained in:
parent
0a6475cb0d
commit
e6b1ba6a28
@ -1,5 +1,79 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Upload List handle error 1`] = `
|
||||||
|
<span
|
||||||
|
class=""
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-upload ant-upload-select ant-upload-select-text"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="ant-upload"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
accept=""
|
||||||
|
style="display: none;"
|
||||||
|
type="file"
|
||||||
|
/>
|
||||||
|
<button>
|
||||||
|
upload
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="ant-upload-list ant-upload-list-text"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-upload-list-item ant-upload-list-item-error"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-upload-list-item-info"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<i
|
||||||
|
class="anticon anticon-paper-clip"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
class="ant-upload-list-item-name"
|
||||||
|
title="foo.png"
|
||||||
|
>
|
||||||
|
foo.png
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<i
|
||||||
|
class="anticon anticon-cross"
|
||||||
|
title="删除文件"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="ant-upload-list-item-progress fade-leave"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-progress ant-progress-line ant-progress-status-normal"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="ant-progress-outer"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-progress-inner"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-progress-bg"
|
||||||
|
style="width: 0%; height: 2px;"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Upload List should be uploading when upload a file 1`] = `
|
exports[`Upload List should be uploading when upload a file 1`] = `
|
||||||
<span
|
<span
|
||||||
class=""
|
class=""
|
||||||
@ -100,7 +174,7 @@ exports[`Upload List should be uploading when upload a file 2`] = `
|
|||||||
class="ant-upload-list ant-upload-list-text"
|
class="ant-upload-list ant-upload-list-text"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-upload-list-item ant-upload-list-item-error"
|
class="ant-upload-list-item ant-upload-list-item-done"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-upload-list-item-info"
|
class="ant-upload-list-item-info"
|
||||||
|
11
components/upload/__tests__/requests.js
Normal file
11
components/upload/__tests__/requests.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export const successRequest = ({ onSuccess, file }) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
onSuccess(null, file);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const errorRequest = ({ onError }) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
onError();
|
||||||
|
});
|
||||||
|
};
|
@ -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();
|
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={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();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
wrapper = mount(
|
||||||
|
<Upload
|
||||||
|
action="http://jsonplaceholder.typicode.com/posts/"
|
||||||
|
onChange={onChange}
|
||||||
|
customRequest={errorRequest}
|
||||||
|
>
|
||||||
<button>upload</button>
|
<button>upload</button>
|
||||||
</Upload>
|
</Upload>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user