From 22f04b4023038e72fe74ff6d19c7ea4068c532cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 14 Feb 2018 14:47:03 +0100 Subject: [PATCH] [FIX] mail: tests: improved mock_server mocked initMessaging Before this commit, if we wanted to add channels on rpc initMessaging, we had to mock this rpc completely. Now, with this commit, we can use data 'initMessaging', whose keys can overwrite the default mocked initMessaging. For instance, if this.data.initMessaging has the key 'channel_slots', then the mocked initMessaging rpc will return a new state for the existing channels to the chat_manager. This is needed in order to reduce the size of tests than need some custom initMessaging state, such as any test that needs at least one non-static channel (i.e. neither channel_inbox nor channel_starred). --- .../mail/static/tests/helpers/mock_server.js | 22 +++++++++++++++++-- addons/mail/views/mail_templates.xml | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/tests/helpers/mock_server.js b/addons/mail/static/tests/helpers/mock_server.js index f0c09386a5a..a2aef300736 100644 --- a/addons/mail/static/tests/helpers/mock_server.js +++ b/addons/mail/static/tests/helpers/mock_server.js @@ -4,6 +4,24 @@ odoo.define('mail.MockServer', function (require) { var MockServer = require('web.MockServer'); MockServer.include({ + /** + * Param 'data' may have a key 'initMessaging' which contains + * a partial overwrite of the result from mockInitMessaging. + * + * Note: we must delete this key, so that this is not + * handled as a model definition. + * + * @override + * @param {Object} [data.initMessaging] + */ + init: function (data, options) { + if (data && data.initMessaging) { + this.initMessagingData = data.initMessaging; + delete data.initMessaging; + } + this._super.apply(this, arguments); + }, + /** * Simulate the '/mail/init_messaging' route * @@ -11,7 +29,7 @@ MockServer.include({ * @return {Object} */ _mockInitMessaging: function () { - return { + return _.defaults(this.initMessagingData || {}, { 'needaction_inbox_counter': 0, 'starred_counter': 0, 'channel_slots': [], @@ -19,7 +37,7 @@ MockServer.include({ 'mention_partner_suggestions': [], 'shortcodes': [], 'menu_id': false, - }; + }); }, /** * @override diff --git a/addons/mail/views/mail_templates.xml b/addons/mail/views/mail_templates.xml index 28d92c9e157..6769462d404 100644 --- a/addons/mail/views/mail_templates.xml +++ b/addons/mail/views/mail_templates.xml @@ -54,6 +54,8 @@