[FIX] web,mail: tooltip service: correctly apply default delay
The delay of tooltips opened with the tooltip service can be given in xml, with attribute data-tooltip-delay. If not specified, there is a fallback in the service to 400ms. Before this commit, the fallback wasn't correctly applied, because we parsed the xml delay into an integer, which was NaN when the delay wasn't specified, and as NaN isn't undefined, the fallback wasn't applied. As a consequence, we opened the tooltip in a setTimeout with NaN as delay, and it thus opened directly. closes odoo/odoo#113425 X-original-commit: 553b2775a4b31c75d1d246816b749e4521e25726 Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { start, startServer } from "@mail/../tests/helpers/test_utils";
|
||||
import { click, getFixture, patchWithCleanup, triggerHotkey } from "@web/../tests/helpers/utils";
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { session } from "@web/session";
|
||||
import { dom, nextTick } from "web.test_utils";
|
||||
@@ -79,6 +80,12 @@ QUnit.module("mail", {}, function () {
|
||||
QUnit.test("many2many_avatar_user in kanban view", async function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
patchWithCleanup(browser, {
|
||||
setTimeout: async (fn) => {
|
||||
await new Promise((r) => setTimeout(r))
|
||||
fn();
|
||||
},
|
||||
});
|
||||
const pyEnv = await startServer();
|
||||
const resUsersIds = pyEnv["res.users"].create([
|
||||
{ name: "Mario" },
|
||||
|
||||
@@ -129,16 +129,19 @@ export const tooltipService = {
|
||||
if (elementsWithTooltips.has(el)) {
|
||||
openTooltip(el, elementsWithTooltips.get(el));
|
||||
} else if (el.matches("[data-tooltip], [data-tooltip-template]")) {
|
||||
const {
|
||||
tooltip,
|
||||
tooltipInfo,
|
||||
tooltipDelay,
|
||||
tooltipTemplate: template,
|
||||
tooltipPosition: position,
|
||||
} = el.dataset;
|
||||
const delay = parseInt(tooltipDelay);
|
||||
const info = tooltipInfo ? JSON.parse(tooltipInfo) : null;
|
||||
openTooltip(el, { tooltip, template, delay, info, position });
|
||||
const dataset = el.dataset;
|
||||
const params = {
|
||||
tooltip: dataset.tooltip,
|
||||
template: dataset.tooltipTemplate,
|
||||
position: dataset.tooltipPosition,
|
||||
};
|
||||
if (dataset.tooltipInfo) {
|
||||
params.info = JSON.parse(dataset.tooltipInfo);
|
||||
}
|
||||
if (dataset.tooltipDelay) {
|
||||
params.delay = parseInt(dataset.tooltipDelay, 10);
|
||||
}
|
||||
openTooltip(el, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -343,14 +343,27 @@ QUnit.module("Tooltip service", (hooks) => {
|
||||
assert.containsNone(target, ".o_popover_container .o_popover");
|
||||
});
|
||||
|
||||
QUnit.test("tooltip with a delay", async (assert) => {
|
||||
QUnit.test("tooltip with no delay (default delay)", async (assert) => {
|
||||
assert.expect(1);
|
||||
class MyComponent extends Component {}
|
||||
MyComponent.template = xml`<button data-tooltip="'helpful tooltip'" data-tooltip-delay="2000">Action</button>`;
|
||||
MyComponent.template = xml`<button class="myBtn" data-tooltip="'helpful tooltip'">Action</button>`;
|
||||
const mockSetTimeout = (fn, delay) => {
|
||||
assert.strictEqual(delay, 400);
|
||||
};
|
||||
await makeParent(MyComponent, { mockSetTimeout });
|
||||
target.querySelector("button.myBtn").dispatchEvent(new Event("mouseenter"));
|
||||
await nextTick();
|
||||
});
|
||||
|
||||
QUnit.test("tooltip with a delay", async (assert) => {
|
||||
assert.expect(1);
|
||||
class MyComponent extends Component {}
|
||||
MyComponent.template = xml`<button class="myBtn" data-tooltip="'helpful tooltip'" data-tooltip-delay="2000">Action</button>`;
|
||||
const mockSetTimeout = (fn, delay) => {
|
||||
assert.strictEqual(delay, 2000);
|
||||
};
|
||||
await makeParent(MyComponent, { mockSetTimeout });
|
||||
target.querySelector("button").dispatchEvent(new Event("mouseenter"));
|
||||
target.querySelector("button.myBtn").dispatchEvent(new Event("mouseenter"));
|
||||
await nextTick();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user