mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-02 12:07:54 +08:00
3aeeeb2aed
* refactor: transfer、tooltip (#4306) * refactor(transfer): use composition api (#4135) * refactor(transfer): use composition api * fix: remove console * refactor(tooltip): use composition api (#4059) * refactor(tooltip): use composition api * chore: useConfigInject * fix: remove useless * style: format code * refactor: transfer * refactor: tooltip Co-authored-by: ajuner <106791576@qq.com> * Refactor mentions (#4341) * refactor(mentions): use compositionAPI (#4313) * refactor: mentions * refactor: mentions Co-authored-by: ajuner <106791576@qq.com> * Refactor progress (#4358) * fix: timepicker error border not show #4331 * fix(UploadDragger): fix UploadDrager no export (#4334) * refactor(switch): support customize checked value #4329 (#4332) * refactor(switch): support customize checked value #4329 * test: add test case * refactor: update props name * refactor: update ts * refactor: optimize * style: uncheckedValue to unCheckedValue * test: update snap * feat: udpate switch ts * docs: remove ie11 * fix: tree-select throw error when use slot title * fix: TypeScript definition of Table interface for typescript 4.3.5 (#4353) * fix type for typescript 4.3.5 * Update interface.ts close #4296 * fix: dropdown submenu style error #4351 close #4351 * fix(notification): 完善notification类型 (#4346) * refactor(progress): use composition API (#4355) * refactor(progress): use composition API * refactor(vc-progress): update * refactor: progress * refactor: progress * fix: timepicker error border not show #4331 * fix(UploadDragger): fix UploadDrager no export (#4334) * refactor(switch): support customize checked value #4329 (#4332) * refactor(switch): support customize checked value #4329 * test: add test case * refactor: update props name * refactor: update ts * refactor: optimize * style: uncheckedValue to unCheckedValue * test: update snap * feat: udpate switch ts * docs: remove ie11 * fix: tree-select throw error when use slot title * fix: TypeScript definition of Table interface for typescript 4.3.5 (#4353) * fix type for typescript 4.3.5 * Update interface.ts close #4296 * fix: dropdown submenu style error #4351 close #4351 * fix(notification): 完善notification类型 (#4346) * refactor(progress): use composition API (#4355) * refactor(progress): use composition API * refactor(vc-progress): update * refactor: progress * refactor: progress Co-authored-by: Jarvis <35361626+fanhaoyuan@users.noreply.github.com> Co-authored-by: John <John60676@qq.com> Co-authored-by: 艾斯特洛 <axetroy.dev@gmail.com> Co-authored-by: zanllp <qc@zanllp.cn> * docs: add changelog * refactor: tree * refactor: tree * style: lint * refactor: tree * 热factor: tree * refactor: tree * refactor: tree * refactor: tree * refactor: directory tree * refactor: tree * refactor: tree-select * refactor: tree-select * refactor: tree-select * refactor: tree-select * refactor: tree-select * style: lint format * refactor: tree-select * refactor: tree-select * refactor: tree-select * refactor: tree-select * refactor: tree-select * refactor: tree-select * fix: upload ts error * fix: update tree title render & switchIcon * test: update tree test * feat: add VirtualScroll tree * refactor: datePicker & calendar & trigger (#4522) * style: update * test: update calendar test * test: update test * test: update test * refactor: slider * feat: update slider css * refactor: slider to ts * refactor: slider to ts * perf: update default itemHeight * test: update * fix: uddate ts type * fix: update skeleton * fix: update skeleton * refactor: update vc-pagination * refactor: pagination * refactor: timeline * refactor: steps * refactor: collapse * refactor: collapse * refactor: popconfirm * refactor: popover * refactor: dropdown * doc: merge doc * chore: vite for dev (#4602) * style: js to jsx * doc: add site * style: lint * style: format ts type * doc: update * style: format code * style: format site * doc: update * style: dmeo * style: format scripts * chore: remove sub-modules * chore: update vite * site: add site build * test: update snap * doc(select): add tip (#4606) * refactor: table (#4641) * refactor: table * refactor: table * refactor: table * refactor: table * refactor: table * refactor: table * refactor: table * refactor: table * refactor: table * fix: column not pass to cell * doc: uppate table * fix: update bodyCell headerCell * doc: remove examples * refactor: table * fix: table title not work * fix: table selection * fix: table checkStrictly * refactor: table * fix: table template error * feat: table support summary * test: update snap * perf: table * docs(table): fix ajax demo (#4639) * test: update table * refactor: remove old table * doc: update table doc * doc: update doc * doc: update select * doc: update summary Co-authored-by: John <John60676@qq.com> * doc: update doc * fix: menu arrow not work * test: update * doc: add next site * style: format * doc: update * doc: update site script * fix: expand icon not fixed * feat: use renderSlot * test: update table snap * feat: confirm support reactively * feat: configProvider.config * feat: message support configprovider.config * feat: notification support configprovider.config * doc: update doc * fix: typescript compile error * style: add import eslint * doc: update demo * chore: set transpileOnly true * style: fix eslint error * test: update snap * doc: update * test: mock date * test: update snap * chore: remove gulp-typescript (#4675) * feat: V3 form (#4678) * chore: update husky * perf: update formItem * perf: useInjectFormItemContext * fix: table ts error * doc: add Customized Form Controls demo * feat: export useInjectFormItemContext * doc: update form doc * doc: update doc * doc: update doc * feat: autocomplete support option slot * doc: update * feat: add form item rest * style: remove omit.js * refactor: autocomplete * doc: add changelog to site * doc: update site anchor * doc: update doc layout * test: update table test * doc: update * chore: udpate gulp script * chore: udpate gulp script * doc: add changelog * doc: update * test: ignore some test wait vue-test-utils * fix: form id error #4582 close #4582 * doc: add select Responsive demo * doc: remove temp doc Co-authored-by: ajuner <106791576@qq.com> Co-authored-by: Jarvis <35361626+fanhaoyuan@users.noreply.github.com> Co-authored-by: John <John60676@qq.com> Co-authored-by: 艾斯特洛 <axetroy.dev@gmail.com> Co-authored-by: zanllp <qc@zanllp.cn> Co-authored-by: Amour1688 <lcz_1996@foxmail.com>
505 lines
13 KiB
JavaScript
505 lines
13 KiB
JavaScript
import { mount } from '@vue/test-utils';
|
|
import Transfer from '..';
|
|
import * as Vue from 'vue';
|
|
import { sleep, asyncExpect } from '../../../tests/utils';
|
|
import mountTest from '../../../tests/shared/mountTest';
|
|
|
|
const listCommonProps = {
|
|
dataSource: [
|
|
{
|
|
key: 'a',
|
|
title: 'a',
|
|
},
|
|
{
|
|
key: 'b',
|
|
title: 'b',
|
|
},
|
|
{
|
|
key: 'c',
|
|
title: 'c',
|
|
disabled: true,
|
|
},
|
|
],
|
|
selectedKeys: ['a'],
|
|
targetKeys: ['b'],
|
|
lazy: false,
|
|
};
|
|
|
|
const listDisabledProps = {
|
|
dataSource: [
|
|
{
|
|
key: 'a',
|
|
title: 'a',
|
|
disabled: true,
|
|
},
|
|
{
|
|
key: 'b',
|
|
title: 'b',
|
|
},
|
|
],
|
|
selectedKeys: ['a', 'b'],
|
|
targetKeys: [],
|
|
lazy: false,
|
|
};
|
|
|
|
const searchTransferProps = {
|
|
dataSource: [
|
|
{
|
|
key: '0',
|
|
title: 'content1',
|
|
description: 'description of content1',
|
|
chosen: false,
|
|
},
|
|
{
|
|
key: '1',
|
|
title: 'content2',
|
|
description: 'description of content2',
|
|
chosen: false,
|
|
},
|
|
{
|
|
key: '2',
|
|
title: 'content3',
|
|
description: 'description of content3',
|
|
chosen: false,
|
|
},
|
|
{
|
|
key: '3',
|
|
title: 'content4',
|
|
description: 'description of content4',
|
|
chosen: false,
|
|
},
|
|
{
|
|
key: '4',
|
|
title: 'content5',
|
|
description: 'description of content5',
|
|
chosen: false,
|
|
},
|
|
{
|
|
key: '5',
|
|
title: 'content6',
|
|
description: 'description of content6',
|
|
chosen: false,
|
|
},
|
|
],
|
|
selectedKeys: [],
|
|
targetKeys: ['3', '4'],
|
|
lazy: false,
|
|
};
|
|
|
|
describe('Transfer', () => {
|
|
mountTest(Transfer);
|
|
it('should render correctly', () => {
|
|
const wrapper = mount({
|
|
setup() {
|
|
return () => <Transfer {...{ ...listCommonProps }} />;
|
|
},
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
});
|
|
|
|
it('should move selected keys to corresponding list', done => {
|
|
const handleChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
{
|
|
setup() {
|
|
return () => <Transfer {...{ ...listCommonProps, onChange: handleChange }} />;
|
|
},
|
|
},
|
|
{
|
|
sync: false,
|
|
},
|
|
);
|
|
Vue.nextTick(() => {
|
|
wrapper.findAll('.ant-btn')[0].trigger('click'); // move selected keys to right list
|
|
expect(handleChange).toHaveBeenCalledWith(['a', 'b'], 'right', ['a']);
|
|
done();
|
|
});
|
|
});
|
|
it('should move selected keys expect disabled to corresponding list', done => {
|
|
const handleChange = jest.fn();
|
|
const wrapper = mount(
|
|
{
|
|
setup() {
|
|
return () => <Transfer {...{ ...listDisabledProps, onChange: handleChange }} />;
|
|
},
|
|
},
|
|
{
|
|
sync: false,
|
|
},
|
|
);
|
|
Vue.nextTick(() => {
|
|
wrapper.findAll('.ant-btn')[0].trigger('click');
|
|
expect(handleChange).toHaveBeenCalledWith(['b'], 'right', ['b']);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should uncheck checkbox when click on checked item', async () => {
|
|
const handleSelectChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
{
|
|
setup() {
|
|
return () => <Transfer {...{ ...listCommonProps, onSelectChange: handleSelectChange }} />;
|
|
},
|
|
},
|
|
{
|
|
sync: false,
|
|
},
|
|
);
|
|
|
|
await sleep();
|
|
wrapper.findAll('.ant-transfer-list-content-item')[0].trigger('click');
|
|
expect(handleSelectChange).toHaveBeenLastCalledWith([], []);
|
|
});
|
|
|
|
it('should check checkbox when click on unchecked item', async () => {
|
|
const handleSelectChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
{
|
|
setup() {
|
|
return () => <Transfer {...{ ...listCommonProps, onSelectChange: handleSelectChange }} />;
|
|
},
|
|
},
|
|
{
|
|
sync: false,
|
|
},
|
|
);
|
|
|
|
await sleep();
|
|
wrapper.findAll('.ant-transfer-list-content-item')[2].trigger('click');
|
|
await sleep();
|
|
expect(handleSelectChange).toHaveBeenLastCalledWith(['a'], ['b']);
|
|
});
|
|
|
|
it('should not check checkbox when click on disabled item', async () => {
|
|
const handleSelectChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
{
|
|
setup() {
|
|
return () => <Transfer {...{ ...listCommonProps, onSelectChange: handleSelectChange }} />;
|
|
},
|
|
},
|
|
{
|
|
sync: false,
|
|
},
|
|
);
|
|
|
|
await sleep();
|
|
wrapper.findAll('.ant-transfer-list-content-item')[1].trigger('click');
|
|
expect(handleSelectChange).not.toHaveBeenCalled();
|
|
});
|
|
|
|
xit('should check all item when click on check all', done => {
|
|
const handleSelectChange = jest.fn();
|
|
const wrapper = mount(Transfer, {
|
|
props: listCommonProps,
|
|
listeners: {
|
|
selectChange: handleSelectChange,
|
|
},
|
|
sync: false,
|
|
});
|
|
Vue.nextTick(() => {
|
|
wrapper
|
|
.findAll('.ant-transfer-list-header input[type="checkbox"]')
|
|
.filter(n => {
|
|
return !n.vnode.data.domProps.checked;
|
|
})
|
|
.trigger('change');
|
|
expect(handleSelectChange).toHaveBeenCalledWith(['a'], ['b']);
|
|
done();
|
|
});
|
|
});
|
|
|
|
xit('should uncheck all item when click on uncheck all', done => {
|
|
const handleSelectChange = jest.fn();
|
|
const wrapper = mount(Transfer, {
|
|
props: listCommonProps,
|
|
listeners: {
|
|
selectChange: handleSelectChange,
|
|
},
|
|
sync: false,
|
|
});
|
|
Vue.nextTick(() => {
|
|
wrapper
|
|
.findAll('.ant-transfer-list-header input[type="checkbox"]')
|
|
.filter(n => {
|
|
return n.vnode.data.domProps.checked;
|
|
})
|
|
.trigger('change');
|
|
expect(handleSelectChange).toHaveBeenCalledWith([], []);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should call `filterOption` when use input in search box', done => {
|
|
const filterOption = (inputValue, option) => inputValue === option.title;
|
|
|
|
const wrapper = mount(
|
|
{
|
|
setup() {
|
|
return () => (
|
|
<Transfer
|
|
{...{
|
|
...listCommonProps,
|
|
showSearch: true,
|
|
filterOption,
|
|
}}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
sync: false,
|
|
},
|
|
);
|
|
|
|
Vue.nextTick(() => {
|
|
const input = wrapper.findAll('.ant-transfer-list-body-search-wrapper input')[0];
|
|
input.element.value = 'a';
|
|
input.trigger('input');
|
|
Vue.nextTick(() => {
|
|
expect(
|
|
wrapper
|
|
.findAll('.ant-transfer-list-content')[0]
|
|
.find('.ant-transfer-list-content-item')
|
|
.findAll('input[type="checkbox"]'),
|
|
).toHaveLength(1);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should display the correct count of items when filter by input', done => {
|
|
const filterOption = (inputValue, option) => option.description.indexOf(inputValue) > -1;
|
|
const renderFunc = item => item.title;
|
|
const wrapper = mount(
|
|
{
|
|
setup() {
|
|
return () => (
|
|
<Transfer
|
|
{...{
|
|
...searchTransferProps,
|
|
showSearch: true,
|
|
filterOption,
|
|
render: renderFunc,
|
|
}}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
sync: false,
|
|
},
|
|
);
|
|
|
|
Vue.nextTick(() => {
|
|
const input = wrapper.findAll('.ant-transfer-list-body-search-wrapper input')[0];
|
|
input.element.value = 'content2';
|
|
input.trigger('input');
|
|
Vue.nextTick(() => {
|
|
expect(
|
|
wrapper
|
|
.findAll('.ant-transfer-list')[0]
|
|
.findAll('.ant-transfer-list-header-selected > span')[0]
|
|
.text()
|
|
.trim(),
|
|
).toEqual('1 item');
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
xit('should just check the filtered item when click on check all after search by input', done => {
|
|
const filterOption = (inputValue, option) => option.description.indexOf(inputValue) > -1;
|
|
const renderFunc = item => item.title;
|
|
const handleSelectChange = jest.fn();
|
|
const wrapper = mount(Transfer, {
|
|
props: {
|
|
...searchTransferProps,
|
|
showSearch: true,
|
|
filterOption,
|
|
render: renderFunc,
|
|
},
|
|
listeners: {
|
|
selectChange: handleSelectChange,
|
|
},
|
|
sync: false,
|
|
});
|
|
Vue.nextTick(() => {
|
|
const input = wrapper.findAll('.ant-transfer-list-body-search-wrapper input')[0];
|
|
input.element.value = 'content2';
|
|
input.trigger('input');
|
|
Vue.nextTick(() => {
|
|
wrapper
|
|
.findAll('.ant-transfer-list')[0]
|
|
.findAll('.ant-transfer-list-header input[type="checkbox"]')
|
|
.filter(n => {
|
|
return !n.vnode.data.domProps.checked;
|
|
})
|
|
.trigger('change');
|
|
expect(handleSelectChange).toHaveBeenCalledWith(['1'], []);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
xit('should transfer just the filtered item after search by input', done => {
|
|
const filterOption = (inputValue, option) => option.description.indexOf(inputValue) > -1;
|
|
const renderFunc = item => item.title;
|
|
const handleChange = jest.fn();
|
|
const handleSelectChange = (sourceSelectedKeys, targetSelectedKeys) => {
|
|
wrapper.setProps({
|
|
selectedKeys: [...sourceSelectedKeys, ...targetSelectedKeys],
|
|
});
|
|
};
|
|
const wrapper = mount(Transfer, {
|
|
props: {
|
|
...searchTransferProps,
|
|
showSearch: true,
|
|
filterOption,
|
|
render: renderFunc,
|
|
},
|
|
listeners: {
|
|
selectChange: handleSelectChange,
|
|
change: handleChange,
|
|
},
|
|
sync: false,
|
|
});
|
|
Vue.nextTick(() => {
|
|
const input = wrapper.findAll('.ant-transfer-list-body-search-wrapper input')[0];
|
|
input.element.value = 'content2';
|
|
input.trigger('input');
|
|
Vue.nextTick(() => {
|
|
wrapper
|
|
.findAll('.ant-transfer-list')[0]
|
|
.findAll('.ant-transfer-list-header input[type="checkbox"]')
|
|
.filter(n => {
|
|
return !n.element.checked;
|
|
})
|
|
.trigger('change');
|
|
Vue.nextTick(() => {
|
|
wrapper.findAll('.ant-btn')[0].trigger('click');
|
|
expect(handleChange).toHaveBeenCalledWith(['1', '3', '4'], 'right', ['1']);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
xit('should check correctly when there is a search text', done => {
|
|
const newProps = { ...listCommonProps };
|
|
delete newProps.targetKeys;
|
|
delete newProps.selectedKeys;
|
|
const handleSelectChange = jest.fn();
|
|
const wrapper = mount(Transfer, {
|
|
props: {
|
|
...newProps,
|
|
showSearch: true,
|
|
render: item => item.title,
|
|
},
|
|
listeners: {
|
|
selectChange: handleSelectChange,
|
|
},
|
|
sync: false,
|
|
});
|
|
Vue.nextTick(() => {
|
|
wrapper
|
|
.findAll('.ant-transfer-list-content-item')
|
|
.filter(n => {
|
|
return n.vnode.data.key === 'b';
|
|
})
|
|
.trigger('click');
|
|
expect(handleSelectChange).toHaveBeenLastCalledWith(['b'], []);
|
|
|
|
const input = wrapper.findAll('.ant-transfer-list-body-search-wrapper input')[0];
|
|
input.element.value = 'a';
|
|
input.trigger('input');
|
|
Vue.nextTick(() => {
|
|
wrapper
|
|
.findAll('.ant-transfer-list')[0]
|
|
.findAll('.ant-transfer-list-header input[type="checkbox"]')
|
|
.trigger('change');
|
|
Vue.nextTick(() => {
|
|
expect(handleSelectChange).toHaveBeenLastCalledWith(['b', 'a'], []);
|
|
wrapper
|
|
.findAll('.ant-transfer-list')[0]
|
|
.findAll('.ant-transfer-list-header input[type="checkbox"]')
|
|
.trigger('change');
|
|
expect(handleSelectChange).toHaveBeenLastCalledWith(['b'], []);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should show sorted targetkey', () => {
|
|
const sortedTargetKeyProps = {
|
|
dataSource: [
|
|
{
|
|
key: 'a',
|
|
title: 'a',
|
|
},
|
|
{
|
|
key: 'b',
|
|
title: 'b',
|
|
},
|
|
{
|
|
key: 'c',
|
|
title: 'c',
|
|
},
|
|
],
|
|
targetKeys: ['c', 'b'],
|
|
lazy: false,
|
|
};
|
|
const wrapper = mount({
|
|
setup() {
|
|
return () => <Transfer {...sortedTargetKeyProps} render={item => item.title} />;
|
|
},
|
|
});
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
});
|
|
it('should add custom styles when their props are provided', async () => {
|
|
const style = {
|
|
backgroundColor: 'red',
|
|
};
|
|
const listStyle = {
|
|
backgroundColor: 'blue',
|
|
};
|
|
const operationStyle = {
|
|
backgroundColor: 'yellow',
|
|
};
|
|
const transferProps = {
|
|
props: {
|
|
...listCommonProps,
|
|
listStyle,
|
|
operationStyle,
|
|
},
|
|
style,
|
|
};
|
|
const component = mount(
|
|
{
|
|
render() {
|
|
return <Transfer {...transferProps} />;
|
|
},
|
|
},
|
|
{ sync: false },
|
|
);
|
|
await asyncExpect(() => {
|
|
const wrapper = component.find('.ant-transfer');
|
|
// const list = component.findAll('.ant-transfer-list');
|
|
// const listSource = list[0];
|
|
// const listTarget = list[list.length - 1];
|
|
// const operation = component.findAll('.ant-transfer-operation')[0];
|
|
expect(wrapper.element.style).toHaveProperty('backgroundColor', 'red');
|
|
// expect(listSource.element.style).toHaveProperty('backgroundColor', 'blue');
|
|
// expect(listTarget.element.style).toHaveProperty('backgroundColor', 'blue');
|
|
// expect(operation.element.style).toHaveProperty('backgroundColor', 'yellow');
|
|
});
|
|
});
|
|
});
|