diff options
| author | Julien Giannone <jgi@odoo.com> | 2020-10-07 14:01:14 +0000 |
|---|---|---|
| committer | Julien Giannone <jgi@odoo.com> | 2020-11-23 07:39:26 +0000 |
| commit | 884bebb0f549dc4385cec9542f74e0bba64ccb08 (patch) | |
| tree | d972bce16bbf7a255be0a963974294bb048b9cad /addons/mail/static/src/components | |
| parent | 87ea687169c9a0047b41b11ab143544142c82aae (diff) | |
[FIX] mail: Sidebar channel find shows all channels
When searching for a channel in Discuss, the search results include
all matching channels even those user is already member of
task-2347837
closes odoo/odoo#60063
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/components')
| -rw-r--r-- | addons/mail/static/src/components/composer_suggestion/composer_suggestion_channel_tests.js | 2 | ||||
| -rw-r--r-- | addons/mail/static/src/components/discuss/tests/discuss_sidebar_tests.js | 145 |
2 files changed, 146 insertions, 1 deletions
diff --git a/addons/mail/static/src/components/composer_suggestion/composer_suggestion_channel_tests.js b/addons/mail/static/src/components/composer_suggestion/composer_suggestion_channel_tests.js index 047fc997b49..7a211483e59 100644 --- a/addons/mail/static/src/components/composer_suggestion/composer_suggestion_channel_tests.js +++ b/addons/mail/static/src/components/composer_suggestion/composer_suggestion_channel_tests.js @@ -104,7 +104,7 @@ QUnit.test('channel mention suggestion correct data', async function (assert) { ); }); -QUnit.test('partner mention suggestion active', async function (assert) { +QUnit.test('channel mention suggestion active', async function (assert) { assert.expect(2); this.data['mail.channel'].records.push({ id: 20 }); diff --git a/addons/mail/static/src/components/discuss/tests/discuss_sidebar_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_sidebar_tests.js new file mode 100644 index 00000000000..23d74c5cbe3 --- /dev/null +++ b/addons/mail/static/src/components/discuss/tests/discuss_sidebar_tests.js @@ -0,0 +1,145 @@ +odoo.define('mail/static/src/components/discuss/tests/discuss_sidebar_tests.js', function (require) { +'use strict'; + +const { makeDeferred } = require('mail/static/src/utils/deferred/deferred.js'); +const { + afterEach, + afterNextRender, + beforeEach, + nextAnimationFrame, + start, +} = require('mail/static/src/utils/test_utils.js'); + +QUnit.module('mail', {}, function () { +QUnit.module('components', {}, function () { +QUnit.module('discuss', {}, function () { +QUnit.module('discuss_sidebar_tests.js', { + beforeEach() { + beforeEach(this); + + this.start = async params => { + const { env, widget } = await start(Object.assign({}, params, { + autoOpenDiscuss: true, + data: this.data, + hasDiscuss: true, + })); + this.env = env; + this.widget = widget; + }; + }, + afterEach() { + afterEach(this); + }, +}); + +QUnit.test('sidebar find shows channels matching search term', async function (assert) { + assert.expect(3); + + this.data['mail.channel'].records.push({ + channel_partner_ids: [], + channel_type: 'channel', + id: 20, + members: [], + name: 'test', + public: 'public', + }); + const searchReadDef = makeDeferred(); + await this.start({ + async mockRPC(route, args) { + const res = await this._super(...arguments); + if (args.method === 'search_read') { + searchReadDef.resolve(); + } + return res; + }, + }); + await afterNextRender(() => + document.querySelector(`.o_DiscussSidebar_groupHeaderItemAdd`).click() + ); + document.querySelector(`.o_DiscussSidebar_itemNew`).focus(); + document.execCommand('insertText', false, "test"); + document.querySelector(`.o_DiscussSidebar_itemNew`) + .dispatchEvent(new window.KeyboardEvent('keydown')); + document.querySelector(`.o_DiscussSidebar_itemNew`) + .dispatchEvent(new window.KeyboardEvent('keyup')); + + await searchReadDef; + await nextAnimationFrame(); // ensures search_read rpc is rendered. + const results = document.querySelectorAll('.ui-autocomplete .ui-menu-item a'); + assert.ok( + results, + "should have autocomplete suggestion after typing on 'find or create channel' input" + ); + assert.strictEqual( + results.length, + // When searching for a single existing channel, the results list will have at least 3 lines: + // One for the existing channel itself + // One for creating a public channel with the search term + // One for creating a private channel with the search term + 3 + ); + assert.strictEqual( + results[0].textContent, + "test", + "autocomplete suggestion should target the channel matching search term" + ); +}); + +QUnit.test('sidebar find shows channels matching search term even when user is member', async function (assert) { + assert.expect(3); + + this.data['mail.channel'].records.push({ + channel_partner_ids: [this.data.currentPartnerId], + channel_type: 'channel', + id: 20, + members: [this.data.currentPartnerId], + name: 'test', + public: 'public', + }); + const searchReadDef = makeDeferred(); + await this.start({ + async mockRPC(route, args) { + const res = await this._super(...arguments); + if (args.method === 'search_read') { + searchReadDef.resolve(); + } + return res; + }, + }); + await afterNextRender(() => + document.querySelector(`.o_DiscussSidebar_groupHeaderItemAdd`).click() + ); + document.querySelector(`.o_DiscussSidebar_itemNew`).focus(); + document.execCommand('insertText', false, "test"); + document.querySelector(`.o_DiscussSidebar_itemNew`) + .dispatchEvent(new window.KeyboardEvent('keydown')); + document.querySelector(`.o_DiscussSidebar_itemNew`) + .dispatchEvent(new window.KeyboardEvent('keyup')); + + await searchReadDef; + await nextAnimationFrame(); + const results = document.querySelectorAll('.ui-autocomplete .ui-menu-item a'); + assert.ok( + results, + "should have autocomplete suggestion after typing on 'find or create channel' input" + ); + assert.strictEqual( + results.length, + // When searching for a single existing channel, the results list will have at least 3 lines: + // One for the existing channel itself + // One for creating a public channel with the search term + // One for creating a private channel with the search term + 3 + ); + assert.strictEqual( + results[0].textContent, + "test", + "autocomplete suggestion should target the channel matching search term even if user is member" + ); +}); + +}); +}); +}); + +}); |
