[FIX] web: close popover on pointerdown

**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) <mcm@odoo.com>
Signed-off-by: Bruno Boi (boi) <boi@odoo.com>
This commit is contained in:
Bruno Boi
2023-10-02 12:58:52 +00:00
parent 01666d9c21
commit bf954def41
@@ -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");
});
});