From 63e2c6bffa72af8019c353985e8d9863aeeec207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 28 Apr 2022 13:35:58 +0000 Subject: [PATCH] [IMP] mail:tests: use insertText helper (step 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-2836093 closes odoo/odoo#90027 Signed-off-by: Alexandre Kühn (aku) --- .../channel_invitation_form_tests.js | 9 ++-- .../components/chat_window_manager_tests.js | 21 +++------- .../chatter_suggested_recipient_tests.js | 7 ++-- .../components/chatter_tests.js | 21 +++------- .../components/composer_tests.js | 38 +++++------------ .../components/discuss_inbox_tests.js | 12 ++---- .../components/discuss_tests.js | 41 ++++++------------- .../components/thread_view_tests.js | 20 ++++----- 8 files changed, 53 insertions(+), 116 deletions(-) diff --git a/addons/mail/static/tests/qunit_suite_tests/components/channel_invitation_form_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/channel_invitation_form_tests.js index fe6b0faa292..e8dea292876 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/channel_invitation_form_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/channel_invitation_form_tests.js @@ -1,7 +1,6 @@ /** @odoo-module **/ import { - afterNextRender, start, startServer, } from '@mail/../tests/helpers/test_utils'; @@ -66,7 +65,7 @@ QUnit.test('should be able to search for a new user to invite from an existing c channel_type: 'chat', public: 'private', }); - const { click } = await start({ + const { click, insertText } = await start({ autoOpenDiscuss: true, discuss: { context: { @@ -76,7 +75,7 @@ QUnit.test('should be able to search for a new user to invite from an existing c hasDiscuss: true, }); await click(`.o_ThreadViewTopbar_inviteButton`); - await afterNextRender(() => document.execCommand('insertText', false, "TestPartner2")); + await insertText('.o_ChannelInvitationForm_searchInput', "TestPartner2"); assert.strictEqual( document.querySelector(`.o_ChannelInvitationForm_selectablePartnerName`).textContent, "TestPartner2", @@ -106,7 +105,7 @@ QUnit.test('should be able to create a new group chat from an existing chat', as channel_type: 'chat', public: 'private', }); - const { click } = await start({ + const { click, insertText } = await start({ autoOpenDiscuss: true, discuss: { context: { @@ -117,7 +116,7 @@ QUnit.test('should be able to create a new group chat from an existing chat', as }); await click(`.o_ThreadViewTopbar_inviteButton`); - await afterNextRender(() => document.execCommand('insertText', false, "TestPartner2")); + await insertText('.o_ChannelInvitationForm_searchInput', "TestPartner2"); await click(`.o_ChannelInvitationForm_selectablePartnerCheckbox`); await click(`.o_ChannelInvitationForm_inviteButton`); assert.strictEqual( diff --git a/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js index e4322a07eb4..a1b8f6db184 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js @@ -906,15 +906,12 @@ QUnit.test('chat window: composer state conservation on toggle discuss', async f const pyEnv = await startServer(); pyEnv['mail.channel'].create(); - const { click, createMessagingMenuComponent, messaging } = await this.start(); + const { click, createMessagingMenuComponent, insertText, messaging } = await this.start(); const messagingMenuComponent = await createMessagingMenuComponent(); await click(`.o_MessagingMenu_toggler`); await click(`.o_MessagingMenu_dropdownMenu .o_NotificationList_preview`); // Set content of the composer of the chat window - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, 'XDU for the win !'); - }); + await insertText('.o_ComposerTextInput_textarea', 'XDU for the win !'); assert.containsNone( document.body, '.o_Composer .o_AttachmentCard', @@ -1824,13 +1821,10 @@ QUnit.test('chat window should scroll to the newly posted message just after pos res_id: mailChannelId1, }); } - await this.start(); + const { insertText } = 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'); - }); + await insertText('.o_ComposerTextInput_textarea', 'WOLOLO'); // Send a new message in the chatwindow to trigger the scroll await afterNextRender(() => triggerEvent( @@ -1859,7 +1853,7 @@ QUnit.test('chat window: post message on non-mailing channel with "CTRL-Enter" k }], ], }); - const { click, createMessagingMenuComponent } = await this.start({ + const { click, createMessagingMenuComponent, insertText } = await this.start({ env: { device: { isMobile: true, // here isMobile is used for the small screen size, not actually for the mobile devices @@ -1871,10 +1865,7 @@ QUnit.test('chat window: post message on non-mailing channel with "CTRL-Enter" k await click(`.o_MessagingMenu_toggler`); await click(`.o_MessagingMenu_dropdownMenu .o_NotificationList_preview`); // insert some HTML in editable - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "Test"); - }); + await insertText('.o_ComposerTextInput_textarea', "Test"); await afterNextRender(() => { const kevt = new window.KeyboardEvent('keydown', { ctrlKey: true, key: "Enter" }); document.querySelector('.o_ComposerTextInput_textarea').dispatchEvent(kevt); diff --git a/addons/mail/static/tests/qunit_suite_tests/components/chatter_suggested_recipient_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/chatter_suggested_recipient_tests.js index b9af2612892..5840b8cbf50 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/chatter_suggested_recipient_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/chatter_suggested_recipient_tests.js @@ -1,6 +1,6 @@ /** @odoo-module **/ -import { afterNextRender, start, startServer } from '@mail/../tests/helpers/test_utils'; +import { start, startServer } from '@mail/../tests/helpers/test_utils'; QUnit.module('mail', {}, function () { QUnit.module('components', {}, function () { @@ -226,7 +226,7 @@ QUnit.test("suggested recipients should not be notified when posting an internal const pyEnv = await startServer(); const resPartnerId1 = pyEnv['res.partner'].create({ display_name: "John Jane", email: "john@jane.be" }); const resFakeId1 = pyEnv['res.fake'].create({ partner_ids: [resPartnerId1] }); - const { click, createChatterContainerComponent } = await start({ + const { click, createChatterContainerComponent, insertText } = await start({ async mockRPC(route, args) { if (route === '/mail/message/post') { assert.strictEqual( @@ -243,8 +243,7 @@ QUnit.test("suggested recipients should not be notified when posting an internal threadModel: 'res.fake', }); await click(`.o_ChatterTopbar_buttonLogNote`); - document.querySelector('.o_ComposerTextInput_textarea').focus(); - await afterNextRender(() => document.execCommand('insertText', false, "Dummy Message")); + await insertText('.o_ComposerTextInput_textarea', "Dummy Message"); await click('.o_Composer_buttonSend'); }); diff --git a/addons/mail/static/tests/qunit_suite_tests/components/chatter_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/chatter_tests.js index cf008b0bb55..57dcb368ed9 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/chatter_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/chatter_tests.js @@ -371,7 +371,7 @@ QUnit.test('post message with "CTRL-Enter" keyboard shortcut', async function (a const pyEnv = await startServer(); const resPartnerId1 = pyEnv['res.partner'].create(); - const { click, createChatterContainerComponent } = await start(); + const { click, createChatterContainerComponent, insertText } = await start(); await createChatterContainerComponent({ threadId: resPartnerId1, threadModel: 'res.partner', @@ -383,10 +383,7 @@ QUnit.test('post message with "CTRL-Enter" keyboard shortcut', async function (a ); await click('.o_ChatterTopbar_buttonSendMessage'); - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "Test"); - }); + await insertText('.o_ComposerTextInput_textarea', "Test"); await afterNextRender(() => { const kevt = new window.KeyboardEvent('keydown', { ctrlKey: true, key: "Enter" }); document.querySelector('.o_ComposerTextInput_textarea').dispatchEvent(kevt); @@ -403,7 +400,7 @@ QUnit.test('post message with "META-Enter" keyboard shortcut', async function (a const pyEnv = await startServer(); const resPartnerId1 = pyEnv['res.partner'].create(); - const { click, createChatterContainerComponent } = await start(); + const { click, createChatterContainerComponent, insertText } = await start(); await createChatterContainerComponent({ threadId: resPartnerId1, threadModel: 'res.partner', @@ -415,10 +412,7 @@ QUnit.test('post message with "META-Enter" keyboard shortcut', async function (a ); await click('.o_ChatterTopbar_buttonSendMessage'); - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "Test"); - }); + await insertText('.o_ComposerTextInput_textarea', "Test"); await afterNextRender(() => { const kevt = new window.KeyboardEvent('keydown', { key: "Enter", metaKey: true }); document.querySelector('.o_ComposerTextInput_textarea').dispatchEvent(kevt); @@ -438,7 +432,7 @@ QUnit.test('do not post message with "Enter" keyboard shortcut', async function const pyEnv = await startServer(); const resPartnerId1 = pyEnv['res.partner'].create(); - const { click, createChatterContainerComponent } = await start(); + const { click, createChatterContainerComponent, insertText } = await start(); await createChatterContainerComponent({ threadId: resPartnerId1, threadModel: 'res.partner', @@ -450,10 +444,7 @@ QUnit.test('do not post message with "Enter" keyboard shortcut', async function ); await click('.o_ChatterTopbar_buttonSendMessage'); - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "Test"); - }); + await insertText('.o_ComposerTextInput_textarea', "Test"); const kevt = new window.KeyboardEvent('keydown', { key: "Enter" }); document.querySelector('.o_ComposerTextInput_textarea').dispatchEvent(kevt); await nextAnimationFrame(); diff --git a/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js index d2b557bd0f5..25deefadc5c 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js @@ -220,16 +220,13 @@ QUnit.test('add an emoji after some text', async function (assert) { const pyEnv = await startServer(); const mailChanelId1 = pyEnv['mail.channel'].create(); - const { click, createComposerComponent, messaging } = await start(); + const { click, createComposerComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ id: mailChanelId1, model: 'mail.channel', }); await createComposerComponent(thread.composer); - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "Blabla"); - }); + await insertText('.o_ComposerTextInput_textarea', "Blabla"); assert.strictEqual( document.querySelector(`.o_ComposerTextInput_textarea`).value, "Blabla", @@ -250,17 +247,14 @@ QUnit.test('add emoji replaces (keyboard) text selection', async function (asser const pyEnv = await startServer(); const mailChanelId1 = pyEnv['mail.channel'].create(); - const { click, createComposerComponent, messaging } = await start(); + const { click, createComposerComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ id: mailChanelId1, model: 'mail.channel', }); await createComposerComponent(thread.composer); const composerTextInputTextArea = document.querySelector(`.o_ComposerTextInput_textarea`); - await afterNextRender(() => { - composerTextInputTextArea.focus(); - document.execCommand('insertText', false, "Blabla"); - }); + await insertText('.o_ComposerTextInput_textarea', "Blabla"); assert.strictEqual( composerTextInputTextArea.value, "Blabla", @@ -513,10 +507,7 @@ QUnit.test('mention a channel after some text', async function (assert) { "", "text content of composer should be empty initially" ); - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - await afterNextRender(() => - document.execCommand('insertText', false, "bluhbluh ") - ); + await insertText('.o_ComposerTextInput_textarea', "bluhbluh "); assert.strictEqual( document.querySelector(`.o_ComposerTextInput_textarea`).value, "bluhbluh ", @@ -858,10 +849,7 @@ QUnit.test('mention a partner after some text', async function (assert) { "", "text content of composer should be empty initially" ); - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - await afterNextRender(() => - document.execCommand('insertText', false, "bluhbluh ") - ); + await insertText('.o_ComposerTextInput_textarea', "bluhbluh "); assert.strictEqual( document.querySelector(`.o_ComposerTextInput_textarea`).value, "bluhbluh ", @@ -1059,7 +1047,7 @@ QUnit.test('composer text input cleared on message post', async function (assert const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - const { click, createComposerComponent, messaging } = await start({ + const { click, createComposerComponent, insertText, messaging } = await start({ async mockRPC(route, args) { if (route === '/mail/message/post') { assert.step('message_post'); @@ -1073,10 +1061,7 @@ QUnit.test('composer text input cleared on message post', async function (assert }); await createComposerComponent(thread.composer); // Type message - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "test message"); - }); + await insertText('.o_ComposerTextInput_textarea', "test message"); assert.strictEqual( document.querySelector(`.o_ComposerTextInput_textarea`).value, "test message", @@ -1563,7 +1548,7 @@ QUnit.test('send message only once when button send is clicked twice quickly', a const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerComponent, messaging } = await start({ + const { createComposerComponent, insertText, messaging } = await start({ async mockRPC(route, args) { if (route === '/mail/message/post') { assert.step('message_post'); @@ -1577,10 +1562,7 @@ QUnit.test('send message only once when button send is clicked twice quickly', a }); await createComposerComponent(thread.composer); // Type message - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "test message"); - }); + await insertText('.o_ComposerTextInput_textarea', "test message"); await afterNextRender(() => { document.querySelector(`.o_Composer_buttonSend`).click(); diff --git a/addons/mail/static/tests/qunit_suite_tests/components/discuss_inbox_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/discuss_inbox_tests.js index 4d8a86f4dc0..413e030fea8 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/discuss_inbox_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/discuss_inbox_tests.js @@ -334,7 +334,7 @@ QUnit.test('"reply to" composer should log note if message replied to is a note' notification_type: 'inbox', res_partner_id: pyEnv.currentPartnerId, }); - const { click } = await this.start({ + const { click, insertText } = await this.start({ async mockRPC(route, args) { if (route === '/mail/message/post') { assert.step('/mail/message/post'); @@ -377,9 +377,7 @@ QUnit.test('"reply to" composer should log note if message replied to is a note' "Send button text should be 'Log'" ); - await afterNextRender(() => - document.execCommand('insertText', false, "Test") - ); + await insertText('.o_ComposerTextInput_textarea', "Test"); await click('.o_Composer_buttonSend'); assert.verifySteps(['/mail/message/post']); }); @@ -403,7 +401,7 @@ QUnit.test('"reply to" composer should send message if message replied to is not notification_type: 'inbox', res_partner_id: pyEnv.currentPartnerId, }); - const { click } = await this.start({ + const { click, insertText } = await this.start({ async mockRPC(route, args) { if (route === '/mail/message/post') { assert.step('/mail/message/post'); @@ -446,9 +444,7 @@ QUnit.test('"reply to" composer should send message if message replied to is not "Send button text should be 'Send'" ); - await afterNextRender(() => - document.execCommand('insertText', false, "Test") - ); + await insertText('.o_ComposerTextInput_textarea', "Test"); await click('.o_Composer_buttonSend'); assert.verifySteps(['/mail/message/post']); }); diff --git a/addons/mail/static/tests/qunit_suite_tests/components/discuss_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/discuss_tests.js index d5873448f1e..52ea33cbef4 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/discuss_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/discuss_tests.js @@ -1263,7 +1263,7 @@ QUnit.test('should not be able to reply to temporary/transient messages', async const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - const { click } = await this.start({ + const { click, insertText } = await this.start({ discuss: { params: { default_active_id: `mail.channel_${mailChannelId1}`, @@ -1271,10 +1271,7 @@ QUnit.test('should not be able to reply to temporary/transient messages', async }, }); // these user interactions is to forge a transient message response from channel command "/who" - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "/who"); - }); + await insertText('.o_ComposerTextInput_textarea', "/who"); await click('.o_Composer_buttonSend'); // click on message to show actions on the transient message resulting from the "/who" command await click('.o_Message'); @@ -2661,7 +2658,7 @@ QUnit.test('post a simple message', async function (assert) { const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); let postedMessageId; - const { click, messaging } = await this.start({ + const { click, insertText, messaging } = await this.start({ discuss: { params: { default_active_id: `mail.channel_${mailChannelId1}`, @@ -2718,10 +2715,7 @@ QUnit.test('post a simple message', async function (assert) { ); // insert some HTML in editable - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "Test"); - }); + await insertText('.o_ComposerTextInput_textarea', "Test"); assert.strictEqual( document.querySelector(`.o_ComposerTextInput_textarea`).value, "Test", @@ -2763,7 +2757,7 @@ QUnit.test('post message on channel with "Enter" keyboard shortcut', async funct const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - await this.start({ + const { insertText } = await this.start({ discuss: { params: { default_active_id: `mail.channel_${mailChannelId1}`, @@ -2777,10 +2771,7 @@ QUnit.test('post message on channel with "Enter" keyboard shortcut', async funct ); // insert some HTML in editable - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "Test"); - }); + await insertText('.o_ComposerTextInput_textarea', "Test"); await afterNextRender(() => { const kevt = new window.KeyboardEvent('keydown', { key: "Enter" }); document.querySelector('.o_ComposerTextInput_textarea').dispatchEvent(kevt); @@ -2800,7 +2791,7 @@ QUnit.test('do not post message on channel with "SHIFT-Enter" keyboard shortcut' const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - await this.start({ + const { insertText } = await this.start({ discuss: { params: { default_active_id: `mail.channel_${mailChannelId1}`, @@ -2814,10 +2805,7 @@ QUnit.test('do not post message on channel with "SHIFT-Enter" keyboard shortcut' ); // insert some HTML in editable - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "Test"); - }); + await insertText('.o_ComposerTextInput_textarea', "Test"); const kevt = new window.KeyboardEvent('keydown', { key: "Enter", shiftKey: true }); document.querySelector('.o_ComposerTextInput_textarea').dispatchEvent(kevt); await nextAnimationFrame(); @@ -3123,7 +3111,7 @@ QUnit.test('reply to message from inbox (message linked to document)', async fun notification_type: 'inbox', res_partner_id: pyEnv.currentPartnerId, // must be for current partner }); - const { click, messaging } = await this.start({ + const { click, insertText, messaging } = await this.start({ async mockRPC(route, args) { if (route === '/mail/message/post') { assert.step('message_post'); @@ -3203,9 +3191,7 @@ QUnit.test('reply to message from inbox (message linked to document)', async fun "composer text input should be auto-focus" ); - await afterNextRender(() => - document.execCommand('insertText', false, "Test") - ); + await insertText('.o_ComposerTextInput_textarea', "Test"); await click('.o_Composer_buttonSend'); assert.verifySteps(['message_post']); assert.notOk( @@ -3987,7 +3973,7 @@ QUnit.test('send message only once when enter is pressed twice quickly', async f const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - await this.start({ + const { insertText } = await this.start({ discuss: { context: { active_id: `mail.channel_${mailChannelId1}`, @@ -4001,10 +3987,7 @@ QUnit.test('send message only once when enter is pressed twice quickly', async f }, }); // Type message - await afterNextRender(() => { - document.querySelector(`.o_ComposerTextInput_textarea`).focus(); - document.execCommand('insertText', false, "test message"); - }); + await insertText('.o_ComposerTextInput_textarea', "test message"); await afterNextRender(() => { const enterEvent = new window.KeyboardEvent('keydown', { key: 'Enter' }); document.querySelector(`.o_ComposerTextInput_textarea`) diff --git a/addons/mail/static/tests/qunit_suite_tests/components/thread_view_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/thread_view_tests.js index 6b737c3145c..41b2c151d23 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/thread_view_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/thread_view_tests.js @@ -459,7 +459,7 @@ QUnit.test('[technical] new messages separator on posting message', async functi }); const [mailChannelPartnerId] = pyEnv['mail.channel.partner'].search([['channel_id', '=', mailChannelId1], ['partner_id', '=', pyEnv.currentPartnerId]]); pyEnv['mail.channel.partner'].write([mailChannelPartnerId], { seen_message_id: mailMessageId1 }); - const { createThreadViewComponent, messaging } = await start(); + const { createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ id: mailChannelId1, model: 'mail.channel' @@ -482,8 +482,7 @@ QUnit.test('[technical] new messages separator on posting message', async functi "should not display 'new messages' separator" ); - document.querySelector('.o_ComposerTextInput_textarea').focus(); - await afterNextRender(() => document.execCommand('insertText', false, "hey !")); + await insertText('.o_ComposerTextInput_textarea', "hey !"); await afterNextRender(() => { // need to remove focus from text area to avoid set_last_seen_message document.querySelector('.o_Composer_buttonSend').focus(); @@ -630,7 +629,7 @@ QUnit.test('new messages separator on posting message', async function (assert) channel_type: 'channel', name: "General", }); - const { click, createThreadViewComponent, messaging } = await start(); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ id: mailChannelId1, model: 'mail.channel' @@ -653,8 +652,7 @@ QUnit.test('new messages separator on posting message', async function (assert) "should not display 'new messages' separator" ); - document.querySelector('.o_ComposerTextInput_textarea').focus(); - await afterNextRender(() => document.execCommand('insertText', false, "hey !")); + await insertText('.o_ComposerTextInput_textarea', "hey !"); await click('.o_Composer_buttonSend'); assert.containsOnce( document.body, @@ -1515,7 +1513,7 @@ QUnit.test('first unseen message should be directly preceded by the new message name: "General", uuid: 'channel20uuid', }); - const { click, createThreadViewComponent, messaging } = await start(); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ id: mailChannelId1, model: 'mail.channel' @@ -1527,8 +1525,7 @@ QUnit.test('first unseen message should be directly preceded by the new message }); await createThreadViewComponent(threadViewer.threadView); // send a command that leads to receiving a transient message - document.querySelector('.o_ComposerTextInput_textarea').focus(); - await afterNextRender(() => document.execCommand('insertText', false, "/who")); + await insertText('.o_ComposerTextInput_textarea', "/who"); await click('.o_Composer_buttonSend'); // composer is focused by default, we remove that focus @@ -1569,7 +1566,7 @@ QUnit.test('composer should be focused automatically after clicking on the send const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create({}); - const { click, createThreadViewComponent, messaging } = await start(); + const { click, createThreadViewComponent, insertText, messaging } = await start(); const thread = messaging.models['Thread'].findFromIdentifyingData({ id: mailChannelId1, model: 'mail.channel' @@ -1580,8 +1577,7 @@ QUnit.test('composer should be focused automatically after clicking on the send thread: link(thread), }); await createThreadViewComponent(threadViewer.threadView); - document.querySelector('.o_ComposerTextInput_textarea').focus(); - await afterNextRender(() => document.execCommand('insertText', false, "Dummy Message")); + await insertText('.o_ComposerTextInput_textarea', "Dummy Message"); await click('.o_Composer_buttonSend'); assert.hasClass( document.querySelector('.o_Composer'),