From b2b8c06df5d0a94d07f074d4b5b4ff34ff206f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Thu, 10 Mar 2022 12:17:04 +0300 Subject: [PATCH] AutoComplete test added --- .../autocomplete/AutoComplete.spec.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/components/autocomplete/AutoComplete.spec.js diff --git a/src/components/autocomplete/AutoComplete.spec.js b/src/components/autocomplete/AutoComplete.spec.js new file mode 100644 index 000000000..093b91942 --- /dev/null +++ b/src/components/autocomplete/AutoComplete.spec.js @@ -0,0 +1,58 @@ +import { mount } from '@vue/test-utils'; +import PrimeVue from '@/components/config/PrimeVue'; +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: [ + {"name": "Afghanistan", "code": "AF"}, + {"name": "Bahrain", "code": "BH"}, + {"name": "Chile", "code": "CL"}, + {"name": "Denmark", "code": "DK"} + ] + } + } + }); + + 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); + }); + + it('search copmlete', async () => { + const event = {'target': { 'value': 'b' }}; + + wrapper.vm.onInput(event); + await wrapper.vm.$nextTick(); + + wrapper.vm.search(event , event.target.value, 'input'); + await wrapper.vm.$nextTick(); + + await wrapper.setProps({ + suggestions: [ + {"name": "Bahrain", "code": "BH"} + ] + }); + + expect(wrapper.find('.p-autocomplete-items').exists()).toBe(true); + expect(wrapper.findAll('.p-autocomplete-item').length).toBe(1); + }); +}); \ No newline at end of file