update test helpers and improve widget tests

This commit is contained in:
Géry Debongnie
2019-02-06 10:33:12 +01:00
parent 49ecc05297
commit 9b947d8118
7 changed files with 199 additions and 54 deletions
@@ -3,10 +3,20 @@
exports[`can be rendered 1`] = `
"<div class=\\"o_home_menu\\">
<div class=\\"o_apps\\">
<a href=\\"#menu_id=14&amp;action_id=43\\" class=\\"o_app\\">
<i class=\\"fa fa-test o_app_icon fa-3x fa-fw\\"></i>
<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\\">
Demo
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>
@@ -11,6 +11,31 @@ exports[`can render one menu item 1`] = `
"<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\\">
Discuss
</a>
<ul class=\\"o_menu_sections\\">
<li>
<a href=\\"#\\" role=\\"button\\" class=\\"dropdown-toggle o-no-caret\\" data-toggle=\\"dropdown\\">
<span>
Integrations
</span>
</a>
<div class=\\"dropdown-menu\\" role=\\"menu\\">
<a href=\\"\\" data-toggle=\\"collapse\\" data-target=\\"#someid\\" role=\\"menuitem\\" class=\\"dropdown-item\\">
<span>
Github Repositories
</span>
</a>
</div>
</li>
</ul>
</div>"
`;
@@ -18,5 +43,13 @@ exports[`mobile mode: navbar is different 1`] = `
"<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\\">
Notes
</a>
<ul class=\\"o_menu_sections\\">
<li>MOBILEMODE</li>
</ul>
</div>"
`;
+6 -25
View File
@@ -1,43 +1,24 @@
import { HomeMenu, Props } from "../../src/ts/widgets/home_menu";
import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
import { MenuItem } from "../../src/ts/widgets/root";
import * as helpers from "../helpers";
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
let env: ReturnType<typeof makeTestEnv>;
let env: ReturnType<typeof helpers.makeTestEnv>;
let props: Props;
let templates: string;
beforeAll(async () => {
templates = await loadTemplates();
templates = await helpers.loadTemplates();
});
beforeEach(() => {
fixture = makeTestFixture();
env = makeTestEnv();
fixture = helpers.makeTestFixture();
env = helpers.makeTestEnv();
env.qweb.loadTemplates(templates);
const demoItem: MenuItem = <any>{
id: 14,
name: "Demo",
parentId: false,
action: false,
icon: "fa fa-test",
children: [],
actionId: 43
};
demoItem.app = demoItem;
props = {
menuInfo: {
menus: {
14: demoItem
},
actionMap: { 43: demoItem },
roots: [14]
}
};
props = { menuInfo: helpers.makeDemoMenuInfo() };
});
afterEach(() => {
+10 -5
View File
@@ -1,24 +1,27 @@
import { Navbar, Props } from "../../src/ts/widgets/navbar";
import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
import * as helpers from "../helpers";
import { MenuInfo } from "../../src/ts/widgets/root";
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
let env: ReturnType<typeof makeTestEnv>;
let env: ReturnType<typeof helpers.makeTestEnv>;
let props: Props;
let menuInfo: MenuInfo;
let templates: string;
beforeAll(async () => {
templates = await loadTemplates();
templates = await helpers.loadTemplates();
});
beforeEach(() => {
fixture = makeTestFixture();
env = makeTestEnv();
fixture = helpers.makeTestFixture();
env = helpers.makeTestEnv();
env.qweb.loadTemplates(templates);
props = { inHome: false, app: null };
menuInfo = helpers.makeDemoMenuInfo();
});
afterEach(() => {
@@ -36,12 +39,14 @@ test("can be rendered", async () => {
});
test("can render one menu item", async () => {
props.app = menuInfo.menus[96]!;
const navbar = new Navbar(env, props);
await navbar.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("mobile mode: navbar is different", async () => {
props.app = menuInfo.menus[205]!;
env.isMobile = true;
const navbar = new Navbar(env, props);
await navbar.mount(fixture);