2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-09-25 08:51:32 +00:00
|
|
|
import { asyncExpect } from '../../../tests/utils';
|
2019-01-12 03:33:27 +00:00
|
|
|
import Select from '..';
|
2020-04-04 14:03:18 +00:00
|
|
|
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
2019-01-12 03:33:27 +00:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2020-03-07 11:45:13 +00:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-08-04 06:39:23 +00:00
|
|
|
function $$(className) {
|
|
|
|
return document.body.querySelectorAll(className);
|
|
|
|
}
|
|
|
|
function getStyle(el, prop) {
|
|
|
|
const style = window.getComputedStyle ? window.getComputedStyle(el) : el.currentStyle;
|
2018-06-21 14:28:10 +00:00
|
|
|
|
2020-08-04 06:39:23 +00:00
|
|
|
// If a css property's value is `auto`, it will return an empty string.
|
|
|
|
return prop ? style[prop] : style;
|
|
|
|
}
|
2018-06-21 14:28:10 +00:00
|
|
|
describe('Select', () => {
|
2020-08-04 06:39:23 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
document.body.innerHTML = '';
|
|
|
|
});
|
2019-01-12 03:33:27 +00:00
|
|
|
focusTest(Select);
|
2020-08-04 06:39:23 +00:00
|
|
|
mountTest({
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Select />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2018-06-21 14:28:10 +00:00
|
|
|
|
|
|
|
it('should have default notFoundContent', async () => {
|
2021-06-21 06:23:55 +00:00
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <Select mode="multiple" />;
|
|
|
|
},
|
2018-06-21 14:28:10 +00:00
|
|
|
},
|
2021-06-21 06:23:55 +00:00
|
|
|
{
|
|
|
|
sync: false,
|
|
|
|
attachTo: 'body',
|
|
|
|
},
|
|
|
|
);
|
2018-06-21 14:28:10 +00:00
|
|
|
await asyncExpect(() => {
|
2020-10-28 07:37:31 +00:00
|
|
|
wrapper.findAll('.ant-select-selector')[0].element.dispatchEvent(new MouseEvent('mousedown'));
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-21 14:28:10 +00:00
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2020-10-26 10:31:50 +00:00
|
|
|
expect($$('.ant-select-item-option').length).toBe(0);
|
2020-10-28 07:37:31 +00:00
|
|
|
expect($$('.ant-empty-description')[0].innerHTML).toBe('No Data');
|
2020-10-26 10:31:50 +00:00
|
|
|
}, 100);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-21 14:28:10 +00:00
|
|
|
|
|
|
|
it('should support set notFoundContent to null', async () => {
|
2021-06-21 06:23:55 +00:00
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <Select mode="multiple" notFoundContent={null} />;
|
|
|
|
},
|
2018-06-21 14:28:10 +00:00
|
|
|
},
|
2021-06-21 06:23:55 +00:00
|
|
|
{
|
|
|
|
sync: false,
|
|
|
|
attachTo: 'body',
|
|
|
|
},
|
|
|
|
);
|
2018-06-21 14:28:10 +00:00
|
|
|
await asyncExpect(() => {
|
2020-10-28 07:37:31 +00:00
|
|
|
wrapper.findAll('.ant-select-selector')[0].element.dispatchEvent(new MouseEvent('mousedown'));
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2020-08-04 06:39:23 +00:00
|
|
|
|
2018-06-21 14:28:10 +00:00
|
|
|
await asyncExpect(() => {
|
2020-10-26 10:31:50 +00:00
|
|
|
expect($$('.ant-select-item-option').length).toBe(0);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
});
|
2018-06-21 14:28:10 +00:00
|
|
|
|
|
|
|
it('should not have default notFoundContent when mode is combobox', async () => {
|
2021-06-21 06:23:55 +00:00
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <Select mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE} />;
|
|
|
|
},
|
2018-06-21 14:28:10 +00:00
|
|
|
},
|
2021-06-21 06:23:55 +00:00
|
|
|
{
|
|
|
|
sync: false,
|
|
|
|
attachTo: 'body',
|
|
|
|
},
|
|
|
|
);
|
2018-06-21 14:28:10 +00:00
|
|
|
await asyncExpect(() => {
|
2020-10-28 07:37:31 +00:00
|
|
|
wrapper.findAll('.ant-select-selector')[0].element.dispatchEvent(new MouseEvent('mousedown'));
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-21 14:28:10 +00:00
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2020-10-26 10:31:50 +00:00
|
|
|
expect($$('.ant-select-item-option').length).toBe(0);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
});
|
2018-06-21 14:28:10 +00:00
|
|
|
|
|
|
|
it('should not have notFoundContent when mode is combobox and notFoundContent is set', async () => {
|
2021-06-21 06:23:55 +00:00
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Select mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE} notFoundContent="not at all" />
|
|
|
|
);
|
|
|
|
},
|
2018-06-21 14:28:10 +00:00
|
|
|
},
|
2021-06-21 06:23:55 +00:00
|
|
|
{
|
|
|
|
sync: false,
|
|
|
|
},
|
|
|
|
);
|
2018-06-21 14:28:10 +00:00
|
|
|
await asyncExpect(() => {
|
2020-10-28 07:37:31 +00:00
|
|
|
wrapper.findAll('.ant-select-selector')[0].element.dispatchEvent(new MouseEvent('mousedown'));
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-21 14:28:10 +00:00
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2020-10-26 10:31:50 +00:00
|
|
|
expect($$('.ant-select-item-option').length).toBe(0);
|
|
|
|
expect($$('.ant-select-item-empty').length).toBe(1);
|
|
|
|
// expect($$('.ant-select-item-option')[0].innerHTML).toMatchSnapshot();
|
|
|
|
}, 100);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-12-11 03:40:27 +00:00
|
|
|
|
|
|
|
it('should be controlled by open prop', async () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const onDropdownVisibleChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
props: {
|
|
|
|
open: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Select open={this.open} onDropdownVisibleChange={onDropdownVisibleChange}>
|
2020-08-04 06:39:23 +00:00
|
|
|
<Select.Option value="1">1</Select.Option>
|
2019-01-12 03:33:27 +00:00
|
|
|
</Select>
|
|
|
|
);
|
2018-12-11 03:40:27 +00:00
|
|
|
},
|
|
|
|
},
|
2020-08-04 06:39:23 +00:00
|
|
|
{ sync: false, attachTo: 'body' },
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2020-08-04 06:39:23 +00:00
|
|
|
|
2018-12-11 03:40:27 +00:00
|
|
|
await asyncExpect(() => {
|
2020-08-04 06:39:23 +00:00
|
|
|
expect(getStyle($$('.ant-select-dropdown')[0], 'display')).toBe('block');
|
2020-10-26 10:31:50 +00:00
|
|
|
}, 100);
|
2018-12-11 03:40:27 +00:00
|
|
|
await asyncExpect(() => {
|
2020-10-28 07:37:31 +00:00
|
|
|
wrapper.findAll('.ant-select-selector')[0].element.dispatchEvent(new MouseEvent('mousedown'));
|
2020-10-26 10:31:50 +00:00
|
|
|
});
|
2020-10-28 07:37:31 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(onDropdownVisibleChange).toHaveBeenLastCalledWith(false);
|
|
|
|
});
|
2018-12-11 03:40:27 +00:00
|
|
|
await asyncExpect(() => {
|
2020-08-04 06:39:23 +00:00
|
|
|
expect(getStyle($$('.ant-select-dropdown')[0], 'display')).toBe('block');
|
2019-01-12 03:33:27 +00:00
|
|
|
wrapper.setProps({ open: false });
|
|
|
|
});
|
2020-08-04 06:39:23 +00:00
|
|
|
|
2018-12-11 03:40:27 +00:00
|
|
|
await asyncExpect(() => {
|
2020-08-04 06:39:23 +00:00
|
|
|
expect(getStyle($$('.ant-select-dropdown')[0], 'display')).toBe('none');
|
2020-10-28 07:37:31 +00:00
|
|
|
wrapper.findAll('.ant-select-selector')[0].element.dispatchEvent(new MouseEvent('mousedown'));
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(onDropdownVisibleChange).toHaveBeenLastCalledWith(true);
|
2020-08-04 06:39:23 +00:00
|
|
|
expect(getStyle($$('.ant-select-dropdown')[0], 'display')).toBe('none');
|
|
|
|
}, 500);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2019-01-05 08:22:25 +00:00
|
|
|
|
|
|
|
describe('Select Custom Icons', () => {
|
|
|
|
it('should support customized icons', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2019-01-05 08:22:25 +00:00
|
|
|
return (
|
|
|
|
<Select
|
2020-04-04 14:03:18 +00:00
|
|
|
removeIcon={<CloseOutlined />}
|
|
|
|
clearIcon={<CloseOutlined />}
|
|
|
|
menuItemSelectedIcon={<CloseOutlined />}
|
2019-01-05 08:22:25 +00:00
|
|
|
>
|
2020-08-04 06:39:23 +00:00
|
|
|
<Select.Option value="1">1</Select.Option>
|
2019-01-05 08:22:25 +00:00
|
|
|
</Select>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2019-01-05 08:22:25 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|