2022-09-14 11:26:01 +00:00
|
|
|
import { config, mount } from '@vue/test-utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Listbox from './Listbox.vue';
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
config.global.mocks = {
|
|
|
|
$primevue: {
|
|
|
|
config: {
|
|
|
|
locale: {
|
|
|
|
aria: {
|
|
|
|
trueLabel: 'trueLabel',
|
|
|
|
falseLabel: 'falseLabel',
|
|
|
|
nullLabel: 'nullLabel'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
describe('Listbox.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = mount(Listbox, {
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should exist', () => {
|
|
|
|
expect(wrapper.find('.p-listbox.p-component').exists()).toBe(true);
|
|
|
|
expect(wrapper.findAll('li.p-listbox-item').length).toBe(5);
|
|
|
|
expect(wrapper.findAll('li.p-listbox-item')[0].attributes()['aria-label']).toBe('New York');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should select a list item', async () => {
|
|
|
|
await wrapper.vm.onOptionSelect({}, wrapper.vm.options[0]);
|
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([wrapper.vm.options[0]]);
|
|
|
|
|
|
|
|
await wrapper.setProps({ modelValue: wrapper.vm.options[0] });
|
|
|
|
|
|
|
|
expect(wrapper.findAll('li.p-listbox-item')[0].classes()).toContain('p-highlight');
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|