diff --git a/web/static/src/ts/widgets/root.ts b/web/static/src/ts/widgets/root.ts
index c4659171..59ea343e 100644
--- a/web/static/src/ts/widgets/root.ts
+++ b/web/static/src/ts/widgets/root.ts
@@ -32,7 +32,7 @@ export interface MenuInfo {
roots: number[];
}
-interface Props {
+export interface Props {
menuInfo: MenuInfo;
}
diff --git a/web/static/tests/helpers.ts b/web/static/tests/helpers.ts
index e170caeb..eba7da34 100644
--- a/web/static/tests/helpers.ts
+++ b/web/static/tests/helpers.ts
@@ -25,7 +25,11 @@ export function makeTestWEnv(): WEnv {
};
}
-export function makeTestEnv(): Env {
+export interface MockEnv extends Env {
+ router: MockRouter;
+}
+
+export function makeTestEnv(): MockEnv {
const ajax = new MockAjax();
const actionManager = new MockActionManager();
const router = new MockRouter();
@@ -61,14 +65,23 @@ class MockActionManager implements IActionManager {
}
class MockRouter implements IRouter {
- navigate(query: Query) {}
+ currentQuery: Query = {};
+
+ navigate(query: Query) {
+ this.currentQuery = query;
+ }
on(event: RouterEvent, owner: any, callback: Callback) {}
getQuery(): Query {
- return {};
+ return this.currentQuery;
}
+
formatURL(path: string, query: Query): string {
return "";
}
+
+ setQuery(query: Query) {
+ this.currentQuery = query;
+ }
}
export function normalize(str: string): string {
diff --git a/web/static/tests/widgets/__snapshots__/root.test.ts.snap b/web/static/tests/widgets/__snapshots__/root.test.ts.snap
new file mode 100644
index 00000000..13390b0c
--- /dev/null
+++ b/web/static/tests/widgets/__snapshots__/root.test.ts.snap
@@ -0,0 +1,110 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`can be rendered (in home menu) 1`] = `
+"
"
+`;
+
+exports[`if url has action_id, will render action and navigate to proper menu_id 1`] = `
+""
+`;
diff --git a/web/static/tests/widgets/root.test.ts b/web/static/tests/widgets/root.test.ts
new file mode 100644
index 00000000..d5d0d894
--- /dev/null
+++ b/web/static/tests/widgets/root.test.ts
@@ -0,0 +1,45 @@
+import { Root, Props } from "../../src/ts/widgets/root";
+import * as helpers from "../helpers";
+
+//------------------------------------------------------------------------------
+// Setup and helpers
+//------------------------------------------------------------------------------
+
+let fixture: HTMLElement;
+let env: ReturnType;
+let props: Props;
+let templates: string;
+
+beforeAll(async () => {
+ templates = await helpers.loadTemplates();
+});
+
+beforeEach(() => {
+ fixture = helpers.makeTestFixture();
+ env = helpers.makeTestEnv();
+ env.qweb.loadTemplates(templates);
+ props = { menuInfo: helpers.makeDemoMenuInfo() };
+});
+
+afterEach(() => {
+ fixture.remove();
+});
+
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
+test("can be rendered (in home menu)", async () => {
+ const navbar = new Root(env, props);
+ await navbar.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 navbar = new Root(env, props);
+ await navbar.mount(fixture);
+ 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" });
+});