mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
update test helpers and improve widget tests
This commit is contained in:
@@ -8,19 +8,23 @@ import { ActionManager } from "./services/action_manager";
|
||||
import { MenuInfo, MenuItem } from "./widgets/root";
|
||||
import { Env } from "./widgets/widget";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
interface InitializedData {
|
||||
env: Env;
|
||||
menuInfo: MenuInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* makeEnvironment returns the main environment for the application.
|
||||
* init returns the main environment for the application.
|
||||
*
|
||||
* Note that it does not make much sense (except for tests) to have more than
|
||||
* one environment. For example, with two environment, the router code in one
|
||||
* environment will probably interfere with the code from the other environment.
|
||||
*
|
||||
* For this reason, the result of makeEnvironment is memoized: every call to
|
||||
* For this reason, the result of init is memoized: every call to
|
||||
* this function will actually return the same environment.
|
||||
*/
|
||||
export const init = memoize(async function(): Promise<InitializedData> {
|
||||
@@ -61,13 +65,9 @@ export const init = memoize(async function(): Promise<InitializedData> {
|
||||
// Adapters
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function loadMenus(): MenuInfo {
|
||||
const menuItems: BaseMenuItem[] = (<any>window).odoo.menus;
|
||||
const menuInfo = getMenuInfo(menuItems);
|
||||
delete (<any>window).odoo.menus; // overkill?
|
||||
return menuInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load xml templates as a string.
|
||||
*/
|
||||
async function loadTemplates(): Promise<string> {
|
||||
const result = await fetch("templates.xml");
|
||||
if (!result.ok) {
|
||||
@@ -76,6 +76,16 @@ async function loadTemplates(): Promise<string> {
|
||||
return result.text();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all menu items
|
||||
*/
|
||||
function loadMenus(): MenuInfo {
|
||||
const menuItems: BaseMenuItem[] = (<any>window).odoo.menus;
|
||||
const menuInfo = getMenuInfo(menuItems);
|
||||
delete (<any>window).odoo.menus; // overkill?
|
||||
return menuInfo;
|
||||
}
|
||||
|
||||
interface BaseMenuItem {
|
||||
id: number;
|
||||
name: string;
|
||||
|
||||
@@ -106,7 +106,6 @@ export class Root extends Widget<Props, State> {
|
||||
if (app) {
|
||||
this.updateState({ currentApp: app });
|
||||
}
|
||||
debugger;
|
||||
this.env.router.navigate(query);
|
||||
this.env.actionManager.doAction(actionId);
|
||||
} else {
|
||||
|
||||
+118
-11
@@ -1,15 +1,16 @@
|
||||
import { QWeb } from "../src/ts/core/qweb_vdom";
|
||||
import { idGenerator } from "../src/ts/core/utils";
|
||||
import { WEnv } from "../src/ts/core/component";
|
||||
import { Env } from "../src/ts/widgets/widget";
|
||||
import { IAjax, RPCQuery } from "../src/ts/core/ajax";
|
||||
import { Registry } from "../src/ts/core/registry";
|
||||
import { NotificationManager } from "../src/ts/core/notifications";
|
||||
|
||||
import { IActionManager, ActionEvent } from "../src/ts/services/action_manager";
|
||||
import { Callback } from "../src/ts/core/event_bus";
|
||||
import { IRouter, Query, RouterEvent } from "../src/ts/core/router";
|
||||
import { readFile } from "fs";
|
||||
import { IAjax, RPCQuery } from "../src/ts/core/ajax";
|
||||
import { WEnv } from "../src/ts/core/component";
|
||||
import { Callback } from "../src/ts/core/event_bus";
|
||||
import { NotificationManager } from "../src/ts/core/notifications";
|
||||
import { QWeb } from "../src/ts/core/qweb_vdom";
|
||||
import { Registry } from "../src/ts/core/registry";
|
||||
import { IRouter, Query, RouterEvent } from "../src/ts/core/router";
|
||||
import { idGenerator } from "../src/ts/core/utils";
|
||||
import { getMenuInfo } from "../src/ts/init";
|
||||
import { ActionEvent, IActionManager } from "../src/ts/services/action_manager";
|
||||
import { MenuInfo } from "../src/ts/widgets/root";
|
||||
import { Env } from "../src/ts/widgets/widget";
|
||||
|
||||
export function makeTestFixture() {
|
||||
let fixture = document.createElement("div");
|
||||
@@ -81,3 +82,109 @@ export async function loadTemplates(): Promise<string> {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function makeDemoMenuInfo(): MenuInfo {
|
||||
return getMenuInfo([
|
||||
{
|
||||
id: 96,
|
||||
name: "Discuss",
|
||||
parent_id: false,
|
||||
action: "ir.actions.client,131",
|
||||
icon: "fa fa-comment",
|
||||
children: [
|
||||
{
|
||||
id: 97,
|
||||
name: "Integrations",
|
||||
parent_id: 96,
|
||||
action: false,
|
||||
icon: false,
|
||||
children: [
|
||||
{
|
||||
id: 188,
|
||||
name: "Github Repositories",
|
||||
parent_id: 97,
|
||||
action: "ir.actions.act_window,233",
|
||||
icon: false,
|
||||
children: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 205,
|
||||
name: "Notes",
|
||||
parent_id: false,
|
||||
action: "ir.actions.act_window,250",
|
||||
icon: "fa fa-pen",
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 409,
|
||||
name: "CRM",
|
||||
parent_id: false,
|
||||
action: "ir.actions.act_window,597",
|
||||
icon: "fa fa-handshake",
|
||||
children: [
|
||||
{
|
||||
id: 418,
|
||||
name: "Sales",
|
||||
parent_id: 409,
|
||||
action: false,
|
||||
icon: false,
|
||||
children: [
|
||||
{
|
||||
id: 423,
|
||||
name: "My Pipeline",
|
||||
parent_id: 418,
|
||||
action: "ir.actions.act_window,597",
|
||||
icon: false,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 812,
|
||||
name: "My Quotations",
|
||||
parent_id: 418,
|
||||
action: "ir.actions.act_window,1051",
|
||||
icon: false,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 419,
|
||||
name: "Team Pipelines",
|
||||
parent_id: 418,
|
||||
action: "ir.actions.act_window,275",
|
||||
icon: false,
|
||||
children: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 421,
|
||||
name: "Leads",
|
||||
parent_id: 409,
|
||||
action: false,
|
||||
icon: false,
|
||||
children: [
|
||||
{
|
||||
id: 422,
|
||||
name: "Leads",
|
||||
parent_id: 421,
|
||||
action: "ir.actions.act_window,595",
|
||||
icon: false,
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 752,
|
||||
name: "Scoring Rules",
|
||||
parent_id: 421,
|
||||
icon: false,
|
||||
action: "ir.actions.act_window,1083",
|
||||
children: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,20 @@
|
||||
exports[`can be rendered 1`] = `
|
||||
"<div class=\\"o_home_menu\\">
|
||||
<div class=\\"o_apps\\">
|
||||
<a href=\\"#menu_id=14&action_id=43\\" class=\\"o_app\\">
|
||||
<i class=\\"fa fa-test o_app_icon fa-3x fa-fw\\"></i>
|
||||
<a href=\\"#menu_id=96&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&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&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>"
|
||||
`;
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user