adapt tests

This commit is contained in:
Géry Debongnie
2019-02-20 09:46:22 +01:00
parent 7f3886ebba
commit 203ce91e92
16 changed files with 185 additions and 173 deletions
+24 -13
View File
@@ -1,4 +1,6 @@
import { Root, Props } from "../../src/ts/widgets/root";
import { Env, makeEnv } from "../../src/ts/env";
import { Store } from "../../src/ts/store";
import { Root } from "../../src/ts/widgets/root";
import * as helpers from "../helpers";
//------------------------------------------------------------------------------
@@ -6,8 +8,8 @@ import * as helpers from "../helpers";
//------------------------------------------------------------------------------
let fixture: HTMLElement;
let env: ReturnType<typeof helpers.makeTestEnv>;
let props: Props;
let store: Store;
let env: Env;
let templates: string;
beforeAll(async () => {
@@ -16,9 +18,9 @@ beforeAll(async () => {
beforeEach(() => {
fixture = helpers.makeTestFixture();
env = helpers.makeTestEnv();
env.qweb.loadTemplates(templates);
props = { menuInfo: helpers.makeDemoMenuInfo() };
store = helpers.makeTestStore();
env = makeEnv(store, templates);
// props = { menuInfo: helpers.makeDemoMenuInfo() };
});
afterEach(() => {
@@ -30,29 +32,38 @@ afterEach(() => {
//------------------------------------------------------------------------------
test("can be rendered (in home menu)", async () => {
const root = new Root(env, props);
const root = new Root(env, 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 () => {
env.router.setQuery({ action_id: "595" });
const root = new Root(env, props);
const router = new helpers.MockRouter({ action_id: "595" });
store = helpers.makeTestStore({ router });
env = makeEnv(store, templates);
const root = new Root(env, store);
await root.mount(fixture);
expect(env.services.router.getQuery()).toEqual({
action_id: "595",
menu_id: "409"
});
expect(fixture.innerHTML).toMatchSnapshot();
// we check here that the url was changed to set app id as menu_id
expect(env.router.currentQuery).toEqual({ action_id: "595", menu_id: "409" });
});
test("start with no action => clicks on client action => discuss is rendered", async () => {
const root = new Root(env, props);
const root = new Root(env, store);
await root.mount(fixture);
expect(env.router.currentQuery).toEqual({});
expect(env.services.router.getQuery()).toEqual({});
// discuss menu item
await (<any>document.querySelector('[data-menu="96"]')).click();
await helpers.nextTick();
expect(fixture.innerHTML).toMatchSnapshot();
expect(env.router.currentQuery).toEqual({ action_id: "131", menu_id: "96" });
expect(env.services.router.getQuery()).toEqual({
action_id: "131",
menu_id: "96"
});
});