primevue-mirror/components/lib/cascadeselect/CascadeSelect.spec.js

140 lines
5.4 KiB
JavaScript
Raw Normal View History

2022-12-08 11:04:25 +00:00
import { nextTick } from 'vue';
2022-09-06 12:03:37 +00:00
import { mount } from '@vue/test-utils';
2022-12-08 11:04:25 +00:00
import PrimeVue from 'primevue/config';
2022-09-06 12:03:37 +00:00
import CascadeSelect from './CascadeSelect.vue';
describe('CascadeSelect.vue', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(CascadeSelect, {
global: {
plugins: [PrimeVue],
stubs: {
teleport: true
}
},
props: {
modelValue: null,
options: [
{
name: 'Australia',
code: 'AU',
states: [
{
name: 'New South Wales',
cities: [
2022-09-14 11:26:01 +00:00
{ cname: 'Sydney', code: 'A-SY' },
{ cname: 'Newcastle', code: 'A-NE' },
{ cname: 'Wollongong', code: 'A-WO' }
2022-09-06 12:03:37 +00:00
]
},
{
name: 'Queensland',
cities: [
2022-09-14 11:26:01 +00:00
{ cname: 'Brisbane', code: 'A-BR' },
{ cname: 'Townsville', code: 'A-TO' }
2022-09-06 12:03:37 +00:00
]
2022-09-14 11:26:01 +00:00
}
2022-09-06 12:03:37 +00:00
]
},
{
2022-09-14 11:26:01 +00:00
name: 'Canada',
2022-09-06 12:03:37 +00:00
code: 'CA',
states: [
{
name: 'Quebec',
cities: [
2022-09-14 11:26:01 +00:00
{ cname: 'Montreal', code: 'C-MO' },
{ cname: 'Quebec City', code: 'C-QU' }
2022-09-06 12:03:37 +00:00
]
},
{
name: 'Ontario',
cities: [
2022-09-14 11:26:01 +00:00
{ cname: 'Ottawa', code: 'C-OT' },
{ cname: 'Toronto', code: 'C-TO' }
2022-09-06 12:03:37 +00:00
]
2022-09-14 11:26:01 +00:00
}
2022-09-06 12:03:37 +00:00
]
},
{
name: 'United States',
code: 'US',
states: [
{
name: 'California',
cities: [
2022-09-14 11:26:01 +00:00
{ cname: 'Los Angeles', code: 'US-LA' },
{ cname: 'San Diego', code: 'US-SD' },
{ cname: 'San Francisco', code: 'US-SF' }
2022-09-06 12:03:37 +00:00
]
},
{
name: 'Florida',
cities: [
2022-09-14 11:26:01 +00:00
{ cname: 'Jacksonville', code: 'US-JA' },
{ cname: 'Miami', code: 'US-MI' },
{ cname: 'Tampa', code: 'US-TA' },
{ cname: 'Orlando', code: 'US-OR' }
2022-09-06 12:03:37 +00:00
]
},
{
name: 'Texas',
cities: [
2022-09-14 11:26:01 +00:00
{ cname: 'Austin', code: 'US-AU' },
{ cname: 'Dallas', code: 'US-DA' },
{ cname: 'Houston', code: 'US-HO' }
2022-09-06 12:03:37 +00:00
]
}
]
}
],
optionLabel: 'cname',
optionGroupLabel: 'name',
optionGroupChildren: ['states', 'cities']
}
});
});
2022-12-08 11:04:25 +00:00
it('should exist', () => {
2022-09-06 12:03:37 +00:00
expect(wrapper.find('.p-cascadeselect.p-component').exists()).toBe(true);
});
2022-09-14 11:26:01 +00:00
it('should show list and sublist', async () => {
2022-09-06 12:03:37 +00:00
expect(wrapper.find('.p-cascadeselect.p-component').exists()).toBe(true);
await wrapper.trigger('click');
expect(wrapper.find('.p-cascadeselect-panel.p-cascadeselect-items').exists()).toBe(true);
expect(wrapper.findAll('.p-cascadeselect-item').length).toBe(3);
expect(wrapper.findAll('.p-cascadeselect-item-text')[0].text()).toBe('Australia');
const firstGroup = wrapper.findAll('.p-cascadeselect-item-content')[0];
2022-09-14 11:26:01 +00:00
2022-09-06 12:03:37 +00:00
await firstGroup.trigger('click');
expect(wrapper.find('.p-cascadeselect-panel.p-cascadeselect-sublist').exists()).toBe(true);
const sublist = wrapper.find('.p-cascadeselect-panel.p-cascadeselect-sublist');
expect(sublist.findAll('.p-cascadeselect-item.p-cascadeselect-item-group').length).toBe(2);
expect(sublist.findAll('.p-cascadeselect-item-text')[0].text()).toBe('New South Wales');
});
2022-12-08 11:04:25 +00:00
it('should accept custom icons', async () => {
wrapper.setProps({
dropdownIcon: 'pi pi-discord',
optionGroupIcon: 'pi pi-bell'
});
await nextTick();
expect(wrapper.find('.p-cascadeselect-trigger-icon').classes()).toContain('pi-discord');
await wrapper.trigger('click');
expect(wrapper.find('.p-cascadeselect-group-icon').classes()).toContain('pi-bell');
});
2022-09-14 11:26:01 +00:00
});