diff --git a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js index 220f4278fa9..e2d049d6f87 100644 --- a/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js +++ b/addons/mail/static/src/components/chat_window_manager/chat_window_manager_tests.js @@ -1617,6 +1617,44 @@ QUnit.test('chat window with a thread: keep scroll position in message list on f ); }); +QUnit.test('chat window should scroll to the newly posted message just after posting it', async function (assert) { + assert.expect(1); + + this.data['mail.channel'].records.push({ + id: 20, + is_minimized: true, + state: 'open', + }); + for (let i = 0; i < 10; i++) { + this.data['mail.message'].records.push({ + channel_ids: [20], + model: 'mail.channel', + res_id: 20, + }); + } + await this.start(); + + // Set content of the composer of the chat window + await afterNextRender(() => { + document.querySelector('.o_ComposerTextInput_textarea').focus(); + document.execCommand('insertText', false, 'WOLOLO'); + }); + // Send a new message in the chatwindow to trigger the scroll + await afterNextRender(() => + triggerEvent( + document.querySelector('.o_ChatWindow .o_ComposerTextInput_textarea'), + 'keydown', + { key: 'Enter' }, + ) + ); + const messageList = document.querySelector('.o_MessageList'); + assert.strictEqual( + messageList.scrollHeight - messageList.scrollTop, + messageList.clientHeight, + "chat window should scroll to the newly posted message just after posting it" + ); +}); + QUnit.test('[technical] chat window: composer state conservation on toggle home menu when folded', async function (assert) { // technical as show/hide home menu simulation are involved and home menu implementation // have side-effects on DOM that may make chat window components not work diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js index 2be5919204b..d51f8c37249 100644 --- a/addons/mail/static/src/models/composer/composer.js +++ b/addons/mail/static/src/models/composer/composer.js @@ -182,7 +182,7 @@ function factory(dependencies) { thread.loadNewMessages(); } for (const threadView of this.thread.threadViews) { - threadView.addComponentHint('current-partner-just-posted-message', messageId); + threadView.addComponentHint('current-partner-just-posted-message', { messageId }); } this._reset(); }