1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
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 dashboarrd'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');
});
});
});
|