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

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-02-20 09:46:22 +01:00
import { Env, makeEnv } from "../../src/ts/env";
import { Store } from "../../src/ts/store";
import { Root } from "../../src/ts/widgets/root";
2019-02-06 10:42:00 +01:00
import * as helpers from "../helpers";
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
2019-02-20 09:46:22 +01:00
let store: Store;
let env: Env;
2019-02-06 10:42:00 +01:00
let templates: string;
beforeAll(async () => {
templates = await helpers.loadTemplates();
});
beforeEach(() => {
fixture = helpers.makeTestFixture();
2019-02-20 09:46:22 +01:00
store = helpers.makeTestStore();
env = makeEnv(store, templates);
// props = { menuInfo: helpers.makeDemoMenuInfo() };
2019-02-06 10:42:00 +01:00
});
afterEach(() => {
fixture.remove();
});
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
test("can be rendered (in home menu)", async () => {
2019-02-20 09:46:22 +01:00
const root = new Root(env, 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-02-20 09:46:22 +01:00
const router = new helpers.MockRouter({ action_id: "595" });
store = helpers.makeTestStore({ router });
env = makeEnv(store, templates);
2019-02-20 14:55:49 +01:00
await helpers.nextTick();
2019-02-20 09:46:22 +01:00
const root = new Root(env, store);
2019-02-06 13:26:21 +01:00
await root.mount(fixture);
2019-02-20 09:46:22 +01:00
expect(env.services.router.getQuery()).toEqual({
action_id: "595",
menu_id: "409"
});
2019-02-06 10:42:00 +01:00
expect(fixture.innerHTML).toMatchSnapshot();
// we check here that the url was changed to set app id as menu_id
});
2019-02-06 13:26:21 +01:00
test("start with no action => clicks on client action => discuss is rendered", async () => {
2019-02-20 09:46:22 +01:00
const root = new Root(env, store);
2019-02-06 13:26:21 +01:00
await root.mount(fixture);
2019-02-20 09:46:22 +01:00
expect(env.services.router.getQuery()).toEqual({});
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-02-20 09:46:22 +01:00
expect(env.services.router.getQuery()).toEqual({
action_id: "131",
menu_id: "96"
});
2019-02-06 13:26:21 +01:00
});