diff options
| author | Xavier Dubuc <xdu@odoo.com> | 2020-10-02 09:42:58 +0000 |
|---|---|---|
| committer | Xavier Dubuc <xdu@odoo.com> | 2020-10-06 13:06:04 +0000 |
| commit | 9dbec7af98d5fe547b76d0cb7bc11348b60a5285 (patch) | |
| tree | 1e0a44dc1fe91ee019c95b4727448308c698399f /addons/mail | |
| parent | bafb2dfa54ab2e06e1c56fdadf918139e62eaa91 (diff) | |
[IMP] mail: test new message separator in some edge cases
task-2348620
closes odoo/odoo#59279
X-original-commit: 53ed641a60e6d572a12d96406b64af5b55fe177e
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail')
3 files changed, 135 insertions, 9 deletions
diff --git a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js index d29730626b0..1a261265dc7 100644 --- a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js +++ b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js @@ -1868,6 +1868,116 @@ QUnit.test('chat window does not fetch messages if hidden', async function (asse ); }); +QUnit.test('new message separator is shown in a chat window of a chat on receiving new message', async function (assert) { + assert.expect(6); + + this.data['res.partner'].records.push({ id: 10, name: "Demo" }); + this.data['res.users'].records.push({ + id: 42, + name: "Foreigner user", + partner_id: 10, + }); + this.data['mail.channel'].records = [ + { + id: 10, + channel_type: "chat", + is_minimized: true, + is_pinned: false, + members: [this.data.currentPartnerId, 10], + message_unread_counter: 0, + uuid: 'channel-10-uuid', + }, + ]; + await this.start({ + mockRPC(route, args) { + if (args.method === 'channel_fold') { + const channel_uuid = args.kwargs.uuid; + assert.strictEqual(channel_uuid, 'channel-10-uuid', "chat window fold state should have been sent to server"); + assert.step(`rpc:channel_fold:${channel_uuid}`); + } + return this._super(...arguments); + }, + }); + + // simulate receiving a message + await afterNextRender(async () => this.env.services.rpc({ + route: '/mail/chat_post', + params: { + context: { + mockedUserId: 42, + }, + uuid: 'channel-10-uuid', + message_content: "hu", + }, + })); + assert.containsOnce( + document.body, + '.o_ChatWindow', + "a chat window should be visible after receiving a new message from a chat" + ); + assert.containsOnce( + document.body, + '.o_Message', + "chat window should have a single message (the newly received one)" + ); + assert.containsOnce( + document.body, + '.o_MessageList_separatorNewMessages', + "should display 'new messages' separator in the conversation, from reception of new messages" + ); + assert.verifySteps( + ['rpc:channel_fold:channel-10-uuid'], + "fold state of chat window of chat should have been updated to server" + ); +}); + +QUnit.test('focusing a chat window of a chat should make new message separator disappear [REQUIRE FOCUS]', async function (assert) { + assert.expect(2); + + this.data['res.partner'].records.push({ id: 10, name: "Demo" }); + this.data['res.users'].records.push({ + id: 42, + name: "Foreigner user", + partner_id: 10, + }); + this.data['mail.channel'].records = [ + { + id: 10, + channel_type: "chat", + is_minimized: true, + is_pinned: false, + members: [this.data.currentPartnerId, 10], + message_unread_counter: 0, + uuid: 'channel-10-uuid', + }, + ]; + await this.start(); + + // simulate receiving a message + await afterNextRender(async () => this.env.services.rpc({ + route: '/mail/chat_post', + params: { + context: { + mockedUserId: 42, + }, + uuid: 'channel-10-uuid', + message_content: "hu", + }, + })); + assert.containsOnce( + document.body, + '.o_MessageList_separatorNewMessages', + "should display 'new messages' separator in the conversation, from reception of new messages" + ); + + await afterNextRender(() => document.querySelector('.o_ComposerTextInput_textarea').focus()); + assert.containsNone( + document.body, + '.o_MessageList_separatorNewMessages', + "new message separator should no longer be shown, after focus on composer text input of chat window" + ); +}); + }); }); }); diff --git a/addons/mail/static/src/components/thread_view/thread_view_tests.js b/addons/mail/static/src/components/thread_view/thread_view_tests.js index 9dc5145c121..320512a0f8c 100644 --- a/addons/mail/static/src/components/thread_view/thread_view_tests.js +++ b/addons/mail/static/src/components/thread_view/thread_view_tests.js @@ -426,7 +426,8 @@ QUnit.test('show message subject if thread is mailing channel', async function ( ); }); -QUnit.test('new messages separator on posting message', async function (assert) { +QUnit.test('[technical] new messages separator on posting message', async function (assert) { + // technical as we need to remove focus from text input to avoid `channel_seen` call assert.expect(4); this.data['mail.channel'].records = [{ @@ -434,8 +435,14 @@ QUnit.test('new messages separator on posting message', async function (assert) id: 20, is_pinned: true, message_unread_counter: 0, + seen_message_id: 10, name: "General", }]; + this.data['mail.message'].records.push({ + body: "first message", + channel_ids: [20], + id: 10, + }); await this.start(); const thread = this.env.models['mail.thread'].findFromIdentifyingData({ id: 20, @@ -447,10 +454,10 @@ QUnit.test('new messages separator on posting message', async function (assert) }); await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true }); - assert.containsNone( + assert.containsOnce( document.body, - '.o_MessageList_message', - "should have no messages" + '.o_Message', + "should display one message in thread initially" ); assert.containsNone( document.body, @@ -460,13 +467,17 @@ QUnit.test('new messages separator on posting message', async function (assert) document.querySelector('.o_ComposerTextInput_textarea').focus(); await afterNextRender(() => document.execCommand('insertText', false, "hey !")); - await afterNextRender(() => - document.querySelector('.o_Composer_buttonSend').click() - ); - assert.containsOnce( + await afterNextRender(() => { + // need to remove focus from text area to avoid channel_seen + document.querySelector('.o_Composer_buttonSend').focus(); + document.querySelector('.o_Composer_buttonSend').click(); + + }); + assert.containsN( document.body, '.o_Message', - "should have the message current partner just posted" + 2, + "should display 2 messages (initial & newly posted), after posting a message" ); assert.containsNone( document.body, diff --git a/addons/mail/static/tests/helpers/mock_server.js b/addons/mail/static/tests/helpers/mock_server.js index 2961b2ea311..e2daa7c38d9 100644 --- a/addons/mail/static/tests/helpers/mock_server.js +++ b/addons/mail/static/tests/helpers/mock_server.js @@ -959,6 +959,11 @@ MockServer.include({ ); if (kwargs.author_id === this.currentPartnerId) { this._mockMailChannel_SetLastSeenMessage([channel.id], messageId); + } else { + this._mockWrite('mail.channel', [ + [channel.id], + { message_unread_counter: (channel.message_unread_counter || 0) + 1 }, + ]) } return messageId; }, |
