diff options
| author | Sébastien Theys <seb@odoo.com> | 2020-09-07 11:06:36 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-09-07 12:28:36 +0000 |
| commit | 0e13ad22267e928a50fdc7d4f045f03b49385aa9 (patch) | |
| tree | 3b7a3684ad2d0c209f911ea47e31c602209fc41b /addons/mail/static/src/components | |
| parent | 3783654b87851bdeb11e32da78bb5b62865b869a (diff) | |
[FIX] mail: allow tests to await specific events
task-2333915
closes odoo/odoo#57185
X-original-commit: 699106ce65a87f7a24f04e1d8f232b5a6b4e210a
Related: odoo/enterprise#13013
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
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/discuss/tests/discuss_tests.js | 157 | ||||
| -rw-r--r-- | addons/mail/static/src/components/message_list/message_list.js | 14 |
2 files changed, 93 insertions, 78 deletions
diff --git a/addons/mail/static/src/components/discuss/tests/discuss_tests.js b/addons/mail/static/src/components/discuss/tests/discuss_tests.js index 87ad3640919..c63ec07520b 100644 --- a/addons/mail/static/src/components/discuss/tests/discuss_tests.js +++ b/addons/mail/static/src/components/discuss/tests/discuss_tests.js @@ -3,7 +3,6 @@ odoo.define('mail/static/src/components/discuss/tests/discuss_tests.js', functio const BusService = require('bus.BusService'); -const { makeDeferred } = require('mail/static/src/utils/deferred/deferred.js'); const { afterEach, afterNextRender, @@ -23,11 +22,12 @@ QUnit.module('discuss_tests.js', { beforeEach(this); this.start = async params => { - const { env, widget } = await start(Object.assign({}, params, { + const { afterEvent, env, widget } = await start(Object.assign({}, params, { autoOpenDiscuss: true, data: this.data, hasDiscuss: true, })); + this.afterEvent = afterEvent; this.env = env; this.widget = widget; }; @@ -1837,29 +1837,19 @@ QUnit.test('restore thread scroll position', async function (assert) { res_id: 12, }); } - const messageFetchChannel11Def = makeDeferred(); - const messageFetchChannel12Def = makeDeferred(); - await afterNextRender(async () => { - await this.start({ - discuss: { - params: { - default_active_id: 'mail.channel_11', - }, + await this.start({ + discuss: { + params: { + default_active_id: 'mail.channel_11', }, - async mockRPC(route, args) { - const res = await this._super(...arguments); - // domain should be like [['channel_id', 'in', [X]]] with X the channel id - if (route.includes('message_fetch') && args.kwargs.domain[0][2].includes(11)) { - messageFetchChannel11Def.resolve(); - } - if (route.includes('message_fetch') && args.kwargs.domain[0][2].includes(12)) { - messageFetchChannel12Def.resolve(); - } - return res; + }, + waitUntilEvent: { + eventName: 'o-component-message-list-scrolled', + message: "should wait until channel 11 scrolled to its last message", + predicate: ({ threadViewer }) => { + return threadViewer.thread.model === 'mail.channel' && threadViewer.thread.id === 11; }, - }); - // wait until messages are fetched, ignore other renders that are too early - await messageFetchChannel11Def; + }, }); assert.strictEqual( document.querySelectorAll(` @@ -1869,34 +1859,42 @@ QUnit.test('restore thread scroll position', async function (assert) { "should have 25 messages in channel 11" ); - // scroll to top of channel11 - await afterNextRender(() => { - document.querySelector(`.o_Discuss_thread .o_ThreadView_messageList`).scrollTop = 0; + await this.afterEvent({ + eventName: 'o-component-message-list-scrolled', + func: () => document.querySelector(`.o_Discuss_thread .o_ThreadView_messageList`).scrollTop = 0, + message: "should wait until channel 11 changed its scroll position to top", + predicate: ({ threadViewer }) => { + return threadViewer.thread.model === 'mail.channel' && threadViewer.thread.id === 11; + }, }); assert.strictEqual( document.querySelector(`.o_Discuss_thread .o_ThreadView_messageList`).scrollTop, 0, - "should have scrolled to top of thread" + "should have scrolled to top of channel 11", ); - const scrollChannel12Def = makeDeferred(); - const onScroll = () => { - scrollChannel12Def.resolve(); - }; - document.addEventListener('o-message-list-scrolled', onScroll); - // select channel 12 - await afterNextRender(async () => { - document.querySelector(` - .o_DiscussSidebar_groupChannel - .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 12 && - thread.model === 'mail.channel' - ).localId - }"] - `).click(); - // wait until messages are fetched, ignore other renders that are too early - await messageFetchChannel12Def; + // Ensure scrollIntoView of channel 12 has enough time to complete before + // going back to channel 11. Await is needed to prevent the scrollIntoView + // initially planned for channel 12 to actually apply on channel 11. + // task-2333535 + await this.afterEvent({ + eventName: 'o-component-message-list-scrolled', + func: () => { + // select channel 12 + document.querySelector(` + .o_DiscussSidebar_groupChannel + .o_DiscussSidebar_item[data-thread-local-id="${ + this.env.models['mail.thread'].find(thread => + thread.id === 12 && + thread.model === 'mail.channel' + ).localId + }"] + `).click(); + }, + message: "should wait until channel 12 scrolled to its last message", + predicate: ({ threadViewer }) => { + return threadViewer.thread.model === 'mail.channel' && threadViewer.thread.id === 12; + }, }); assert.strictEqual( document.querySelectorAll(` @@ -1906,43 +1904,50 @@ QUnit.test('restore thread scroll position', async function (assert) { "should have 24 messages in channel 12" ); - // Ensure scrollIntoView of channel 12 has enough time to complete before - // going back to channel 11. Await is needed to prevent the scrollIntoView - // initially planned for channel 12 to actually apply on channel 11. - // task-2333535 - await scrollChannel12Def; - document.removeEventListener('o-message-list-scrolled', onScroll); - - // select channel 11 - await afterNextRender(() => - document.querySelector(` - .o_DiscussSidebar_groupChannel - .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 11 && - thread.model === 'mail.channel' - ).localId - }"] - `).click() - ); + await this.afterEvent({ + eventName: 'o-component-message-list-scrolled', + func: () => { + // select channel 11 + document.querySelector(` + .o_DiscussSidebar_groupChannel + .o_DiscussSidebar_item[data-thread-local-id="${ + this.env.models['mail.thread'].find(thread => + thread.id === 11 && + thread.model === 'mail.channel' + ).localId + }"] + `).click(); + }, + message: "should wait until channel 11 restored its scroll position", + predicate: ({ threadViewer }) => { + return threadViewer.thread.model === 'mail.channel' && threadViewer.thread.id === 11; + }, + }); assert.strictEqual( document.querySelector(`.o_Discuss_thread .o_ThreadView_messageList`).scrollTop, 0, "should have recovered scroll position of channel 11 (scroll to top)" ); - // select channel12 - await afterNextRender(() => - document.querySelector(` - .o_DiscussSidebar_groupChannel - .o_DiscussSidebar_item[data-thread-local-id="${ - this.env.models['mail.thread'].find(thread => - thread.id === 12 && - thread.model === 'mail.channel' - ).localId - }"] - `).click() - ); + await this.afterEvent({ + eventName: 'o-component-message-list-scrolled', + func: () => { + // select channel 12 + document.querySelector(` + .o_DiscussSidebar_groupChannel + .o_DiscussSidebar_item[data-thread-local-id="${ + this.env.models['mail.thread'].find(thread => + thread.id === 12 && + thread.model === 'mail.channel' + ).localId + }"] + `).click(); + }, + message: "should wait until channel 12 recovered its scroll position", + predicate: ({ threadViewer }) => { + return threadViewer.thread.model === 'mail.channel' && threadViewer.thread.id === 12; + }, + }); const messageList = document.querySelector(` .o_Discuss_thread .o_ThreadView_messageList diff --git a/addons/mail/static/src/components/message_list/message_list.js b/addons/mail/static/src/components/message_list/message_list.js index 17531eabbca..3189b97b627 100644 --- a/addons/mail/static/src/components/message_list/message_list.js +++ b/addons/mail/static/src/components/message_list/message_list.js @@ -333,6 +333,9 @@ class MessageList extends Component { isProcessed = true; } if (isProcessed) { + this.env.messagingBus.trigger('o-component-message-list-thread-cache-changed', { + threadViewer: this.threadView.threadViewer, + }); this.threadView.markComponentHintProcessed(hint); } } @@ -397,6 +400,9 @@ class MessageList extends Component { if (this.props.order === 'asc' && this.props.hasScrollAdjust) { this.el.scrollTop = this.el.scrollHeight - scrollHeight + scrollTop; } + this.env.messagingBus.trigger('o-component-message-list-more-messages-loaded', { + threadViewer: this.threadView.threadViewer, + }); this.threadView.markComponentHintProcessed(hint); } @@ -526,8 +532,12 @@ class MessageList extends Component { if (!this.threadView || !this.threadView.threadViewer) { return; } - this.trigger('o-message-list-scrolled'); - this.threadView.threadViewer.saveThreadCacheScrollPositionsAsInitial(this.el.scrollTop); + const scrollTop = this.el.scrollTop; + this.env.messagingBus.trigger('o-component-message-list-scrolled', { + scrollTop, + threadViewer: this.threadView.threadViewer, + }); + this.threadView.threadViewer.saveThreadCacheScrollPositionsAsInitial(scrollTop); if (!this._isAutoLoadOnScrollActive) { return; } |
