From 742ac28a4476b01cab0ed7c053bcd79e07595ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Fri, 23 Feb 2018 10:16:30 +0100 Subject: [PATCH] [FIX] web: doAction always resolved with the action Before this commit, doAction returns a deferred that is resolved when the action is performed (the exact moment depends of the type of the action). However, the deferred was not resolved with the action. This is misleading, hence a traceback in the web_client when clicking on 'Run JS Tests' in debug mode (enterprise): after doAction, the web_client should hide the home_menu depending on the type of the action. With this commit, any doAction returns a deferred that is resolved with the performed action. --- .../static/src/js/chrome/action_manager.js | 11 ++++--- .../tests/chrome/action_manager_tests.js | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index 1651e5d72d9..236d7517d04 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -140,9 +140,10 @@ var ActionManager = Widget.extend({ * is useful when we come from a loadState()) * @param {boolean} [options.replace_last_action=false] set to true to * replace last part of the breadcrumbs with the action - * @return {Deferred} resolved when the action is loaded and appended to the - * DOM ; rejected if the action can't be executed (e.g. if doAction has - * been called to execute another action before this one was complete). + * @return {$.Deferred} resolved with the action when the action is + * loaded and appended to the DOM ; rejected if the action can't be + * executed (e.g. if doAction has been called to execute another action + * before this one was complete). */ doAction: function (action, options) { var self = this; @@ -179,7 +180,9 @@ var ActionManager = Widget.extend({ self._preprocessAction(action, options); - return self._handleAction(action, options); + return self._handleAction(action, options).then(function () { + return action; + }); }); }, /** diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 90b3c1bf510..4d682b8994c 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -2525,6 +2525,35 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + + QUnit.test('doAction resolved with an action', function (assert) { + assert.expect(4); + var done = assert.async(); + + this.actions.push({ + id: 21, + name: 'A Close Action', + type: 'ir.actions.act_window_close', + }); + + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + }); + + actionManager.doAction(21).then(function (action) { + assert.ok(action, "doAction should be resolved with an action"); + assert.strictEqual(action.id, 21, + "should be resolved with correct action id"); + assert.strictEqual(action.name, 'A Close Action', + "should be resolved with correct action name"); + assert.strictEqual(action.type, 'ir.actions.act_window_close', + "should be resolved with correct action type"); + actionManager.destroy(); + done(); + }); + }); }); });