mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
small refactoring...
This commit is contained in:
@@ -1,51 +1,54 @@
|
||||
import { NotificationManager } from "../../src/ts/services/notifications";
|
||||
import {
|
||||
NotificationManager,
|
||||
INotification
|
||||
} from "../../src/ts/services/notifications";
|
||||
|
||||
test("can subscribe and add notification", () => {
|
||||
let notified = false;
|
||||
let notifs: INotification[] = [];
|
||||
const notifications = new NotificationManager();
|
||||
notifications.on("notification_added", {}, () => (notified = true));
|
||||
expect(notified).toBe(false);
|
||||
notifications.on("notifications_updated", {}, n => (notifs = n));
|
||||
expect(notifs.length).toBe(0);
|
||||
const id = notifications.add({ title: "test", message: "message" });
|
||||
expect(notified).toBe(true);
|
||||
expect(notifs.length).toBe(1);
|
||||
expect(id).toBeDefined();
|
||||
});
|
||||
|
||||
test("can close a notification", () => {
|
||||
let notifs: INotification[] = [];
|
||||
const notifications = new NotificationManager();
|
||||
let notified = false;
|
||||
notifications.on("notification_removed", {}, () => (notified = true));
|
||||
notifications.on("notifications_updated", {}, n => (notifs = n));
|
||||
|
||||
const id = notifications.add({ title: "test", message: "message" });
|
||||
expect(notified).toBe(false);
|
||||
expect(notifs.length).toBe(1);
|
||||
|
||||
notifications.close(id);
|
||||
expect(notified).toBe(true);
|
||||
expect(notifs.length).toBe(0);
|
||||
});
|
||||
|
||||
test("notifications closes themselves after a while", () => {
|
||||
jest.useFakeTimers();
|
||||
let notifs: INotification[] = [];
|
||||
const notifications = new NotificationManager();
|
||||
let removed = false;
|
||||
notifications.on("notification_removed", {}, () => (removed = true));
|
||||
notifications.on("notifications_updated", {}, n => (notifs = n));
|
||||
|
||||
notifications.add({ title: "test", message: "message" });
|
||||
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
expect(removed).toBe(false);
|
||||
expect(notifs.length).toBe(1);
|
||||
jest.runAllTimers();
|
||||
expect(removed).toBe(true);
|
||||
expect(notifs.length).toBe(0);
|
||||
});
|
||||
|
||||
test("sticky notifications do not close themselves after a while", () => {
|
||||
jest.useFakeTimers();
|
||||
let notifs: INotification[] = [];
|
||||
const notifications = new NotificationManager();
|
||||
let removed = false;
|
||||
notifications.on("notification_removed", {}, () => (removed = true));
|
||||
notifications.on("notifications_updated", {}, n => (notifs = n));
|
||||
|
||||
notifications.add({ title: "test", message: "message", sticky: true });
|
||||
|
||||
expect(setTimeout).toHaveBeenCalledTimes(0);
|
||||
expect(removed).toBe(false);
|
||||
expect(notifs.length).toBe(1);
|
||||
jest.runAllTimers();
|
||||
expect(removed).toBe(false);
|
||||
expect(notifs.length).toBe(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user