summaryrefslogtreecommitdiff
path: root/addons/mail/static/tests/thread_window/basic_thread_window_tests.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2020-01-29 16:26:28 +0000
committerAlexandre Kühn <aku@odoo.com>2020-01-30 15:23:02 +0000
commitf61b4669a9607c3cb800d5ec33ab0001086f2d97 (patch)
treead12b67b70f4ee1f86ada4c7c582184afcb6f211 /addons/mail/static/tests/thread_window/basic_thread_window_tests.js
parentcd70571d84eefd38084bd599dfbdd46bde391074 (diff)
[FIX] mail: no traceback on click channel mention from chat window
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 `<Number>.detach()`, which is treated like `undefined()`, hence crash. closes odoo/odoo#44329 X-original-commit: 710fda06c3b30ff2267fcc1d123f15ce031b6f3a Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/tests/thread_window/basic_thread_window_tests.js')
-rw-r--r--addons/mail/static/tests/thread_window/basic_thread_window_tests.js86
1 files changed, 86 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 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: `<p><a href="#" class="o_mail_redirect" data-oe-id="2" data-oe-model="mail.channel">#R&D Tasks</a></p>`,
+ 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();
+});
+
});
});
});