ant-design-vue/components/upload/__tests__/uploadlist.test.js

437 lines
12 KiB
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
import { mount } from '@vue/test-utils';
2020-07-25 13:27:58 +00:00
import * as Vue from 'vue';
2019-01-12 03:33:27 +00:00
import Upload from '..';
import { errorRequest, successRequest } from './requests';
import PropsTypes from '../../_util/vue-types';
import { UploadListProps } from '../interface';
2020-08-14 07:55:16 +00:00
import { sleep } from '../../../tests/utils';
import { h } from 'vue';
2018-06-02 07:12:53 +00:00
2019-01-12 03:33:27 +00:00
UploadListProps.items = PropsTypes.any;
2018-06-02 07:12:53 +00:00
2019-01-12 03:33:27 +00:00
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
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',
},
];
2018-06-02 07:12:53 +00:00
describe('Upload List', () => {
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
// jsdom not support `createObjectURL` yet. Let's handle this.
const originCreateObjectURL = window.URL.createObjectURL;
window.URL.createObjectURL = jest.fn(() => '');
const originHTMLCanvasElementGetContext = window.HTMLCanvasElement.prototype.getContext;
window.HTMLCanvasElement.prototype.getContext = jest.fn(() => '');
2018-06-02 07:12:53 +00:00
// https://github.com/ant-design/ant-design/issues/4653
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
afterAll(() => {
window.URL.createObjectURL = originCreateObjectURL;
window.HTMLCanvasElement.prototype.getContext = originHTMLCanvasElementGetContext;
});
2020-08-14 09:04:45 +00:00
it('should use file.thumbUrl for <img /> in priority', done => {
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2018-06-02 07:12:53 +00:00
defaultFileList: fileList,
listType: 'picture',
action: '',
},
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
2018-06-02 07:12:53 +00:00
Vue.nextTick(() => {
fileList.forEach((file, i) => {
2020-08-14 07:55:16 +00:00
const linkNode = wrapper.findAll('.ant-upload-list-item-thumbnail')[i];
const imgNode = wrapper.findAll('.ant-upload-list-item-thumbnail img')[i];
2019-01-12 03:33:27 +00:00
expect(linkNode.attributes().href).toBe(file.url);
expect(imgNode.attributes().src).toBe(file.thumbUrl);
});
done();
});
});
2018-06-02 07:12:53 +00:00
// https://github.com/ant-design/ant-design/issues/7269
2020-08-14 09:04:45 +00:00
it('should remove correct item when uid is 0', done => {
2019-01-12 03:33:27 +00: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',
},
];
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2018-06-02 07:12:53 +00:00
defaultFileList: list,
action: '',
},
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
2018-06-02 07:12:53 +00:00
setTimeout(async () => {
2019-01-12 03:33:27 +00:00
expect(wrapper.findAll('.ant-upload-list-item').length).toBe(2);
wrapper
2020-08-14 07:55:16 +00:00
.findAll('.ant-upload-list-item')[0]
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
.find('.anticon-delete')
2019-01-12 03:33:27 +00:00
.trigger('click');
await delay(400);
2018-06-02 07:12:53 +00:00
// wrapper.update();
2019-01-12 03:33:27 +00:00
expect(wrapper.findAll('.ant-upload-list-item').length).toBe(1);
done();
}, 0);
});
2018-06-02 07:12:53 +00:00
2020-08-14 07:55:16 +00:00
xit('should be uploading when upload a file', done => {
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2019-05-25 10:24:22 +00:00
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
2018-06-02 07:12:53 +00:00
customRequest: successRequest,
2020-08-14 07:55:16 +00:00
onChange: ({ file }) => {
2018-06-02 07:12:53 +00:00
if (file.status === 'uploading') {
2019-01-12 03:33:27 +00:00
expect(wrapper.html()).toMatchSnapshot();
done();
2018-06-02 07:12:53 +00:00
}
if (file.status === 'done') {
2019-01-12 03:33:27 +00:00
expect(wrapper.html()).toMatchSnapshot();
done();
2018-06-02 07:12:53 +00:00
}
},
},
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
2018-06-02 07:12:53 +00:00
setTimeout(() => {
const mockFile = new File(['foo'], 'foo.png', {
type: 'image/png',
2019-01-12 03:33:27 +00:00
});
2020-08-14 07:55:16 +00:00
wrapper.findComponent({ name: 'ajaxUploader' }).vm.onChange({
2018-06-02 07:12:53 +00:00
target: {
files: [mockFile],
},
2019-01-12 03:33:27 +00:00
});
}, 0);
});
2018-06-02 07:12:53 +00:00
2020-08-14 07:55:16 +00:00
xit('handle error', done => {
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2019-05-25 10:24:22 +00:00
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
2018-06-02 07:12:53 +00:00
customRequest: errorRequest,
},
listeners: {
change: ({ file }) => {
if (file.status !== 'uploading') {
2019-01-12 03:33:27 +00:00
expect(wrapper.html()).toMatchSnapshot();
done();
2018-06-02 07:12:53 +00:00
}
},
},
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
2018-06-02 07:12:53 +00:00
setTimeout(() => {
const mockFile = new File(['foo'], 'foo.png', {
type: 'image/png',
2019-01-12 03:33:27 +00:00
});
2020-08-14 07:55:16 +00:00
wrapper.findComponent({ name: 'ajaxUploader' }).vm.onChange({
2018-06-02 07:12:53 +00:00
target: {
files: [mockFile],
},
2019-01-12 03:33:27 +00:00
});
}, 0);
});
2018-06-02 07:12:53 +00:00
2020-08-14 07:55:16 +00:00
xit('does concat filelist when beforeUpload returns false', done => {
2019-01-12 03:33:27 +00:00
const handleChange = jest.fn();
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2019-05-25 10:24:22 +00:00
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
2018-06-02 07:12:53 +00:00
listType: 'picture',
defaultFileList: fileList,
beforeUpload: () => false,
2020-08-14 07:55:16 +00:00
onChange: handleChange,
2018-06-02 07:12:53 +00:00
},
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
2018-06-02 07:12:53 +00:00
setTimeout(() => {
const mockFile = new File(['foo'], 'foo.png', {
type: 'image/png',
2019-01-12 03:33:27 +00:00
});
2020-08-14 07:25:17 +00:00
wrapper.findComponent({ name: 'ajaxUploader' }).vm.onChange({
2018-06-02 07:12:53 +00:00
target: {
files: [mockFile],
},
2019-01-12 03:33:27 +00:00
});
2018-06-02 07:12:53 +00:00
Vue.nextTick(() => {
2019-01-12 03:33:27 +00:00
expect(wrapper.vm.sFileList.length).toBe(fileList.length + 1);
expect(handleChange.mock.calls[0][0].fileList).toHaveLength(3);
done();
});
}, 0);
});
2018-06-02 07:12:53 +00:00
// https://github.com/ant-design/ant-design/issues/7762
// it('work with form validation', (done) => {
// let errors
// const TestForm = {
// methods: {
// handleSubmit () {
// const { validateFields } = this.form
// validateFields((err) => {
// errors = err
// })
// },
// },
// render () {
// const { getFieldDecorator } = this.form
// return (
// <Form onSubmit={this.handleSubmit}>
// <Form.Item>
// {getFieldDecorator('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>upload</button>
// </Upload>
// )}
// </Form.Item>
// </Form>
// )
// },
// }
// const App = Form.create()(TestForm)
// console.dir(App)
// const wrapper = mount(() => {
// return <App />
// })
// setTimeout(async () => {
// wrapper.find(Form).trigger('submit')
// expect(errors.file.errors).toEqual([{ message: 'file required', field: 'file' }])
// const mockFile = new File(['foo'], 'foo.png', {
// type: 'image/png',
// })
2020-08-14 07:55:16 +00:00
// wrapper.findComponent({ name: 'ajaxUploader' }).vm.onChange({
2018-06-02 07:12:53 +00:00
// target: {
// files: [mockFile],
// },
// })
// wrapper.find(Form).trigger('submit')
// expect(errors).toBeNull()
// done()
// }, 0)
// })
2020-08-14 09:04:45 +00:00
it('should support onPreview', async () => {
2019-01-12 03:33:27 +00:00
const handlePreview = jest.fn();
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2018-06-02 07:12:53 +00:00
defaultFileList: fileList,
listType: 'picture-card',
action: '',
2020-08-14 07:55:16 +00:00
onPreview: handlePreview,
2018-06-02 07:12:53 +00:00
},
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
2020-08-14 07:55:16 +00:00
await sleep(500);
wrapper.findAll('.anticon-eye')[0].trigger('click');
expect(handlePreview).toBeCalledWith(fileList[0]);
wrapper.findAll('.anticon-eye')[1].trigger('click');
expect(handlePreview).toBeCalledWith(fileList[1]);
2019-01-12 03:33:27 +00:00
});
2018-06-02 07:12:53 +00:00
2020-08-14 09:04:45 +00:00
it('should support onRemove', done => {
2019-01-12 03:33:27 +00:00
const handleRemove = jest.fn();
const handleChange = jest.fn();
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2018-06-02 07:12:53 +00:00
defaultFileList: fileList,
listType: 'picture-card',
action: '',
2018-11-16 03:35:58 +00:00
remove: handleRemove,
2020-08-14 07:55:16 +00:00
onChange: handleChange,
2018-06-02 07:12:53 +00:00
},
2020-08-14 07:55:16 +00:00
2018-06-02 07:12:53 +00:00
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
jest.setTimeout(300000);
2018-06-02 07:12:53 +00:00
setTimeout(async () => {
2020-08-14 07:55:16 +00:00
wrapper.findAll('.anticon-delete')[0].trigger('click');
2019-01-12 03:33:27 +00:00
expect(handleRemove).toBeCalledWith(fileList[0]);
2020-08-14 07:55:16 +00:00
wrapper.findAll('.anticon-delete')[1].trigger('click');
2019-01-12 03:33:27 +00:00
expect(handleRemove).toBeCalledWith(fileList[1]);
await delay(0);
expect(handleChange.mock.calls.length).toBe(2);
done();
}, 0);
});
2018-06-02 07:12:53 +00:00
2020-08-14 07:55:16 +00:00
xit('should generate thumbUrl from file', done => {
2019-01-12 03:33:27 +00:00
const handlePreview = jest.fn();
const newFileList = [...fileList];
const newFile = { ...fileList[0], uid: -3, originFileObj: new File([], 'xxx.png') };
delete newFile.thumbUrl;
newFileList.push(newFile);
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2018-06-02 07:12:53 +00:00
defaultFileList: newFileList,
listType: 'picture-card',
action: '',
2020-08-14 07:55:16 +00:00
onPreview: handlePreview,
2018-06-02 07:12:53 +00:00
},
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
2018-06-02 07:12:53 +00:00
setTimeout(async () => {
2019-01-12 03:33:27 +00:00
const newFile = { ...fileList[2], uid: -4, originFileObj: new File([], 'xxx.png') };
2020-08-14 07:55:16 +00:00
newFileList.push(newFile);
2018-06-02 07:12:53 +00:00
wrapper.setProps({
2020-08-14 07:55:16 +00:00
defaultFileList: [...newFileList],
2019-01-12 03:33:27 +00:00
});
await delay(200);
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
expect(wrapper.vm.sFileList[2].thumbUrl).not.toBe(undefined);
2019-01-12 03:33:27 +00:00
done();
}, 1000);
});
2018-06-02 07:12:53 +00:00
2020-08-14 09:04:45 +00:00
it('should non-image format file preview', done => {
2018-06-02 07:12:53 +00:00
const list = [
{
name: 'not-image',
status: 'done',
uid: -3,
url: 'https://cdn.xxx.com/aaa.zip',
thumbUrl: 'data:application/zip;base64,UEsDBAoAAAAAADYZYkwAAAAAAAAAAAAAAAAdAAk',
originFileObj: new File([], 'aaa.zip'),
},
{
name: 'image',
status: 'done',
uid: -4,
url: 'https://cdn.xxx.com/aaa',
},
{
name: 'not-image',
status: 'done',
uid: -5,
url: 'https://cdn.xxx.com/aaa.xx',
},
{
name: 'not-image',
status: 'done',
uid: -6,
url: 'https://cdn.xxx.com/aaa.png/xx.xx',
},
{
name: 'image',
status: 'done',
uid: -7,
url: 'https://cdn.xxx.com/xx.xx/aaa.png',
},
{
name: 'image',
status: 'done',
uid: -8,
url: 'https://cdn.xxx.com/xx.xx/aaa.png',
thumbUrl: 'data:image/png;base64,UEsDBAoAAAAAADYZYkwAAAAAAAAAAAAAAAAdAAk',
},
{
name: 'image',
status: 'done',
uid: -9,
url: 'https://cdn.xxx.com/xx.xx/aaa.png?query=123',
},
{
name: 'image',
status: 'done',
uid: -10,
url: 'https://cdn.xxx.com/xx.xx/aaa.png#anchor',
},
{
name: 'image',
status: 'done',
uid: -11,
url: 'https://cdn.xxx.com/xx.xx/aaa.png?query=some.query.with.dot',
},
2019-01-12 03:33:27 +00:00
];
2018-06-02 07:12:53 +00:00
const props = {
2020-07-25 07:46:49 +00:00
props: {
2018-06-02 07:12:53 +00:00
defaultFileList: list,
listType: 'picture',
action: '',
},
slots: {
2020-08-14 07:55:16 +00:00
default: () => h('button', 'upload'),
2018-06-02 07:12:53 +00:00
},
sync: false,
2019-01-12 03:33:27 +00:00
};
const wrapper = mount(Upload, props);
2018-06-02 07:12:53 +00:00
Vue.nextTick(() => {
2019-01-12 03:33:27 +00:00
expect(wrapper.html()).toMatchSnapshot();
done();
});
});
});