Files
owl/web/static/tests/ui/root.test.ts
T

64 lines
1.9 KiB
TypeScript
Raw Normal View History

import { Root } from "../../src/ts/ui/root";
2019-02-06 10:42:00 +01:00
import * as helpers from "../helpers";
2019-03-04 22:47:20 +01:00
import { makeTestData, makeTestEnv } from "../helpers";
2019-02-06 10:42:00 +01:00
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
beforeEach(() => {
fixture = helpers.makeTestFixture();
});
afterEach(() => {
fixture.remove();
});
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
test("can be rendered (in home menu)", async () => {
2019-03-04 22:47:20 +01:00
const data = await makeTestData();
const testEnv = makeTestEnv(data);
const root = new Root(testEnv, testEnv.store);
2019-02-06 13:26:21 +01:00
await root.mount(fixture);
2019-02-06 10:42:00 +01:00
expect(fixture.innerHTML).toMatchSnapshot();
});
test("if url has action_id, will render action and navigate to proper menu_id", async () => {
2019-03-04 22:47:20 +01:00
const data = await makeTestData();
2019-03-02 08:34:29 +01:00
const router = new helpers.MockRouter({ action_id: "131" });
2019-03-04 22:47:20 +01:00
const testEnv = makeTestEnv({ ...data, router });
2019-02-20 14:55:49 +01:00
await helpers.nextTick();
2019-02-20 09:46:22 +01:00
2019-03-04 22:47:20 +01:00
const root = new Root(testEnv, testEnv.store);
2019-02-06 13:26:21 +01:00
await root.mount(fixture);
await helpers.nextTick();
2019-03-04 22:47:20 +01:00
expect(router.getQuery()).toEqual({
2019-03-02 08:34:29 +01:00
action_id: "131",
menu_id: "96"
2019-02-20 09:46:22 +01:00
});
2019-02-06 10:42:00 +01:00
expect(fixture.innerHTML).toMatchSnapshot();
});
2019-02-06 13:26:21 +01:00
test("start with no action => clicks on client action => discuss is rendered", async () => {
2019-03-04 22:47:20 +01:00
const data = await makeTestData();
const testEnv = makeTestEnv(data);
const root = new Root(testEnv, testEnv.store);
2019-02-06 13:26:21 +01:00
await root.mount(fixture);
2019-03-04 22:47:20 +01:00
expect(testEnv.services.router.getQuery()).toEqual({ home: true });
2019-02-06 13:26:21 +01:00
// discuss menu item
await (<any>document.querySelector('[data-menu="96"]')).click();
await helpers.nextTick();
expect(fixture.innerHTML).toMatchSnapshot();
2019-03-04 22:47:20 +01:00
expect(testEnv.services.router.getQuery()).toEqual({
2019-02-20 09:46:22 +01:00
action_id: "131",
menu_id: "96"
});
2019-02-06 13:26:21 +01:00
});