From 9dffcf4cf6db493a4ec69e7a4eeff41cb075656d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 6 Mar 2019 09:56:39 +0100 Subject: [PATCH] display empty action when invalid tag for client action --- .../src/ts/store/action_manager_mixin.ts | 8 ++--- web/static/src/ts/ui/root.ts | 4 +-- .../tests/ui/__snapshots__/root.test.ts.snap | 34 +++++++++++++++++++ web/static/tests/ui/root.test.ts | 15 ++++++++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/web/static/src/ts/store/action_manager_mixin.ts b/web/static/src/ts/store/action_manager_mixin.ts index 2a140383..f0622e1b 100644 --- a/web/static/src/ts/store/action_manager_mixin.ts +++ b/web/static/src/ts/store/action_manager_mixin.ts @@ -117,17 +117,17 @@ export function actionManagerMixin>( descr: ClientActionDescription ): Action["executor"] | undefined { let key = descr.tag; - let Widget = this.actionRegistry.get(key); - if (!Widget) { + let ActionWidget = this.actionRegistry.get(key); + if (!ActionWidget) { this.addNotification({ title: "Invalid Client Action", type: "warning", message: `Cannot find widget '${key}' in the action registry` }); - return; + ActionWidget = Widget; } return async function executor(this: Action, parent: Widget) { - const widget = new Widget!(parent, {}); + const widget = new ActionWidget!(parent, {}); const div = document.createElement("div"); await widget.mount(div); this.widget = widget; diff --git a/web/static/src/ts/ui/root.ts b/web/static/src/ts/ui/root.ts index 21e46863..c6e40708 100644 --- a/web/static/src/ts/ui/root.ts +++ b/web/static/src/ts/ui/root.ts @@ -24,9 +24,7 @@ export class Root extends Widget { } mounted() { - this.store.on("state_updated", this, newState => { - this.updateState(newState); - }); + this.store.on("state_updated", this, this.updateState); // loading indicator this.store.on("rpc_status", this, status => { diff --git a/web/static/tests/ui/__snapshots__/root.test.ts.snap b/web/static/tests/ui/__snapshots__/root.test.ts.snap index 7c048591..397ef6de 100644 --- a/web/static/tests/ui/__snapshots__/root.test.ts.snap +++ b/web/static/tests/ui/__snapshots__/root.test.ts.snap @@ -34,6 +34,40 @@ exports[`can be rendered (in home menu) 1`] = ` " `; +exports[`clicks on client action with invalid key => empty widget is rendered + warning 1`] = ` +"
+
+ + + + Discuss + +
    + + +
+ +
+ +
+
+ +
+ +
+ + Invalid Client Action +
+
+ Cannot find widget 'mail.discuss' in the action registry +
+
+ +
+
Loading
+
" +`; + exports[`if url has action_id, will render action and navigate to proper menu_id 1`] = ` "
diff --git a/web/static/tests/ui/root.test.ts b/web/static/tests/ui/root.test.ts index e99cf0c9..3fa1872f 100644 --- a/web/static/tests/ui/root.test.ts +++ b/web/static/tests/ui/root.test.ts @@ -1,6 +1,7 @@ import { Root } from "../../src/ts/ui/root"; import * as helpers from "../helpers"; import { makeTestData, makeTestEnv } from "../helpers"; +import { Registry } from "../../src/ts/core/registry"; //------------------------------------------------------------------------------ // Setup and helpers @@ -61,3 +62,17 @@ test("start with no action => clicks on client action => discuss is rendered", a menu_id: "96" }); }); + +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 root = new Root(testEnv, testEnv.store); + await root.mount(fixture); + + // discuss menu item + await (document.querySelector('[data-menu="96"]')).click(); + await helpers.nextTick(); + + expect(fixture.innerHTML).toMatchSnapshot(); +});