Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
puppeteer: Fix flaky wait for narrow change after sending a message.
Aman Agrawaldae2a68ad96c
diff --git a/web/e2e-tests/compose.test.ts b/web/e2e-tests/compose.test.tsindex 02adf09532b..658199f5ce2 100644--- a/web/e2e-tests/compose.test.ts+++ b/web/e2e-tests/compose.test.ts@@ -134,11 +134,15 @@ async function test_narrow_to_private_messages_with_cordelia(page: Page): Promisasync function test_send_multirecipient_pm_from_cordelia_pm_narrow(page: Page): Promise<void> {const recipients = ["[email protected]", "[email protected]"];const multiple_recipients_pm = "A direct message group to check spaces";- await common.send_message(page, "private", {- recipient: recipients.join(", "),- outside_view: true,- content: multiple_recipients_pm,- });+ await common.send_message(+ page,+ "private",+ {+ recipient: recipients.join(", "),+ content: multiple_recipients_pm,+ },+ false,+ );// Go back to the combined feed view and make sure all messages are loaded.await page.click("#left-sidebar-navigation-list .top_left_all_messages");diff --git a/web/e2e-tests/drafts.test.ts b/web/e2e-tests/drafts.test.tsindex 4f2ee69cd1b..a3f101beb02 100644--- a/web/e2e-tests/drafts.test.ts+++ b/web/e2e-tests/drafts.test.ts@@ -306,7 +306,6 @@ async function drafts_test(page: Page): Promise<void> {await common.send_message(page, "private", {recipient: "[email protected], [email protected]",content: "howdy doo",- outside_view: true,});await create_private_message_draft(page);// Close and try restoring it by opening the composebox again.diff --git a/web/e2e-tests/edit.test.ts b/web/e2e-tests/edit.test.tsindex ddcbde2ef33..70f385449d0 100644--- a/web/e2e-tests/edit.test.ts+++ b/web/e2e-tests/edit.test.ts@@ -38,7 +38,7 @@ async function test_stream_message_edit(page: Page): Promise<void> {await edit_stream_message(page, "test edited");- const message_list_id = await common.get_current_msg_list_id(page, true);+ const message_list_id = await common.get_current_msg_list_id(page, false);await common.check_messages_sent(page, message_list_id, [["Verona > edits", ["test edited"]]]);}@@ -47,11 +47,16 @@ async function test_edit_message_with_slash_me(page: Page): Promise<void> {"messagebox",)}])[last()]`;- await common.send_message(page, "stream", {- stream_name: "Verona",- topic: "edits",- content: "/me test editing a message with me",- });+ await common.send_message(+ page,+ "stream",+ {+ stream_name: "Verona",+ topic: "edits",+ content: "/me test editing a message with me",+ },+ false,+ );await page.waitForSelector(`xpath/${last_message_xpath}//*[${common.has_class_x("status-message",@@ -88,7 +93,7 @@ async function test_edit_private_message(page: Page): Promise<void> {await page.click(".message_edit_save");await common.wait_for_fully_processed_message(page, "test edited pm");- const message_list_id = await common.get_current_msg_list_id(page, true);+ const message_list_id = await common.get_current_msg_list_id(page, false);await common.check_messages_sent(page, message_list_id, [["You and Cordelia, Lear's daughter", ["test edited pm"]],]);diff --git a/web/e2e-tests/lib/common.ts b/web/e2e-tests/lib/common.tsindex 853a9a660e1..1f0e993bf89 100644--- a/web/e2e-tests/lib/common.ts+++ b/web/e2e-tests/lib/common.ts@@ -411,12 +411,8 @@ export async function send_message(page: Page,type: "stream" | "private",params: Message,+ wait_for_narrow_change = true,): Promise<void> {- // If a message is outside the view, we do not need- // to wait for it to be processed later.- const outside_view = params.outside_view;- delete params.outside_view;-// Compose box content should be empty before sending the message.await assert_compose_box_content(page, "");@@ -449,12 +445,15 @@ export async function send_message(await page.waitForSelector("#compose-send-button", {visible: true});await page.click("#compose-send-button");+ if (wait_for_narrow_change) {+ // After the message is sent, wait for the narrow+ // to change to the message recipient.+ await get_current_msg_list_id(page, true);+ }+// Sending should clear compose box content.await assert_compose_box_content(page, "");-- if (!outside_view) {- await wait_for_fully_processed_message(page, params.content);- }+ await wait_for_fully_processed_message(page, params.content);// Close the compose box after sending the message.await page.evaluate(() => {@@ -465,8 +464,24 @@ export async function send_message(}export async function send_multiple_messages(page: Page, msgs: Message[]): Promise<void> {+ let last_msg_stream;+ let last_msg_topic;+ let last_msg_recipient;for (const msg of msgs) {- await send_message(page, msg.stream_name !== undefined ? "stream" : "private", msg);+ const msg_type = msg.stream_name !== undefined ? "stream" : "private";+ // Check if `msg` and `last_msg` are in the same narrow.+ let wait_for_narrow_change = true;+ if (+ msg.stream_name === last_msg_stream &&+ msg.topic === last_msg_topic &&+ msg.recipient === last_msg_recipient+ ) {+ wait_for_narrow_change = false;+ }+ last_msg_stream = msg.stream_name;+ last_msg_topic = msg.topic;+ last_msg_recipient = msg.recipient;+ await send_message(page, msg_type, msg, wait_for_narrow_change);}}diff --git a/web/e2e-tests/message-basics.test.ts b/web/e2e-tests/message-basics.test.tsindex 1731a3c3b85..48d07e2f5d7 100644--- a/web/e2e-tests/message-basics.test.ts+++ b/web/e2e-tests/message-basics.test.ts@@ -517,27 +517,23 @@ async function message_basic_tests(page: Page): Promise<void> {stream_name: "Verona",topic: "other topic",content: "verona other topic c",- outside_view: true,},- {stream_name: "Denmark", topic: "test", content: "denmark message", outside_view: true},+ {stream_name: "Denmark", topic: "test", content: "denmark message"},{recipient: "[email protected], [email protected]",content: "group direct message a",- outside_view: true,},{recipient: "[email protected], [email protected]",content: "group direct message b",- outside_view: true,},- {recipient: "[email protected]", content: "direct message c", outside_view: true},+ {recipient: "[email protected]", content: "direct message c"},{stream_name: "Verona", topic: "test", content: "verona test d"},{recipient: "[email protected], [email protected]",content: "group direct message d",- outside_view: true,},- {recipient: "[email protected]", content: "direct message e", outside_view: true},+ {recipient: "[email protected]", content: "direct message e"},]);await page.click("#left-sidebar-navigation-list .top_left_all_messages");diff --git a/web/e2e-tests/stars.test.ts b/web/e2e-tests/stars.test.tsindex e8a4cbda864..aa6dc362ec7 100644--- a/web/e2e-tests/stars.test.ts+++ b/web/e2e-tests/stars.test.ts@@ -61,7 +61,7 @@ async function stars_test(page: Page): Promise<void> {await toggle_test_star_message(page);await page.click("#left-sidebar-navigation-list .top_left_all_messages");- message_list_id = await common.get_current_msg_list_id(page, true);+ message_list_id = await common.get_current_msg_list_id(page, false);await page.waitForSelector(`.message-list[data-message-list-id='${message_list_id}'] .zulip-icon-star-filled`,{visible: true},