diff --git a/addons/mail/static/tests/composer/composer_tests.js b/addons/mail/static/tests/composer/composer_tests.js index ffa4d07b22d..61ef6428e0b 100644 --- a/addons/mail/static/tests/composer/composer_tests.js +++ b/addons/mail/static/tests/composer/composer_tests.js @@ -10,7 +10,6 @@ import { dragenterFiles, dropFiles, insertText, - nextAnimationFrame, pasteFiles, scroll, start, @@ -886,6 +885,5 @@ QUnit.test("Message is sent only once when pressing enter twice in a row", async triggerHotkey("Enter"); triggerHotkey("Enter"); // weak test, no guarantee that we waited long enough for the potential second message to be posted - await nextAnimationFrame(); await contains(".o-mail-Message-content", { text: "Hello World!" }); }); diff --git a/addons/mail/static/tests/discuss/call/call_tests.js b/addons/mail/static/tests/discuss/call/call_tests.js index fa0da1fc1f7..d095ab38c06 100644 --- a/addons/mail/static/tests/discuss/call/call_tests.js +++ b/addons/mail/static/tests/discuss/call/call_tests.js @@ -5,7 +5,6 @@ import { click, contains, mockGetMedia, - nextAnimationFrame, start, startServer, } from "@mail/../tests/helpers/test_utils"; @@ -105,7 +104,6 @@ QUnit.test("should disconnect when closing page while in call", async (assert) = await contains(".o-discuss-Call"); // simulate page close window.dispatchEvent(new Event("pagehide"), { bubble: true }); - await nextAnimationFrame(); assert.verifySteps(["sendBeacon_leave_call"]); }); diff --git a/addons/mail/static/tests/discuss/voice_message/voice_message_tests.js b/addons/mail/static/tests/discuss/voice_message/voice_message_tests.js index 88924752e3a..1d338ab0d13 100644 --- a/addons/mail/static/tests/discuss/voice_message/voice_message_tests.js +++ b/addons/mail/static/tests/discuss/voice_message/voice_message_tests.js @@ -6,7 +6,6 @@ import { contains, createFile, mockGetMedia, - nextAnimationFrame, start, startServer, } from "@mail/../tests/helpers/test_utils"; @@ -161,7 +160,7 @@ QUnit.test("make voice message in chat", async () => { openDiscuss(channelId); await click("button[title='Voice Message']"); await contains(".o-mail-VoiceRecorder", { text: "00 : 00" }); - await nextAnimationFrame(); + await Promise.resolve(); // simulate 10 sec elapsed patchDate(2023, 6, 31, 13, 0, 11); // +1 so exactly 10 sec elapsed // simulate some microphone data @@ -171,7 +170,6 @@ QUnit.test("make voice message in chat", async () => { await contains(".o-mail-VoicePlayer"); // wait for audio stream decode + drawing of waves await voicePlayerDrawing; - await nextAnimationFrame(); await contains(".o-mail-VoicePlayer button[title='Play']"); await contains(".o-mail-VoicePlayer canvas", { count: 2 }); // 1 for global waveforms, 1 for played waveforms await contains(".o-mail-VoicePlayer", { text: "00 : 04" }); // duration of call_02_in_.mp3 diff --git a/addons/mail/static/tests/discuss_app/inbox_tests.js b/addons/mail/static/tests/discuss_app/inbox_tests.js index d7ee54fd30a..cd0f7c6679f 100644 --- a/addons/mail/static/tests/discuss_app/inbox_tests.js +++ b/addons/mail/static/tests/discuss_app/inbox_tests.js @@ -1,13 +1,6 @@ /* @odoo-module */ -import { - click, - contains, - insertText, - nextAnimationFrame, - start, - startServer, -} from "@mail/../tests/helpers/test_utils"; +import { click, contains, insertText, start, startServer } from "@mail/../tests/helpers/test_utils"; import { patchWithCleanup, triggerHotkey, makeDeferred } from "@web/../tests/helpers/utils"; @@ -615,7 +608,6 @@ QUnit.test("emptying inbox displays rainbow man in inbox", async () => { openDiscuss(); await click("button", { text: "Mark all read" }); await contains("button:contains(Inbox) .badge", { count: 0 }); - await nextAnimationFrame(); await contains(".o_reward_rainbow"); }); @@ -645,7 +637,6 @@ QUnit.test("emptying inbox doesn't display rainbow man in another thread", async needaction_inbox_counter: 0, }); await contains("button:contains(Inbox) .badge", { count: 0 }); - await nextAnimationFrame(); // weak test, no guarantee that we waited long enough for the potential rainbow man to show await contains(".o_reward_rainbow", { count: 0 }); }); diff --git a/addons/mail/static/tests/discuss_app/sidebar_tests.js b/addons/mail/static/tests/discuss_app/sidebar_tests.js index 5b2c4f1ad50..c18574a318d 100644 --- a/addons/mail/static/tests/discuss_app/sidebar_tests.js +++ b/addons/mail/static/tests/discuss_app/sidebar_tests.js @@ -1,14 +1,7 @@ /* @odoo-module */ import { Command } from "@mail/../tests/helpers/command"; -import { - click, - contains, - insertText, - nextAnimationFrame, - start, - startServer, -} from "@mail/../tests/helpers/test_utils"; +import { click, contains, insertText, start, startServer } from "@mail/../tests/helpers/test_utils"; import { getOrigin } from "@web/core/utils/urls"; @@ -1036,7 +1029,6 @@ QUnit.test("Do no channel_info after unpin", async (assert) => { message_type: "comment", }, }); - await nextAnimationFrame(); // weak test, no guarantee that we waited long enough for the potential rpc to be done assert.verifySteps([]); }); diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js index 75ba021fa9d..ef3bae00d0a 100644 --- a/addons/mail/static/tests/helpers/test_utils.js +++ b/addons/mail/static/tests/helpers/test_utils.js @@ -49,21 +49,6 @@ function _createFakeDataTransfer(files) { }; } -//------------------------------------------------------------------------------ -// Public: rendering timers -//------------------------------------------------------------------------------ - -/** - * Returns a promise resolved at the next animation frame. - * - * @returns {Promise} - */ -function nextAnimationFrame() { - return new Promise(function (resolve) { - setTimeout(() => requestAnimationFrame(() => resolve())); - }); -} - //------------------------------------------------------------------------------ // Public: test lifecycle //------------------------------------------------------------------------------ @@ -422,7 +407,6 @@ export { dragenterFiles, dropFiles, insertText, - nextAnimationFrame, pasteFiles, scroll, start, diff --git a/addons/mail/static/tests/message/link_preview_test.js b/addons/mail/static/tests/message/link_preview_test.js index 9ffd48e9c77..1ed302063a6 100644 --- a/addons/mail/static/tests/message/link_preview_test.js +++ b/addons/mail/static/tests/message/link_preview_test.js @@ -1,13 +1,6 @@ /* @odoo-module */ -import { - click, - contains, - insertText, - nextAnimationFrame, - start, - startServer, -} from "@mail/../tests/helpers/test_utils"; +import { click, contains, insertText, start, startServer } from "@mail/../tests/helpers/test_utils"; QUnit.module("link preview"); @@ -266,10 +259,8 @@ QUnit.test("No crash on receiving link preview of non-known message", async (ass const { env, openDiscuss } = await start(); openDiscuss(); env.services.rpc("/mail/link_preview", { message_id: messageId }); - await nextAnimationFrame(); assert.ok(true); env.services.rpc("/mail/link_preview/delete", { link_preview_id: linkPreviewId }); - await nextAnimationFrame(); assert.ok(true); }); diff --git a/addons/mail/static/tests/message/message_tests.js b/addons/mail/static/tests/message/message_tests.js index 250f08e026c..7cd6936a6ed 100644 --- a/addons/mail/static/tests/message/message_tests.js +++ b/addons/mail/static/tests/message/message_tests.js @@ -1,14 +1,7 @@ /* @odoo-module */ import { Command } from "@mail/../tests/helpers/command"; -import { - click, - contains, - insertText, - nextAnimationFrame, - start, - startServer, -} from "@mail/../tests/helpers/test_utils"; +import { click, contains, insertText, start, startServer } from "@mail/../tests/helpers/test_utils"; import { deserializeDateTime } from "@web/core/l10n/dates"; import { getOrigin } from "@web/core/utils/urls"; @@ -1278,9 +1271,8 @@ QUnit.test( openDiscuss(channelId); await contains(".o-mail-Message-avatar"); assert.doesNotHaveClass($(".o-mail-Message-avatarContainer"), "cursor-pointer"); - - click(".o-mail-Message-avatar").catch(() => {}); - await nextAnimationFrame(); + await click(".o-mail-Message-avatar"); + // weak test, no guarantee that we waited long enough for the potential chat window to show await contains(".o-mail-ChatWindow", { count: 0 }); } ); diff --git a/addons/mail/static/tests/web/chatter_topbar_tests.js b/addons/mail/static/tests/web/chatter_topbar_tests.js index 4b249b29c97..5e3cc53bd1d 100644 --- a/addons/mail/static/tests/web/chatter_topbar_tests.js +++ b/addons/mail/static/tests/web/chatter_topbar_tests.js @@ -1,12 +1,6 @@ /* @odoo-module */ -import { - click, - contains, - nextAnimationFrame, - start, - startServer, -} from "@mail/../tests/helpers/test_utils"; +import { click, contains, start, startServer } from "@mail/../tests/helpers/test_utils"; import { DELAY_FOR_SPINNER } from "@mail/core/web/chatter"; import { makeDeferred } from "@web/../tests/helpers/utils"; @@ -272,13 +266,10 @@ QUnit.test("composer state conserved when clicking on another topbar button", as await contains("button", { text: "Send message" }); await contains("button", { text: "Log note" }); await contains("button[aria-label='Attach files']"); - await click("button", { text: "Log note" }); await contains("button:contains(Log note).active"); await contains("button:contains(Send message).active", { count: 0 }); - - $(`button[aria-label='Attach files']`)[0].click(); - await nextAnimationFrame(); + await click(".o-mail-Chatter-topbar button[aria-label='Attach files']"); await contains("button:contains(Log note).active"); await contains("button:contains(Send message).active", { count: 0 }); }); diff --git a/addons/mail/static/tests/web/follower_list_menu_tests.js b/addons/mail/static/tests/web/follower_list_menu_tests.js index 6e827db877a..0af847f192e 100644 --- a/addons/mail/static/tests/web/follower_list_menu_tests.js +++ b/addons/mail/static/tests/web/follower_list_menu_tests.js @@ -1,12 +1,6 @@ /* @odoo-module */ -import { - click, - contains, - nextAnimationFrame, - start, - startServer, -} from "@mail/../tests/helpers/test_utils"; +import { click, contains, scroll, start, startServer } from "@mail/../tests/helpers/test_utils"; import { patchWithCleanup } from "@web/../tests/helpers/utils"; @@ -226,14 +220,14 @@ QUnit.test("Load 100 followers at once", async () => { const { openFormView } = await start(); await openFormView("res.partner", partnerIds[0]); await contains("button[title='Show Followers']", { text: "210" }); - await click("button[title='Show Followers']"); await contains(".o-mail-Follower", { text: "Mitchell Admin" }); await contains(".o-mail-Follower", { count: 100 }); - $(".o-mail-Followers-dropdown span:contains(Load more)")[0].scrollIntoView(); + await contains(".o-mail-Followers-dropdown span", { text: "Load more" }); + await scroll(".o-mail-Followers-dropdown", "bottom"); await contains(".o-mail-Follower", { count: 200 }); - await nextAnimationFrame(); // give enough time for the Load more button to scroll out of view - $(".o-mail-Followers-dropdown span:contains(Load more)")[0].scrollIntoView(); + await new Promise(setTimeout); // give enough time for the useVisible hook to register load more as hidden + await scroll(".o-mail-Followers-dropdown", "bottom"); await contains(".o-mail-Follower", { count: 210 }); await contains(".o-mail-Followers-dropdown span", { count: 0, text: "Load more" }); }); @@ -267,10 +261,11 @@ QUnit.test("Load 100 recipients at once", async () => { await contains("button[title='Show all recipients']"); await click("button[title='Show all recipients']"); await contains(".o-mail-RecipientList li", { count: 100 }); - $(".o-mail-RecipientList span:contains(Load more)")[0].scrollIntoView(); + await contains(".o-mail-RecipientList span", { text: "Load more" }); + await scroll(".o-mail-RecipientList", "bottom"); await contains(".o-mail-RecipientList li", { count: 200 }); - await nextAnimationFrame(); // give enough time for the Load more button to scroll out of view - $(".o-mail-RecipientList span:contains(Load more)")[0].scrollIntoView(); + await new Promise(setTimeout); // give enough time for the useVisible hook to register load more as hidden + await scroll(".o-mail-RecipientList", "bottom"); await contains(".o-mail-RecipientList li", { count: 210 }); await contains(".o-mail-RecipientList span", { count: 0, text: "Load more" }); }); @@ -324,7 +319,7 @@ QUnit.test( QUnit.test( 'Show "No Followers" dropdown-item if there are no followers and user does not have write access', - async (assert) => { + async () => { const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({}); const { openView } = await start({