From c5e63850dd8a48ae697c68c29d23f153e392ed78 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Wed, 27 Jul 2022 12:17:33 +0000 Subject: [PATCH] [FIX] web: fix tooltip rendering crashing because of lack of env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the merge of the new views, we introduced an owl directive which is t-call-context, that allows a t-call to execute in a controlled context that is not the context of the component itself. In doing so, we forgot that some existing templates rely on the presence of the env in the rendering context for things like knowing if we are in debug mode or if the device is small/mobile. This commit fixes that by simply adding the env to the rendering context of tooltuips. closes odoo/odoo#96875 Signed-off-by: Géry Debongnie --- addons/web/static/src/core/tooltip/tooltip.xml | 2 +- .../static/tests/core/tooltip/tooltip_service_tests.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/core/tooltip/tooltip.xml b/addons/web/static/src/core/tooltip/tooltip.xml index bff6a9f28c7..8eb108ae901 100644 --- a/addons/web/static/src/core/tooltip/tooltip.xml +++ b/addons/web/static/src/core/tooltip/tooltip.xml @@ -3,7 +3,7 @@
- +
diff --git a/addons/web/static/tests/core/tooltip/tooltip_service_tests.js b/addons/web/static/tests/core/tooltip/tooltip_service_tests.js index 193faced077..5c1c5a9f4b2 100644 --- a/addons/web/static/tests/core/tooltip/tooltip_service_tests.js +++ b/addons/web/static/tests/core/tooltip/tooltip_service_tests.js @@ -26,6 +26,7 @@ const mainComponents = registry.category("main_components"); * @param {function} [options.mockClearTimeout] the mocked clearTimeout to use (by default, does nothing) * @param {function} [options.mockClearInterval] the mocked clearInterval to use (by default, does nothing) * @param {function} [options.onPopoverAdded] use this callback to check what is being passed to the popover service + * @param {Object} [options.extraEnv] an object whose keys should be added to the env * @param {{[templateName:string]: string}} [options.templates] additional templates * @returns {Promise} */ @@ -47,7 +48,10 @@ export async function makeParent(Child, options = {}) { registry.category("services").add("popover", popoverService); registry.category("services").add("tooltip", tooltipService); registry.category("services").add("localization", makeFakeLocalizationService()); - const env = await makeTestEnv(); + let env = await makeTestEnv(); + if (options.extraEnv) { + env = Object.create(env, Object.getOwnPropertyDescriptors(options.extraEnv)); + } patchWithCleanup(env.services.popover, { add(...args) { @@ -300,9 +304,9 @@ QUnit.module("Tooltip service", (hooks) => { `; const templates = { - my_tooltip_template: "tooltip", + my_tooltip_template: "", }; - await makeParent(MyComponent, { templates }); + await makeParent(MyComponent, { templates, extraEnv: { tooltip_text: "tooltip" } }); assert.containsNone(target, ".o_popover_container .o-tooltip"); target.querySelector("button").dispatchEvent(new Event("mouseenter"));