add web client test

This commit is contained in:
Géry Debongnie
2019-02-06 10:42:00 +01:00
parent 9b947d8118
commit 78e8986ae9
4 changed files with 172 additions and 4 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ export interface MenuInfo {
roots: number[];
}
interface Props {
export interface Props {
menuInfo: MenuInfo;
}
+16 -3
View File
@@ -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 {
@@ -0,0 +1,110 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`can be rendered (in home menu) 1`] = `
"<div class=\\"o_web_client\\">
<div class=\\"o_navbar o_in_home\\">
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
</div>
<div class=\\"o_home_menu\\">
<div class=\\"o_apps\\">
<a href=\\"#menu_id=96&amp;action_id=131\\" class=\\"o_app\\">
<i class=\\"fa fa-comment o_app_icon fa-3x fa-fw\\"></i>
<div class=\\"o_caption\\">
Discuss
</div>
</a><a href=\\"#menu_id=205&amp;action_id=250\\" class=\\"o_app\\">
<i class=\\"fa fa-pen o_app_icon fa-3x fa-fw\\"></i>
<div class=\\"o_caption\\">
Notes
</div>
</a><a href=\\"#menu_id=409&amp;action_id=597\\" class=\\"o_app\\">
<i class=\\"fa fa-handshake o_app_icon fa-3x fa-fw\\"></i>
<div class=\\"o_caption\\">
CRM
</div>
</a>
</div>
</div>
<div class=\\"o_notification_container\\">
</div>
</div>"
`;
exports[`if url has action_id, will render action and navigate to proper menu_id 1`] = `
"<div class=\\"o_web_client\\">
<div class=\\"o_navbar\\">
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
<a class=\\"o_menu_brand\\" href=\\"\\" role=\\"button\\">
CRM
</a>
<ul class=\\"o_menu_sections\\">
<li>
<a href=\\"#\\" role=\\"button\\" class=\\"dropdown-toggle o-no-caret\\" data-toggle=\\"dropdown\\">
<span>
Sales
</span>
</a>
<div class=\\"dropdown-menu\\" role=\\"menu\\">
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
My Pipeline
</span>
</a>
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
My Quotations
</span>
</a>
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
Team Pipelines
</span>
</a>
</div>
</li><li>
<a href=\\"#\\" role=\\"button\\" class=\\"dropdown-toggle o-no-caret\\" data-toggle=\\"dropdown\\">
<span>
Leads
</span>
</a>
<div class=\\"dropdown-menu\\" role=\\"menu\\">
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
Leads
</span>
</a>
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
Scoring Rules
</span>
</a>
</div>
</li>
</ul>
</div>
<div class=\\"o_content\\"></div>
<div class=\\"o_notification_container\\">
</div>
</div>"
`;
+45
View File
@@ -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<typeof helpers.makeTestEnv>;
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" });
});