From 14b21445943b71dd9bb795046cc1d2faad0a0d37 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, 17 Mar 2022 17:15:02 +0300 Subject: [PATCH] Create MegaMenu.spec.js --- src/components/megamenu/MegaMenu.spec.js | 88 ++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/components/megamenu/MegaMenu.spec.js diff --git a/src/components/megamenu/MegaMenu.spec.js b/src/components/megamenu/MegaMenu.spec.js new file mode 100644 index 000000000..2c077a40f --- /dev/null +++ b/src/components/megamenu/MegaMenu.spec.js @@ -0,0 +1,88 @@ +import { mount } from '@vue/test-utils'; +import MegaMenu from './MegaMenu.vue'; + +describe('MegaMenu.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(MegaMenu, { + global: { + stubs: { + 'router-link': true + } + }, + props: { + model: [ + { + label: 'Videos', icon: 'pi pi-fw pi-video', + items: [ + [ + { + label: 'Video 1', + items: [{label: 'Video 1.1'}, {label: 'Video 1.2'}] + }, + { + label: 'Video 2', + items: [{label: 'Video 2.1'}, {label: 'Video 2.2'}] + } + ] + ] + }, + { + label: 'Users', icon: 'pi pi-fw pi-users', + items: [ + [ + { + label: 'User 1', + items: [{label: 'User 1.1'}, {label: 'User 1.2'}] + } + ], + [ + { + label: 'User 2', + items: [{label: 'User 2.1'}, {label: 'User 2.2'}] + }, + { + label: 'User 3', + items: [{label: 'User 3.1'}, {label: 'User 3.2'}] + } + ] + ] + } + ] + } + }); + }); + + it('should exists', () => { + expect(wrapper.find('.p-megamenu.p-component').exists()).toBe(true); + expect(wrapper.find('.p-megamenu-root-list').exists()).toBe(true); + expect(wrapper.findAll('ul.p-megamenu-submenu').length).toBe(5); + expect(wrapper.findAll('li.p-menuitem').length).toBe(12); + expect(wrapper.findAll('li.p-menuitem')[0].findAll('span.p-menuitem-text')[0].text()).toBe('Videos'); + expect(wrapper.findAll('li.p-megamenu-submenu-header')[0].text()).toBe('Video 1'); + expect(wrapper.findAll('li.p-menuitem')[1].findAll('span.p-menuitem-text')[0].text()).toBe('Video 1.1'); + }); + + it('should select item', async () => { + const firstItem = wrapper.findAll('li.p-menuitem')[0]; + + await wrapper.vm.onCategoryClick({}, wrapper.vm.model[0]); + + expect(firstItem.classes()).toContain('p-menuitem-active'); + }); + + it('should deselect item', async () => { + const firstItem = wrapper.findAll('li.p-menuitem')[0]; + + await wrapper.vm.onCategoryClick({}, wrapper.vm.model[0].items[0][0].items[0]); + + expect(firstItem.classes()).not.toContain('p-menuitem-active'); + }); + + it('should orientation work', async () => { + await wrapper.setProps({ orientation: 'vertical' }); + + expect(wrapper.find('.p-megamenu-vertical').exists()).toBe(true); + }); +}); \ No newline at end of file