Files
odoo_source/addons/bus/static/tests/assets_watchdog_tests.js
T
tsm-odoo 901a43f532 [IMP] bus, *: improve multi tab service
*: calendar, im_livechat, survey.

Following @ged-odoo review, the multi tab service has been improved:
    - multi_tab_service.js has been moved to the correct location.
    - _callLocalStorage method has been removed and replaced by
      getItemFromLocalStorage/setItemToLocalStorage.
    - underscore.js calls have been removed.
    - multi_tab_service is now using function closure style  instead of class.
    - multi_tab service is now using its own bus instance.
    - service name is now in snake case as per convention.
    - tests have been added.
    - multi tab service now handles setting/removing/getting values
      shared between  all the tabs.

closes odoo/odoo#96386

Enterprise: https://github.com/odoo/enterprise/pull/29694
Related: odoo/enterprise#29694
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2022-07-27 03:34:51 +02:00

70 lines
2.3 KiB
JavaScript

/** @odoo-module */
import { busService } from "@bus/services/bus_service";
import { presenceService } from "@bus/services/presence_service";
import { multiTabService } from "@bus/multi_tab_service";
import { createWebClient } from "@web/../tests/webclient/helpers";
import { assetsWatchdogService } from "@bus/services/assets_watchdog_service";
import { click, getFixture, nextTick, patchWithCleanup } from "@web/../tests/helpers/utils";
import { browser } from "@web/core/browser/browser";
import { registry } from "@web/core/registry";
const serviceRegistry = registry.category("services");
QUnit.module("Bus Assets WatchDog", (hooks) => {
let target;
hooks.beforeEach((assert) => {
serviceRegistry.add("assetsWatchdog", assetsWatchdogService);
serviceRegistry.add("bus_service", busService);
serviceRegistry.add("presence", presenceService);
serviceRegistry.add("multi_tab", multiTabService);
patchWithCleanup(browser, {
setTimeout(fn) {
return this._super(fn, 0);
},
location: {
reload: () => assert.step("reloadPage"),
},
});
target = getFixture();
});
QUnit.test("can listen on bus and displays notifications in DOM", async (assert) => {
assert.expect(4);
let pollNumber = 0;
const mockRPC = async (route, args) => {
if (route === "/longpolling/poll") {
if (pollNumber > 0) {
return new Promise(() => {}); // let it hang to avoid further calls
}
pollNumber++;
return [{
message: {
type: 'bundle_changed',
payload: { server_version: "NEW_MAJOR_VERSION" },
},
}];
}
};
await createWebClient({
mockRPC,
});
await nextTick();
assert.containsOnce(target, ".o_notification_body");
assert.strictEqual(
target.querySelector(".o_notification_body .o_notification_content").textContent,
"The page appears to be out of date."
);
// reload by clicking on the reload button
await click(target, ".o_notification_buttons .btn-primary");
assert.verifySteps(["reloadPage"]);
});
});