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 { MenuInfo, MenuItem } from "./widgets/root";
|
||||||
import { Env } from "./widgets/widget";
|
import { Env } from "./widgets/widget";
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Types
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
interface InitializedData {
|
interface InitializedData {
|
||||||
env: Env;
|
env: Env;
|
||||||
menuInfo: MenuInfo;
|
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
|
* 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
|
* one environment. For example, with two environment, the router code in one
|
||||||
* environment will probably interfere with the code from the other environment.
|
* 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.
|
* this function will actually return the same environment.
|
||||||
*/
|
*/
|
||||||
export const init = memoize(async function(): Promise<InitializedData> {
|
export const init = memoize(async function(): Promise<InitializedData> {
|
||||||
@@ -61,13 +65,9 @@ export const init = memoize(async function(): Promise<InitializedData> {
|
|||||||
// Adapters
|
// Adapters
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
function loadMenus(): MenuInfo {
|
/**
|
||||||
const menuItems: BaseMenuItem[] = (<any>window).odoo.menus;
|
* Load xml templates as a string.
|
||||||
const menuInfo = getMenuInfo(menuItems);
|
*/
|
||||||
delete (<any>window).odoo.menus; // overkill?
|
|
||||||
return menuInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadTemplates(): Promise<string> {
|
async function loadTemplates(): Promise<string> {
|
||||||
const result = await fetch("templates.xml");
|
const result = await fetch("templates.xml");
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
@@ -76,6 +76,16 @@ async function loadTemplates(): Promise<string> {
|
|||||||
return result.text();
|
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 {
|
interface BaseMenuItem {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ export class Root extends Widget<Props, State> {
|
|||||||
if (app) {
|
if (app) {
|
||||||
this.updateState({ currentApp: app });
|
this.updateState({ currentApp: app });
|
||||||
}
|
}
|
||||||
debugger;
|
|
||||||
this.env.router.navigate(query);
|
this.env.router.navigate(query);
|
||||||
this.env.actionManager.doAction(actionId);
|
this.env.actionManager.doAction(actionId);
|
||||||
} else {
|
} 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 { 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() {
|
export function makeTestFixture() {
|
||||||
let fixture = document.createElement("div");
|
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`] = `
|
exports[`can be rendered 1`] = `
|
||||||
"<div class=\\"o_home_menu\\">
|
"<div class=\\"o_home_menu\\">
|
||||||
<div class=\\"o_apps\\">
|
<div class=\\"o_apps\\">
|
||||||
<a href=\\"#menu_id=14&action_id=43\\" class=\\"o_app\\">
|
<a href=\\"#menu_id=96&action_id=131\\" class=\\"o_app\\">
|
||||||
<i class=\\"fa fa-test o_app_icon fa-3x fa-fw\\"></i>
|
<i class=\\"fa fa-comment o_app_icon fa-3x fa-fw\\"></i>
|
||||||
<div class=\\"o_caption\\">
|
<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>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,6 +11,31 @@ exports[`can render one menu item 1`] = `
|
|||||||
"<div class=\\"o_navbar\\">
|
"<div class=\\"o_navbar\\">
|
||||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
<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>"
|
</div>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -18,5 +43,13 @@ exports[`mobile mode: navbar is different 1`] = `
|
|||||||
"<div class=\\"o_navbar\\">
|
"<div class=\\"o_navbar\\">
|
||||||
<a aria-label=\\"Applications\\" class=\\"o_title fa fa-th\\" href=\\"#\\" title=\\"Applications\\" accesskey=\\"h\\"></a>
|
<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>"
|
</div>"
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,43 +1,24 @@
|
|||||||
import { HomeMenu, Props } from "../../src/ts/widgets/home_menu";
|
import { HomeMenu, Props } from "../../src/ts/widgets/home_menu";
|
||||||
import { makeTestEnv, makeTestFixture, loadTemplates } from "../helpers";
|
import * as helpers from "../helpers";
|
||||||
import { MenuItem } from "../../src/ts/widgets/root";
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Setup and helpers
|
// Setup and helpers
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
let fixture: HTMLElement;
|
let fixture: HTMLElement;
|
||||||
let env: ReturnType<typeof makeTestEnv>;
|
let env: ReturnType<typeof helpers.makeTestEnv>;
|
||||||
let props: Props;
|
let props: Props;
|
||||||
let templates: string;
|
let templates: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
templates = await loadTemplates();
|
templates = await helpers.loadTemplates();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = makeTestFixture();
|
fixture = helpers.makeTestFixture();
|
||||||
env = makeTestEnv();
|
env = helpers.makeTestEnv();
|
||||||
env.qweb.loadTemplates(templates);
|
env.qweb.loadTemplates(templates);
|
||||||
const demoItem: MenuItem = <any>{
|
props = { menuInfo: helpers.makeDemoMenuInfo() };
|
||||||
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]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
import { Navbar, Props } from "../../src/ts/widgets/navbar";
|
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
|
// Setup and helpers
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
let fixture: HTMLElement;
|
let fixture: HTMLElement;
|
||||||
let env: ReturnType<typeof makeTestEnv>;
|
let env: ReturnType<typeof helpers.makeTestEnv>;
|
||||||
let props: Props;
|
let props: Props;
|
||||||
|
let menuInfo: MenuInfo;
|
||||||
let templates: string;
|
let templates: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
templates = await loadTemplates();
|
templates = await helpers.loadTemplates();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = makeTestFixture();
|
fixture = helpers.makeTestFixture();
|
||||||
env = makeTestEnv();
|
env = helpers.makeTestEnv();
|
||||||
env.qweb.loadTemplates(templates);
|
env.qweb.loadTemplates(templates);
|
||||||
props = { inHome: false, app: null };
|
props = { inHome: false, app: null };
|
||||||
|
menuInfo = helpers.makeDemoMenuInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -36,12 +39,14 @@ test("can be rendered", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("can render one menu item", async () => {
|
test("can render one menu item", async () => {
|
||||||
|
props.app = menuInfo.menus[96]!;
|
||||||
const navbar = new Navbar(env, props);
|
const navbar = new Navbar(env, props);
|
||||||
await navbar.mount(fixture);
|
await navbar.mount(fixture);
|
||||||
expect(fixture.innerHTML).toMatchSnapshot();
|
expect(fixture.innerHTML).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("mobile mode: navbar is different", async () => {
|
test("mobile mode: navbar is different", async () => {
|
||||||
|
props.app = menuInfo.menus[205]!;
|
||||||
env.isMobile = true;
|
env.isMobile = true;
|
||||||
const navbar = new Navbar(env, props);
|
const navbar = new Navbar(env, props);
|
||||||
await navbar.mount(fixture);
|
await navbar.mount(fixture);
|
||||||
|
|||||||
Reference in New Issue
Block a user