2022-09-06 12:03:37 +00:00
|
|
|
import PrimeVue from '@/components/config/PrimeVue';
|
2022-09-14 11:26:01 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
import MultiSelect from './MultiSelect.vue';
|
|
|
|
|
|
|
|
describe('MultiSelect.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
wrapper = mount(MultiSelect, {
|
|
|
|
global: {
|
|
|
|
plugins: [PrimeVue],
|
|
|
|
stubs: {
|
|
|
|
teleport: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
modelValue: null,
|
|
|
|
options: [
|
2022-09-14 11:26:01 +00:00
|
|
|
{ name: 'New York', code: 'NY' },
|
|
|
|
{ name: 'Rome', code: 'RM' },
|
|
|
|
{ name: 'London', code: 'LDN' },
|
|
|
|
{ name: 'Istanbul', code: 'IST' },
|
|
|
|
{ name: 'Paris', code: 'PRS' }
|
2022-09-06 12:03:37 +00:00
|
|
|
],
|
|
|
|
optionLabel: 'name',
|
|
|
|
placeholder: 'Select Cities'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
it('should exist', async () => {
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.find('.p-multiselect.p-component').exists()).toBe(true);
|
|
|
|
expect(wrapper.find('.p-multiselect-label.p-placeholder').text()).toBe('Select Cities');
|
2022-09-14 11:26:01 +00:00
|
|
|
expect(wrapper.find('.p-multiselect-panel').exists()).toBe(false);
|
|
|
|
|
|
|
|
await wrapper.vm.onContainerClick();
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.findAll('li.p-multiselect-item').length).toBe(5);
|
|
|
|
expect(wrapper.findAll('li.p-multiselect-item')[0].attributes()['aria-label']).toBe('New York');
|
|
|
|
expect(wrapper.findAll('li.p-multiselect-item')[0].findAll('span')[1].text()).toBe('New York');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should select an item', async () => {
|
|
|
|
await wrapper.vm.onOptionSelect({}, wrapper.vm.options[0]);
|
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([[wrapper.vm.options[0]]]);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.setProps({ modelValue: [wrapper.vm.options[0]] });
|
|
|
|
await wrapper.vm.onContainerClick();
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.findAll('li.p-multiselect-item')[0].classes()).toContain('p-highlight');
|
|
|
|
expect(wrapper.find('.p-multiselect-label').text()).toBe('New York');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should select multiple item', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.setProps({ modelValue: [wrapper.vm.options[0]] });
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
await wrapper.vm.onOptionSelect({}, wrapper.vm.options[1]);
|
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([[wrapper.vm.options[0], wrapper.vm.options[1]]]);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.setProps({ modelValue: [wrapper.vm.options[0], wrapper.vm.options[1]] });
|
|
|
|
await wrapper.vm.onContainerClick();
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
expect(wrapper.findAll('li.p-multiselect-item')[0].classes()).toContain('p-highlight');
|
|
|
|
expect(wrapper.findAll('li.p-multiselect-item')[1].classes()).toContain('p-highlight');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should close panel', async () => {
|
|
|
|
await wrapper.vm.onCloseClick();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.find('.p-multiselect-panel').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should chip work', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
await wrapper.setProps({
|
|
|
|
display: 'chip',
|
|
|
|
modelValue: [wrapper.vm.options[0]]
|
|
|
|
});
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.find('.p-multiselect-token').exists()).toBe(true);
|
|
|
|
expect(wrapper.find('.p-multiselect-token-label').text()).toBe('New York');
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|