[FIX] web: fix tooltip rendering crashing because of lack of env

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 <ged@odoo.com>
This commit is contained in:
Samuel Degueldre
2022-07-28 05:04:35 +02:00
parent 2cbad9a3f7
commit c5e63850dd
2 changed files with 8 additions and 4 deletions
@@ -3,7 +3,7 @@
<t t-name="web.Tooltip" owl="1">
<div class="o-tooltip px-2 py-1">
<t t-if="props.template" t-call="{{props.template}}" t-call-context="props.info"/>
<t t-if="props.template" t-call="{{props.template}}" t-call-context="{ env, ...props.info }"/>
<small t-else="" t-esc="props.tooltip"/>
</div>
</t>
@@ -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<Component>}
*/
@@ -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: "<i>tooltip</i>",
my_tooltip_template: "<i t-esc='env.tooltip_text'/>",
};
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"));