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
+19 -9
View File
@@ -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;
-1
View File
@@ -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 {