2017-01-24 14:59:39 +08:00
|
|
|
import React from 'react';
|
2020-08-29 21:28:44 +08:00
|
|
|
import { act } from 'react-dom/test-utils';
|
2017-01-24 14:59:39 +08:00
|
|
|
import Upload from '..';
|
2022-06-16 23:29:04 +08:00
|
|
|
import { fireEvent, render, sleep, waitFor } from '../../../tests/utils';
|
2017-11-29 20:28:19 +08:00
|
|
|
import Form from '../../form';
|
2022-06-16 23:29:04 +08:00
|
|
|
import UploadList from '../UploadList';
|
|
|
|
import { previewImage } from '../utils';
|
2018-05-31 22:37:09 +08:00
|
|
|
import { setup, teardown } from './mock';
|
2022-06-16 23:29:04 +08:00
|
|
|
import { errorRequest, successRequest } from './requests';
|
2017-08-20 15:39:02 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
const fileList = [
|
|
|
|
{
|
|
|
|
uid: '-1',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uid: '-2',
|
|
|
|
name: 'yyy.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
},
|
|
|
|
];
|
2017-01-24 14:59:39 +08:00
|
|
|
|
|
|
|
describe('Upload List', () => {
|
2020-09-07 16:41:28 +08:00
|
|
|
// Mock for rc-util raf
|
|
|
|
window.requestAnimationFrame = callback => {
|
|
|
|
window.setTimeout(callback, 16);
|
|
|
|
};
|
|
|
|
window.cancelAnimationFrame = id => {
|
|
|
|
window.clearTimeout(id);
|
|
|
|
};
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
// jsdom not support `createObjectURL` yet. Let's handle this.
|
|
|
|
const originCreateObjectURL = window.URL.createObjectURL;
|
|
|
|
window.URL.createObjectURL = jest.fn(() => '');
|
|
|
|
|
|
|
|
// Mock dom
|
|
|
|
let size = { width: 0, height: 0 };
|
|
|
|
function setSize(width, height) {
|
|
|
|
size = { width, height };
|
|
|
|
}
|
2020-04-22 11:59:56 +08:00
|
|
|
const mockWidthGet = jest.spyOn(Image.prototype, 'width', 'get');
|
|
|
|
const mockHeightGet = jest.spyOn(Image.prototype, 'height', 'get');
|
|
|
|
const mockSrcSet = jest.spyOn(Image.prototype, 'src', 'set');
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
|
|
let drawImageCallback = null;
|
|
|
|
function hookDrawImageCall(callback) {
|
|
|
|
drawImageCallback = callback;
|
|
|
|
}
|
2020-04-22 11:59:56 +08:00
|
|
|
const mockGetCanvasContext = jest.spyOn(HTMLCanvasElement.prototype, 'getContext');
|
|
|
|
const mockToDataURL = jest.spyOn(HTMLCanvasElement.prototype, 'toDataURL');
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
|
|
// HTMLCanvasElement.prototype
|
|
|
|
|
2018-05-31 22:37:09 +08:00
|
|
|
beforeEach(() => setup());
|
2019-05-06 12:04:39 +08:00
|
|
|
afterEach(() => {
|
|
|
|
teardown();
|
|
|
|
drawImageCallback = null;
|
|
|
|
});
|
|
|
|
|
2020-04-01 17:38:21 +08:00
|
|
|
let open;
|
|
|
|
beforeAll(() => {
|
|
|
|
open = jest.spyOn(window, 'open').mockImplementation(() => {});
|
2020-04-22 11:59:56 +08:00
|
|
|
mockWidthGet.mockImplementation(() => size.width);
|
|
|
|
mockHeightGet.mockImplementation(() => size.height);
|
|
|
|
mockSrcSet.mockImplementation(function fn() {
|
|
|
|
if (this.onload) {
|
|
|
|
this.onload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mockGetCanvasContext.mockReturnValue({
|
|
|
|
drawImage: (...args) => {
|
|
|
|
if (drawImageCallback) drawImageCallback(...args);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
mockToDataURL.mockReturnValue('data:image/png;base64,');
|
2020-04-01 17:38:21 +08:00
|
|
|
});
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
afterAll(() => {
|
|
|
|
window.URL.createObjectURL = originCreateObjectURL;
|
2020-04-22 11:59:56 +08:00
|
|
|
mockWidthGet.mockRestore();
|
|
|
|
mockHeightGet.mockRestore();
|
|
|
|
mockSrcSet.mockRestore();
|
|
|
|
mockGetCanvasContext.mockRestore();
|
|
|
|
mockToDataURL.mockRestore();
|
2020-04-01 17:38:21 +08:00
|
|
|
open.mockRestore();
|
2019-05-06 12:04:39 +08:00
|
|
|
});
|
2018-05-31 22:37:09 +08:00
|
|
|
|
2017-01-24 14:59:39 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/4653
|
|
|
|
it('should use file.thumbUrl for <img /> in priority', () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2017-01-24 14:59:39 +08:00
|
|
|
<Upload defaultFileList={fileList} listType="picture">
|
2018-06-22 21:05:13 +08:00
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2017-01-24 14:59:39 +08:00
|
|
|
);
|
|
|
|
fileList.forEach((file, i) => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const linkNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail')[i];
|
|
|
|
const imgNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail img')[i];
|
|
|
|
expect(linkNode.getAttribute('href')).toBe(file.url);
|
|
|
|
expect(imgNode.getAttribute('src')).toBe(file.thumbUrl);
|
2017-01-24 14:59:39 +08:00
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2017-01-24 14:59:39 +08:00
|
|
|
});
|
2017-08-20 15:39:02 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/7269
|
|
|
|
it('should remove correct item when uid is 0', async () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
jest.useFakeTimers();
|
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uid: '1',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
},
|
|
|
|
];
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container, unmount } = render(
|
2017-08-20 15:39:02 +08:00
|
|
|
<Upload defaultFileList={list}>
|
2018-06-22 21:05:13 +08:00
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2017-08-20 15:39:02 +08:00
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(container.querySelectorAll('.ant-upload-list-item').length).toBe(2);
|
|
|
|
fireEvent.click(
|
|
|
|
container.querySelectorAll('.ant-upload-list-item')[0].querySelector('.anticon-delete'),
|
|
|
|
);
|
2020-11-21 19:00:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
// Upload use Promise to wait remove action. Let's wait this also.
|
2020-11-21 19:00:11 +08:00
|
|
|
await act(async () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
for (let i = 0; i < 10; i += 1) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await Promise.resolve();
|
|
|
|
}
|
|
|
|
});
|
2020-11-21 19:00:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
// Progress motion to active
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
2020-11-21 19:00:11 +08:00
|
|
|
});
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
// Progress motion to done
|
|
|
|
// React 17 will reach deadline, so we need check if already done
|
|
|
|
if (container.querySelector('.ant-upload-animate-leave-active')) {
|
|
|
|
fireEvent.animationEnd(container.querySelector('.ant-upload-animate-leave-active'));
|
|
|
|
}
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
2020-11-21 19:00:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(container.querySelectorAll('.ant-upload-list-text-container')).toHaveLength(1);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
|
|
|
|
|
|
|
jest.useRealTimers();
|
2017-08-20 15:39:02 +08:00
|
|
|
});
|
2017-10-10 15:59:13 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
it('should be uploading when upload a file', async () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
const done = jest.fn();
|
2017-10-12 14:09:17 +08:00
|
|
|
let wrapper;
|
2020-03-18 00:02:23 +08:00
|
|
|
let latestFileList = null;
|
2022-06-16 23:29:04 +08:00
|
|
|
const onChange = async ({ file, fileList: eventFileList }) => {
|
2020-03-18 00:02:23 +08:00
|
|
|
expect(eventFileList === latestFileList).toBeFalsy();
|
2017-10-12 14:09:17 +08:00
|
|
|
if (file.status === 'uploading') {
|
2022-06-16 23:29:04 +08:00
|
|
|
await Promise.resolve();
|
|
|
|
expect(wrapper.container.firstChild).toMatchSnapshot();
|
2017-10-12 14:09:17 +08:00
|
|
|
}
|
2017-10-15 17:30:50 +08:00
|
|
|
if (file.status === 'done') {
|
2022-06-16 23:29:04 +08:00
|
|
|
done();
|
2017-10-15 17:30:50 +08:00
|
|
|
}
|
2020-03-18 00:02:23 +08:00
|
|
|
|
|
|
|
latestFileList = eventFileList;
|
2017-10-15 17:30:50 +08:00
|
|
|
};
|
2022-06-16 23:29:04 +08:00
|
|
|
wrapper = render(
|
2017-10-15 17:30:50 +08:00
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
onChange={onChange}
|
|
|
|
customRequest={successRequest}
|
|
|
|
>
|
2018-06-22 21:05:13 +08:00
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2017-10-15 17:30:50 +08:00
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.change(wrapper.container.querySelector('input'), {
|
2017-10-15 17:30:50 +08:00
|
|
|
target: {
|
2018-12-07 16:17:45 +08:00
|
|
|
files: [{ name: 'foo.png' }],
|
2017-10-15 17:30:50 +08:00
|
|
|
},
|
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
await act(async () => {
|
|
|
|
await Promise.resolve();
|
|
|
|
await Promise.resolve();
|
|
|
|
});
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(done).toHaveBeenCalled();
|
|
|
|
|
|
|
|
wrapper.unmount();
|
|
|
|
|
|
|
|
jest.useRealTimers();
|
2017-10-15 17:30:50 +08:00
|
|
|
});
|
|
|
|
|
2021-02-26 22:38:11 +08:00
|
|
|
it('handle error', async () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
jest.useFakeTimers();
|
2021-02-26 22:38:11 +08:00
|
|
|
const onChange = jest.fn();
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const {
|
|
|
|
container: wrapper,
|
|
|
|
unmount,
|
|
|
|
baseElement,
|
|
|
|
} = render(
|
2017-10-15 17:30:50 +08:00
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
onChange={onChange}
|
|
|
|
customRequest={errorRequest}
|
|
|
|
>
|
2018-06-22 21:05:13 +08:00
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2017-10-10 15:59:13 +08:00
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.change(wrapper.querySelector('input'), {
|
2017-10-10 15:59:13 +08:00
|
|
|
target: {
|
2018-12-07 16:17:45 +08:00
|
|
|
files: [{ name: 'foo.png' }],
|
2017-10-10 15:59:13 +08:00
|
|
|
},
|
|
|
|
});
|
2021-02-26 22:38:11 +08:00
|
|
|
|
2021-03-29 15:49:28 +08:00
|
|
|
await act(async () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
await Promise.resolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Wait twice since `errorRequest` also use timeout for mock
|
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
2021-03-29 15:49:28 +08:00
|
|
|
});
|
2021-02-26 22:38:11 +08:00
|
|
|
|
|
|
|
expect(onChange).toHaveBeenLastCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
file: expect.objectContaining({
|
|
|
|
status: 'error',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
if (wrapper.querySelector('.ant-upload-animate-appear-active')) {
|
|
|
|
fireEvent.animationEnd(wrapper.querySelector('.ant-upload-animate-appear-active'));
|
|
|
|
}
|
2021-02-26 22:38:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
act(() => {
|
|
|
|
jest.runAllTimers();
|
2021-03-29 15:49:28 +08:00
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.firstChild).toMatchSnapshot();
|
2021-02-26 22:38:11 +08:00
|
|
|
|
|
|
|
// Error message
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.mouseEnter(wrapper.querySelector('.ant-upload-list-item'));
|
2021-02-26 22:38:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await act(() => {
|
2021-02-26 22:38:11 +08:00
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(baseElement.querySelector('.ant-tooltip')).not.toHaveClass('.ant-tooltip-hidden');
|
2021-02-26 22:38:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
jest.useRealTimers();
|
|
|
|
unmount();
|
2017-10-10 15:59:13 +08:00
|
|
|
});
|
2017-11-29 20:28:19 +08:00
|
|
|
|
2021-02-26 15:18:37 +08:00
|
|
|
it('does concat fileList when beforeUpload returns false', async () => {
|
2017-11-29 20:28:19 +08:00
|
|
|
const handleChange = jest.fn();
|
2020-08-18 15:44:31 +08:00
|
|
|
const ref = React.createRef();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2017-11-29 20:28:19 +08:00
|
|
|
<Upload
|
2020-08-18 15:44:31 +08:00
|
|
|
ref={ref}
|
2017-11-29 20:28:19 +08:00
|
|
|
listType="picture"
|
|
|
|
defaultFileList={fileList}
|
|
|
|
onChange={handleChange}
|
|
|
|
beforeUpload={() => false}
|
|
|
|
>
|
2018-06-22 21:05:13 +08:00
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2017-11-29 20:28:19 +08:00
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.change(wrapper.querySelector('input'), {
|
2017-11-29 20:28:19 +08:00
|
|
|
target: {
|
2018-12-07 16:17:45 +08:00
|
|
|
files: [{ name: 'foo.png' }],
|
2017-11-29 20:28:19 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-02-26 15:18:37 +08:00
|
|
|
await sleep();
|
|
|
|
|
2020-08-18 15:44:31 +08:00
|
|
|
expect(ref.current.fileList.length).toBe(fileList.length + 1);
|
2018-02-11 16:11:13 +08:00
|
|
|
expect(handleChange.mock.calls[0][0].fileList).toHaveLength(3);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2017-11-29 20:28:19 +08:00
|
|
|
});
|
|
|
|
|
2019-09-11 21:46:56 +08:00
|
|
|
it('In the case of listType=picture, the error status does not show the download.', () => {
|
2021-02-26 15:18:37 +08:00
|
|
|
global.testName =
|
|
|
|
'In the case of listType=picture, the error status does not show the download.';
|
2019-09-11 21:46:56 +08:00
|
|
|
const file = { status: 'error', uid: 'file' };
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-02-20 22:47:14 +08:00
|
|
|
<Upload listType="picture" fileList={[file]} showUploadList={{ showDownloadIcon: true }}>
|
2019-09-11 21:46:56 +08:00
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2020-11-21 19:00:11 +08:00
|
|
|
|
|
|
|
// Has error item className
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.mouseEnter(wrapper.querySelector('.ant-upload-list-item-error'));
|
2020-11-21 19:00:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.querySelectorAll('div.ant-upload-list-item i.anticon-download').length).toBe(0);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-09-11 21:46:56 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('In the case of listType=picture-card, the error status does not show the download.', () => {
|
2021-02-26 15:18:37 +08:00
|
|
|
global.testName =
|
|
|
|
'In the case of listType=picture-card, the error status does not show the download.';
|
2019-09-11 21:46:56 +08:00
|
|
|
const file = { status: 'error', uid: 'file' };
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-02-20 22:47:14 +08:00
|
|
|
<Upload listType="picture-card" fileList={[file]} showUploadList={{ showDownloadIcon: true }}>
|
2019-09-11 21:46:56 +08:00
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.querySelectorAll('div.ant-upload-list-item i.anticon-download').length).toBe(0);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-09-11 21:46:56 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('In the case of listType=text, the error status does not show the download.', () => {
|
|
|
|
const file = { status: 'error', uid: 'file' };
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-02-20 22:47:14 +08:00
|
|
|
<Upload listType="text" fileList={[file]} showUploadList={{ showDownloadIcon: true }}>
|
2019-09-11 21:46:56 +08:00
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.querySelectorAll('div.ant-upload-list-item i.anticon-download').length).toBe(0);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-09-11 21:46:56 +08:00
|
|
|
});
|
|
|
|
|
2017-12-04 15:59:23 +08:00
|
|
|
it('should support onPreview', () => {
|
|
|
|
const handlePreview = jest.fn();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2018-12-07 16:17:45 +08:00
|
|
|
<Upload listType="picture-card" defaultFileList={fileList} onPreview={handlePreview}>
|
2018-06-22 21:05:13 +08:00
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2017-12-04 15:59:23 +08:00
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.anticon-eye')[0]);
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handlePreview).toHaveBeenCalledWith(fileList[0]);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.anticon-eye')[1]);
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handlePreview).toHaveBeenCalledWith(fileList[1]);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2017-12-04 15:59:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should support onRemove', async () => {
|
|
|
|
const handleRemove = jest.fn();
|
|
|
|
const handleChange = jest.fn();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2017-12-04 15:59:23 +08:00
|
|
|
<Upload
|
|
|
|
listType="picture-card"
|
|
|
|
defaultFileList={fileList}
|
|
|
|
onRemove={handleRemove}
|
|
|
|
onChange={handleChange}
|
|
|
|
>
|
2018-06-22 21:05:13 +08:00
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2017-12-04 15:59:23 +08:00
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.anticon-delete')[0]);
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handleRemove).toHaveBeenCalledWith(fileList[0]);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.anticon-delete')[1]);
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(handleRemove).toHaveBeenCalledWith(fileList[1]);
|
2019-07-31 18:06:31 +08:00
|
|
|
await sleep();
|
2017-12-04 15:59:23 +08:00
|
|
|
expect(handleChange.mock.calls.length).toBe(2);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2017-12-04 15:59:23 +08:00
|
|
|
});
|
|
|
|
|
2019-09-11 21:46:56 +08:00
|
|
|
it('should support onDownload', async () => {
|
|
|
|
const handleDownload = jest.fn();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2019-09-11 21:46:56 +08:00
|
|
|
<Upload
|
|
|
|
listType="picture-card"
|
|
|
|
defaultFileList={[
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
onDownload={handleDownload}
|
2020-02-20 22:47:14 +08:00
|
|
|
showUploadList={{
|
|
|
|
showDownloadIcon: true,
|
|
|
|
}}
|
2019-09-11 21:46:56 +08:00
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.anticon-download')[0]);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-09-11 21:46:56 +08:00
|
|
|
});
|
|
|
|
|
2020-02-20 22:47:14 +08:00
|
|
|
it('should support no onDownload', async () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2019-09-11 21:46:56 +08:00
|
|
|
<Upload
|
|
|
|
listType="picture-card"
|
|
|
|
defaultFileList={[
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
},
|
|
|
|
]}
|
2020-02-20 22:47:14 +08:00
|
|
|
showUploadList={{
|
|
|
|
showDownloadIcon: true,
|
|
|
|
}}
|
2019-09-11 21:46:56 +08:00
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.anticon-download')[0]);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-09-11 21:46:56 +08:00
|
|
|
});
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
describe('should generate thumbUrl from file', () => {
|
|
|
|
[
|
|
|
|
{ width: 100, height: 200, name: 'height large than width' },
|
|
|
|
{ width: 200, height: 100, name: 'width large than height' },
|
|
|
|
].forEach(({ width, height, name }) => {
|
|
|
|
it(name, async () => {
|
|
|
|
setSize(width, height);
|
|
|
|
const onDrawImage = jest.fn();
|
|
|
|
hookDrawImageCall(onDrawImage);
|
|
|
|
|
|
|
|
const handlePreview = jest.fn();
|
|
|
|
const newFileList = [...fileList];
|
|
|
|
const newFile = {
|
|
|
|
...fileList[0],
|
|
|
|
uid: '-3',
|
|
|
|
originFileObj: new File([], 'xxx.png', { type: 'image/png' }),
|
|
|
|
};
|
|
|
|
delete newFile.thumbUrl;
|
|
|
|
newFileList.push(newFile);
|
2020-08-18 15:44:31 +08:00
|
|
|
const ref = React.createRef();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { unmount } = render(
|
2020-08-18 15:44:31 +08:00
|
|
|
<Upload
|
|
|
|
ref={ref}
|
|
|
|
listType="picture-card"
|
|
|
|
defaultFileList={newFileList}
|
|
|
|
onPreview={handlePreview}
|
|
|
|
>
|
2019-05-06 12:04:39 +08:00
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2019-07-31 18:06:31 +08:00
|
|
|
await sleep();
|
2019-05-06 12:04:39 +08:00
|
|
|
|
2020-08-18 15:44:31 +08:00
|
|
|
expect(ref.current.fileList[2].thumbUrl).not.toBe(undefined);
|
2019-05-06 12:04:39 +08:00
|
|
|
expect(onDrawImage).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// Offset check
|
|
|
|
const [, offsetX, offsetY] = onDrawImage.mock.calls[0];
|
|
|
|
if (width > height) {
|
2020-10-23 11:18:57 +08:00
|
|
|
expect(offsetX === 0).toBeTruthy();
|
2019-05-06 12:04:39 +08:00
|
|
|
} else {
|
2020-10-23 11:18:57 +08:00
|
|
|
expect(offsetY === 0).toBeTruthy();
|
2019-05-06 12:04:39 +08:00
|
|
|
}
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-05-06 12:04:39 +08:00
|
|
|
});
|
|
|
|
});
|
2017-12-04 15:59:23 +08:00
|
|
|
});
|
2018-03-11 22:24:09 +08:00
|
|
|
|
|
|
|
it('should non-image format file preview', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
2018-04-04 17:17:01 +08:00
|
|
|
name: 'not-image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-3',
|
2018-03-11 22:24:09 +08:00
|
|
|
url: 'https://cdn.xxx.com/aaa.zip',
|
|
|
|
thumbUrl: 'data:application/zip;base64,UEsDBAoAAAAAADYZYkwAAAAAAAAAAAAAAAAdAAk',
|
|
|
|
originFileObj: new File([], 'aaa.zip'),
|
|
|
|
},
|
2018-04-04 17:17:01 +08:00
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-4',
|
2018-04-04 17:17:01 +08:00
|
|
|
url: 'https://cdn.xxx.com/aaa',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'not-image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-5',
|
2018-04-04 17:17:01 +08:00
|
|
|
url: 'https://cdn.xxx.com/aaa.xx',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'not-image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-6',
|
2018-04-04 17:17:01 +08:00
|
|
|
url: 'https://cdn.xxx.com/aaa.png/xx.xx',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-7',
|
2018-04-04 17:17:01 +08:00
|
|
|
url: 'https://cdn.xxx.com/xx.xx/aaa.png',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-8',
|
2018-04-04 17:17:01 +08:00
|
|
|
url: 'https://cdn.xxx.com/xx.xx/aaa.png',
|
|
|
|
thumbUrl: 'data:image/png;base64,UEsDBAoAAAAAADYZYkwAAAAAAAAAAAAAAAAdAAk',
|
|
|
|
},
|
2018-04-17 13:49:03 +08:00
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-9',
|
2018-04-17 13:49:03 +08:00
|
|
|
url: 'https://cdn.xxx.com/xx.xx/aaa.png?query=123',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-10',
|
2018-04-17 13:49:03 +08:00
|
|
|
url: 'https://cdn.xxx.com/xx.xx/aaa.png#anchor',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
2018-08-02 17:34:55 +08:00
|
|
|
uid: '-11',
|
2018-04-17 13:49:03 +08:00
|
|
|
url: 'https://cdn.xxx.com/xx.xx/aaa.png?query=some.query.with.dot',
|
|
|
|
},
|
2018-08-09 20:30:02 +08:00
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
|
|
|
uid: '-12',
|
2021-10-13 14:16:57 +08:00
|
|
|
url: 'https://publish-pic-cpu.baidu.com/1296beb3-50d9-4276-885f-52645cbb378e.jpeg@w_228%2ch_152',
|
2019-03-18 10:47:17 +08:00
|
|
|
type: 'image/png',
|
2018-08-09 20:30:02 +08:00
|
|
|
},
|
2018-03-11 22:24:09 +08:00
|
|
|
];
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2018-12-07 16:17:45 +08:00
|
|
|
<Upload listType="picture" defaultFileList={list}>
|
2018-06-22 21:05:13 +08:00
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2018-03-11 22:24:09 +08:00
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.firstChild).toMatchSnapshot();
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2018-03-11 22:24:09 +08:00
|
|
|
});
|
2018-10-11 15:11:44 +08:00
|
|
|
|
2021-02-26 22:38:11 +08:00
|
|
|
it('not crash when uploading not provides percent', async () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { unmount } = render(
|
2021-02-26 22:38:11 +08:00
|
|
|
<Upload
|
|
|
|
listType="picture"
|
|
|
|
defaultFileList={[
|
|
|
|
{
|
|
|
|
name: 'bamboo.png',
|
|
|
|
status: 'uploading',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
jest.runAllTimers();
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2021-02-26 22:38:11 +08:00
|
|
|
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
2019-09-29 12:33:24 +08:00
|
|
|
it('should support showRemoveIcon and showPreviewIcon', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'uploading',
|
|
|
|
uid: '-4',
|
|
|
|
url: 'https://cdn.xxx.com/aaa',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
|
|
|
uid: '-5',
|
|
|
|
url: 'https://cdn.xxx.com/aaa',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2019-09-29 12:33:24 +08:00
|
|
|
<Upload
|
|
|
|
listType="picture"
|
|
|
|
defaultFileList={list}
|
|
|
|
showUploadList={{
|
|
|
|
showRemoveIcon: false,
|
|
|
|
showPreviewIcon: false,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
2018-12-07 16:17:45 +08:00
|
|
|
</Upload>,
|
2018-03-11 22:24:09 +08:00
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.firstChild).toMatchSnapshot();
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2018-03-11 22:24:09 +08:00
|
|
|
});
|
2021-01-16 18:06:26 +08:00
|
|
|
|
2020-02-17 14:55:16 +08:00
|
|
|
it('should support custom onClick in custom icon', async () => {
|
|
|
|
const handleRemove = jest.fn();
|
|
|
|
const handleChange = jest.fn();
|
|
|
|
const myClick = jest.fn();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-02-17 14:55:16 +08:00
|
|
|
<Upload
|
|
|
|
listType="picture-card"
|
|
|
|
defaultFileList={fileList}
|
|
|
|
onRemove={handleRemove}
|
|
|
|
onChange={handleChange}
|
|
|
|
showUploadList={{
|
|
|
|
showRemoveIcon: true,
|
2020-02-19 13:20:43 +08:00
|
|
|
removeIcon: (
|
|
|
|
<i className="custom-delete" onClick={myClick}>
|
|
|
|
RM
|
|
|
|
</i>
|
|
|
|
),
|
2020-02-17 14:55:16 +08:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.custom-delete')[0]);
|
2020-02-17 14:55:16 +08:00
|
|
|
expect(handleRemove).toHaveBeenCalledWith(fileList[0]);
|
|
|
|
expect(myClick).toHaveBeenCalled();
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.custom-delete')[1]);
|
2020-02-17 14:55:16 +08:00
|
|
|
expect(handleRemove).toHaveBeenCalledWith(fileList[1]);
|
|
|
|
expect(myClick).toHaveBeenCalled();
|
|
|
|
await sleep();
|
|
|
|
expect(handleChange.mock.calls.length).toBe(2);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2020-02-17 14:55:16 +08:00
|
|
|
});
|
2020-10-10 13:32:27 +08:00
|
|
|
|
2020-02-17 14:55:16 +08:00
|
|
|
it('should support removeIcon and downloadIcon', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'uploading',
|
|
|
|
uid: '-4',
|
|
|
|
url: 'https://cdn.xxx.com/aaa',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'image',
|
|
|
|
status: 'done',
|
|
|
|
uid: '-5',
|
|
|
|
url: 'https://cdn.xxx.com/aaa',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-02-17 14:55:16 +08:00
|
|
|
<Upload
|
|
|
|
listType="picture"
|
|
|
|
defaultFileList={list}
|
|
|
|
showUploadList={{
|
|
|
|
showRemoveIcon: true,
|
|
|
|
showDownloadIcon: true,
|
2021-10-13 14:16:57 +08:00
|
|
|
showPreviewIcon: true,
|
|
|
|
removeIcon: <i>RM</i>,
|
2020-02-17 14:55:16 +08:00
|
|
|
downloadIcon: <i>DL</i>,
|
2021-10-13 14:16:57 +08:00
|
|
|
previewIcon: <i>PV</i>,
|
2020-02-17 14:55:16 +08:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.firstChild).toMatchSnapshot();
|
|
|
|
unmount();
|
2020-10-10 13:32:27 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper2, unmount: unmount2 } = render(
|
2020-10-10 13:32:27 +08:00
|
|
|
<Upload
|
|
|
|
listType="picture"
|
|
|
|
defaultFileList={list}
|
|
|
|
showUploadList={{
|
|
|
|
showRemoveIcon: true,
|
|
|
|
showDownloadIcon: true,
|
2021-10-13 14:16:57 +08:00
|
|
|
showPreviewIcon: true,
|
|
|
|
removeIcon: () => <i>RM</i>,
|
2020-10-10 13:32:27 +08:00
|
|
|
downloadIcon: () => <i>DL</i>,
|
2021-10-13 14:16:57 +08:00
|
|
|
previewIcon: () => <i>PV</i>,
|
2020-10-10 13:32:27 +08:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper2.firstChild).toMatchSnapshot();
|
|
|
|
unmount2();
|
2020-02-17 14:55:16 +08:00
|
|
|
});
|
2018-10-11 15:11:44 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/7762
|
2019-07-03 20:14:39 +08:00
|
|
|
it('work with form validation', async () => {
|
|
|
|
let formRef;
|
|
|
|
|
|
|
|
const TestForm = () => {
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
formRef = form;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form form={form}>
|
|
|
|
<Form.Item
|
|
|
|
name="file"
|
|
|
|
valuePropName="fileList"
|
|
|
|
getValueFromEvent={e => e.fileList}
|
|
|
|
rules={[
|
|
|
|
{
|
|
|
|
required: true,
|
|
|
|
validator: (rule, value, callback) => {
|
|
|
|
if (!value || value.length === 0) {
|
|
|
|
callback('file required');
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<Upload beforeUpload={() => false}>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-04-15 23:33:10 +08:00
|
|
|
const { container, unmount } = render(<TestForm />);
|
2018-10-11 15:11:44 +08:00
|
|
|
|
2022-04-15 23:33:10 +08:00
|
|
|
fireEvent.submit(container.querySelector('form'));
|
2019-08-29 23:41:46 +08:00
|
|
|
await sleep();
|
2019-07-03 20:14:39 +08:00
|
|
|
expect(formRef.getFieldError(['file'])).toEqual(['file required']);
|
2018-10-11 15:11:44 +08:00
|
|
|
|
2022-04-15 23:33:10 +08:00
|
|
|
fireEvent.change(container.querySelector('input'), {
|
2018-10-11 15:11:44 +08:00
|
|
|
target: {
|
2018-12-07 16:17:45 +08:00
|
|
|
files: [{ name: 'foo.png' }],
|
2018-10-11 15:11:44 +08:00
|
|
|
},
|
|
|
|
});
|
2019-07-03 20:14:39 +08:00
|
|
|
|
2022-04-15 23:33:10 +08:00
|
|
|
fireEvent.submit(container.querySelector('form'));
|
2019-08-29 23:41:46 +08:00
|
|
|
await sleep();
|
2019-07-03 20:14:39 +08:00
|
|
|
expect(formRef.getFieldError(['file'])).toEqual([]);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-04-15 23:33:10 +08:00
|
|
|
unmount();
|
2018-10-11 15:11:44 +08:00
|
|
|
});
|
2019-03-07 09:57:20 +08:00
|
|
|
|
|
|
|
it('return when prop onPreview not exists', () => {
|
2020-08-18 15:44:31 +08:00
|
|
|
const ref = React.createRef();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { unmount } = render(<UploadList ref={ref} />);
|
2020-08-18 15:44:31 +08:00
|
|
|
expect(ref.current.handlePreview()).toBe(undefined);
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-03-07 09:57:20 +08:00
|
|
|
});
|
|
|
|
|
2019-09-11 21:46:56 +08:00
|
|
|
it('return when prop onDownload not exists', () => {
|
|
|
|
const file = new File([''], 'test.txt', { type: 'text/plain' });
|
|
|
|
const items = [{ uid: 'upload-list-item', url: '' }];
|
2020-08-18 15:44:31 +08:00
|
|
|
const ref = React.createRef();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { unmount } = render(
|
2020-02-20 22:47:14 +08:00
|
|
|
<UploadList
|
2020-08-18 15:44:31 +08:00
|
|
|
ref={ref}
|
2020-02-20 22:47:14 +08:00
|
|
|
items={items}
|
|
|
|
locale={{ downloadFile: '' }}
|
|
|
|
showUploadList={{ showDownloadIcon: true }}
|
2020-02-24 13:10:29 +08:00
|
|
|
/>,
|
2020-08-18 15:44:31 +08:00
|
|
|
);
|
|
|
|
expect(ref.current.handleDownload(file)).toBe(undefined);
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-09-11 21:46:56 +08:00
|
|
|
});
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
it('previewFile should work correctly', async () => {
|
2019-03-07 12:38:14 +08:00
|
|
|
const items = [{ uid: 'upload-list-item', url: '' }];
|
2022-06-16 23:29:04 +08:00
|
|
|
const previewFunc = jest.fn(previewImage);
|
|
|
|
const { container: wrapper, unmount } = render(
|
|
|
|
<Upload
|
|
|
|
fileList={items}
|
|
|
|
previewFile={previewFunc}
|
|
|
|
locale={{ previewFile: '' }}
|
|
|
|
listType="picture-card"
|
|
|
|
/>,
|
2020-08-18 15:44:31 +08:00
|
|
|
);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.change(wrapper.querySelector('input'), {
|
|
|
|
target: {
|
|
|
|
files: [{ name: 'foo.png' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await sleep();
|
|
|
|
expect(wrapper.querySelector('.ant-upload-list-item-thumbnail').getAttribute('href')).toBe(
|
|
|
|
null,
|
|
|
|
);
|
|
|
|
|
|
|
|
unmount();
|
2019-03-07 09:57:20 +08:00
|
|
|
});
|
|
|
|
|
2019-09-11 21:46:56 +08:00
|
|
|
it('downloadFile should work correctly', async () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const downloadFunc = jest.fn();
|
|
|
|
const items = [{ uid: 'upload-list-item', name: 'test', url: '', status: 'done' }];
|
|
|
|
const { container: wrapper, unmount } = render(
|
2019-09-11 21:46:56 +08:00
|
|
|
<UploadList
|
2022-06-16 23:29:04 +08:00
|
|
|
showDownloadIcon
|
2019-09-11 21:46:56 +08:00
|
|
|
listType="picture-card"
|
|
|
|
items={items}
|
2022-06-16 23:29:04 +08:00
|
|
|
onDownload={downloadFunc}
|
|
|
|
locale={{ downloadFile: 'Download file' }}
|
2019-09-11 21:46:56 +08:00
|
|
|
/>,
|
2020-08-18 15:44:31 +08:00
|
|
|
);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
|
|
|
// Not throw
|
2022-06-16 23:29:04 +08:00
|
|
|
const btn = wrapper.querySelector('.ant-btn');
|
|
|
|
expect(btn.getAttribute('title')).toBe('Download file');
|
|
|
|
fireEvent.click(btn);
|
|
|
|
expect(downloadFunc).toBeCalled();
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-09-11 21:46:56 +08:00
|
|
|
});
|
|
|
|
|
2019-03-07 12:38:14 +08:00
|
|
|
it('extname should work correctly when url not exists', () => {
|
|
|
|
const items = [{ uid: 'upload-list-item', url: '' }];
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2019-03-07 12:38:14 +08:00
|
|
|
<UploadList listType="picture-card" items={items} locale={{ previewFile: '' }} />,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-list-item-thumbnail').length).toBe(1);
|
|
|
|
unmount();
|
2019-03-07 09:57:20 +08:00
|
|
|
});
|
|
|
|
|
2020-02-24 13:10:29 +08:00
|
|
|
it('extname should work correctly when url exists', done => {
|
2019-09-11 21:46:56 +08:00
|
|
|
const items = [{ status: 'done', uid: 'upload-list-item', url: '/example' }];
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2019-09-11 21:46:56 +08:00
|
|
|
<UploadList
|
|
|
|
listType="picture"
|
|
|
|
onDownload={file => {
|
|
|
|
expect(file.url).toBe('/example');
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2020-02-20 22:47:14 +08:00
|
|
|
done();
|
2019-09-11 21:46:56 +08:00
|
|
|
}}
|
|
|
|
items={items}
|
|
|
|
locale={{ downloadFile: '' }}
|
2020-02-20 22:47:14 +08:00
|
|
|
showDownloadIcon
|
2019-09-11 21:46:56 +08:00
|
|
|
/>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelector('div.ant-upload-list-item .anticon-download'));
|
2019-09-11 21:46:56 +08:00
|
|
|
});
|
|
|
|
|
2019-03-07 09:57:20 +08:00
|
|
|
it('when picture-card is loading, icon should render correctly', () => {
|
|
|
|
const items = [{ status: 'uploading', uid: 'upload-list-item' }];
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2019-03-07 09:57:20 +08:00
|
|
|
<UploadList listType="picture-card" items={items} locale={{ uploading: 'uploading' }} />,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-list-item-thumbnail').length).toBe(1);
|
|
|
|
expect(wrapper.querySelector('.ant-upload-list-item-thumbnail').textContent).toBe('uploading');
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-03-07 09:57:20 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('onPreview should be called, when url exists', () => {
|
|
|
|
const onPreview = jest.fn();
|
|
|
|
const items = [{ thumbUrl: 'thumbUrl', url: 'url', uid: 'upload-list-item' }];
|
2022-06-16 23:29:04 +08:00
|
|
|
const {
|
|
|
|
container: wrapper,
|
|
|
|
rerender,
|
|
|
|
unmount,
|
|
|
|
} = render(
|
2019-03-07 09:57:20 +08:00
|
|
|
<UploadList
|
|
|
|
listType="picture-card"
|
|
|
|
items={items}
|
|
|
|
locale={{ uploading: 'uploading' }}
|
|
|
|
onPreview={onPreview}
|
|
|
|
/>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelector('.ant-upload-list-item-thumbnail'));
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onPreview).toHaveBeenCalled();
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelector('.ant-upload-list-item-name'));
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onPreview).toHaveBeenCalled();
|
2022-06-16 23:29:04 +08:00
|
|
|
rerender(
|
|
|
|
<UploadList
|
|
|
|
listType="picture-card"
|
|
|
|
items={[{ thumbUrl: 'thumbUrl', uid: 'upload-list-item' }]}
|
|
|
|
locale={{ uploading: 'uploading' }}
|
|
|
|
onPreview={onPreview}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
fireEvent.click(wrapper.querySelector('.ant-upload-list-item-name'));
|
2019-04-03 15:54:26 +08:00
|
|
|
expect(onPreview).toHaveBeenCalled();
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-03-07 09:57:20 +08:00
|
|
|
});
|
2019-03-18 10:47:17 +08:00
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
it('upload image file should be converted to the base64', async () => {
|
2019-03-18 10:47:17 +08:00
|
|
|
const mockFile = new File([''], 'foo.png', {
|
|
|
|
type: 'image/png',
|
|
|
|
});
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const previewFunc = jest.fn(previewImage);
|
|
|
|
|
|
|
|
const { unmount } = render(
|
|
|
|
<Upload
|
|
|
|
fileList={[
|
|
|
|
{
|
|
|
|
originFileObj: mockFile,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
previewFile={previewFunc}
|
|
|
|
locale={{ uploading: 'uploading' }}
|
|
|
|
listType="picture-card"
|
|
|
|
/>,
|
2019-03-18 10:47:17 +08:00
|
|
|
);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-07-14 11:25:57 +08:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(previewFunc).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
await previewFunc(mockFile).then(dataUrl => {
|
|
|
|
expect(dataUrl).toEqual('data:image/png;base64,');
|
|
|
|
});
|
|
|
|
unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('upload svg file with <foreignObject> should not have CORS error', async () => {
|
|
|
|
const mockFile = new File(
|
|
|
|
[
|
|
|
|
'<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><foreignObject x="20" y="20" width="160" height="160"><div xmlns="http://www.w3.org/1999/xhtml">Test</div></foreignObject></svg>',
|
|
|
|
],
|
|
|
|
'bar.svg',
|
|
|
|
{ type: 'image/svg+xml' },
|
|
|
|
);
|
|
|
|
|
|
|
|
const previewFunc = jest.fn(previewImage);
|
|
|
|
|
|
|
|
const { unmount } = render(
|
|
|
|
<Upload
|
|
|
|
fileList={[{ originFileObj: mockFile }]}
|
|
|
|
previewFile={previewFunc}
|
|
|
|
locale={{ uploading: 'uploading' }}
|
|
|
|
listType="picture-card"
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(previewFunc).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
await previewFunc(mockFile).then(dataUrl => {
|
|
|
|
expect(dataUrl).toEqual('data:image/png;base64,');
|
|
|
|
});
|
|
|
|
unmount();
|
2019-03-18 10:47:17 +08:00
|
|
|
});
|
|
|
|
|
2019-05-06 12:04:39 +08:00
|
|
|
it("upload non image file shouldn't be converted to the base64", async () => {
|
2019-03-18 10:47:17 +08:00
|
|
|
const mockFile = new File([''], 'foo.7z', {
|
|
|
|
type: 'application/x-7z-compressed',
|
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
const previewFunc = jest.fn(previewImage);
|
2019-03-18 10:47:17 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { unmount } = render(
|
|
|
|
<Upload
|
|
|
|
fileList={[
|
|
|
|
{
|
|
|
|
originFileObj: mockFile,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
previewFile={previewFunc}
|
|
|
|
locale={{ uploading: 'uploading' }}
|
|
|
|
listType="picture-card"
|
|
|
|
/>,
|
2019-03-18 10:47:17 +08:00
|
|
|
);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(previewFunc).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
await previewFunc(mockFile).then(dataUrl => {
|
|
|
|
expect(dataUrl).toBe('');
|
|
|
|
});
|
|
|
|
|
|
|
|
unmount();
|
2019-05-06 12:04:39 +08:00
|
|
|
});
|
|
|
|
|
2019-07-01 17:52:37 +08:00
|
|
|
describe('customize previewFile support', () => {
|
|
|
|
function test(name, renderInstance) {
|
|
|
|
it(name, async () => {
|
|
|
|
const mockThumbnail = 'mock-image';
|
2020-12-09 17:12:32 +08:00
|
|
|
const previewFile = jest.fn(() => Promise.resolve(mockThumbnail));
|
2019-07-01 17:52:37 +08:00
|
|
|
const file = {
|
|
|
|
...fileList[0],
|
|
|
|
originFileObj: renderInstance(),
|
|
|
|
};
|
|
|
|
delete file.thumbUrl;
|
2020-08-18 15:44:31 +08:00
|
|
|
const ref = React.createRef();
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-08-18 15:44:31 +08:00
|
|
|
<Upload ref={ref} listType="picture" defaultFileList={[file]} previewFile={previewFile}>
|
2019-08-11 16:38:04 +08:00
|
|
|
<button type="button">button</button>
|
2019-07-01 17:52:37 +08:00
|
|
|
</Upload>,
|
|
|
|
);
|
|
|
|
expect(previewFile).toHaveBeenCalledWith(file.originFileObj);
|
2020-08-18 15:44:31 +08:00
|
|
|
await sleep(100);
|
2019-07-01 17:52:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(
|
|
|
|
wrapper.querySelector('.ant-upload-list-item-thumbnail img').getAttribute('src'),
|
|
|
|
).toBe(mockThumbnail);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2019-07-01 17:52:37 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
test('File', () => new File([], 'xxx.png'));
|
|
|
|
test('Blob', () => new Blob());
|
2019-03-18 10:47:17 +08:00
|
|
|
});
|
2019-08-04 12:18:46 +08:00
|
|
|
|
2020-04-14 19:32:16 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/22958
|
|
|
|
describe('customize isImageUrl support', () => {
|
|
|
|
const list = [
|
|
|
|
...fileList,
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl:
|
|
|
|
'http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg@!panda_style?spm=a2c4g.11186623.2.17.4dc56b29BHokyg&file=example.jpg@!panda_style',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
it('should not render <img /> when file.thumbUrl use "!" as separator', () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-04-14 19:32:16 +08:00
|
|
|
<Upload listType="picture-card" fileList={list}>
|
|
|
|
<button type="button">button</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail img');
|
2020-04-14 19:32:16 +08:00
|
|
|
expect(imgNode.length).toBe(2);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2020-04-14 19:32:16 +08:00
|
|
|
});
|
|
|
|
it('should render <img /> when custom imageUrl return true', () => {
|
2020-12-09 17:12:32 +08:00
|
|
|
const isImageUrl = jest.fn(() => true);
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-04-14 19:32:16 +08:00
|
|
|
<Upload listType="picture-card" fileList={list} isImageUrl={isImageUrl}>
|
|
|
|
<button type="button">button</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail img');
|
2020-04-14 19:32:16 +08:00
|
|
|
expect(isImageUrl).toHaveBeenCalled();
|
|
|
|
expect(imgNode.length).toBe(3);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2020-04-14 19:32:16 +08:00
|
|
|
});
|
|
|
|
it('should not render <img /> when custom imageUrl return false', () => {
|
2020-12-09 17:12:32 +08:00
|
|
|
const isImageUrl = jest.fn(() => false);
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2020-04-14 19:32:16 +08:00
|
|
|
<Upload listType="picture-card" fileList={list} isImageUrl={isImageUrl}>
|
|
|
|
<button type="button">button</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail img');
|
2020-04-14 19:32:16 +08:00
|
|
|
expect(isImageUrl).toHaveBeenCalled();
|
|
|
|
expect(imgNode.length).toBe(0);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2020-04-14 19:32:16 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-06 21:47:01 +08:00
|
|
|
describe('thumbUrl support for non-image', () => {
|
2020-09-08 14:47:31 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
|
|
|
|
2020-07-06 21:47:01 +08:00
|
|
|
const nonImageFile = new File([''], 'foo.7z', { type: 'application/x-7z-compressed' });
|
2020-09-08 14:47:31 +08:00
|
|
|
|
|
|
|
/** Wait for a long promise since `rc-util` internal has at least 3 promise wait */
|
|
|
|
async function waitPromise() {
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
for (let i = 0; i < 10; i += 1) {
|
|
|
|
await Promise.resolve();
|
|
|
|
}
|
|
|
|
/* eslint-enable */
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should render <img /> when upload non-image file and configure thumbUrl in onChange', async () => {
|
2020-07-06 21:47:01 +08:00
|
|
|
let wrapper;
|
2020-09-08 14:47:31 +08:00
|
|
|
const onChange = jest.fn(({ fileList: files }) => {
|
2020-08-29 21:28:44 +08:00
|
|
|
const newFileList = files.map(item => ({
|
2020-07-06 21:47:01 +08:00
|
|
|
...item,
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
}));
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
wrapper.rerender(
|
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
listType="picture-card"
|
|
|
|
fileList={newFileList}
|
|
|
|
onChange={onChange}
|
|
|
|
customRequest={successRequest}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2020-09-08 14:47:31 +08:00
|
|
|
});
|
2020-08-29 21:28:44 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
wrapper = render(
|
2020-07-06 21:47:01 +08:00
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
listType="picture-card"
|
|
|
|
fileList={[]}
|
|
|
|
onChange={onChange}
|
|
|
|
customRequest={successRequest}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.container.querySelectorAll('.ant-upload-list-item-thumbnail img');
|
|
|
|
expect(imgNode.length).toBe(0);
|
2020-09-08 14:47:31 +08:00
|
|
|
|
|
|
|
// Simulate change is a timeout change
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.change(wrapper.container.querySelector('input'), {
|
|
|
|
target: { files: [nonImageFile] },
|
|
|
|
});
|
2020-09-08 14:47:31 +08:00
|
|
|
|
|
|
|
// Wait for `rc-upload` process file
|
|
|
|
await waitPromise();
|
|
|
|
|
|
|
|
// Wait for mock request finish request
|
|
|
|
jest.runAllTimers();
|
|
|
|
|
|
|
|
// Basic called times
|
|
|
|
expect(onChange).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// Check for images
|
2022-06-16 23:29:04 +08:00
|
|
|
await act(() => {
|
2020-09-08 14:47:31 +08:00
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
const afterImgNode = wrapper.container.querySelectorAll(
|
|
|
|
'.ant-upload-list-item-thumbnail img',
|
|
|
|
);
|
2020-09-08 14:47:31 +08:00
|
|
|
expect(afterImgNode.length).toBeTruthy();
|
2021-02-26 15:18:37 +08:00
|
|
|
|
|
|
|
wrapper.unmount();
|
2020-07-06 21:47:01 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render <img /> when upload non-image file without thumbUrl in onChange', done => {
|
2021-02-26 15:18:37 +08:00
|
|
|
global.testName =
|
|
|
|
'should not render <img /> when upload non-image file without thumbUrl in onChange';
|
2020-07-06 21:47:01 +08:00
|
|
|
let wrapper;
|
|
|
|
const onChange = async ({ fileList: files }) => {
|
2022-06-16 23:29:04 +08:00
|
|
|
wrapper.rerender(
|
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
listType="picture-card"
|
|
|
|
fileList={files}
|
|
|
|
onChange={onChange}
|
|
|
|
customRequest={successRequest}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2020-07-06 21:47:01 +08:00
|
|
|
|
|
|
|
await sleep();
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.container.querySelectorAll('.ant-upload-list-item-thumbnail img');
|
2020-07-06 21:47:01 +08:00
|
|
|
expect(imgNode.length).toBe(0);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2020-07-06 21:47:01 +08:00
|
|
|
done();
|
|
|
|
};
|
2022-06-16 23:29:04 +08:00
|
|
|
wrapper = render(
|
2020-07-06 21:47:01 +08:00
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
listType="picture-card"
|
|
|
|
fileList={[]}
|
|
|
|
onChange={onChange}
|
|
|
|
customRequest={successRequest}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.container.querySelectorAll('.ant-upload-list-item-thumbnail img');
|
2020-07-06 21:47:01 +08:00
|
|
|
expect(imgNode.length).toBe(0);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.change(wrapper.container.querySelector('input'), {
|
|
|
|
target: { files: [nonImageFile] },
|
|
|
|
});
|
2020-07-06 21:47:01 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-15 15:56:35 +08:00
|
|
|
it('[deprecated] should support transformFile', done => {
|
2021-02-26 15:18:37 +08:00
|
|
|
let wrapper;
|
2021-03-04 16:59:06 +08:00
|
|
|
let lastFile;
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2019-08-04 12:18:46 +08:00
|
|
|
const handleTransformFile = jest.fn();
|
|
|
|
const onChange = ({ file }) => {
|
|
|
|
if (file.status === 'done') {
|
2021-03-04 16:59:06 +08:00
|
|
|
expect(file).not.toBe(lastFile);
|
2019-08-04 12:18:46 +08:00
|
|
|
expect(handleTransformFile).toHaveBeenCalled();
|
2021-02-26 15:18:37 +08:00
|
|
|
wrapper.unmount();
|
2019-08-04 12:18:46 +08:00
|
|
|
done();
|
|
|
|
}
|
2021-03-04 16:59:06 +08:00
|
|
|
|
|
|
|
lastFile = file;
|
2019-08-04 12:18:46 +08:00
|
|
|
};
|
2022-06-16 23:29:04 +08:00
|
|
|
wrapper = render(
|
2019-08-04 12:18:46 +08:00
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
transformFile={handleTransformFile}
|
|
|
|
onChange={onChange}
|
|
|
|
customRequest={successRequest}
|
|
|
|
>
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.change(wrapper.container.querySelector('input'), {
|
2019-08-04 12:18:46 +08:00
|
|
|
target: {
|
|
|
|
files: [{ name: 'foo.png' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2020-08-24 16:33:24 +08:00
|
|
|
|
|
|
|
it('should render button inside UploadList when listStyle is picture-card', () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const {
|
|
|
|
container: wrapper,
|
|
|
|
rerender,
|
|
|
|
unmount,
|
|
|
|
} = render(
|
2020-08-24 16:33:24 +08:00
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
listType="picture-card"
|
|
|
|
fileList={[
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
showUploadList
|
|
|
|
>
|
|
|
|
<button className="trigger" type="button">
|
|
|
|
upload
|
|
|
|
</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-list button.trigger').length).toBeGreaterThan(0);
|
|
|
|
rerender(
|
|
|
|
<Upload
|
|
|
|
action="http://jsonplaceholder.typicode.com/posts/"
|
|
|
|
listType="picture-card"
|
|
|
|
fileList={[
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
showUploadList={false}
|
|
|
|
>
|
|
|
|
<button className="trigger" type="button">
|
|
|
|
upload
|
|
|
|
</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-list button.trigger').length).toBe(0);
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2020-08-24 16:33:24 +08:00
|
|
|
});
|
2020-09-07 16:41:28 +08:00
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/26536
|
|
|
|
it('multiple file upload should keep the internal fileList async', async () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
|
|
|
|
const uploadRef = React.createRef();
|
|
|
|
|
|
|
|
const MyUpload = () => {
|
|
|
|
const [testFileList, setTestFileList] = React.useState([]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Upload
|
|
|
|
ref={uploadRef}
|
|
|
|
fileList={testFileList}
|
|
|
|
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
|
|
|
|
multiple
|
|
|
|
onChange={info => {
|
|
|
|
setTestFileList([...info.fileList]);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button type="button">Upload</button>
|
|
|
|
</Upload>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { unmount } = render(<MyUpload />);
|
2020-09-07 16:41:28 +08:00
|
|
|
|
|
|
|
// Mock async update in a frame
|
2021-03-13 23:46:32 +08:00
|
|
|
const fileNames = ['light', 'bamboo', 'little'];
|
2020-09-07 16:41:28 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await act(() => {
|
2021-03-13 23:46:32 +08:00
|
|
|
uploadRef.current.onBatchStart(
|
|
|
|
fileNames.map(fileName => {
|
|
|
|
const file = new File([], fileName);
|
|
|
|
file.uid = fileName;
|
|
|
|
|
|
|
|
return {
|
|
|
|
file,
|
|
|
|
parsedFile: file,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2020-09-07 16:41:28 +08:00
|
|
|
|
2021-03-13 23:46:32 +08:00
|
|
|
expect(uploadRef.current.fileList).toHaveLength(fileNames.length);
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await act(() => {
|
2021-03-13 23:46:32 +08:00
|
|
|
jest.runAllTimers();
|
|
|
|
});
|
|
|
|
expect(uploadRef.current.fileList).toHaveLength(fileNames.length);
|
2020-09-07 16:41:28 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2020-09-07 16:41:28 +08:00
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
2020-09-17 16:14:42 +08:00
|
|
|
|
|
|
|
it('itemRender', () => {
|
2021-05-06 14:12:26 +08:00
|
|
|
const onDownload = jest.fn();
|
|
|
|
const onRemove = jest.fn();
|
|
|
|
const onPreview = jest.fn();
|
|
|
|
const itemRender = (originNode, file, currFileList, actions) => {
|
2020-09-17 16:14:42 +08:00
|
|
|
const { name, status, uid, url } = file;
|
|
|
|
const index = currFileList.indexOf(file);
|
|
|
|
return (
|
2021-05-06 14:12:26 +08:00
|
|
|
<div className="custom-item-render">
|
|
|
|
<span>
|
|
|
|
{`uid:${uid} name: ${name} status: ${status} url: ${url} ${index + 1}/${
|
|
|
|
currFileList.length
|
|
|
|
}`}
|
|
|
|
</span>
|
|
|
|
<span onClick={actions.remove} className="custom-item-render-action-remove">
|
|
|
|
remove
|
|
|
|
</span>
|
|
|
|
<span onClick={actions.download} className="custom-item-render-action-download">
|
|
|
|
download
|
|
|
|
</span>
|
|
|
|
<span onClick={actions.preview} className="custom-item-render-action-preview">
|
|
|
|
preview
|
|
|
|
</span>
|
|
|
|
</div>
|
2020-09-17 16:14:42 +08:00
|
|
|
);
|
|
|
|
};
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2021-05-06 14:12:26 +08:00
|
|
|
<UploadList
|
|
|
|
onDownload={onDownload}
|
|
|
|
onPreview={onPreview}
|
|
|
|
onRemove={onRemove}
|
|
|
|
locale={{}}
|
|
|
|
items={fileList}
|
|
|
|
itemRender={itemRender}
|
|
|
|
/>,
|
|
|
|
);
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.firstChild).toMatchSnapshot();
|
2021-02-26 15:18:37 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.custom-item-render-action-remove')[0]);
|
2021-05-06 14:12:26 +08:00
|
|
|
expect(onRemove.mock.calls[0][0]).toEqual(fileList[0]);
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.custom-item-render-action-download')[0]);
|
2021-05-06 14:12:26 +08:00
|
|
|
expect(onDownload.mock.calls[0][0]).toEqual(fileList[0]);
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
fireEvent.click(wrapper.querySelectorAll('.custom-item-render-action-preview')[0]);
|
2021-05-06 14:12:26 +08:00
|
|
|
expect(onPreview.mock.calls[0][0]).toEqual(fileList[0]);
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2020-09-17 16:14:42 +08:00
|
|
|
});
|
2021-02-26 22:38:11 +08:00
|
|
|
|
|
|
|
it('LIST_IGNORE should not add in list', async () => {
|
|
|
|
const beforeUpload = jest.fn(() => Upload.LIST_IGNORE);
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(<Upload beforeUpload={beforeUpload} />);
|
2021-02-26 22:38:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
await act(() => {
|
|
|
|
fireEvent.change(wrapper.querySelector('input'), {
|
2021-02-26 22:38:11 +08:00
|
|
|
target: {
|
|
|
|
files: [{ file: 'foo.png' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
await sleep();
|
|
|
|
|
|
|
|
expect(beforeUpload).toHaveBeenCalled();
|
2022-06-16 23:29:04 +08:00
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-list-text-container')).toHaveLength(0);
|
2021-02-26 22:38:11 +08:00
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2021-02-26 22:38:11 +08:00
|
|
|
});
|
2021-03-10 17:32:32 +08:00
|
|
|
|
|
|
|
it('Not crash when fileList is null', () => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const defaultWrapper = render(<Upload defaultFileList={null} />);
|
2021-03-10 17:32:32 +08:00
|
|
|
defaultWrapper.unmount();
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const wrapper = render(<Upload fileList={null} />);
|
2021-03-10 17:32:32 +08:00
|
|
|
wrapper.unmount();
|
|
|
|
});
|
2022-04-12 12:03:46 +08:00
|
|
|
|
|
|
|
it('should not exist crossorigin attribute when does not set file.crossorigin in case of listType="picture"', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2022-04-12 12:03:46 +08:00
|
|
|
<Upload fileList={list} listType="picture">
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
|
|
|
list.forEach((file, i) => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail img')[i];
|
|
|
|
expect(imgNode.getAttribute('crossOrigin')).toBe(null);
|
2022-04-12 12:03:46 +08:00
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2022-04-12 12:03:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should exist crossorigin attribute when set file.crossorigin in case of listType="picture"', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
crossOrigin: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uid: '1',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
crossOrigin: 'anonymous',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uid: '2',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
crossOrigin: 'use-credentials',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2022-04-12 12:03:46 +08:00
|
|
|
<Upload fileList={list} listType="picture">
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
|
|
|
list.forEach((file, i) => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail img')[i];
|
|
|
|
expect(imgNode.getAttribute('crossOrigin')).not.toBe(undefined);
|
|
|
|
expect(imgNode.getAttribute('crossOrigin')).toBe(file.crossOrigin);
|
2022-04-12 12:03:46 +08:00
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2022-04-12 12:03:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not exist crossorigin attribute when does not set file.crossorigin in case of listType="picture-card"', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2022-04-12 12:03:46 +08:00
|
|
|
<Upload fileList={list} listType="picture">
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
|
|
|
list.forEach((file, i) => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail img')[i];
|
|
|
|
expect(imgNode.getAttribute('crossOrigin')).toBe(null);
|
2022-04-12 12:03:46 +08:00
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2022-04-12 12:03:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should exist crossorigin attribute when set file.crossorigin in case of listType="picture-card"', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
crossOrigin: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uid: '1',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
crossOrigin: 'anonymous',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uid: '2',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
crossOrigin: 'use-credentials',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-06-16 23:29:04 +08:00
|
|
|
const { container: wrapper, unmount } = render(
|
2022-04-12 12:03:46 +08:00
|
|
|
<Upload fileList={list} listType="picture">
|
|
|
|
<button type="button">upload</button>
|
|
|
|
</Upload>,
|
|
|
|
);
|
|
|
|
list.forEach((file, i) => {
|
2022-06-16 23:29:04 +08:00
|
|
|
const imgNode = wrapper.querySelectorAll('.ant-upload-list-item-thumbnail img')[i];
|
|
|
|
expect(imgNode.getAttribute('crossOrigin')).not.toBe(undefined);
|
|
|
|
expect(imgNode.getAttribute('crossOrigin')).toBe(file.crossOrigin);
|
2022-04-12 12:03:46 +08:00
|
|
|
});
|
2022-06-16 23:29:04 +08:00
|
|
|
unmount();
|
2022-04-12 12:03:46 +08:00
|
|
|
});
|
2022-06-23 16:45:24 +08:00
|
|
|
|
|
|
|
describe('should not display upload file-select button when listType is picture-card and children is empty', () => {
|
|
|
|
it('when showUploadList is true', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const { container: wrapper, unmount } = render(
|
|
|
|
<Upload fileList={list} listType="picture-card" />,
|
|
|
|
);
|
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-select').length).toBe(1);
|
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-select')[0].style.display).toBe('none');
|
|
|
|
unmount();
|
|
|
|
});
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/36183
|
|
|
|
it('when showUploadList is false', () => {
|
|
|
|
const list = [
|
|
|
|
{
|
|
|
|
uid: '0',
|
|
|
|
name: 'xxx.png',
|
|
|
|
status: 'done',
|
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const { container: wrapper, unmount } = render(
|
|
|
|
<Upload fileList={list} showUploadList={false} listType="picture-card" />,
|
|
|
|
);
|
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-select').length).toBe(1);
|
|
|
|
expect(wrapper.querySelectorAll('.ant-upload-select')[0].style.display).toBe('none');
|
|
|
|
unmount();
|
|
|
|
});
|
|
|
|
});
|
2017-01-24 14:59:39 +08:00
|
|
|
});
|