Files
odoo_source/addons/calendar/static/tests/calendar_notification_tests.js
T
Florian Damhaut c1014d9cd6 [FIX] calendar: notification detail correct redirection
Step to reproduce:
- Create an event in calendar with reminder
- (Move the event to trigger the reminder)
- Click on 'Details'

Current Behaviour:
- Open a new event

Behaviour after PR:
- Open the event linked to the notification

opw-2761492

closes odoo/odoo#85089

X-original-commit: e1787f5a107f452f5c50e4e931cdd7afcea04e48
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Damhaut Florian (flda) <flda@odoo.com>
2022-03-07 08:47:40 +00:00

223 lines
8.1 KiB
JavaScript

/** @odoo-module */
import * as legacyRegistry from "web.Registry";
import * as BusService from "bus.BusService";
import * as RamStorage from "web.RamStorage";
import * as AbstractStorageService from "web.AbstractStorageService";
import { createWebClient } from "@web/../tests/webclient/helpers";
import { calendarNotificationService } from "@calendar/js/services/calendar_notification_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 LocalStorageService = AbstractStorageService.extend({
storage: new RamStorage(),
});
const serviceRegistry = registry.category("services");
QUnit.module("Calendar Notification", (hooks) => {
let legacyServicesRegistry;
let target;
hooks.beforeEach(() => {
target = getFixture();
legacyServicesRegistry = new legacyRegistry();
legacyServicesRegistry.add("bus_service", BusService);
legacyServicesRegistry.add("local_storage", LocalStorageService);
serviceRegistry.add("calendarNotification", calendarNotificationService);
patchWithCleanup(browser, {
setTimeout: (fn) => fn(),
clearTimeout: () => {},
});
});
QUnit.test(
"can listen on bus and display notifications in DOM and click OK",
async (assert) => {
assert.expect(5);
let pollNumber = 0;
const mockRPC = (route, args) => {
if (route === "/longpolling/poll") {
if (pollNumber > 0) {
return new Promise(() => {}); // let it hang to avoid further calls
}
pollNumber++;
return Promise.resolve([
{
id: "prout",
message: {
type: "calendar.alarm",
payload: [{
alarm_id: 1,
event_id: 2,
title: "Meeting",
message: "Very old meeting message",
timer: 20 * 60,
notify_at: "1978-04-14 12:45:00",
}],
},
},
]);
}
if (route === "/calendar/notify") {
return Promise.resolve([]);
}
if (route === "/calendar/notify_ack") {
assert.step("notifyAck");
return Promise.resolve(true);
}
};
await createWebClient({
legacyParams: { serviceRegistry: legacyServicesRegistry },
mockRPC,
});
await nextTick();
assert.containsOnce(target, ".o_notification_body");
assert.strictEqual(
target.querySelector(".o_notification_body .o_notification_content")
.textContent,
"Very old meeting message"
);
await click(target.querySelector(".o_notification_buttons .btn"));
assert.verifySteps(["notifyAck"]);
assert.containsNone(target, ".o_notification");
}
);
QUnit.test(
"can listen on bus and display notifications in DOM and click Detail",
async (assert) => {
assert.expect(5);
let pollNumber = 0;
const mockRPC = (route, args) => {
if (route === "/longpolling/poll") {
if (pollNumber > 0) {
return new Promise(() => {}); // let it hang to avoid further calls
}
pollNumber++;
return Promise.resolve([
{
id: "prout",
message: {
type: "calendar.alarm",
payload: [{
alarm_id: 1,
event_id: 2,
title: "Meeting",
message: "Very old meeting message",
timer: 20 * 60,
notify_at: "1978-04-14 12:45:00",
}],
},
},
]);
}
if (route === "/calendar/notify") {
return Promise.resolve([]);
}
};
const fakeActionService = {
name: "action",
start() {
return {
doAction(actionId) {
assert.step(actionId.type);
return Promise.resolve(true);
},
loadState(state, options) {
return Promise.resolve(true);
},
};
},
};
serviceRegistry.add("action", fakeActionService, { force: true });
await createWebClient({
legacyParams: { serviceRegistry: legacyServicesRegistry },
mockRPC,
});
await nextTick();
assert.containsOnce(target, ".o_notification_body");
assert.strictEqual(
target.querySelector(".o_notification_body .o_notification_content")
.textContent,
"Very old meeting message"
);
await click(target.querySelectorAll(".o_notification_buttons .btn")[1]);
assert.verifySteps(["ir.actions.act_window"]);
assert.containsNone(target, ".o_notification");
}
);
QUnit.test(
"can listen on bus and display notifications in DOM and click Snooze",
async (assert) => {
assert.expect(4);
let pollNumber = 0;
const mockRPC = (route, args) => {
if (route === "/longpolling/poll") {
if (pollNumber > 0) {
return new Promise(() => {}); // let it hang to avoid further calls
}
pollNumber++;
return Promise.resolve([
{
message: {
id: "prout",
type: "calendar.alarm",
payload: [{
alarm_id: 1,
event_id: 2,
title: "Meeting",
message: "Very old meeting message",
timer: 20 * 60,
notify_at: "1978-04-14 12:45:00",
}],
},
},
]);
}
if (route === "/calendar/notify") {
return Promise.resolve([]);
}
if (route === "/calendar/notify_ack") {
assert.step("notifyAck");
return Promise.resolve(true);
}
};
await createWebClient({
legacyParams: { serviceRegistry: legacyServicesRegistry },
mockRPC,
});
await nextTick();
assert.containsOnce(target, ".o_notification_body");
assert.strictEqual(
target.querySelector(".o_notification_body .o_notification_content")
.textContent,
"Very old meeting message"
);
await click(target.querySelectorAll(".o_notification_buttons .btn")[2]);
assert.verifySteps([], "should only close the notification withtout calling a rpc");
assert.containsNone(target, ".o_notification");
}
);
});