diff options
| author | Xavier Dubuc <xdu@odoo.com> | 2020-09-04 16:08:57 +0000 |
|---|---|---|
| committer | Xavier Dubuc <xdu@odoo.com> | 2020-09-18 07:27:33 +0000 |
| commit | ca457e990c87cd0405a2b7416a6c8064a9a83e21 (patch) | |
| tree | 4994ce07b35be4c88d69ce06638b3e8e45a21816 /addons/mail/static/src/components/thread_view/thread_view_tests.js | |
| parent | 6e83898e17d4aac93ce11b20d589b5a637eb6a8c (diff) | |
[FIX] mail: fix notification partners display in popover
Handle notification creation in convertData correctly.
task-2324260
closes odoo/odoo#57970
X-original-commit: 7305bcf4edcbaa31b86bdc7b4ece460f30515c27
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/components/thread_view/thread_view_tests.js')
| -rw-r--r-- | addons/mail/static/src/components/thread_view/thread_view_tests.js | 226 |
1 files changed, 225 insertions, 1 deletions
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 3a141e751ec..d93f911e04a 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 @@ -46,9 +46,10 @@ QUnit.module('thread_view_tests.js', { }; this.start = async params => { - const { env, widget } = await start(Object.assign({}, params, { + const { afterEvent, env, widget } = await start(Object.assign({}, params, { data: this.data, })); + this.afterEvent = afterEvent; this.env = env; this.widget = widget; }; @@ -566,6 +567,229 @@ QUnit.test('new messages separator on receiving new message', async function (as ); }); +QUnit.test('new messages separator on posting message', async function (assert) { + assert.expect(4); + + this.data['mail.channel'].records = [{ + channel_type: 'channel', + id: 20, + is_pinned: true, + message_unread_counter: 0, + name: "General", + }]; + await this.start(); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel' + }); + const threadViewer = this.env.models['mail.thread_viewer'].create({ + hasThreadView: true, + thread: [['link', thread]], + }); + await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true }); + + assert.containsNone( + document.body, + '.o_MessageList_message', + "should have no messages" + ); + assert.containsNone( + document.body, + '.o_MessageList_separatorNewMessages', + "should not display 'new messages' separator" + ); + + document.querySelector('.o_ComposerTextInput_textarea').focus(); + await afterNextRender(() => document.execCommand('insertText', false, "hey !")); + await afterNextRender(() => + document.querySelector('.o_Composer_buttonSend').click() + ); + assert.containsOnce( + document.body, + '.o_Message', + "should have the message current partner just posted" + ); + assert.containsNone( + document.body, + '.o_MessageList_separatorNewMessages', + "still no separator shown when current partner posted a message" + ); +}); + +QUnit.test('new messages separator on receiving new message', async function (assert) { + assert.expect(6); + + this.data['res.partner'].records.push({ + id:11, + name: "Foreigner partner", + }); + this.data['res.users'].records.push({ + id: 42, + name: "Foreigner user", + partner_id: 11, + }); + this.data['mail.channel'].records.push({ + channel_type: 'channel', + id: 20, + is_pinned: true, + message_unread_counter: 0, + name: "General", + seen_message_id: 1, + uuid: 'randomuuid', + }); + this.data['mail.message'].records.push({ + body: "blah", + channel_ids: [20], + id: 1, + }); + await this.start(); + const thread = this.env.models['mail.thread'].findFromIdentifyingData({ + id: 20, + model: 'mail.channel' + }); + const threadViewer = this.env.models['mail.thread_viewer'].create({ + hasThreadView: true, + thread: [['link', thread]], + }); + await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true }); + + assert.containsOnce( + document.body, + '.o_MessageList_message', + "should have an initial message" + ); + assert.containsNone( + document.body, + '.o_MessageList_separatorNewMessages', + "should not display 'new messages' separator" + ); + + document.querySelector('.o_ComposerTextInput_textarea').blur(); + // simulate receiving a message + await afterNextRender(async () => this.env.services.rpc({ + route: '/mail/chat_post', + params: { + context: { + mockedUserId: 42, + }, + uuid: thread.uuid, + message_content: "hu", + }, + })); + assert.containsN( + document.body, + '.o_Message', + 2, + "should now have 2 messages after receiving a new message" + ); + assert.containsOnce( + document.body, + '.o_MessageList_separatorNewMessages', + "'new messages' separator should be shown" + ); + + assert.containsOnce( + document.body, + `.o_MessageList_separatorNewMessages ~ .o_Message[data-message-local-id="${ + this.env.models['mail.message'].findFromIdentifyingData({id: 2}).localId + }"]`, + "'new messages' separator should be shown above new message received" + ); + + await afterNextRender(() => document.querySelector('.o_ComposerTextInput_textarea').focus()); + assert.containsNone( + document.body, + '.o_MessageList_separatorNewMessages', + "'new messages' separator should no longer be shown as last message has been seen" + ); +}); + +QUnit.test('basic rendering of canceled notification', async function (assert) { + assert.expect(8); + + this.data['mail.channel'].records.push({ id: 11 }); + this.data['res.partner'].records.push({ id: 12, name: "Someone" }); + this.data['mail.message'].records.push({ + channel_ids: [11], + id: 10, + message_type: 'email', + model: 'mail.channel', + notification_ids: [11], + res_id: 11, + }); + this.data['mail.notification'].records.push({ + failure_type: 'SMTP', + id: 11, + mail_message_id: 10, + notification_status: 'canceled', + notification_type: 'email', + res_partner_id: 12, + }); + await this.start(); + const threadViewer = await this.env.models['mail.thread_viewer'].create({ + hasThreadView: true, + thread: [['insert', { + id: 11, + model: 'mail.channel', + }]], + }); + await this.afterEvent({ + eventName: 'o-component-message-list-thread-cache-changed', + func: () => { + this.createThreadViewComponent(threadViewer.threadView); + }, + message: "thread become loaded with messages", + predicate: ({ threadViewer }) => { + return threadViewer.thread.model === 'mail.channel' && threadViewer.thread.id === 11; + }, + }); + + assert.containsOnce( + document.body, + '.o_Message_notificationIconClickable', + "should display the notification icon container on the message" + ); + assert.containsOnce( + document.body, + '.o_Message_notificationIcon', + "should display the notification icon on the message" + ); + assert.hasClass( + document.querySelector('.o_Message_notificationIcon'), + 'fa-envelope-o', + "notification icon shown on the message should represent email" + ); + + await afterNextRender(() => { + document.querySelector('.o_Message_notificationIconClickable').click(); + }); + assert.containsOnce( + document.body, + '.o_NotificationPopover', + "notification popover should be opened after notification has been clicked" + ); + assert.containsOnce( + document.body, + '.o_NotificationPopover_notificationIcon', + "an icon should be shown in notification popover" + ); + assert.containsOnce( + document.body, + '.o_NotificationPopover_notificationIcon.fa.fa-trash-o', + "the icon shown in notification popover should be the canceled icon" + ); + assert.containsOnce( + document.body, + '.o_NotificationPopover_notificationPartnerName', + "partner name should be shown in notification popover" + ); + assert.strictEqual( + document.querySelector('.o_NotificationPopover_notificationPartnerName').textContent.trim(), + "Someone", + "partner name shown in notification popover should be the one concerned by the notification" + ); +}); + }); }); }); |
