diff --git a/addons/im_livechat/static/tests/composer_patch_tests.js b/addons/im_livechat/static/tests/composer_patch_tests.js index 2a1804addc5..912e8b3a221 100644 --- a/addons/im_livechat/static/tests/composer_patch_tests.js +++ b/addons/im_livechat/static/tests/composer_patch_tests.js @@ -83,7 +83,7 @@ QUnit.test('Receives visitor typing status "is typing"', async (assert) => { }); const { env, openDiscuss } = await start(); await openDiscuss(channelId); - assert.strictEqual($(".o-discuss-Typing").text(), ""); + await contains(".o-discuss-Typing", { text: "" }); const channel = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]])[0]; // simulate receive typing notification from livechat visitor "is typing" await afterNextRender(() => diff --git a/addons/mail/static/tests/activity/activity_menu_tests.js b/addons/mail/static/tests/activity/activity_menu_tests.js index d67ccc7d4b3..789cfe38a80 100644 --- a/addons/mail/static/tests/activity/activity_menu_tests.js +++ b/addons/mail/static/tests/activity/activity_menu_tests.js @@ -4,10 +4,11 @@ import { click, contains, start, startServer } from "@mail/../tests/helpers/test QUnit.module("activity menu"); -QUnit.test("should update activities when opening the activity menu", async (assert) => { +QUnit.test("should update activities when opening the activity menu", async () => { const pyEnv = await startServer(); await start(); - assert.strictEqual($(".o-mail-ActivityMenu-counter").text(), ""); + await contains(".o_menu_systray i[aria-label='Activities']"); + await contains(".o-mail-ActivityMenu-counter", { count: 0 }); const partnerId = pyEnv["res.partner"].create({}); pyEnv["mail.activity"].create({ res_id: partnerId, diff --git a/addons/mail/static/tests/activity/activity_tests.js b/addons/mail/static/tests/activity/activity_tests.js index 2a59434dbe2..2749ba13601 100644 --- a/addons/mail/static/tests/activity/activity_tests.js +++ b/addons/mail/static/tests/activity/activity_tests.js @@ -90,7 +90,7 @@ QUnit.test("activity simplest layout", async () => { await contains(".o-mail-Activity-info span", { count: 0, text: "Upload Document" }); }); -QUnit.test("activity with note layout", async (assert) => { +QUnit.test("activity with note layout", async () => { const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({}); pyEnv["mail.activity"].create({ @@ -101,8 +101,7 @@ QUnit.test("activity with note layout", async (assert) => { const { openFormView } = await start(); openFormView("res.partner", partnerId); await contains(".o-mail-Activity"); - await contains(".o-mail-Activity-note"); - assert.strictEqual($(".o-mail-Activity-note").text(), "There is no good or bad note"); + await contains(".o-mail-Activity-note", { text: "There is no good or bad note" }); }); QUnit.test("activity info layout when planned after tomorrow", async () => { diff --git a/addons/mail/static/tests/discuss/core/suggestion_tests.js b/addons/mail/static/tests/discuss/core/suggestion_tests.js index 1e7fba8ad21..4125c461886 100644 --- a/addons/mail/static/tests/discuss/core/suggestion_tests.js +++ b/addons/mail/static/tests/discuss/core/suggestion_tests.js @@ -62,7 +62,7 @@ QUnit.test("command suggestion should only open if command is the first characte await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 }); }); -QUnit.test("Sort partner suggestions by recent chats", async (assert) => { +QUnit.test("Sort partner suggestions by recent chats", async () => { const pyEnv = await startServer(); const [partner_1, partner_2, partner_3] = pyEnv["res.partner"].create([ { name: "User 1" }, @@ -117,9 +117,9 @@ QUnit.test("Sort partner suggestions by recent chats", async (assert) => { await insertText(".o-mail-Composer-input[placeholder='Message #General…']", "@"); await insertText(".o-mail-Composer-input", "User"); await contains(".o-mail-Composer-suggestion strong", { count: 3 }); - assert.strictEqual($(".o-mail-Composer-suggestion").eq(0).text(), "User 2"); - assert.strictEqual($(".o-mail-Composer-suggestion").eq(1).text(), "User 1"); - assert.strictEqual($(".o-mail-Composer-suggestion").eq(2).text(), "User 3"); + await contains(".o-mail-Composer-suggestion:eq(0) strong", { text: "User 2" }); + await contains(".o-mail-Composer-suggestion:eq(1) strong", { text: "User 1" }); + await contains(".o-mail-Composer-suggestion:eq(2) strong", { text: "User 3" }); }); QUnit.test("mention suggestion are shown after deleting a character", async () => { diff --git a/addons/mail/static/tests/discuss/core/web/chat_window_new_message_tests.js b/addons/mail/static/tests/discuss/core/web/chat_window_new_message_tests.js index e0978e42e3d..e01231c40f3 100644 --- a/addons/mail/static/tests/discuss/core/web/chat_window_new_message_tests.js +++ b/addons/mail/static/tests/discuss/core/web/chat_window_new_message_tests.js @@ -7,16 +7,7 @@ import { } from "@mail/core/common/chat_window_service"; import { Command } from "@mail/../tests/helpers/command"; import { patchUiSize } from "@mail/../tests/helpers/patch_ui_size"; -import { - afterNextRender, - click, - contains, - insertText, - start, - startServer, -} from "@mail/../tests/helpers/test_utils"; - -import { makeDeferred } from "@web/../tests/helpers/utils"; +import { click, contains, insertText, start, startServer } from "@mail/../tests/helpers/test_utils"; QUnit.module("chat window: new message"); @@ -87,7 +78,6 @@ QUnit.test( ], }, ]); - const imSearchDef = makeDeferred(); patchUiSize({ width: 1920 }); assert.ok( CHAT_WINDOW_END_GAP_WIDTH * 2 + @@ -96,44 +86,23 @@ QUnit.test( 1920, "should have enough space to open 3 chat windows simultaneously" ); - await start({ - mockRPC(route, args) { - if (args.method === "im_search") { - imSearchDef.resolve(); - } - }, - }); + await start(); // open "new message" chat window await click(".o_menu_systray i[aria-label='Messages']"); await click("button", { text: "New Message" }); - await contains(".o-mail-ChatWindow-name", { text: "New message" }); await contains(".o-mail-ChatWindow", { count: 2 }); + await contains(".o-mail-ChatWindow-name:eq(1)", { text: "New message" }); await contains(".o-mail-ChatWindow .o-discuss-ChannelSelector"); - assert.ok( - Array.from(document.querySelectorAll(".o-mail-ChatWindow")) - .pop() - .textContent.includes("New message") - ); - // open channel-2 await click(".o_menu_systray i[aria-label='Messages']"); await click(".o-mail-NotificationItem-name", { text: "channel-2" }); await contains(".o-mail-ChatWindow", { count: 3 }); - assert.ok( - Array.from(document.querySelectorAll(".o-mail-ChatWindow"))[1].textContent.includes( - "New message" - ) - ); - + await contains(".o-mail-ChatWindow-name:eq(1)", { text: "New message" }); // search for a user in "new message" autocomplete - await afterNextRender(async () => { - await insertText(".o-discuss-ChannelSelector input", "131"); - await imSearchDef; - }); + await insertText(".o-discuss-ChannelSelector input", "131"); await click(".o-discuss-ChannelSelector-suggestion a", { text: "Partner 131" }); await contains(".o-mail-ChatWindow-name", { count: 0, text: "New message" }); - - assert.strictEqual($(".o-mail-ChatWindow-name:eq(1)").text(), "Partner 131"); + await contains(".o-mail-ChatWindow-name:eq(1)", { text: "Partner 131" }); } ); diff --git a/addons/mail/static/tests/discuss_app/discuss_tests.js b/addons/mail/static/tests/discuss_app/discuss_tests.js index d8f437bd9eb..d62dd62192f 100644 --- a/addons/mail/static/tests/discuss_app/discuss_tests.js +++ b/addons/mail/static/tests/discuss_app/discuss_tests.js @@ -833,24 +833,15 @@ QUnit.test("post a simple message", async (assert) => { text: "There are no messages in this conversation.", }); await contains(".o-mail-Message", { count: 0 }); - await contains(".o-mail-Composer-input", { value: "" }); - - // insert some HTML in editable await insertText(".o-mail-Composer-input", "Test"); - await contains(".o-mail-Composer-input", { value: "Test" }); - await click(".o-mail-Composer-send:not(:disabled)"); - await contains(".o-mail-Message"); - assert.verifySteps(["message_post"]); await contains(".o-mail-Composer-input", { value: "" }); - pyEnv["mail.message"].search([], { order: "id DESC" }); - const $message = $(".o-mail-Message"); + await contains(".o-mail-Message-author", { text: "Mitchell Admin" }); await contains(".o-mail-Message-content", { text: "Test" }); - assert.strictEqual($message.find(".o-mail-Message-author").text(), "Mitchell Admin"); - assert.strictEqual($message.find(".o-mail-Message-body").text(), "Test"); + assert.verifySteps(["message_post"]); }); -QUnit.test("starred: unstar all", async (assert) => { +QUnit.test("starred: unstar all", async () => { const pyEnv = await startServer(); pyEnv["mail.message"].create([ { body: "not empty", starred_partner_ids: [pyEnv.currentPartnerId] }, @@ -859,7 +850,7 @@ QUnit.test("starred: unstar all", async (assert) => { const { openDiscuss } = await start(); openDiscuss("mail.box_starred"); await contains(".o-mail-Message", { count: 2 }); - assert.strictEqual($("button:contains(Starred) .badge").text(), "2"); + await contains("button:contains(Starred) .badge", { text: "2" }); await click("button:contains(Unstar all):not(:disabled)"); await contains("button:contains(Starred) .badge", { count: 0 }); await contains(".o-mail-Message", { count: 0 }); diff --git a/addons/mail/static/tests/discuss_app/jump_to_present_tests.js b/addons/mail/static/tests/discuss_app/jump_to_present_tests.js index d71f93ff362..44e8c756700 100644 --- a/addons/mail/static/tests/discuss_app/jump_to_present_tests.js +++ b/addons/mail/static/tests/discuss_app/jump_to_present_tests.js @@ -44,7 +44,7 @@ QUnit.test("Basic jump to present when scrolling to outdated messages", async (a await contains(".o-mail-Thread", { scroll: "bottom" }); }); -QUnit.test("Jump to old reply should prompt jump to presence", async (assert) => { +QUnit.test("Jump to old reply should prompt jump to presence", async () => { // make scroll behavior instantaneous. patchWithCleanup(Element.prototype, { scrollIntoView() { @@ -84,21 +84,12 @@ QUnit.test("Jump to old reply should prompt jump to presence", async (assert) => await contains(".o-mail-Message", { count: 30 }); await click(".o-mail-MessageInReply .cursor-pointer"); await contains(".o-mail-Message", { count: 46 }); - assert.isVisible((await contains(".o-mail-Message:contains(Hello world!):eq(0)"))[0]); - assert.strictEqual( - $(".o-mail-Message-body:contains(Hello world!):eq(0)").text(), - "Hello world!", - "should correctly execute HTML tags in parent message when using 'load around' feature" - ); + await contains(".o-mail-Message-content:eq(0)", { text: "Hello world!" }); await contains(".o-mail-Thread-jumpPresent", { text: "You're viewing older messagesJump to Present", }); await click(".o-mail-Thread-jumpPresent"); - await contains(".o-mail-Thread-jumpPresent", { - count: 0, - text: "You're viewing older messagesJump to Present", - }); - + await contains(".o-mail-Thread-jumpPresent", { count: 0 }); await contains(".o-mail-Message", { count: 30 }); await contains(".o-mail-Thread", { scroll: "bottom" }); }); diff --git a/addons/mail/static/tests/discuss_app/sidebar_tests.js b/addons/mail/static/tests/discuss_app/sidebar_tests.js index 63c86ab0be8..1e398b0352b 100644 --- a/addons/mail/static/tests/discuss_app/sidebar_tests.js +++ b/addons/mail/static/tests/discuss_app/sidebar_tests.js @@ -309,7 +309,7 @@ QUnit.test("sidebar: unpin channel from bus", async () => { await contains(".o-mail-Discuss-threadName", { count: 0, value: "General" }); }); -QUnit.test("chat - channel should count unread message [REQUIRE FOCUS]", async (assert) => { +QUnit.test("chat - channel should count unread message [REQUIRE FOCUS]", async () => { const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({ name: "Demo", @@ -330,9 +330,7 @@ QUnit.test("chat - channel should count unread message [REQUIRE FOCUS]", async ( }); const { openDiscuss } = await start(); openDiscuss(); - await contains(".o-discuss-badge"); - assert.strictEqual($(".o-discuss-badge").text(), "1"); - + await contains(".o-discuss-badge", { text: "1" }); await click(".o-mail-DiscussSidebarChannel span", { text: "Demo" }); await contains(".o-discuss-badge", { count: 0 }); }); diff --git a/addons/mail/static/tests/message/message_tests.js b/addons/mail/static/tests/message/message_tests.js index cf2fbe9840b..085746ed678 100644 --- a/addons/mail/static/tests/message/message_tests.js +++ b/addons/mail/static/tests/message/message_tests.js @@ -372,7 +372,7 @@ QUnit.test("Other messages are grayed out when replying to another one", async ( }); }); -QUnit.test("Parent message body is displayed on replies", async (assert) => { +QUnit.test("Parent message body is displayed on replies", async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ channel_type: "channel", @@ -388,13 +388,12 @@ QUnit.test("Parent message body is displayed on replies", async (assert) => { await click(".o-mail-Message [title='Reply']"); await insertText(".o-mail-Composer-input", "FooBarFoo"); await click(".o-mail-Composer-send:not(:disabled)"); - await contains(".o-mail-MessageInReply-message"); - assert.ok($(".o-mail-MessageInReply-message")[0].innerText, "Hello world"); + await contains(".o-mail-MessageInReply-message", { text: "Hello world" }); }); QUnit.test( "Updating the parent message of a reply also updates the visual of the reply", - async (assert) => { + async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ channel_type: "channel", @@ -421,7 +420,6 @@ QUnit.test( insertText(input, "Goodbye World", { replace: true }); triggerHotkey("Enter", false); await contains(".o-mail-MessageInReply-message", { text: "Goodbye World" }); - assert.strictEqual($(".o-mail-MessageInReply-message")[0].innerText, "Goodbye World"); } ); @@ -765,7 +763,7 @@ QUnit.test("toggle_star message", async (assert) => { QUnit.test( "Name of message author is only displayed in chat window for partners others than the current user", - async (assert) => { + async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ channel_type: "channel" }); const partnerId = pyEnv["res.partner"].create({ name: "Not the current user" }); @@ -785,8 +783,7 @@ QUnit.test( await start(); await click(".o_menu_systray i[aria-label='Messages']"); await click(".o-mail-NotificationItem"); - await contains(".o-mail-Message-author"); - assert.equal($(".o-mail-Message-author").text(), "Not the current user"); + await contains(".o-mail-Message-author", { text: "Not the current user" }); } ); @@ -1047,7 +1044,7 @@ QUnit.test( } ); -QUnit.test("allow attachment delete on authored message", async (assert) => { +QUnit.test("allow attachment delete on authored message", async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ name: "test" }); pyEnv["mail.message"].create({ @@ -1071,13 +1068,8 @@ QUnit.test("allow attachment delete on authored message", async (assert) => { }); const { openDiscuss } = await start(); openDiscuss(channelId); - await contains(".o-mail-AttachmentImage"); - await contains(".o-mail-AttachmentImage div[title='Remove']"); - await click(".o-mail-AttachmentImage div[title='Remove']"); - await contains(".modal-dialog"); - assert.strictEqual($(".modal-body").text(), 'Do you really want to delete "BLAH"?'); - + await contains(".modal-dialog .modal-body", { text: 'Do you really want to delete "BLAH"?' }); await click(".modal-footer .btn-primary"); await contains(".o-mail-AttachmentCard", { count: 0 }); }); diff --git a/addons/mail/static/tests/messaging_menu/messaging_menu_tests.js b/addons/mail/static/tests/messaging_menu/messaging_menu_tests.js index c7663ce34c3..5703cdafe11 100644 --- a/addons/mail/static/tests/messaging_menu/messaging_menu_tests.js +++ b/addons/mail/static/tests/messaging_menu/messaging_menu_tests.js @@ -37,7 +37,7 @@ QUnit.test("messaging menu should have topbar buttons", async () => { await contains("button:contains(Channels).fw-bolder", { count: 0 }); }); -QUnit.test("counter is taking into account failure notification", async (assert) => { +QUnit.test("counter is taking into account failure notification", async () => { patchBrowserNotification("denied"); const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({}); @@ -58,15 +58,14 @@ QUnit.test("counter is taking into account failure notification", async (assert) notification_type: "email", }); await start(); - await contains(".o-mail-MessagingMenu-counter"); - assert.strictEqual($(".o-mail-MessagingMenu-counter").text(), "1"); + await contains(".o-mail-MessagingMenu-counter", { text: "1" }); }); QUnit.test("rendering with OdooBot has a request (default)", async (assert) => { patchBrowserNotification("default"); await start(); await contains(".o-mail-MessagingMenu-counter"); - assert.strictEqual($(".o-mail-MessagingMenu-counter").text(), "1"); + await contains(".o-mail-MessagingMenu-counter", { text: "1" }); await click(".o_menu_systray i[aria-label='Messages']"); await contains(".o-mail-NotificationItem"); assert.ok( @@ -292,8 +291,8 @@ QUnit.test( await start(); await click(".o_menu_systray i[aria-label='Messages']"); await contains(".o-mail-NotificationItem", { count: 2 }); - assert.ok($(".o-mail-NotificationItem:eq(0)").text().includes("Company")); - assert.ok($(".o-mail-NotificationItem:eq(1)").text().includes("Partner")); + await contains(".o-mail-NotificationItem-name:eq(0)", { text: "Company" }); + await contains(".o-mail-NotificationItem-name:eq(1)", { text: "Partner" }); } ); @@ -818,46 +817,43 @@ QUnit.test( } ); -QUnit.test( - "single preview for channel if it has unread and needaction messages", - async (assert) => { - const pyEnv = await startServer(); - const partnerId = pyEnv["res.partner"].create({ name: "Partner1" }); - const channelId = pyEnv["discuss.channel"].create({ - name: "Test", - channel_member_ids: [ - Command.create({ message_unread_counter: 2, partner_id: pyEnv.currentPartnerId }), - ], - }); - const messageId = pyEnv["mail.message"].create({ - author_id: partnerId, - body: "Message with needaction", - model: "discuss.channel", - needaction: true, - needaction_partner_ids: [pyEnv.currentPartnerId], - res_id: channelId, - }); - pyEnv["mail.notification"].create({ - mail_message_id: messageId, - notification_status: "sent", - notification_type: "inbox", - res_partner_id: pyEnv.currentPartnerId, - }); - pyEnv["mail.message"].create({ - author_id: partnerId, - body: "Most-recent Message", - model: "discuss.channel", - res_id: channelId, - }); +QUnit.test("single preview for channel if it has unread and needaction messages", async () => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ name: "Partner1" }); + const channelId = pyEnv["discuss.channel"].create({ + name: "Test", + channel_member_ids: [ + Command.create({ message_unread_counter: 2, partner_id: pyEnv.currentPartnerId }), + ], + }); + const messageId = pyEnv["mail.message"].create({ + author_id: partnerId, + body: "Message with needaction", + model: "discuss.channel", + needaction: true, + needaction_partner_ids: [pyEnv.currentPartnerId], + res_id: channelId, + }); + pyEnv["mail.notification"].create({ + mail_message_id: messageId, + notification_status: "sent", + notification_type: "inbox", + res_partner_id: pyEnv.currentPartnerId, + }); + pyEnv["mail.message"].create({ + author_id: partnerId, + body: "Most-recent Message", + model: "discuss.channel", + res_id: channelId, + }); - await start(); - await click(".o_menu_systray i[aria-label='Messages']"); - await contains(".o-mail-NotificationItem"); - assert.ok($(".o-mail-NotificationItem").text().includes("Test")); - assert.ok($(".o-mail-NotificationItem .badge").text().includes("1")); - assert.ok($(".o-mail-NotificationItem").text().includes("Message with needaction")); - } -); + await start(); + await click(".o_menu_systray i[aria-label='Messages']"); + await contains(".o-mail-NotificationItem"); + await contains(".o-mail-NotificationItem-name", { text: "Test" }); + await contains(".o-mail-NotificationItem .badge", { text: "1" }); + await contains(".o-mail-NotificationItem-text", { text: "Partner1: Message with needaction" }); +}); QUnit.test("chat should show unread counter on receiving new messages", async () => { // unread and needaction are conceptually the same in chat diff --git a/addons/mail/static/tests/messaging_menu/notification_tests.js b/addons/mail/static/tests/messaging_menu/notification_tests.js index bafcc2449e4..9dc9c531f4f 100644 --- a/addons/mail/static/tests/messaging_menu/notification_tests.js +++ b/addons/mail/static/tests/messaging_menu/notification_tests.js @@ -236,33 +236,30 @@ QUnit.test("non-failure notifications are ignored", async () => { await contains(".o-mail-NotificationItem", { count: 0 }); }); -QUnit.test( - "marked as read thread notifications are ordered by last message date", - async (assert) => { - const pyEnv = await startServer(); - const [channelId_1, channelId_2] = pyEnv["discuss.channel"].create([ - { name: "Channel 2019" }, - { name: "Channel 2020" }, - ]); - pyEnv["mail.message"].create([ - { - date: "2019-01-01 00:00:00", - model: "discuss.channel", - res_id: channelId_1, - }, - { - date: "2020-01-01 00:00:00", - model: "discuss.channel", - res_id: channelId_2, - }, - ]); - await start(); - await click(".o_menu_systray i[aria-label='Messages']"); - await contains(".o-mail-NotificationItem-name", { count: 2 }); - assert.strictEqual($(".o-mail-NotificationItem-name:eq(0)").text(), "Channel 2020"); - assert.strictEqual($(".o-mail-NotificationItem-name:eq(1)").text(), "Channel 2019"); - } -); +QUnit.test("marked as read thread notifications are ordered by last message date", async () => { + const pyEnv = await startServer(); + const [channelId_1, channelId_2] = pyEnv["discuss.channel"].create([ + { name: "Channel 2019" }, + { name: "Channel 2020" }, + ]); + pyEnv["mail.message"].create([ + { + date: "2019-01-01 00:00:00", + model: "discuss.channel", + res_id: channelId_1, + }, + { + date: "2020-01-01 00:00:00", + model: "discuss.channel", + res_id: channelId_2, + }, + ]); + await start(); + await click(".o_menu_systray i[aria-label='Messages']"); + await contains(".o-mail-NotificationItem-name", { count: 2 }); + await contains(".o-mail-NotificationItem-name:eq(0)", { text: "Channel 2020" }); + await contains(".o-mail-NotificationItem-name:eq(1)", { text: "Channel 2019" }); +}); QUnit.test("thread notifications are re-ordered on receiving a new message", async () => { const pyEnv = await startServer(); diff --git a/addons/mail/static/tests/thread/thread_tests.js b/addons/mail/static/tests/thread/thread_tests.js index b052bd06ea2..54e31b9c0da 100644 --- a/addons/mail/static/tests/thread/thread_tests.js +++ b/addons/mail/static/tests/thread/thread_tests.js @@ -1023,7 +1023,7 @@ QUnit.test("New message separator not appearing after showing composer on thread await contains(".o-mail-Thread-newMessage", { count: 0 }); }); -QUnit.test("Transient messages are added at the end of the thread", async (assert) => { +QUnit.test("Transient messages are added at the end of the thread", async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ name: "General" }); const { openDiscuss } = await start(); @@ -1034,6 +1034,6 @@ QUnit.test("Transient messages are added at the end of the thread", async (asser await insertText(".o-mail-Composer-input", "/help"); await click(".o-mail-Composer-send:not(:disabled)"); await contains(".o-mail-Message", { count: 2 }); - const lastMessage = document.querySelectorAll(".o-mail-Message")[1]; - assert.ok(lastMessage.innerText.includes("You are in channel #General")); + await contains(".o-mail-Message-author:eq(0)", { text: "Mitchell Admin" }); + await contains(".o-mail-Message-author:eq(1)", { text: "OdooBot" }); }); diff --git a/addons/mail/static/tests/web/chatter_tests.js b/addons/mail/static/tests/web/chatter_tests.js index 4bc262bca6a..87fa72f0fd0 100644 --- a/addons/mail/static/tests/web/chatter_tests.js +++ b/addons/mail/static/tests/web/chatter_tests.js @@ -311,7 +311,7 @@ QUnit.test("base rendering when chatter has no attachment", async (assert) => { await contains(".o-mail-Message", { count: 30 }); }); -QUnit.test("base rendering when chatter has no record", async (assert) => { +QUnit.test("base rendering when chatter has no record", async () => { const { openView } = await start(); openView({ res_model: "res.partner", @@ -322,9 +322,8 @@ QUnit.test("base rendering when chatter has no record", async (assert) => { await contains(".o-mail-AttachmentBox", { count: 0 }); await contains(".o-mail-Chatter .o-mail-Thread"); await contains(".o-mail-Message"); - assert.strictEqual($(".o-mail-Message-body").text(), "Creating a new record..."); + await contains(".o-mail-Message-body", { text: "Creating a new record..." }); await contains("button", { count: 0, text: "Load More" }); - await contains(".o-mail-Message-actions"); await contains(".o-mail-Message-actions i", { 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 b9ebe1c70e4..4b249b29c97 100644 --- a/addons/mail/static/tests/web/chatter_topbar_tests.js +++ b/addons/mail/static/tests/web/chatter_topbar_tests.js @@ -30,7 +30,7 @@ QUnit.test("base rendering", async () => { await contains(".o-mail-Followers"); }); -QUnit.test("rendering with multiple partner followers", async (assert) => { +QUnit.test("rendering with multiple partner followers", async () => { const pyEnv = await startServer(); const [partnerId_1, partnerId_2, partnerId_3] = pyEnv["res.partner"].create([ { name: "Eden Hazard" }, @@ -55,15 +55,13 @@ QUnit.test("rendering with multiple partner followers", async (assert) => { res_model: "res.partner", views: [[false, "form"]], }); - await contains(".o-mail-Followers"); await contains(".o-mail-Followers-button"); - await click(".o-mail-Followers-button"); await contains(".o-mail-Followers-dropdown"); await contains(".o-mail-Follower", { count: 2 }); - assert.strictEqual($(".o-mail-Follower:eq(0)").text().trim(), "Jean Michang"); - assert.strictEqual($(".o-mail-Follower:eq(1)").text().trim(), "Eden Hazard"); + await contains(".o-mail-Follower:eq(0)", { text: "Jean Michang" }); + await contains(".o-mail-Follower:eq(1)", { text: "Eden Hazard" }); }); QUnit.test("log note toggling", async () => { diff --git a/addons/mail/static/tests/web/fields/m2x_avatar_user_tests.js b/addons/mail/static/tests/web/fields/m2x_avatar_user_tests.js index f6afc1f1542..c7245a72e92 100644 --- a/addons/mail/static/tests/web/fields/m2x_avatar_user_tests.js +++ b/addons/mail/static/tests/web/fields/m2x_avatar_user_tests.js @@ -1,16 +1,13 @@ /* @odoo-module */ -import { contains, start, startServer } from "@mail/../tests/helpers/test_utils"; +import { click, contains, start, startServer } from "@mail/../tests/helpers/test_utils"; import { - click, patchWithCleanup, triggerHotkey, triggerEvent, getNodesTextContent, } from "@web/../tests/helpers/utils"; import { registry } from "@web/core/registry"; -import { session } from "@web/session"; -import { nextTick } from "@web/../tests/legacy/helpers/test_utils"; import { popoverService } from "@web/core/popover/popover_service"; import { tooltipService } from "@web/core/tooltip/tooltip_service"; import { browser } from "@web/core/browser/browser"; @@ -47,7 +44,7 @@ const fakeImStatusService = { QUnit.module("M2XAvatarUser"); -QUnit.test("many2many_avatar_user in kanban view", async (assert) => { +QUnit.test("many2many_avatar_user in kanban view", async () => { const pyEnv = await startServer(); const userIds = pyEnv["res.users"].create([ { name: "Mario" }, @@ -82,249 +79,184 @@ QUnit.test("many2many_avatar_user in kanban view", async (assert) => { res_model: "m2x.avatar.user", views: [[false, "kanban"]], }); - await contains(".o_kanban_record .o_field_many2many_avatar_user .o_m2m_avatar_empty"); - assert.strictEqual( - $( - ".o_kanban_record .o_field_many2many_avatar_user .o_m2m_avatar_empty" - )[0].innerText.trim(), - "+2" - ); - await click( - document.querySelector( - ".o_kanban_record .o_field_many2many_avatar_user .o_m2m_avatar_empty" - ) - ); - const tags = document.querySelectorAll(".o_popover > .o_field_tags > .o_tag"); - assert.strictEqual(tags.length, 4); - assert.strictEqual(tags[0].innerText.trim(), "Tapu"); - assert.strictEqual(tags[1].innerText.trim(), "Luigi"); - assert.strictEqual(tags[2].innerText.trim(), "Yoshi"); - assert.strictEqual(tags[3].innerText.trim(), "Mario"); + await click(".o_kanban_record .o_field_many2many_avatar_user .o_m2m_avatar_empty", { + text: "+2", + }); + await click(".o_kanban_record .o_field_many2many_avatar_user .o_m2m_avatar_empty"); + await contains(".o_popover > .o_field_tags > .o_tag", { count: 4 }); + await contains(".o_popover > .o_field_tags > .o_tag:eq(0)", { text: "Tapu" }); + await contains(".o_popover > .o_field_tags > .o_tag:eq(1)", { text: "Luigi" }); + await contains(".o_popover > .o_field_tags > .o_tag:eq(2)", { text: "Yoshi" }); + await contains(".o_popover > .o_field_tags > .o_tag:eq(3)", { text: "Mario" }); }); -QUnit.test( - 'many2one_avatar_user widget edited by the smart action "Assign to..."', - async (assert) => { - const pyEnv = await startServer(); - const [userId_1] = pyEnv["res.users"].create([ - { name: "Mario" }, - { name: "Luigi" }, - { name: "Yoshi" }, - ]); - const avatarUserId_1 = pyEnv["m2x.avatar.user"].create({ user_id: userId_1 }); - const views = { - "m2x.avatar.user,false,form": - '
', - }; - const { openView } = await start({ serverData: { views } }); - await openView({ - res_id: avatarUserId_1, - type: "ir.actions.act_window", - target: "current", - res_model: "m2x.avatar.user", - view_mode: "form", - views: [[false, "form"]], - }); - await contains(".o_field_many2one_avatar_user input", { value: "Mario" }); +QUnit.test('many2one_avatar_user widget edited by the smart action "Assign to..."', async () => { + const pyEnv = await startServer(); + const [userId_1] = pyEnv["res.users"].create([ + { name: "Mario" }, + { name: "Luigi" }, + { name: "Yoshi" }, + ]); + const avatarUserId_1 = pyEnv["m2x.avatar.user"].create({ user_id: userId_1 }); + const views = { + "m2x.avatar.user,false,form": + '', + }; + const { openView } = await start({ serverData: { views } }); + await openView({ + res_id: avatarUserId_1, + type: "ir.actions.act_window", + target: "current", + res_model: "m2x.avatar.user", + view_mode: "form", + views: [[false, "form"]], + }); + await contains(".o_field_many2one_avatar_user input", { value: "Mario" }); + triggerHotkey("control+k"); + await click(".o_command", { text: "Assign to ...ALT + I" }); + await contains(".o_command", { count: 5 }); + await contains(".o_command:eq(0)", { text: "Your Company, Mitchell Admin" }); + await contains(".o_command:eq(1)", { text: "Public user" }); + await contains(".o_command:eq(2)", { text: "Mario" }); + await contains(".o_command:eq(3)", { text: "Luigi" }); + await contains(".o_command:eq(4)", { text: "Yoshi" }); + await click("#o_command_3"); + await contains(".o_field_many2one_avatar_user input", { value: "Luigi" }); +}); - triggerHotkey("control+k"); - await nextTick(); - const idx = [...document.querySelectorAll(".o_command")] - .map((el) => el.textContent) - .indexOf("Assign to ...ALT + I"); - assert.ok(idx >= 0); +QUnit.test('many2one_avatar_user widget edited by the smart action "Assign to me"', async () => { + const pyEnv = await startServer(); + const userId_1 = pyEnv["res.users"].create({ name: "Mario" }); + const avatarUserId_1 = pyEnv["m2x.avatar.user"].create({ user_id: userId_1 }); + const views = { + "m2x.avatar.user,false,form": + '', + }; + const { openView } = await start({ serverData: { views } }); + await openView({ + res_id: avatarUserId_1, + type: "ir.actions.act_window", + target: "current", + res_model: "m2x.avatar.user", + view_mode: "form", + views: [[false, "form"]], + }); + await contains(".o_field_many2one_avatar_user input", { value: "Mario" }); + triggerHotkey("control+k"); + await contains(".o_command", { text: "Assign/Unassign to meALT + SHIFT + I" }); + // Assign me + triggerHotkey("alt+shift+i"); + await contains(".o_field_many2one_avatar_user input", { + value: "Mitchell", // should be "Mitchell Admin" but session is not sync with currentUser + }); + // Unassign me + triggerHotkey("control+k"); + await click(".o_command", { text: "Assign/Unassign to meALT + SHIFT + I" }); + await contains(".o_field_many2one_avatar_user input", { value: "" }); +}); - await click([...document.querySelectorAll(".o_command")][idx]); - await nextTick(); - assert.deepEqual( - [...document.querySelectorAll(".o_command")].map((el) => el.textContent), - ["Your Company, Mitchell Admin", "Public user", "Mario", "Luigi", "Yoshi"] - ); - await click(document.body, "#o_command_3"); - await nextTick(); - await contains(".o_field_many2one_avatar_user input", { value: "Luigi" }); - } -); +QUnit.test('many2many_avatar_user widget edited by the smart action "Assign to..."', async () => { + const pyEnv = await startServer(); + const [userId_1, userId_2] = pyEnv["res.users"].create([ + { name: "Mario" }, + { name: "Yoshi" }, + { name: "Luigi" }, + ]); + const m2xAvatarUserId1 = pyEnv["m2x.avatar.user"].create({ + user_ids: [userId_1, userId_2], + }); + const views = { + "m2x.avatar.user,false,form": + '', + }; + const { openView } = await start({ serverData: { views } }); + await openView({ + res_id: m2xAvatarUserId1, + type: "ir.actions.act_window", + target: "current", + res_model: "m2x.avatar.user", + view_mode: "form", + views: [[false, "form"]], + }); + await contains(".o_tag_badge_text", { count: 2 }); + await contains(".o_tag_badge_text:eq(0)", { text: "Mario" }); + await contains(".o_tag_badge_text:eq(1)", { text: "Yoshi" }); + triggerHotkey("control+k"); + await contains(".o_command", { text: "Assign to ...ALT + I" }); + triggerHotkey("alt+i"); + await contains(".o_command", { count: 3 }); + await contains(".o_command:eq(0)", { text: "Your Company, Mitchell Admin" }); + await contains(".o_command:eq(1)", { text: "Public user" }); + await contains(".o_command:eq(2)", { text: "Luigi" }); + await click("#o_command_2"); + await contains(".o_tag_badge_text", { count: 3 }); + await contains(".o_tag_badge_text:eq(0)", { text: "Mario" }); + await contains(".o_tag_badge_text:eq(1)", { text: "Yoshi" }); + await contains(".o_tag_badge_text:eq(2)", { text: "Luigi" }); +}); -QUnit.test( - 'many2one_avatar_user widget edited by the smart action "Assign to me"', - async (assert) => { - const pyEnv = await startServer(); - const [userId_1, userId_2] = pyEnv["res.users"].create([ - { name: "Mario" }, - { name: "Luigi" }, - ]); - const avatarUserId_1 = pyEnv["m2x.avatar.user"].create({ user_id: userId_1 }); - patchWithCleanup(session, { uid: userId_2, name: "Luigi" }); - const views = { - "m2x.avatar.user,false,form": - '', - }; - const { openView } = await start({ serverData: { views } }); - await openView({ - res_id: avatarUserId_1, - type: "ir.actions.act_window", - target: "current", - res_model: "m2x.avatar.user", - view_mode: "form", - views: [[false, "form"]], - }); - await contains(".o_field_many2one_avatar_user input", { value: "Mario" }); - triggerHotkey("control+k"); - await nextTick(); - const idx = [...document.querySelectorAll(".o_command")] - .map((el) => el.textContent) - .indexOf("Assign/Unassign to meALT + SHIFT + I"); - assert.ok(idx >= 0); +QUnit.test('many2many_avatar_user widget edited by the smart action "Assign to me"', async () => { + const pyEnv = await startServer(); + const [userId_1, userId_2] = pyEnv["res.users"].create([{ name: "Mario" }, { name: "Yoshi" }]); + const m2xAvatarUserId1 = pyEnv["m2x.avatar.user"].create({ + user_ids: [userId_1, userId_2], + }); + const views = { + "m2x.avatar.user,false,form": + '', + }; + const { openView } = await start({ serverData: { views } }); + await openView({ + res_id: m2xAvatarUserId1, + type: "ir.actions.act_window", + target: "current", + res_model: "m2x.avatar.user", + view_mode: "form", + views: [[false, "form"]], + }); + await contains(".o_tag_badge_text", { count: 2 }); + await contains(".o_tag_badge_text:eq(0)", { text: "Mario" }); + await contains(".o_tag_badge_text:eq(1)", { text: "Yoshi" }); + triggerHotkey("control+k"); + await contains(".o_command", { text: "Assign/Unassign to meALT + SHIFT + I" }); + // Assign me + triggerHotkey("alt+shift+i"); + await contains(".o_tag_badge_text", { count: 3 }); + await contains(".o_tag_badge_text:eq(0)", { text: "Mario" }); + await contains(".o_tag_badge_text:eq(1)", { text: "Yoshi" }); + await contains(".o_tag_badge_text:eq(2)", { text: "Your Company, Mitchell Admin" }); + // Unassign me + triggerHotkey("control+k"); + await contains(".o_command", { text: "Assign/Unassign to meALT + SHIFT + I" }); + triggerHotkey("alt+shift+i"); + await contains(".o_tag_badge_text", { count: 2 }); + await contains(".o_tag_badge_text:eq(0)", { text: "Mario" }); + await contains(".o_tag_badge_text:eq(1)", { text: "Yoshi" }); +}); - // Assign me (Luigi) - triggerHotkey("alt+shift+i"); - await nextTick(); - await contains(".o_field_many2one_avatar_user input", { value: "Luigi" }); +QUnit.test("avatar_user widget displays the appropriate user image in list view", async () => { + const pyEnv = await startServer(); + const userId = pyEnv["res.users"].create({ name: "Mario" }); + const avatarUserId = pyEnv["m2x.avatar.user"].create({ user_id: userId }); + const views = { + "m2x.avatar.user,false,list": + '