2022-09-06 12:03:37 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import PrimeVue from '@/components/config/PrimeVue';
|
|
|
|
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-09-14 11:26:01 +00:00
|
|
|
it('should exist', async () => {
|
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-09-14 11:26:01 +00:00
|
|
|
});
|