From 315263f1b3d05ab60db2210f065354a3948f4879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Mon, 4 Sep 2023 13:16:29 +0200 Subject: [PATCH] [REF] mail: tests: remove `waitUntilMessagesLoaded` of `openDiscuss` This is no longer used since tests properly await what they require. Part-of: odoo/odoo#134025 --- .../tests/chat_window/chat_window_tests.js | 4 +-- .../static/tests/discuss_app/discuss_tests.js | 4 +-- .../tests/gif_picker/gif_picker_test.js | 4 +-- .../mail/static/tests/helpers/test_utils.js | 27 +------------------ .../mail/static/tests/mobile/mobile_tests.js | 2 +- .../mail/static/tests/thread/thread_tests.js | 2 +- 6 files changed, 9 insertions(+), 34 deletions(-) diff --git a/addons/mail/static/tests/chat_window/chat_window_tests.js b/addons/mail/static/tests/chat_window/chat_window_tests.js index 6236ba2feab..e010c4ec51e 100644 --- a/addons/mail/static/tests/chat_window/chat_window_tests.js +++ b/addons/mail/static/tests/chat_window/chat_window_tests.js @@ -1005,7 +1005,7 @@ QUnit.test("chat window: scroll conservation on toggle discuss", async () => { await contains(".o-mail-Message", { count: 31 }); await contains(".o-mail-ChatWindow .o-mail-Thread", { scroll: "bottom" }); await scroll(".o-mail-ChatWindow .o-mail-Thread", 142); - openDiscuss(null, { waitUntilMessagesLoaded: false }); + openDiscuss(null); await contains(".o-mail-ChatWindow", { count: 0 }); openView({ res_id: channelId, @@ -1065,7 +1065,7 @@ QUnit.test( await scroll(".o-mail-ChatWindow .o-mail-Thread", 142); // fold chat window await click(".o-mail-ChatWindow-command[title='Fold']"); - openDiscuss(null, { waitUntilMessagesLoaded: false }); + openDiscuss(null); await contains(".o-mail-ChatWindow", { count: 0 }); openView({ res_id: channelId, diff --git a/addons/mail/static/tests/discuss_app/discuss_tests.js b/addons/mail/static/tests/discuss_app/discuss_tests.js index d62dd62192f..592cb9a7b5d 100644 --- a/addons/mail/static/tests/discuss_app/discuss_tests.js +++ b/addons/mail/static/tests/discuss_app/discuss_tests.js @@ -1471,7 +1471,7 @@ QUnit.test("failure on loading messages should display error", async () => { } }, }); - openDiscuss(channelId, { waitUntilMessagesLoaded: false }); + openDiscuss(channelId); await contains(".o-mail-Thread-error", { text: "An error occurred while fetching messages.", }); @@ -1490,7 +1490,7 @@ QUnit.test("failure on loading messages should prompt retry button", async () => } }, }); - openDiscuss(channelId, { waitUntilMessagesLoaded: false }); + openDiscuss(channelId); await contains("button", { text: "Click here to retry" }); }); diff --git a/addons/mail/static/tests/gif_picker/gif_picker_test.js b/addons/mail/static/tests/gif_picker/gif_picker_test.js index ce8b022970b..0af8281f75a 100644 --- a/addons/mail/static/tests/gif_picker/gif_picker_test.js +++ b/addons/mail/static/tests/gif_picker/gif_picker_test.js @@ -194,7 +194,7 @@ QUnit.test( const channelId = pyEnv["discuss.channel"].create({ name: "General" }); patchUiSize({ size: SIZES.SM }); const { openDiscuss } = await start(); - openDiscuss(channelId, { waitUntilMessagesLoaded: false }); + openDiscuss(channelId); await click("span", { text: "General" }); await click("button[aria-label='GIFs']"); await contains(".popover .o-discuss-GifPicker", { count: 0 }); @@ -202,7 +202,7 @@ QUnit.test( } ); -QUnit.test("Searching for a GIF with a failling RPC should display an error", async (assert) => { +QUnit.test("Searching for a GIF with a failling RPC should display an error", async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ name: "" }); const { openDiscuss } = await start({ diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js index 78e214d1e2b..1947fb23b73 100644 --- a/addons/mail/static/tests/helpers/test_utils.js +++ b/addons/mail/static/tests/helpers/test_utils.js @@ -78,7 +78,7 @@ async function nextTick() { //------------------------------------------------------------------------------ function getOpenDiscuss(webClient, { context = {}, params = {}, ...props } = {}) { - return async function openDiscuss(pActiveId, { waitUntilMessagesLoaded = true } = {}) { + return async function openDiscuss(pActiveId) { const actionOpenDiscuss = { // hardcoded actionId, required for discuss_container props validation. id: 104, @@ -101,31 +101,6 @@ function getOpenDiscuss(webClient, { context = {}, params = {}, ...props } = {}) id: threadId, }) ); - if (waitUntilMessagesLoaded) { - const messagesLoadedPromise = makeDeferred(); - const store = webClient.env.services["mail.store"]; - const thread = store.Thread.records[store.discuss.threadLocalId]; - if (thread.isLoaded) { - messagesLoadedPromise.resolve(); - } - let loadMessageRoute = `/mail/${threadId}/messages`; - if (Number.isInteger(threadId)) { - loadMessageRoute = "/discuss/channel/messages"; - } - registry.category("mock_server_callbacks").add( - loadMessageRoute, - ({ channel_id: channelId = threadId }) => { - if (channelId === threadId) { - messagesLoadedPromise.resolve(); - } - }, - { force: true } - ); - return afterNextRender(async () => { - await doAction(webClient, actionOpenDiscuss, { props }); - await messagesLoadedPromise; - }); - } return afterNextRender(() => doAction(webClient, actionOpenDiscuss, { props })); }; } diff --git a/addons/mail/static/tests/mobile/mobile_tests.js b/addons/mail/static/tests/mobile/mobile_tests.js index 901bdf6ec87..856d8ab7a4d 100644 --- a/addons/mail/static/tests/mobile/mobile_tests.js +++ b/addons/mail/static/tests/mobile/mobile_tests.js @@ -11,7 +11,7 @@ QUnit.test("auto-select 'Inbox' when discuss had channel as active thread", asyn patchUiSize({ height: 360, width: 640 }); const { openDiscuss } = await start(); - openDiscuss(channelId, { waitUntilMessagesLoaded: false }); + openDiscuss(channelId); await contains(".o-mail-MessagingMenu-tab.text-primary.fw-bolder", { text: "Channel" }); await click("button", { text: "Mailboxes" }); diff --git a/addons/mail/static/tests/thread/thread_tests.js b/addons/mail/static/tests/thread/thread_tests.js index 54e31b9c0da..2c74fe4e447 100644 --- a/addons/mail/static/tests/thread/thread_tests.js +++ b/addons/mail/static/tests/thread/thread_tests.js @@ -994,7 +994,7 @@ QUnit.test("can be marked as read while loading", async function () { } }, }); - openDiscuss(undefined, { waitUntilMessagesLoaded: false }); + openDiscuss(undefined); await contains(".o-discuss-badge", { text: "1" }); await click(".o-mail-DiscussSidebarChannel span", { text: "Demo" }); await afterNextRender(loadDeferred.resolve);