diff --git a/web/static/src/ts/init.ts b/web/static/src/ts/init.ts index cba3d05d..62c9a24b 100644 --- a/web/static/src/ts/init.ts +++ b/web/static/src/ts/init.ts @@ -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 { @@ -61,13 +65,9 @@ export const init = memoize(async function(): Promise { // Adapters //------------------------------------------------------------------------------ -function loadMenus(): MenuInfo { - const menuItems: BaseMenuItem[] = (window).odoo.menus; - const menuInfo = getMenuInfo(menuItems); - delete (window).odoo.menus; // overkill? - return menuInfo; -} - +/** + * Load xml templates as a string. + */ async function loadTemplates(): Promise { const result = await fetch("templates.xml"); if (!result.ok) { @@ -76,6 +76,16 @@ async function loadTemplates(): Promise { return result.text(); } +/** + * Load all menu items + */ +function loadMenus(): MenuInfo { + const menuItems: BaseMenuItem[] = (window).odoo.menus; + const menuInfo = getMenuInfo(menuItems); + delete (window).odoo.menus; // overkill? + return menuInfo; +} + interface BaseMenuItem { id: number; name: string; diff --git a/web/static/src/ts/widgets/root.ts b/web/static/src/ts/widgets/root.ts index 3306a574..c4659171 100644 --- a/web/static/src/ts/widgets/root.ts +++ b/web/static/src/ts/widgets/root.ts @@ -106,7 +106,6 @@ export class Root extends Widget { if (app) { this.updateState({ currentApp: app }); } - debugger; this.env.router.navigate(query); this.env.actionManager.doAction(actionId); } else { diff --git a/web/static/tests/helpers.ts b/web/static/tests/helpers.ts index 6e18504f..e170caeb 100644 --- a/web/static/tests/helpers.ts +++ b/web/static/tests/helpers.ts @@ -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 { }); }); } + +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: [] + } + ] + } + ] + } + ]); +} diff --git a/web/static/tests/widgets/__snapshots__/home_menu.test.ts.snap b/web/static/tests/widgets/__snapshots__/home_menu.test.ts.snap index af61eea5..739714ea 100644 --- a/web/static/tests/widgets/__snapshots__/home_menu.test.ts.snap +++ b/web/static/tests/widgets/__snapshots__/home_menu.test.ts.snap @@ -3,10 +3,20 @@ exports[`can be rendered 1`] = ` "
diff --git a/web/static/tests/widgets/__snapshots__/navbar.test.ts.snap b/web/static/tests/widgets/__snapshots__/navbar.test.ts.snap index d8647f3a..afd31309 100644 --- a/web/static/tests/widgets/__snapshots__/navbar.test.ts.snap +++ b/web/static/tests/widgets/__snapshots__/navbar.test.ts.snap @@ -11,6 +11,31 @@ exports[`can render one menu item 1`] = ` "" `; @@ -18,5 +43,13 @@ exports[`mobile mode: navbar is different 1`] = ` "
+ + Notes + +
    + +
  • MOBILEMODE
  • +
+
" `; diff --git a/web/static/tests/widgets/home_menu.test.ts b/web/static/tests/widgets/home_menu.test.ts index 0c227e6d..c320fb7f 100644 --- a/web/static/tests/widgets/home_menu.test.ts +++ b/web/static/tests/widgets/home_menu.test.ts @@ -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; +let env: ReturnType; 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 = { - 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(() => { diff --git a/web/static/tests/widgets/navbar.test.ts b/web/static/tests/widgets/navbar.test.ts index 02659a8a..8ce28336 100644 --- a/web/static/tests/widgets/navbar.test.ts +++ b/web/static/tests/widgets/navbar.test.ts @@ -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; +let env: ReturnType; 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);