[FIX] web: mount owl renderer once

Before this commit, owl renderers were mounted twice.
This commit makes owl renderers mounted just once as it should be

X-original-commit: 9234aa5c5c7de2f7af23071a3ff76adf93e9cee7
This commit is contained in:
Michael Mattiello (mcm)
2020-05-27 12:26:04 +00:00
parent bb4b07df3f
commit cf90b56c3c
2 changed files with 36 additions and 2 deletions
@@ -125,7 +125,9 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
this._controlPanelModel.on('search', this, this._onSearch);
this._controlPanelModel.on('get-controller-query-params', this, this._onGetOwnedQueryParams);
}
this.renderer.on_attach_callback();
if (!(this.renderer instanceof owl.Component)) {
this.renderer.on_attach_callback();
}
},
/**
* Called each time the controller is detached from the DOM.
@@ -136,7 +138,9 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
this._controlPanelModel.off('search', this);
this._controlPanelModel.off('get-controller-query-params', this);
}
this.renderer.on_detach_callback();
if (!(this.renderer instanceof owl.Component)) {
this.renderer.on_detach_callback();
}
},
//--------------------------------------------------------------------------
@@ -134,5 +134,35 @@ QUnit.module("Views", {
assert.hasClass(document.activeElement, "o_searchview_input");
view.destroy();
});
QUnit.test('Owl Renderer mounted/willUnmount hooks are properly called', async function (assert) {
// This test could be removed as soon as controllers and renderers will
// both be converted in Owl.
assert.expect(3);
class Renderer extends AbstractRenderer {
mounted() {
assert.step("mounted");
}
willUnmount() {
assert.step("unmounted");
}
}
Renderer.template = xml`<div>Test</div>`;
const view = await createView({
View: getOwlView(Renderer, "test"),
data: this.data,
model: "test_model",
arch: "<test/>",
});
view.destroy();
assert.verifySteps([
"mounted",
"unmounted",
]);
});
});
});