Before this commit, the 'mounted' method of the ControlPanel in the website dashboard was called twice, when entering the dashboard. It happened because the dashboard updated the ControlPanel before being actually mounted, so mounted was called once when the dashboard was mounted, and once when the update was applied. Ideally, this should not be an issue (this isn't an issue with owl). However, in Odoo, we mix layers of Owl Components and legacy widgets. In these situations, the above scenario isn't properly handled (and can't be). As a consequence, in mobile (enterprise), it crashed because an handler bound in mounted (thus twice) was only unbound once. This commit avoids the issue by correctly setting the control panel props before rendering it (the update was actually useless). opw~2417307 closes odoo/odoo#63621 X-original-commit: 623a861877014b57627473b9cc5200bafcbe2521 Signed-off-by: Bruno Boi <brboi@users.noreply.github.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
68 lines
2.2 KiB
JavaScript
68 lines
2.2 KiB
JavaScript
odoo.define('website/static/tests/dashboard_tests', function (require) {
|
|
"use strict";
|
|
|
|
const ControlPanel = require('web.ControlPanel');
|
|
const Dashboard = require('website.backend.dashboard');
|
|
const testUtils = require("web.test_utils");
|
|
|
|
const { createParent, nextTick, prepareTarget } = testUtils;
|
|
|
|
QUnit.module('Website Backend Dashboard', {
|
|
}, function () {
|
|
QUnit.test("mounted is called once for the dashboard's ControlPanel", async function (assert) {
|
|
// This test can be removed as soon as we don't mix legacy and owl layers anymore.
|
|
assert.expect(5);
|
|
|
|
ControlPanel.patch('test.ControlPanel', T => {
|
|
class ControlPanelPatchTest extends T {
|
|
mounted() {
|
|
assert.step('mounted');
|
|
super.mounted(...arguments);
|
|
}
|
|
willUnmount() {
|
|
assert.step('willUnmount');
|
|
super.mounted(...arguments);
|
|
}
|
|
}
|
|
return ControlPanelPatchTest;
|
|
});
|
|
|
|
const params = {
|
|
mockRPC: (route) => {
|
|
if (route === '/website/fetch_dashboard_data') {
|
|
return Promise.resolve({
|
|
dashboards: {
|
|
visits: {},
|
|
sales: { summary: {} },
|
|
},
|
|
groups: { system: true, website_designer: true },
|
|
websites: [
|
|
{id: 1, name: "My Website", domain: "", selected: true},
|
|
],
|
|
});
|
|
}
|
|
return this._super(...arguments);
|
|
},
|
|
};
|
|
const parent = await createParent(params);
|
|
const dashboard = new Dashboard(parent, {});
|
|
await dashboard.appendTo(document.createDocumentFragment());
|
|
|
|
assert.verifySteps([]);
|
|
|
|
dashboard.$el.appendTo(prepareTarget());
|
|
dashboard.on_attach_callback();
|
|
|
|
await nextTick();
|
|
|
|
assert.verifySteps(['mounted']);
|
|
|
|
dashboard.destroy();
|
|
assert.verifySteps(['willUnmount']);
|
|
|
|
ControlPanel.unpatch('test.ControlPanel');
|
|
});
|
|
});
|
|
|
|
});
|