summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/mail/static/src/js/services/chat_manager.js10
-rw-r--r--addons/mail/static/tests/discuss_tests.js89
2 files changed, 90 insertions, 9 deletions
diff --git a/addons/mail/static/src/js/services/chat_manager.js b/addons/mail/static/src/js/services/chat_manager.js
index fb4b6672bc6..2655a07b55b 100644
--- a/addons/mail/static/src/js/services/chat_manager.js
+++ b/addons/mail/static/src/js/services/chat_manager.js
@@ -352,7 +352,6 @@ var ChatManager = AbstractService.extend({
* => list containing a list of members (cached by chat_manager)
*/
getMentionPartnerSuggestions: function (channel) {
- var self = this;
if (!channel) {
return this.mentionPartnerSuggestions;
}
@@ -365,14 +364,7 @@ var ChatManager = AbstractService.extend({
shadow: true
})
.then(function (members) {
- var suggestions = [];
- _.each(self.mentionPartnerSuggestions, function (partners) {
- suggestions.push(_.filter(partners, function (partner) {
- return !_.findWhere(members, { id: partner.id });
- }));
- });
-
- return [suggestions];
+ return [members];
});
}
return channel.membersDeferred;
diff --git a/addons/mail/static/tests/discuss_tests.js b/addons/mail/static/tests/discuss_tests.js
index 6c90cf802f7..348a6357b5d 100644
--- a/addons/mail/static/tests/discuss_tests.js
+++ b/addons/mail/static/tests/discuss_tests.js
@@ -2,10 +2,17 @@ odoo.define('mail.discuss_test', function (require) {
"use strict";
var ChatManager = require('mail.ChatManager');
+var Composers = require('mail.composer');
var mailTestUtils = require('mail.testUtils');
+var concurrency = require('web.concurrency');
+var testUtils = require('web.test_utils');
+
+var BasicComposer = Composers.BasicComposer;
var createBusService = mailTestUtils.createBusService;
var createDiscuss = mailTestUtils.createDiscuss;
+var patchWindowGetSelection = testUtils.patchWindowGetSelection;
+var unpatchWindowGetSelection = testUtils.unpatchWindowGetSelection;
QUnit.module('mail', {}, function () {
@@ -55,5 +62,87 @@ QUnit.test('basic rendering', function (assert) {
});
});
+QUnit.test('@ mention in channel', function (assert) {
+ assert.expect(9);
+ var done = assert.async();
+
+ this.data.initMessaging = {
+ channel_slots: {
+ channel_channel: [{
+ id: 1,
+ channel_type: "channel",
+ name: "general",
+ }],
+ },
+ };
+
+ // Remove the mention throttle to speed up the test
+ var mentionThrottle = BasicComposer.prototype.MENTION_THROTTLE;
+ BasicComposer.prototype.MENTION_THROTTLE = 1;
+
+ var fetchListenersDef = $.Deferred();
+
+ createDiscuss({
+ id: 1,
+ context: {},
+ params: {},
+ data: this.data,
+ services: this.services,
+ mockRPC: function (route, args) {
+ if (args.method === 'channel_fetch_listeners') {
+ fetchListenersDef.resolve();
+ return $.when([ { id: 2, name: 'TestUser'} ]);
+ }
+ return this._super.apply(this, arguments);
+ },
+ })
+ .then(function (discuss) {
+ var $general = discuss.$('.o_mail_chat_sidebar')
+ .find('.o_mail_chat_channel_item[data-channel-id=1]');
+ assert.strictEqual($general.length, 1,
+ "should have the channel item with id 1");
+ assert.strictEqual($general.attr('title'), 'general',
+ "should have the title 'general'");
+
+ // click on general
+ $general.click();
+ var $input = discuss.$('.o_composer_input').first();
+ assert.ok($input.length, "should display a composer input");
+
+ // Simulate '@' typed by user with mocked Window.getSelection
+ // Note: focus is needed in order to trigger rpc 'channel_fetch_listeners'
+ $input.focus();
+ $input.text("@");
+ patchWindowGetSelection();
+ $input.trigger('keyup');
+
+ fetchListenersDef
+ .then(concurrency.delay.bind(concurrency, 0))
+ .then(function () {
+ assert.strictEqual(discuss.$('.dropup.o_composer_mention_dropdown.open').length, 1,
+ "dropup menu for partner mentions should be open");
+
+ var $mentionProposition = discuss.$('.o_mention_proposition');
+ assert.strictEqual($mentionProposition.length, 1,
+ "should display one partner mention proposition");
+ assert.strictEqual($mentionProposition.data('id'), 2,
+ "partner mention should link to the correct partner id");
+ assert.strictEqual($mentionProposition.find('.o_mention_name').text(), "TestUser",
+ "partner mention should display the correct partner name");
+
+ $mentionProposition.click();
+ assert.strictEqual(discuss.$('.o_mention_proposition').length, 0,
+ "should not have any partner mention proposition after clicking on it");
+ assert.strictEqual($input.find('a').text() , "@TestUser",
+ "should have the correct mention link in the composer input");
+
+ BasicComposer.prototype.MENTION_THROTTLE = mentionThrottle;
+ unpatchWindowGetSelection();
+ discuss.destroy();
+ done();
+ });
+ });
+});
+
});
});