diff options
| author | Alexandre Kühn <aku@odoo.com> | 2019-06-13 13:53:01 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2019-07-16 14:36:44 +0000 |
| commit | bdf45dca506f9938bfcd3a7acc8757a16d701d05 (patch) | |
| tree | dbe074599045aef04eb18935eef2859d555a14c5 /addons/mail/static/tests/thread_window | |
| parent | 4bde721f925bfe3d1e867565490d3830da150dcc (diff) | |
[FIX] mail: auto-update out-of-office info on im_status change
Before this commit, chat window's out-of-office info did not change
when direct partner's `im_status` is/was on 'leave'.
Users had to reload page to see updated out-of-office info.
Task-ID 2007663
Diffstat (limited to 'addons/mail/static/tests/thread_window')
| -rw-r--r-- | addons/mail/static/tests/thread_window/basic_thread_window_tests.js | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js index 5a0bc62f880..0445c344649 100644 --- a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js +++ b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js @@ -695,6 +695,119 @@ QUnit.test('no out-of-office status in thread window', function (assert) { parent.destroy(); }); +QUnit.test('auto-update out-of-office info on im_status change', function (assert) { + var done = assert.async(); + assert.expect(5); + + var imStatusDefs = [$.Deferred(), $.Deferred()]; + var channelInfoDefs = [$.Deferred(), $.Deferred()]; + var timeoutMock = mailTestUtils.patchMailTimeouts(); + var step = 0; + + this.data = { + 'mail.message': { + fields: {}, + records: [], + }, + initMessaging: { + channel_slots: { + channel_channel: [{ + id: 1, + name: "DM", + channel_type: "chat", + message_unread_counter: 0, + direct_partner: [{ + id: 666, + name: 'DemoUser1', + im_status: 'online', + }], + }], + }, + }, + }; + + var parent = this.createParent({ + data: this.data, + services: this.services, + mockRPC: function (route, args) { + if (route === '/longpolling/im_status') { + step++; + if (step === 1) { + imStatusDefs[0].resolve(); + return $.when([ + { + id: 666, + im_status: 'leave', + }, + ]); + } else if (step === 2) { + imStatusDefs[1].resolve(); + return $.when([ + { + id: 666, + im_status: 'online', + }, + ]); + } + } + if (args.method === 'channel_info') { + if (step === 1) { + channelInfoDefs[0].resolve(); + return $.when([{ + id: 1, + direct_partner: [{ + out_of_office_message: "Leave me alone", + out_of_office_date_end: false, + }], + }]); + } + else if (step === 2) { + channelInfoDefs[1].resolve(); + return $.when([{ + id: 1, + direct_partner: [{ + out_of_office_message: false, + out_of_office_date_end: false, + }], + }]); + } + } + return this._super.apply(this, arguments); + }, + }); + + // detach channel 1, so that it opens corresponding thread window. + parent.call('mail_service', 'getChannel', 1).detach(); + + assert.containsNone($, '.o_out_of_office', + "should contain no out of office section on chat window initially"); + + timeoutMock.addTime(51*1000); // wait for next im status fetch + + $.when(imStatusDefs[0], channelInfoDefs[0]).then(function () { + assert.containsOnce($, '.o_out_of_office', + "should contain out of office section on chat window"); + assert.containsOnce($, '.o_out_of_office > .o_out_of_office_text', + "should contain out of office text on chat window"); + assert.ok( + $('.o_out_of_office > .o_out_of_office_text') + .text() + .replace(/\s/g, "") + .indexOf("Leavemealone") !== -1, + "should contain out of office text on chat window"); + timeoutMock.addTime(51*1000); // wait for next im status fetch + + $.when(imStatusDefs[1], channelInfoDefs[1]).then(function () { + assert.containsNone($, '.o_out_of_office', + "should no longer contain out of office section on chat window"); + + timeoutMock.runPendingTimeouts(); + parent.destroy(); + done(); + }); + }); +}); + }); }); }); |
