[FIX] mail: check not broken @ mention in discuss
Rev. on this commit: https://github.com/odoo/odoo/commit/02ec09cb1c3e2d7bc7968f40c18f2208d7f3f498 A consequence of the above commit is that @ mention were broken: the dropup menu with partner propositions was not displaying when the user typed the first characters to mention a user (e.g. by typing "[at]demo" in order to show the proposed mention "[at]Demo User" in a dropup menu). This commit fixes the issue by reverting the logic of how mentions are provided by the chat_manager, while removing some dead code. note: [at] = @
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user