diff --git a/web/static/src/ts/env.ts b/web/static/src/ts/env.ts index 3c44c2e9..1d49c180 100644 --- a/web/static/src/ts/env.ts +++ b/web/static/src/ts/env.ts @@ -1,15 +1,27 @@ import { WEnv } from "./core/component"; import { QWeb } from "./core/qweb_vdom"; +import { Registry } from "./core/registry"; import { idGenerator } from "./core/utils"; -import { Notification, RPC, Services, Store } from "./store/store"; +import { RPC } from "./services/ajax"; +import { IRouter } from "./services/router"; +import { ControllerWidget, Store, Notification } from "./store/store"; //------------------------------------------------------------------------------ // Types //------------------------------------------------------------------------------ +export interface Services { + rpc: RPC; + router: IRouter; +} + export interface Env extends WEnv { services: Services; + // registries + actionRegistry: Registry; + viewRegistry: Registry; + // commands activateMenuItem(menuId: number): void; addNotification(notif: Partial): number; @@ -24,30 +36,51 @@ export interface Env extends WEnv { isMobile: boolean; } +export interface InitData { + services: Services; + templates: string; + actionRegistry: Registry; + viewRegistry: Registry; +} + //------------------------------------------------------------------------------ // Environment //------------------------------------------------------------------------------ -export function makeEnv(store: Store, templates: string): Env { +export function makeEnv(data: InitData): Env { const qweb = new QWeb(); qweb.addTemplate("default", "
"); - qweb.loadTemplates(templates); + qweb.loadTemplates(data.templates); + + function throwNonImplementedError(): any { + throw new Error("Not implemented. This feature requires a store."); + } const env: Env = { qweb, getID: idGenerator(), - services: store.services, + services: data.services, + actionRegistry: data.actionRegistry, + viewRegistry: data.viewRegistry, - activateMenuItem: store.activateMenuItem.bind(store), - addNotification: store.addNotification.bind(store), - closeNotification: store.closeNotification.bind(store), - toggleHomeMenu: store.toggleHomeMenu.bind(store), + activateMenuItem: throwNonImplementedError, + addNotification: throwNonImplementedError, + closeNotification: throwNonImplementedError, + toggleHomeMenu: throwNonImplementedError, - rpc: store.rpc.bind(store), + rpc: throwNonImplementedError, debug: false, isMobile: window.innerWidth <= 768 }; return env; } + +export function linkStoreToEnv(env: Env, store: Store) { + env.activateMenuItem = store.activateMenuItem.bind(store); + env.addNotification = store.addNotification.bind(store); + env.closeNotification = store.closeNotification.bind(store); + env.toggleHomeMenu = store.toggleHomeMenu.bind(store); + env.rpc = store.rpc.bind(store); +} diff --git a/web/static/src/ts/main.ts b/web/static/src/ts/main.ts index 780b1583..f153de12 100644 --- a/web/static/src/ts/main.ts +++ b/web/static/src/ts/main.ts @@ -1,6 +1,6 @@ /// -import { makeEnv } from "./env"; +import { makeEnv, linkStoreToEnv } from "./env"; import { loadMenus, loadTemplates } from "./loaders"; import { actionRegistry, viewRegistry } from "./registries"; import { rpc } from "./services/ajax"; @@ -20,8 +20,9 @@ document.addEventListener("DOMContentLoaded", async function() { const templates = await loadTemplates(); const menuInfo = loadMenus(); - const store = new Store(services, menuInfo, actionRegistry, viewRegistry); - const env = makeEnv(store, templates); + const env = makeEnv({ services, templates, actionRegistry, viewRegistry }); + const store = new Store(env, menuInfo); + linkStoreToEnv(env, store); // Creating root widget const rootWidget = new Root(env, store); diff --git a/web/static/src/ts/store/action_manager_mixin.ts b/web/static/src/ts/store/action_manager_mixin.ts index 86bcf7cf..018cdcf6 100644 --- a/web/static/src/ts/store/action_manager_mixin.ts +++ b/web/static/src/ts/store/action_manager_mixin.ts @@ -82,7 +82,7 @@ export function actionManagerMixin>( doActWindowAction(descr: ActWindowActionDescription) { const tag = descr.views[0][1]; - let View = this.viewRegistry.get(tag); + let View = this.env.viewRegistry.get(tag); if (!View) { this.addNotification({ title: "Invalid View type", @@ -105,7 +105,7 @@ export function actionManagerMixin>( doClientAction(descr: ClientActionDescription): Controller["create"] { let key = descr.tag; - let ActionWidget = this.actionRegistry.get(key); + let ActionWidget = this.env.actionRegistry.get(key); if (!ActionWidget) { this.addNotification({ title: "Invalid Client Action", diff --git a/web/static/src/ts/store/rpc_mixin.ts b/web/static/src/ts/store/rpc_mixin.ts index 6708ae85..24e44772 100644 --- a/web/static/src/ts/store/rpc_mixin.ts +++ b/web/static/src/ts/store/rpc_mixin.ts @@ -41,7 +41,7 @@ export function rpcMixin>(Base: T) { this.trigger("rpc_status", "loading"); } this.counter++; - const result = await this.services.rpc(request.route, request.params); + const result = await this.env.services.rpc(request.route, request.params); this.counter--; if (this.counter === 0) { this.trigger("rpc_status", "notloading"); diff --git a/web/static/src/ts/store/store.ts b/web/static/src/ts/store/store.ts index 74970845..203ab32a 100644 --- a/web/static/src/ts/store/store.ts +++ b/web/static/src/ts/store/store.ts @@ -1,9 +1,8 @@ import { EventBus } from "../core/event_bus"; -import { Registry } from "../core/registry"; import { idGenerator } from "../core/utils"; -import { RPC } from "../services/ajax"; -import { IRouter, Query } from "../services/router"; -import { actionManagerMixin, ControllerWidget } from "./action_manager_mixin"; +import { Env } from "../env"; +import { Query } from "../services/router"; +import { actionManagerMixin } from "./action_manager_mixin"; import { rpcMixin } from "./rpc_mixin"; import { MenuItem } from "./store"; @@ -27,6 +26,14 @@ export interface MenuItem { children: MenuItem[]; } +export interface Notification { + id: number; + title: string; + message: string; + type: "notification" | "warning"; + sticky: boolean; +} + export interface MenuInfo { menus: { [key: number]: MenuItem | undefined }; @@ -40,19 +47,6 @@ export interface State { notifications: Notification[]; } -export interface Services { - rpc: RPC; - router: IRouter; -} - -export interface Notification { - id: number; - title: string; - message: string; - type: "notification" | "warning"; - sticky: boolean; -} - //------------------------------------------------------------------------------ // Store //------------------------------------------------------------------------------ @@ -63,23 +57,14 @@ export class BaseStore extends EventBus { notifications: [] }; menuInfo: MenuInfo; - services: Services; - actionRegistry: Registry; - viewRegistry: Registry; + env: Env; currentQuery: Query; generateID = idGenerator(); - constructor( - services: Services, - menuInfo: MenuInfo, - actionRegistry: Registry, - viewRegistry: Registry - ) { + constructor(env: Env, menuInfo: MenuInfo) { super(); - this.services = services; + this.env = env; this.menuInfo = menuInfo; - this.actionRegistry = actionRegistry; - this.viewRegistry = viewRegistry; this.currentQuery = {}; } @@ -94,7 +79,7 @@ export class BaseStore extends EventBus { } this.update({ inHome: !this.state.inHome }); if (this.state.inHome) { - this.services.router.navigate({ home: true }); + this.env.services.router.navigate({ home: true }); } else { this.updateQuery(this.currentQuery); } @@ -102,7 +87,7 @@ export class BaseStore extends EventBus { updateQuery(query: Query) { this.currentQuery = query; - this.services.router.navigate(query); + this.env.services.router.navigate(query); } addNotification(notif: Partial): number { @@ -129,22 +114,17 @@ export class BaseStore extends EventBus { } export class Store extends actionManagerMixin(rpcMixin(BaseStore)) { - constructor( - services: Services, - menuInfo: MenuInfo, - actionRegistry: Registry, - viewRegistry: Registry - ) { - super(services, menuInfo, actionRegistry, viewRegistry); - const query = this.services.router.getQuery(); + constructor(env: Env, menuInfo: MenuInfo) { + super(env, menuInfo); + const query = this.env.services.router.getQuery(); let { app, actionId } = this.getAppAndAction(query); this.state.currentApp = app; if (!actionId) { this.state.inHome = true; - this.services.router.navigate({ home: true }); + this.env.services.router.navigate({ home: true }); } - this.services.router.on("query_changed", this, this.updateAction); - this.updateAction(this.services.router.getQuery()); + this.env.services.router.on("query_changed", this, this.updateAction); + this.updateAction(this.env.services.router.getQuery()); } private updateAction(query: Query) { diff --git a/web/static/src/ts/ui/root.ts b/web/static/src/ts/ui/root.ts index edddd3ec..01e80309 100644 --- a/web/static/src/ts/ui/root.ts +++ b/web/static/src/ts/ui/root.ts @@ -1,11 +1,11 @@ import { debounce } from "../core/utils"; import { Env } from "../env"; +import { Controller } from "../store/action_manager_mixin"; import { State, Store } from "../store/store"; +import { Widget } from "../widget"; import { HomeMenu } from "./home_menu"; import { Navbar } from "./navbar"; import { Notification } from "./notification"; -import { Widget } from "../widget"; -import { Controller } from "../store/action_manager_mixin"; //------------------------------------------------------------------------------ // Root Widget diff --git a/web/static/src/ts/views/form_view.ts b/web/static/src/ts/views/form_view.ts index 47b06a97..f08c5278 100644 --- a/web/static/src/ts/views/form_view.ts +++ b/web/static/src/ts/views/form_view.ts @@ -1,5 +1,5 @@ import { Widget } from "../widget"; -export class FormView extends Widget<{}, { info: any }> { +export class FormView extends Widget<{ info: any }, {}> { inlineTemplate = `
form view:
`; } diff --git a/web/static/src/ts/views/kanban_view.ts b/web/static/src/ts/views/kanban_view.ts index a205d495..63005248 100644 --- a/web/static/src/ts/views/kanban_view.ts +++ b/web/static/src/ts/views/kanban_view.ts @@ -1,5 +1,5 @@ import { Widget } from "../widget"; -export class KanbanView extends Widget<{}, { info: any }> { +export class KanbanView extends Widget<{ info: any }, {}> { inlineTemplate = `
kanban view:
`; } diff --git a/web/static/src/ts/views/list_view.ts b/web/static/src/ts/views/list_view.ts index d0f12a06..87e2a688 100644 --- a/web/static/src/ts/views/list_view.ts +++ b/web/static/src/ts/views/list_view.ts @@ -1,5 +1,5 @@ import { Widget } from "../widget"; -export class ListView extends Widget<{}, { info: any }> { +export class ListView extends Widget<{ info: any }, {}> { inlineTemplate = `
list view:
`; } diff --git a/web/static/tests/helpers/test_data.ts b/web/static/tests/helpers/test_data.ts index 1a7151c9..e3f19604 100644 --- a/web/static/tests/helpers/test_data.ts +++ b/web/static/tests/helpers/test_data.ts @@ -1,39 +1,20 @@ -import { readFile } from "fs"; import { BaseMenuItem, getMenuInfo } from "../../src/ts/loaders"; -import { actionRegistry, viewRegistry } from "../../src/ts/registries"; import { ActionDescription } from "../../src/ts/store/action_manager_mixin"; import { MenuInfo } from "../../src/ts/store/store"; -import { Registry } from "../../src/ts/core/registry"; export interface TestData { menuInfo: MenuInfo; actions: ActionDescription[]; - actionRegistry: typeof actionRegistry; - viewRegistry: typeof viewRegistry; - templates: string; } -let templates: string; - -export async function makeTestData(): Promise { - if (!templates) { - templates = await loadTemplates(); - } - const _actionRegistry: typeof actionRegistry = new Registry(); - (_actionRegistry).map = Object.assign({}, (actionRegistry).map); - const _viewRegistry: typeof actionRegistry = new Registry(); - (_viewRegistry).map = Object.assign({}, (actionRegistry).map); - +export function makeTestData(): TestData { return { menuInfo: makeMenuInfo(), - actions: makeActionData(), - actionRegistry: _actionRegistry, - viewRegistry: _viewRegistry, - templates + actions: makeActionData() }; } -export function makeMenuInfo(): MenuInfo { +function makeMenuInfo(): MenuInfo { const items: BaseMenuItem[] = [ { id: 96, @@ -215,10 +196,28 @@ function makeActionData(): ActionDescription[] { ]; } -function loadTemplates(): Promise { - return new Promise((resolve, reject) => { - readFile("web/static/src/xml/templates.xml", "utf-8", (err, result) => { - resolve(result); - }); - }); -} +// function loadTemplates(): Promise { +// return new Promise((resolve, reject) => { +// readFile("web/static/src/xml/templates.xml", "utf-8", (err, result) => { +// resolve(result); +// }); +// }); +// } + +// export async function makeTestData(): Promise { +// if (!templates) { +// templates = await loadTemplates(); +// } +// const _actionRegistry: typeof actionRegistry = new Registry(); +// (_actionRegistry).map = Object.assign({}, (actionRegistry).map); +// const _viewRegistry: typeof actionRegistry = new Registry(); +// (_viewRegistry).map = Object.assign({}, (actionRegistry).map); + +// return { +// menuInfo: makeMenuInfo(), +// actions: makeActionData(), +// actionRegistry: _actionRegistry, +// viewRegistry: _viewRegistry, +// templates +// }; +// } diff --git a/web/static/tests/helpers/test_env.ts b/web/static/tests/helpers/test_env.ts index c5e0fa3a..4293fefb 100644 --- a/web/static/tests/helpers/test_env.ts +++ b/web/static/tests/helpers/test_env.ts @@ -1,13 +1,17 @@ +import { readFileSync } from "fs"; import { WEnv } from "../../src/ts/core/component"; import { QWeb } from "../../src/ts/core/qweb_vdom"; import { Registry } from "../../src/ts/core/registry"; import { idGenerator } from "../../src/ts/core/utils"; -import { Env, makeEnv } from "../../src/ts/env"; -import { IRouter } from "../../src/ts/services/router"; -import { MenuInfo, Store } from "../../src/ts/store/store"; +import { Env, InitData, linkStoreToEnv, makeEnv } from "../../src/ts/env"; +import { + actionRegistry as AR, + viewRegistry as VR +} from "../../src/ts/registries"; +import { Store } from "../../src/ts/store/store"; import { MockRouter } from "./mock_router"; import { MockServer } from "./mock_server"; -import { TestData } from "./test_data"; +import { makeTestData, TestData } from "./test_data"; //------------------------------------------------------------------------------ // Types @@ -17,11 +21,16 @@ export interface TestEnv extends Env { store: Store; } -export interface TestInfo extends Partial { +export interface TestInfo extends Partial, Partial { mockRPC?(this: MockServer, route: string, params: any): Promise; - router?: IRouter; } +//------------------------------------------------------------------------------ +// Code +//------------------------------------------------------------------------------ + +const TEMPLATES = readFileSync("web/static/src/xml/templates.xml", "utf-8"); + export function makeTestWEnv(): WEnv { return { qweb: new QWeb(), @@ -29,44 +38,50 @@ export function makeTestWEnv(): WEnv { }; } -//------------------------------------------------------------------------------ -// Code -//------------------------------------------------------------------------------ - export function makeTestEnv(info: TestInfo = {}): TestEnv { - const templates = info.templates || ""; - const menuInfo: MenuInfo = info.menuInfo || { - menus: {}, - actionMap: {}, - roots: [] - }; - const actionRegistry = info.actionRegistry || new Registry(); - const viewRegistry = info.viewRegistry || new Registry(); - const actions = info.actions || []; + const templates = info.templates || TEMPLATES; + const testData: TestData = makeTestData(); + if (info.menuInfo) { + testData.menuInfo = info.menuInfo; + } + if (info.actions) { + testData.actions = info.actions; + } - const data: TestData = { - menuInfo, - actions, + const actionRegistry = info.actionRegistry || cloneRegistry(AR); + const viewRegistry = info.viewRegistry || cloneRegistry(VR); + + let rpc = info.services && info.services.rpc; + if (!rpc) { + const mockServer = new MockServer(testData); + rpc = function(route: string, params: any): Promise { + if (info.mockRPC) { + return info.mockRPC.call(mockServer, route, params); + } + return mockServer.rpc(route, params); + }; + } + + const router = (info.services && info.services.router) || new MockRouter(); + const initData: InitData = { + services: { + rpc, + router + }, actionRegistry, viewRegistry, templates }; - const mockServer = new MockServer(data); - - function rpc(route: string, params: any): Promise { - if (info.mockRPC) { - return info.mockRPC.call(mockServer, route, params); - } - return mockServer.rpc(route, params); - } - const services = { - rpc, - router: info.router || new MockRouter() - }; - - const store = new Store(services, menuInfo, actionRegistry, viewRegistry); - const env = makeEnv(store, templates); + const env = makeEnv(initData); + const store = new Store(env, testData.menuInfo); + linkStoreToEnv(env, store); const testEnv = Object.assign({ store }, env); return testEnv; } + +function cloneRegistry(registry: Registry): Registry { + const clone: Registry = new Registry(); + (clone).map = Object.assign({}, (registry).map); + return clone; +} diff --git a/web/static/tests/store/action_manager_mixin_test.ts b/web/static/tests/store/action_manager_mixin_test.ts index 89d41837..fba42cef 100644 --- a/web/static/tests/store/action_manager_mixin_test.ts +++ b/web/static/tests/store/action_manager_mixin_test.ts @@ -1,5 +1,5 @@ -import { makeTestData, makeTestEnv } from "../helpers"; import { Registry } from "../../src/ts/core/registry"; +import { makeTestEnv } from "../helpers"; //------------------------------------------------------------------------------ // Tests @@ -7,9 +7,7 @@ import { Registry } from "../../src/ts/core/registry"; test("does not reload action if already done", async () => { const routes: string[] = []; - const data = await makeTestData(); const testEnv = makeTestEnv({ - ...data, mockRPC(route, params) { routes.push(route); return this.rpc(route, params); @@ -28,9 +26,7 @@ test("does not reload action if already done", async () => { }); test("display a warning if client action is not in registry", async () => { - const data = await makeTestData(); - data.actionRegistry = new Registry(); - const testEnv = makeTestEnv(data); + const testEnv = makeTestEnv({ actionRegistry: new Registry() }); await testEnv.store.doAction(131); @@ -40,9 +36,7 @@ test("display a warning if client action is not in registry", async () => { }); test("display a warning if view is not in registry", async () => { - const data = await makeTestData(); - data.viewRegistry = new Registry(); - const testEnv = makeTestEnv(data); + const testEnv = makeTestEnv({ viewRegistry: new Registry() }); await testEnv.store.doAction(250); diff --git a/web/static/tests/store/store.test.ts b/web/static/tests/store/store.test.ts index d8663e33..092d6432 100644 --- a/web/static/tests/store/store.test.ts +++ b/web/static/tests/store/store.test.ts @@ -1,4 +1,9 @@ -import { makeTestData, makeTestEnv, nextMicroTick } from "../helpers"; +import { Store } from "../../src/ts/store/store"; +import { makeTestEnv, nextMicroTick, TestInfo } from "../helpers"; + +function makeTestStore(info?: TestInfo): Store { + return makeTestEnv(info).store; +} //------------------------------------------------------------------------------ // Tests @@ -8,18 +13,18 @@ describe("rpc", () => { test("properly translate query in route", async () => { expect.assertions(1); - const store = makeTestEnv({ + const store = makeTestStore({ mockRPC(route, params) { expect(route).toBe("/web/dataset/call_kw/test/hey"); return this.rpc(route, params); } - }).store; + }); await store.rpc({ model: "test", method: "hey" }); }); test("trigger proper events", async () => { - const store = makeTestEnv().store; + const store = makeTestStore(); const events: string[] = []; store.on("rpc_status", null, s => { events.push(s); @@ -34,7 +39,7 @@ describe("rpc", () => { describe("notifications", () => { test("can subscribe and add notification", () => { - const store = makeTestEnv().store; + const store = makeTestStore(); expect(store.state.notifications.length).toBe(0); const id = store.addNotification({ title: "test", @@ -45,7 +50,7 @@ describe("notifications", () => { }); test("can close a notification", () => { - const store = makeTestEnv().store; + const store = makeTestStore(); const id = store.addNotification({ title: "test", @@ -59,7 +64,7 @@ describe("notifications", () => { test("notifications closes themselves after a while", () => { jest.useFakeTimers(); - const store = makeTestEnv().store; + const store = makeTestStore(); store.addNotification({ title: "test", message: "message" }); @@ -71,7 +76,7 @@ describe("notifications", () => { test("sticky notifications do not close themselves after a while", () => { jest.useFakeTimers(); - const store = makeTestEnv().store; + const store = makeTestStore(); store.addNotification({ title: "test", @@ -88,32 +93,32 @@ describe("notifications", () => { describe("state transitions", () => { test("toggle menu", async () => { - const data = await makeTestData(); - const store = makeTestEnv(data).store; + const env = makeTestEnv(); + const store = env.store; expect(store.state.inHome).toBe(true); store.toggleHomeMenu(); // should still be in home menu since no app is currently active expect(store.state.inHome).toBe(true); - expect(store.services.router.getQuery()).toEqual({ home: true }); + expect(env.services.router.getQuery()).toEqual({ home: true }); const promise = store.activateMenuItem(96); - expect(store.services.router.getQuery()).toEqual({ home: true }); + expect(env.services.router.getQuery()).toEqual({ home: true }); await promise; store.activateController(store.lastController!); expect(store.state.inHome).toBe(false); - expect(store.services.router.getQuery()).toEqual({ + expect(env.services.router.getQuery()).toEqual({ action_id: "131", menu_id: "96" }); store.toggleHomeMenu(); expect(store.state.inHome).toBe(true); - expect(store.services.router.getQuery()).toEqual({ home: true }); + expect(env.services.router.getQuery()).toEqual({ home: true }); store.toggleHomeMenu(); expect(store.state.inHome).toBe(false); - expect(store.services.router.getQuery()).toEqual({ + expect(env.services.router.getQuery()).toEqual({ action_id: "131", menu_id: "96" }); @@ -121,8 +126,7 @@ describe("state transitions", () => { test("document title", async () => { document.title = "Odoo"; - const data = await makeTestData(); - const store = makeTestEnv(data).store; + const store = makeTestStore(); expect(store.state.inHome).toBe(true); expect(document.title).toBe("Odoo"); const promise = store.activateMenuItem(96); diff --git a/web/static/tests/ui/home_menu.test.ts b/web/static/tests/ui/home_menu.test.ts index d248c50b..65f520ae 100644 --- a/web/static/tests/ui/home_menu.test.ts +++ b/web/static/tests/ui/home_menu.test.ts @@ -1,5 +1,5 @@ import { HomeMenu } from "../../src/ts/ui/home_menu"; -import { makeTestData, makeTestEnv, makeTestFixture } from "../helpers"; +import { makeTestEnv, makeTestFixture } from "../helpers"; //------------------------------------------------------------------------------ // Setup and helpers @@ -20,9 +20,8 @@ afterEach(() => { //------------------------------------------------------------------------------ test("can be rendered", async () => { - const data = await makeTestData(); - const testEnv = makeTestEnv(data); - const props = { menuInfo: data.menuInfo }; + const testEnv = makeTestEnv(); + const props = { menuInfo: testEnv.store.menuInfo }; const homeMenu = new HomeMenu(testEnv, props); await homeMenu.mount(fixture); expect(fixture.innerHTML).toMatchSnapshot(); diff --git a/web/static/tests/ui/navbar.test.ts b/web/static/tests/ui/navbar.test.ts index 421008cf..a8347805 100644 --- a/web/static/tests/ui/navbar.test.ts +++ b/web/static/tests/ui/navbar.test.ts @@ -11,12 +11,11 @@ let env: helpers.TestEnv; let props: Props; let menuInfo: MenuInfo; -beforeEach(async () => { +beforeEach(() => { fixture = helpers.makeTestFixture(); - const data = await helpers.makeTestData(); - env = helpers.makeTestEnv(data); + env = helpers.makeTestEnv(); props = { inHome: false, app: null }; - menuInfo = helpers.makeMenuInfo(); + menuInfo = env.store.menuInfo; }); afterEach(() => { diff --git a/web/static/tests/ui/notification.test.ts b/web/static/tests/ui/notification.test.ts index dca28587..5152e0a7 100644 --- a/web/static/tests/ui/notification.test.ts +++ b/web/static/tests/ui/notification.test.ts @@ -11,8 +11,7 @@ let env: helpers.TestEnv; beforeEach(async () => { fixture = helpers.makeTestFixture(); - const data = await helpers.makeTestData(); - env = helpers.makeTestEnv(data); + env = helpers.makeTestEnv(); }); afterEach(() => { diff --git a/web/static/tests/ui/root.test.ts b/web/static/tests/ui/root.test.ts index e1e03eba..6e2cb525 100644 --- a/web/static/tests/ui/root.test.ts +++ b/web/static/tests/ui/root.test.ts @@ -1,7 +1,7 @@ +import { Registry } from "../../src/ts/core/registry"; import { Root } from "../../src/ts/ui/root"; import * as helpers from "../helpers"; -import { makeTestData, makeTestEnv } from "../helpers"; -import { Registry } from "../../src/ts/core/registry"; +import { makeTestEnv } from "../helpers"; //------------------------------------------------------------------------------ // Setup and helpers @@ -22,17 +22,15 @@ afterEach(() => { //------------------------------------------------------------------------------ test("can be rendered (in home menu)", async () => { - const data = await makeTestData(); - const testEnv = makeTestEnv(data); + const testEnv = makeTestEnv(); const root = new Root(testEnv, testEnv.store); await root.mount(fixture); expect(fixture.innerHTML).toMatchSnapshot(); }); test("if url has action_id, will render action and navigate to proper menu_id", async () => { - const data = await makeTestData(); const router = new helpers.MockRouter({ action_id: "131" }); - const testEnv = makeTestEnv({ ...data, router }); + const testEnv = makeTestEnv({ services: { router } }); await helpers.nextTick(); const root = new Root(testEnv, testEnv.store); @@ -46,8 +44,7 @@ test("if url has action_id, will render action and navigate to proper menu_id", }); test("start with no action => clicks on client action => discuss is rendered", async () => { - const data = await makeTestData(); - const testEnv = makeTestEnv(data); + const testEnv = makeTestEnv(); const root = new Root(testEnv, testEnv.store); await root.mount(fixture); @@ -64,9 +61,7 @@ test("start with no action => clicks on client action => discuss is rendered", a }); test("clicks on client action with invalid key => empty widget is rendered + warning", async () => { - const data = await makeTestData(); - data.actionRegistry = new Registry(); - const testEnv = makeTestEnv(data); + const testEnv = makeTestEnv({ actionRegistry: new Registry() }); const root = new Root(testEnv, testEnv.store); await root.mount(fixture); @@ -78,9 +73,7 @@ test("clicks on client action with invalid key => empty widget is rendered + war }); test("open act window action with invalid viewtype => empty widget is rendered + warning", async () => { - const data = await makeTestData(); - data.viewRegistry = new Registry(); - const testEnv = makeTestEnv(data); + const testEnv = makeTestEnv({ viewRegistry: new Registry() }); const root = new Root(testEnv, testEnv.store); await root.mount(fixture);