[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).
This commit is contained in:
Alexandre Kühn
2018-02-20 13:31:23 +01:00
parent 275910e38c
commit 22f04b4023
2 changed files with 22 additions and 2 deletions
@@ -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
+2
View File
@@ -54,6 +54,8 @@
<template id="qunit_mobile_suite" name="mail_mobile_tests" inherit_id="web.qunit_mobile_suite">
<xpath expr="//t[@t-set='head']" position="inside">
<script type="text/javascript" src="/mail/static/tests/discuss_mobile_tests.js"></script>
<script type="text/javascript" src="/mail/static/tests/helpers/mock_server.js"></script>
<script type="text/javascript" src="/mail/static/tests/helpers/test_utils.js"></script>
</xpath>
</template>