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:
@@ -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