From 7825c893975bff5ccc1f4edbf12d52aced176ec4 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Wed, 19 Oct 2022 04:56:35 +0100 Subject: [PATCH] Fixed tests --- src/components/megamenu/MegaMenu.spec.js | 5 +++-- src/components/megamenu/MegaMenu.vue | 16 +++++++++++----- src/components/panelmenu/PanelMenu.spec.js | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/megamenu/MegaMenu.spec.js b/src/components/megamenu/MegaMenu.spec.js index 15523e3d8f..7e6a868f54 100644 --- a/src/components/megamenu/MegaMenu.spec.js +++ b/src/components/megamenu/MegaMenu.spec.js @@ -69,7 +69,7 @@ describe('MegaMenu.vue', () => { it('should select item', async () => { const firstItem = wrapper.findAll('li.p-menuitem')[0]; - await wrapper.vm.onCategoryClick({}, wrapper.vm.model[0]); + await firstItem.trigger('click'); expect(firstItem.classes()).toContain('p-menuitem-active'); }); @@ -77,7 +77,8 @@ describe('MegaMenu.vue', () => { 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]); + await firstItem.trigger('click'); + await firstItem.trigger('click'); expect(firstItem.classes()).not.toContain('p-menuitem-active'); }); diff --git a/src/components/megamenu/MegaMenu.vue b/src/components/megamenu/MegaMenu.vue index 13abe2d910..8bc174a87b 100755 --- a/src/components/megamenu/MegaMenu.vue +++ b/src/components/megamenu/MegaMenu.vue @@ -232,8 +232,16 @@ export default { const { originalEvent, processedItem } = event; const grouped = this.isProccessedItemGroup(processedItem); const root = ObjectUtils.isEmpty(processedItem.parent); + const selected = this.isSelected(processedItem); - grouped ? this.onItemChange(event) : this.hide(originalEvent, !root); + if (root && selected) { + this.focusedItemInfo = { index: processedItem.index, key: processedItem.key }; + this.activeItem = null; + + DomHandler.focus(this.menubar); + } else { + grouped ? this.onItemChange(event) : this.hide(originalEvent, !root); + } }, onItemMouseEnter(event) { if (this.dirty) { @@ -286,7 +294,7 @@ export default { } }, onArrowLeftKey(event) { - const processedItem = this.findVisibleItem(this.focusedItemInfo.index); + const processedItem = (ObjectUtils.isNotEmpty(this.activeItem) && this.activeItem.key === this.focusedItemInfo.key ? this.activeItem : null) || this.findVisibleItem(this.focusedItemInfo.index); const grouped = this.isProccessedItemGroup(processedItem); if (grouped) { @@ -546,9 +554,7 @@ export default { 'p-megamenu p-component', { 'p-megamenu-horizontal': this.horizontal, - 'p-megamenu-vertical': this.vertical, - 'p-input-filled': this.$primevue.config.inputStyle === 'filled', - 'p-ripple-disabled': this.$primevue.config.ripple === false + 'p-megamenu-vertical': this.vertical } ]; }, diff --git a/src/components/panelmenu/PanelMenu.spec.js b/src/components/panelmenu/PanelMenu.spec.js index 3add8cc1ee..3d6cced3e9 100644 --- a/src/components/panelmenu/PanelMenu.spec.js +++ b/src/components/panelmenu/PanelMenu.spec.js @@ -71,7 +71,7 @@ describe('PanelMenu', () => { await wrapper.vm.onHeaderClick({}, wrapper.vm.model[0]); - expect(wrapper.find('.p-panelmenu-header-action > .p-panelmenu-icon').classes()).toContain('pi-chevron-down'); + expect(wrapper.find('.p-panelmenu-header-action > .p-submenu-icon').classes()).toContain('pi-chevron-down'); expect(wrapper.findAll('.p-toggleable-content')[0].attributes().style).toBe(undefined); });