2019-02-20 09:46:22 +01:00
|
|
|
import { Env, makeEnv } from "../../src/ts/env";
|
|
|
|
|
import { INotification, Store } from "../../src/ts/store";
|
2019-01-30 10:22:24 +01:00
|
|
|
import { Notification } from "../../src/ts/widgets/notification";
|
2019-02-20 09:46:22 +01:00
|
|
|
import * as helpers from "../helpers";
|
2019-01-29 20:42:05 +01:00
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Setup and helpers
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
let fixture: HTMLElement;
|
2019-02-20 09:46:22 +01:00
|
|
|
let store: Store;
|
|
|
|
|
let env: Env;
|
2019-02-02 11:41:19 +01:00
|
|
|
let templates: string;
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2019-02-20 09:46:22 +01:00
|
|
|
templates = await helpers.loadTemplates();
|
2019-02-02 11:41:19 +01:00
|
|
|
});
|
2019-01-29 20:42:05 +01:00
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-02-20 09:46:22 +01:00
|
|
|
fixture = helpers.makeTestFixture();
|
|
|
|
|
fixture = helpers.makeTestFixture();
|
|
|
|
|
store = helpers.makeTestStore();
|
|
|
|
|
env = makeEnv(store, 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-02-18 11:51:01 +01:00
|
|
|
let n = 0;
|
|
|
|
|
let notif;
|
2019-02-20 09:46:22 +01:00
|
|
|
store.on("notification_added", null, _notif => {
|
2019-02-18 11:51:01 +01:00
|
|
|
n++;
|
|
|
|
|
notif = _notif;
|
|
|
|
|
});
|
2019-02-20 09:46:22 +01:00
|
|
|
store.on("notification_closed", null, () => n--);
|
2019-02-18 11:51:01 +01:00
|
|
|
|
2019-02-20 09:46:22 +01:00
|
|
|
env.addNotification({
|
2019-01-29 20:42:05 +01:00
|
|
|
title: "title",
|
|
|
|
|
message: "message",
|
|
|
|
|
sticky: true
|
|
|
|
|
});
|
|
|
|
|
|
2019-02-18 11:51:01 +01:00
|
|
|
const navbar = new Notification(env, notif);
|
2019-01-29 20:42:05 +01:00
|
|
|
await navbar.mount(fixture);
|
2019-02-18 11:51:01 +01:00
|
|
|
expect(n).toBe(1);
|
2019-01-29 20:42:05 +01:00
|
|
|
(<any>fixture.getElementsByClassName("o_close")[0]).click();
|
2019-02-18 11:51:01 +01:00
|
|
|
expect(n).toBe(0);
|
2019-01-29 20:42:05 +01:00
|
|
|
});
|