mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
small refactoring...
This commit is contained in:
@@ -5,11 +5,7 @@ import { Env } from "../src/ts/env";
|
||||
import { IAjax, RPCQuery } from "../src/ts/services/ajax";
|
||||
import { NotificationManager } from "../src/ts/services/notifications";
|
||||
|
||||
import {
|
||||
IActionManager,
|
||||
ActionEvent,
|
||||
ActionWidget
|
||||
} from "../src/ts/services/action_manager";
|
||||
import { IActionManager, ActionEvent } from "../src/ts/services/action_manager";
|
||||
import { Callback } from "../src/ts/core/event_bus";
|
||||
import { IRouter, Query, RouterEvent } from "../src/ts/services/router";
|
||||
|
||||
@@ -55,8 +51,9 @@ class MockAjax implements IAjax {
|
||||
class MockActionManager implements IActionManager {
|
||||
doAction(actionID: number) {}
|
||||
on(event: ActionEvent, owner: any, callback: Callback) {}
|
||||
getCurrentAction(): ActionWidget | null {
|
||||
return null;
|
||||
activate() {}
|
||||
getStack() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ exports[`can be rendered 1`] = `
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
<ul>
|
||||
|
||||
|
||||
</ul>
|
||||
</div>"
|
||||
`;
|
||||
@@ -18,6 +19,7 @@ exports[`can render one menu item 1`] = `
|
||||
menu
|
||||
</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>"
|
||||
`;
|
||||
@@ -27,6 +29,7 @@ exports[`mobile mode: navbar is different 1`] = `
|
||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
||||
<ul>
|
||||
|
||||
<li>MOBILEMODE</li>
|
||||
</ul>
|
||||
</div>"
|
||||
`;
|
||||
|
||||
@@ -13,7 +13,7 @@ let props: Props;
|
||||
beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
env = makeTestEnv();
|
||||
props = { inMenu: false, toggleHomeMenu: () => {} };
|
||||
props = { inMenu: false, toggleHome: () => {} };
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -42,19 +42,21 @@ test("can be rendered", async () => {
|
||||
});
|
||||
|
||||
test("can be closed by clicking on it (if sticky)", async () => {
|
||||
let notif: INotification;
|
||||
let removed = false;
|
||||
env.notifications.on("notification_added", null, _notif => (notif = _notif));
|
||||
let notifs: INotification[] = [];
|
||||
env.notifications.on(
|
||||
"notifications_updated",
|
||||
null,
|
||||
_notifs => (notifs = _notifs)
|
||||
);
|
||||
env.notifications.add({
|
||||
title: "title",
|
||||
message: "message",
|
||||
sticky: true
|
||||
});
|
||||
env.notifications.on("notification_removed", null, () => (removed = true));
|
||||
|
||||
const navbar = new Notification(env, notif!);
|
||||
const navbar = new Notification(env, notifs[0]);
|
||||
await navbar.mount(fixture);
|
||||
expect(removed).toBe(false);
|
||||
expect(notifs.length).toBe(1);
|
||||
(<any>fixture.getElementsByClassName("o_close")[0]).click();
|
||||
expect(removed).toBe(true);
|
||||
expect(notifs.length).toBe(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user