From bf954def41f0e8cef3023a3cdf73ced0edaa68f7 Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Mon, 2 Oct 2023 10:51:47 +0200 Subject: [PATCH] [FIX] web: close popover on pointerdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Preliminary note** The fix mentioned in this commit is already done in another commit [1]. The below commit message stayed the same for history's sake. **Before this commit** A popover would close on outside mousedown event. This is not sufficient enough, has for instance all the draggable stuff makes use of the pointer events instead of the mouse events. This lead to some unwanted behavior, i.e.: - Open the DomainSelectorDialog - Open a ModelFieldSelectorPopover - Try to drag the modal - The popover remain open and its position is not updated. The dialog's dragging is fine. **After this commit** The popovers will close on pointerdown away events. Now: - Open the DomainSelectorDialog - Open a ModelFieldSelectorPopover - Try to drag the modal - The popover is closed and the dragging still works as expected. [1]: 76665eb400168a6fd6e2b5f5fe099c8c4e9c8a5e closes odoo/odoo#137247 X-original-commit: c63dbc4ed0a04e34571c2929f43812873b62fd16 Signed-off-by: Michaƫl Mattiello (mcm) Signed-off-by: Bruno Boi (boi) --- .../core/domain_selector_dialog_tests.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/web/static/tests/core/domain_selector_dialog_tests.js b/addons/web/static/tests/core/domain_selector_dialog_tests.js index ea5a1242544..36638c14c44 100644 --- a/addons/web/static/tests/core/domain_selector_dialog_tests.js +++ b/addons/web/static/tests/core/domain_selector_dialog_tests.js @@ -2,7 +2,7 @@ import { Component, xml } from "@odoo/owl"; import { DomainSelectorDialog } from "@web/core/domain_selector_dialog/domain_selector_dialog"; -import { click, getFixture, mount } from "../helpers/utils"; +import { click, dragAndDrop, getFixture, mount } from "../helpers/utils"; import { makeDialogTestEnv } from "../helpers/mock_env"; import { registry } from "@web/core/registry"; import { notificationService } from "@web/core/notifications/notification_service"; @@ -158,4 +158,24 @@ QUnit.module("Components", (hooks) => { await click(confirmButton); assert.verifySteps([]); }); + + QUnit.test("model_field_selector should close on dialog drag", async (assert) => { + await makeDomainSelectorDialog({ + domain: "[('foo', '=', unknown)]", + }); + + assert.containsNone(fixture, ".o_model_field_selector_popover"); + await click(fixture, ".o_model_field_selector_value"); + assert.containsOnce(fixture, ".o_model_field_selector_popover"); + + const header = fixture.querySelector(".modal-header"); + const headerRect = header.getBoundingClientRect(); + await dragAndDrop(header, document.body, { + // the util function sets the source coordinates at (x; y) + (w/2; h/2) + // so we need to move the dialog based on these coordinates. + x: headerRect.x + headerRect.width / 2 + 20, + y: headerRect.y + headerRect.height / 2 + 50, + }); + assert.containsNone(fixture, ".o_model_field_selector_popover"); + }); });