Files
owl/web/static/tests/ui/root.test.ts
T
2019-03-05 15:35:29 +01:00

64 lines
1.9 KiB
TypeScript

import { Root } from "../../src/ts/ui/root";
import * as helpers from "../helpers";
import { makeTestData, makeTestEnv } from "../helpers";
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
beforeEach(() => {
fixture = helpers.makeTestFixture();
});
afterEach(() => {
fixture.remove();
});
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
test("can be rendered (in home menu)", async () => {
const data = await makeTestData();
const testEnv = makeTestEnv(data);
const root = new Root(testEnv, testEnv.store);
await root.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("if url has action_id, will render action and navigate to proper menu_id", async () => {
const data = await makeTestData();
const router = new helpers.MockRouter({ action_id: "131" });
const testEnv = makeTestEnv({ ...data, router });
await helpers.nextTick();
const root = new Root(testEnv, testEnv.store);
await root.mount(fixture);
await helpers.nextTick();
expect(router.getQuery()).toEqual({
action_id: "131",
menu_id: "96"
});
expect(fixture.innerHTML).toMatchSnapshot();
});
test("start with no action => clicks on client action => discuss is rendered", async () => {
const data = await makeTestData();
const testEnv = makeTestEnv(data);
const root = new Root(testEnv, testEnv.store);
await root.mount(fixture);
expect(testEnv.services.router.getQuery()).toEqual({ home: true });
// discuss menu item
await (<any>document.querySelector('[data-menu="96"]')).click();
await helpers.nextTick();
expect(fixture.innerHTML).toMatchSnapshot();
expect(testEnv.services.router.getQuery()).toEqual({
action_id: "131",
menu_id: "96"
});
});