From 3f295961901365a160dc385edf500ac5fe724ede Mon Sep 17 00:00:00 2001 From: Anna Shakhova <68295572+anna-shakhova@users.noreply.github.com> Date: Wed, 25 Dec 2024 10:50:50 +0100 Subject: [PATCH] ContextMenu: empty shownMenus list on clean (T1257288) (#28621) --- .../ui/context_menu/m_context_menu.ts | 1 + .../contextMenu.tests.js | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/packages/devextreme/js/__internal/ui/context_menu/m_context_menu.ts b/packages/devextreme/js/__internal/ui/context_menu/m_context_menu.ts index cbd0df7fabc1..1fe0640bdd5b 100644 --- a/packages/devextreme/js/__internal/ui/context_menu/m_context_menu.ts +++ b/packages/devextreme/js/__internal/ui/context_menu/m_context_menu.ts @@ -343,6 +343,7 @@ class ContextMenu extends MenuBase { this._overlay = null; } this._detachShowContextMenuEvents(this._getTarget()); + this._shownSubmenus = []; super._clean(); } diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js index dc1e8a680f79..35229a110bbc 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets/contextMenu.tests.js @@ -273,6 +273,41 @@ QUnit.module('Rendering', moduleConfig, () => { }); }); +QUnit.module('Repaint', moduleConfig, () => { + QUnit.test('On repaint all submenus should be hidden without console errors (T1257288)', function(assert) { + if(!isDeviceDesktop(assert)) { + return; + } + + const instance = new ContextMenu(this.$element, { + items: [{ text: 'Item 1', items: [{ text: 'Item 11' }, { text: 'Item 12' }] }], + visible: true, + showSubmenuMode: { name: 'onHover', delay: 0 }, + onItemClick: (e) => e.component.repaint(), + }); + + const $itemsContainer = instance.itemsContainer(); + const $rootItem = $itemsContainer.find(`.${DX_MENU_ITEM_CLASS}`).eq(0); + + $($itemsContainer).trigger($.Event('dxhoverstart', { target: $rootItem.get(0) })); + this.clock.tick(0); + + const $submenus = $(`.${DX_SUBMENU_CLASS}`); + const $nestedSubmenu = $submenus.eq(1); + const $nestedSubmenuItem = $nestedSubmenu.find(`.${DX_MENU_ITEM_CLASS}`).eq(0); + + assert.strictEqual($submenus.length, 2, 'Nested submenu is shown'); + + try { + $($nestedSubmenuItem).trigger('dxclick'); + + assert.ok(true, 'No errors were thrown'); + } catch(e) { + assert.ok(false, `Error: ${e.message}`); + } + }); +}); + QUnit.module('Rendering Scrollable', moduleConfig, () => { const DX_SCROLLABLE_CLASS = 'dx-scrollable'; const DX_SCROLLABLE_CONTAINER_CLASS = 'dx-scrollable-container';