mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
improve notification system
This commit is contained in:
@@ -2,7 +2,9 @@ import { QWeb } from "../src/ts/core/qweb_vdom";
|
||||
import { idGenerator } from "../src/ts/core/utils";
|
||||
import { WEnv } from "../src/ts/core/widget";
|
||||
import { Env } from "../src/ts/env";
|
||||
import { IAjax, RPC } from "../src/ts/services/ajax";
|
||||
import { IAjax, RPCQuery } from "../src/ts/services/ajax";
|
||||
import { NotificationManager } from "../src/ts/services/notifications";
|
||||
|
||||
import {
|
||||
IActionManager,
|
||||
ActionEvent,
|
||||
@@ -28,12 +30,14 @@ export function makeTestEnv(): Env {
|
||||
const ajax = new MockAjax();
|
||||
const actionManager = new MockActionManager();
|
||||
const router = new MockRouter();
|
||||
const notifications = new NotificationManager();
|
||||
let { qweb, getID } = makeTestWEnv();
|
||||
return {
|
||||
qweb,
|
||||
getID,
|
||||
ajax,
|
||||
actionManager,
|
||||
notifications,
|
||||
router,
|
||||
rpc: ajax.rpc,
|
||||
debug: false,
|
||||
@@ -42,7 +46,7 @@ export function makeTestEnv(): Env {
|
||||
}
|
||||
|
||||
class MockAjax implements IAjax {
|
||||
async rpc(rpc: RPC) {
|
||||
async rpc(rpc: RPCQuery) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ test("can subscribe and add notification", () => {
|
||||
test("can close a notification", () => {
|
||||
const notifications: INotificationManager = new NotificationManager();
|
||||
let notified = false;
|
||||
notifications.on("notification_closed", {}, () => (notified = true));
|
||||
notifications.on("notification_removed", {}, () => (notified = true));
|
||||
|
||||
const id = notifications.add(makeNotification());
|
||||
expect(notified).toBe(false);
|
||||
@@ -44,3 +44,31 @@ test("can close a notification", () => {
|
||||
notifications.close(id);
|
||||
expect(notified).toBe(true);
|
||||
});
|
||||
|
||||
test("notifications closes themselves after a while", () => {
|
||||
jest.useFakeTimers();
|
||||
const notifications: INotificationManager = new NotificationManager();
|
||||
let removed = false;
|
||||
notifications.on("notification_removed", {}, () => (removed = true));
|
||||
|
||||
notifications.add(makeNotification());
|
||||
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
expect(removed).toBe(false);
|
||||
jest.runAllTimers();
|
||||
expect(removed).toBe(true);
|
||||
});
|
||||
|
||||
test("sticky notifications do not close themselves after a while", () => {
|
||||
jest.useFakeTimers();
|
||||
const notifications: INotificationManager = new NotificationManager();
|
||||
let removed = false;
|
||||
notifications.on("notification_removed", {}, () => (removed = true));
|
||||
|
||||
notifications.add(makeNotification({ sticky: true }));
|
||||
|
||||
expect(setTimeout).toHaveBeenCalledTimes(0);
|
||||
expect(removed).toBe(false);
|
||||
jest.runAllTimers();
|
||||
expect(removed).toBe(false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user