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';
|
|
|
|
import { nextTick } from 'vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
import AutoComplete from './AutoComplete.vue';
|
|
|
|
|
|
|
|
describe('AutoComplete.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
wrapper = mount(AutoComplete, {
|
|
|
|
global: {
|
|
|
|
plugins: [PrimeVue],
|
|
|
|
stubs: {
|
|
|
|
teleport: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
suggestions: null,
|
|
|
|
field: 'name'
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
countries: [
|
2022-09-14 11:26:01 +00:00
|
|
|
{ name: 'Afghanistan', code: 'AF' },
|
|
|
|
{ name: 'Bahrain', code: 'BH' },
|
|
|
|
{ name: 'Chile', code: 'CL' },
|
|
|
|
{ name: 'Denmark', code: 'DK' }
|
2022-09-06 12:03:37 +00:00
|
|
|
]
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
await wrapper.trigger('click');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should exists', () => {
|
|
|
|
expect(wrapper.find('.p-autocomplete.p-component').exists()).toBe(true);
|
|
|
|
expect(wrapper.find('.p-autocomplete-input').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
it('search complete', async () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
const event = { target: { value: 'b' } };
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
wrapper.vm.onInput(event);
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
wrapper.vm.search(event, event.target.value, 'input');
|
2022-09-06 12:03:37 +00:00
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
await wrapper.setProps({
|
2022-09-14 11:26:01 +00:00
|
|
|
suggestions: [{ name: 'Bahrain', code: 'BH' }]
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find('.p-autocomplete-items').exists()).toBe(true);
|
|
|
|
expect(wrapper.findAll('.p-autocomplete-item').length).toBe(1);
|
|
|
|
});
|
2022-12-08 11:04:25 +00:00
|
|
|
|
2023-09-05 01:19:51 +00:00
|
|
|
it('should show overlay and empty-message if there are no suggestions', async () => {
|
|
|
|
const event = { target: { value: 'b' } };
|
|
|
|
|
|
|
|
wrapper.vm.search(event, event.target.value, 'input');
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
suggestions: []
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find('.p-autocomplete-items').exists()).toBe(true);
|
|
|
|
expect(wrapper.findAll('.p-autocomplete-item').length).toBe(0);
|
|
|
|
expect(wrapper.find('.p-autocomplete-empty-message').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2023-04-05 09:22:45 +00:00
|
|
|
it('dropdown', () => {
|
2022-12-08 11:04:25 +00:00
|
|
|
it('should have correct custom icon', async () => {
|
|
|
|
wrapper.setProps({
|
|
|
|
dropdown: true,
|
|
|
|
dropdownIcon: 'pi pi-discord'
|
|
|
|
});
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
2023-04-05 09:22:45 +00:00
|
|
|
const token = wrapper.find('.p-button').find('span');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
expect(token.classes()).toContain('pi-discord');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-05 09:22:45 +00:00
|
|
|
it('multiple', () => {
|
2022-12-08 11:04:25 +00:00
|
|
|
it('should have correct custom icon', async () => {
|
|
|
|
wrapper.setProps({
|
|
|
|
multiple: true,
|
|
|
|
removeTokenIcon: 'pi pi-discord',
|
|
|
|
modelValue: ['foo', 'bar']
|
|
|
|
});
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
wrapper.findAll('.p-autocomplete-token-icon').forEach((tokenIcon) => {
|
|
|
|
expect(tokenIcon.classes()).toContain('pi-discord');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|