From ed5f1455f2caea064b796c17bb1165b3bb76afef Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 30 May 2024 16:16:21 -0700 Subject: [PATCH] e2e-tests: Consistently move fullname lookups to callers. Signed-off-by: Anders Kaseorg --- web/e2e-tests/compose.test.ts | 6 +++--- web/e2e-tests/drafts.test.ts | 10 ++++++++-- web/e2e-tests/lib/common.ts | 8 +------- web/e2e-tests/stream_create.test.ts | 12 ++++++------ web/e2e-tests/user-deactivation.test.ts | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/web/e2e-tests/compose.test.ts b/web/e2e-tests/compose.test.ts index 81d5ae3861..e88b4cbc89 100644 --- a/web/e2e-tests/compose.test.ts +++ b/web/e2e-tests/compose.test.ts @@ -78,7 +78,7 @@ async function test_reply_by_click_prepopulates_private_message_recipient( assert.ok(private_message !== null); await private_message.click(); await page.waitForSelector("#private_message_recipient", {visible: true}); - const email = await common.get_internal_email_from_name(page, "cordelia"); + const email = await common.get_internal_email_from_name(page, common.fullname.cordelia); assert(email !== undefined); await common.pm_recipient.expect(page, email); await close_compose_box(page); @@ -151,8 +151,8 @@ async function test_send_multirecipient_pm_from_cordelia_pm_narrow(page: Page): await pm.click(); await page.waitForSelector("#compose-textarea", {visible: true}); const recipient_internal_emails = [ - await common.get_internal_email_from_name(page, "othello"), - await common.get_internal_email_from_name(page, "cordelia"), + await common.get_internal_email_from_name(page, common.fullname.othello), + await common.get_internal_email_from_name(page, common.fullname.cordelia), ].join(","); await common.pm_recipient.expect(page, recipient_internal_emails); } diff --git a/web/e2e-tests/drafts.test.ts b/web/e2e-tests/drafts.test.ts index 15817d5759..71453b3d97 100644 --- a/web/e2e-tests/drafts.test.ts +++ b/web/e2e-tests/drafts.test.ts @@ -203,8 +203,14 @@ async function test_restore_private_message_draft_via_draft_overlay(page: Page): await common.check_compose_state(page, { content: "Test direct message.", }); - const cordelia_internal_email = await common.get_internal_email_from_name(page, "cordelia"); - const hamlet_internal_email = await common.get_internal_email_from_name(page, "hamlet"); + const cordelia_internal_email = await common.get_internal_email_from_name( + page, + common.fullname.cordelia, + ); + const hamlet_internal_email = await common.get_internal_email_from_name( + page, + common.fullname.hamlet, + ); await common.pm_recipient.expect(page, `${hamlet_internal_email},${cordelia_internal_email}`); assert.strictEqual( await common.get_text_from_selector(page, "title"), diff --git a/web/e2e-tests/lib/common.ts b/web/e2e-tests/lib/common.ts index a60ff4d024..35b0a03799 100644 --- a/web/e2e-tests/lib/common.ts +++ b/web/e2e-tests/lib/common.ts @@ -49,7 +49,7 @@ export const pm_recipient = { }, }; -export const fullname: Record = { +export const fullname = { cordelia: "Cordelia, Lear's daughter", othello: "Othello, the Moor of Venice", hamlet: "King Hamlet", @@ -237,9 +237,6 @@ export async function get_stream_id(page: Page, stream_name: string): Promise { - if (fullname[name] !== undefined) { - name = fullname[name]; - } return await page.evaluate((name: string) => zulip_test.get_user_id_from_name(name), name); } @@ -247,9 +244,6 @@ export async function get_internal_email_from_name( page: Page, name: string, ): Promise { - if (fullname[name] !== undefined) { - name = fullname[name]; - } return await page.evaluate((fullname: string) => { const user_id = zulip_test.get_user_id_from_name(fullname); return user_id === undefined ? undefined : zulip_test.get_person_by_user_id(user_id).email; diff --git a/web/e2e-tests/stream_create.test.ts b/web/e2e-tests/stream_create.test.ts index c7624eff90..3f518e8622 100644 --- a/web/e2e-tests/stream_create.test.ts +++ b/web/e2e-tests/stream_create.test.ts @@ -52,8 +52,8 @@ async function test_user_filter_ui(page: Page): Promise { // Desdemona should be there by default await await_user_visible(page, "desdemona"); - await add_user_to_stream(page, "cordelia"); - await add_user_to_stream(page, "othello"); + await add_user_to_stream(page, common.fullname.cordelia); + await add_user_to_stream(page, common.fullname.othello); await page.type(`form#stream_creation_form [name="user_list_filter"]`, "ot", {delay: 100}); await page.waitForSelector("#create_stream_subscribers", {visible: true}); @@ -64,16 +64,16 @@ async function test_user_filter_ui(page: Page): Promise { .length === 1, ); - await await_user_hidden(page, "cordelia"); + await await_user_hidden(page, common.fullname.cordelia); await await_user_hidden(page, "desdemona"); - await await_user_visible(page, "othello"); + await await_user_visible(page, common.fullname.othello); // Clear the filter. await clear_ot_filter_with_backspace(page); - await await_user_visible(page, "cordelia"); + await await_user_visible(page, common.fullname.cordelia); await await_user_visible(page, "desdemona"); - await await_user_visible(page, "othello"); + await await_user_visible(page, common.fullname.othello); } async function create_stream(page: Page): Promise { diff --git a/web/e2e-tests/user-deactivation.test.ts b/web/e2e-tests/user-deactivation.test.ts index 2b0f881d7e..ee313c3e40 100644 --- a/web/e2e-tests/user-deactivation.test.ts +++ b/web/e2e-tests/user-deactivation.test.ts @@ -41,7 +41,7 @@ async function test_reactivation_confirmation_modal(page: Page, fullname: string } async function test_deactivate_user(page: Page): Promise { - const cordelia_user_row = await user_row(page, "cordelia"); + const cordelia_user_row = await user_row(page, common.fullname.cordelia); await page.waitForSelector(cordelia_user_row, {visible: true}); await page.waitForSelector(cordelia_user_row + " .fa-user-times"); await page.click(cordelia_user_row + " .deactivate"); @@ -62,7 +62,7 @@ async function test_deactivate_user(page: Page): Promise { } async function test_reactivate_user(page: Page): Promise { - let cordelia_user_row = await user_row(page, "cordelia"); + let cordelia_user_row = await user_row(page, common.fullname.cordelia); await page.waitForSelector(cordelia_user_row + ".deactivated_user"); await page.waitForSelector(cordelia_user_row + " .fa-user-plus"); await page.click(cordelia_user_row + " .reactivate"); @@ -70,12 +70,12 @@ async function test_reactivate_user(page: Page): Promise { await test_reactivation_confirmation_modal(page, common.fullname.cordelia); await page.waitForSelector(cordelia_user_row + ":not(.deactivated_user)", {visible: true}); - cordelia_user_row = await user_row(page, "cordelia"); + cordelia_user_row = await user_row(page, common.fullname.cordelia); await page.waitForSelector(cordelia_user_row + " .fa-user-times"); } async function test_deactivated_users_section(page: Page): Promise { - const cordelia_user_row = await user_row(page, "cordelia"); + const cordelia_user_row = await user_row(page, common.fullname.cordelia); await test_deactivate_user(page); // "Deactivated users" section doesn't render just deactivated users until reloaded.