From f61b4669a9607c3cb800d5ec33ab0001086f2d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 29 Jan 2020 16:26:28 +0000 Subject: [FIX] mail: no traceback on click channel mention from chat window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when clicking on a channel mention from a chat window, it crashed with the following error: `TypeError: channel.detach is not a function` This happens due to `MailService.joinChannel()` returning a promise that is resolved with channel ID, instead of a channel object. `channel.detach()` becomes `.detach()`, which is treated like `undefined()`, hence crash. closes odoo/odoo#44329 X-original-commit: 710fda06c3b30ff2267fcc1d123f15ce031b6f3a Signed-off-by: Alexandre Kühn (aku) --- .../thread_window/basic_thread_window_tests.js | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'addons/mail/static/tests/thread_window/basic_thread_window_tests.js') 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 3dc8ac0336d..597e197ca9d 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 @@ -903,6 +903,92 @@ QUnit.test('non-deletable message attachments', async function (assert) { parent.destroy(); }); +QUnit.test('join channel from click channel mention', async function (assert) { + assert.expect(10); + + this.data['mail.channel'].records = [{ + id: 2, + name: "R&D Tasks", + channel_type: "channel", + }]; + this.data['mail.message'].records.push({ + author_id: [5, "Someone else"], + body: `

#R&D Tasks

`, + id: 10, + res_id: 1, + channel_ids: [1], + }); + + const parent = this.createParent({ + data: this.data, + services: this.services, + session: { partner_id: 3 }, + async mockRPC(route, args) { + if (args.method === 'channel_join_and_get_info') { + const channelID = args.args[0][0]; + assert.step(`channel_join_and_get_info:${channelID}`); + return this.data['mail.channel'].records.find(channel => channel.id === channelID); + } + return this._super(...arguments); + }, + }); + await testUtils.nextTick(); + assert.containsNone( + $, + '.o_thread_window', + "no thread window should be open initially" + ); + + // get channel instance to link to thread window + const channel = parent.call('mail_service', 'getChannel', 1); + channel.detach(); + await testUtils.nextTick(); + assert.containsOnce( + $, + '.o_thread_window', + "should have one thread open in chat window" + ); + assert.strictEqual( + $('.o_thread_window .o_thread_window_title').text().trim(), + "#general", + "should have thread '#general' as open in chat window" + ); + assert.containsOnce( + $, + '.o_thread_window .o_thread_message', + "should contain a single message in chat window" + ); + assert.containsOnce( + $, + '.o_thread_window .o_thread_message a.o_mail_redirect', + "message should have a mention" + ); + assert.containsOnce( + $, + '.o_thread_window .o_thread_message a.o_mail_redirect[data-oe-id="2"][data-oe-model="mail.channel"]', + "message should have a channel mention to R&D Task" + ); + + await testUtils.dom.click($('.o_thread_window .o_thread_message a.o_mail_redirect[data-oe-id="2"][data-oe-model="mail.channel"]')); + assert.verifySteps( + ['channel_join_and_get_info:2'], + "should have joined channel #R&D Task" + ); + assert.containsN( + $, + '.o_thread_window', + 2, + "should now have 2 threads open in chat windows after cliking on channel mention" + ); + assert.strictEqual( + $('.o_thread_window .o_thread_window_title').text().replace(/\s/g, ""), + "#general#R&DTasks", + "should have threads '#general' and '#R&D Tasks' as open in chat windows" + ); + + parent.destroy(); +}); + }); }); }); -- cgit v1.2.3