summaryrefslogtreecommitdiff
path: root/addons/website/static/tests/dashboard_tests.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website/static/tests/dashboard_tests.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website/static/tests/dashboard_tests.js')
-rw-r--r--addons/website/static/tests/dashboard_tests.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/addons/website/static/tests/dashboard_tests.js b/addons/website/static/tests/dashboard_tests.js
new file mode 100644
index 00000000..37ee6b24
--- /dev/null
+++ b/addons/website/static/tests/dashboard_tests.js
@@ -0,0 +1,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');
+ });
+});
+
+});