Files
owl/web/static/tests/widgets/notification.test.ts
T

69 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-01-29 20:42:05 +01:00
import { Env } from "../../src/ts/env";
import { INotification } from "../../src/ts/services/notifications";
2019-01-30 10:22:24 +01:00
import { Notification } from "../../src/ts/widgets/notification";
import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
2019-01-29 20:42:05 +01:00
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
let env: Env;
let templates: string;
beforeAll(async () => {
templates = await loadTemplates();
});
2019-01-29 20:42:05 +01:00
beforeEach(() => {
fixture = makeTestFixture();
env = makeTestEnv();
env.qweb.loadTemplates(templates);
2019-01-29 20:42:05 +01:00
});
afterEach(() => {
fixture.remove();
});
function makeNotification(notif: Partial<INotification> = {}): INotification {
const defaultNotif = {
id: 1,
title: "title",
message: "message",
type: "notification",
sticky: false
};
return Object.assign(defaultNotif, notif);
}
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
test("can be rendered", async () => {
const notif = makeNotification({ title: "title", message: "message" });
const navbar = new Notification(env, notif);
await navbar.mount(fixture);
2019-01-30 10:22:24 +01:00
expect(fixture.innerHTML).toMatchSnapshot();
2019-01-29 20:42:05 +01:00
});
test("can be closed by clicking on it (if sticky)", async () => {
2019-01-31 13:19:30 +01:00
let notifs: INotification[] = [];
env.notifications.on(
"notifications_updated",
null,
_notifs => (notifs = _notifs)
);
2019-01-29 20:42:05 +01:00
env.notifications.add({
title: "title",
message: "message",
sticky: true
});
2019-01-31 13:19:30 +01:00
const navbar = new Notification(env, notifs[0]);
2019-01-29 20:42:05 +01:00
await navbar.mount(fixture);
2019-01-31 13:19:30 +01:00
expect(notifs.length).toBe(1);
2019-01-29 20:42:05 +01:00
(<any>fixture.getElementsByClassName("o_close")[0]).click();
2019-01-31 13:19:30 +01:00
expect(notifs.length).toBe(0);
2019-01-29 20:42:05 +01:00
});