e2e-tests: Consistently move fullname lookups to callers.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-05-30 16:16:21 -07:00
parent 067a342b4e
commit ed5f1455f2
5 changed files with 22 additions and 22 deletions

View File

@ -78,7 +78,7 @@ async function test_reply_by_click_prepopulates_private_message_recipient(
assert.ok(private_message !== null); assert.ok(private_message !== null);
await private_message.click(); await private_message.click();
await page.waitForSelector("#private_message_recipient", {visible: true}); 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); assert(email !== undefined);
await common.pm_recipient.expect(page, email); await common.pm_recipient.expect(page, email);
await close_compose_box(page); 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 pm.click();
await page.waitForSelector("#compose-textarea", {visible: true}); await page.waitForSelector("#compose-textarea", {visible: true});
const recipient_internal_emails = [ const recipient_internal_emails = [
await common.get_internal_email_from_name(page, "othello"), await common.get_internal_email_from_name(page, common.fullname.othello),
await common.get_internal_email_from_name(page, "cordelia"), await common.get_internal_email_from_name(page, common.fullname.cordelia),
].join(","); ].join(",");
await common.pm_recipient.expect(page, recipient_internal_emails); await common.pm_recipient.expect(page, recipient_internal_emails);
} }

View File

@ -203,8 +203,14 @@ async function test_restore_private_message_draft_via_draft_overlay(page: Page):
await common.check_compose_state(page, { await common.check_compose_state(page, {
content: "Test direct message.", content: "Test direct message.",
}); });
const cordelia_internal_email = await common.get_internal_email_from_name(page, "cordelia"); const cordelia_internal_email = await common.get_internal_email_from_name(
const hamlet_internal_email = await common.get_internal_email_from_name(page, "hamlet"); 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}`); await common.pm_recipient.expect(page, `${hamlet_internal_email},${cordelia_internal_email}`);
assert.strictEqual( assert.strictEqual(
await common.get_text_from_selector(page, "title"), await common.get_text_from_selector(page, "title"),

View File

@ -49,7 +49,7 @@ export const pm_recipient = {
}, },
}; };
export const fullname: Record<string, string> = { export const fullname = {
cordelia: "Cordelia, Lear's daughter", cordelia: "Cordelia, Lear's daughter",
othello: "Othello, the Moor of Venice", othello: "Othello, the Moor of Venice",
hamlet: "King Hamlet", hamlet: "King Hamlet",
@ -237,9 +237,6 @@ export async function get_stream_id(page: Page, stream_name: string): Promise<nu
} }
export async function get_user_id_from_name(page: Page, name: string): Promise<number | undefined> { export async function get_user_id_from_name(page: Page, name: string): Promise<number | undefined> {
if (fullname[name] !== undefined) {
name = fullname[name];
}
return await page.evaluate((name: string) => zulip_test.get_user_id_from_name(name), 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, page: Page,
name: string, name: string,
): Promise<string | undefined> { ): Promise<string | undefined> {
if (fullname[name] !== undefined) {
name = fullname[name];
}
return await page.evaluate((fullname: string) => { return await page.evaluate((fullname: string) => {
const user_id = zulip_test.get_user_id_from_name(fullname); 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; return user_id === undefined ? undefined : zulip_test.get_person_by_user_id(user_id).email;

View File

@ -52,8 +52,8 @@ async function test_user_filter_ui(page: Page): Promise<void> {
// Desdemona should be there by default // Desdemona should be there by default
await await_user_visible(page, "desdemona"); await await_user_visible(page, "desdemona");
await add_user_to_stream(page, "cordelia"); await add_user_to_stream(page, common.fullname.cordelia);
await add_user_to_stream(page, "othello"); 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.type(`form#stream_creation_form [name="user_list_filter"]`, "ot", {delay: 100});
await page.waitForSelector("#create_stream_subscribers", {visible: true}); await page.waitForSelector("#create_stream_subscribers", {visible: true});
@ -64,16 +64,16 @@ async function test_user_filter_ui(page: Page): Promise<void> {
.length === 1, .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_hidden(page, "desdemona");
await await_user_visible(page, "othello"); await await_user_visible(page, common.fullname.othello);
// Clear the filter. // Clear the filter.
await clear_ot_filter_with_backspace(page); 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, "desdemona");
await await_user_visible(page, "othello"); await await_user_visible(page, common.fullname.othello);
} }
async function create_stream(page: Page): Promise<void> { async function create_stream(page: Page): Promise<void> {

View File

@ -41,7 +41,7 @@ async function test_reactivation_confirmation_modal(page: Page, fullname: string
} }
async function test_deactivate_user(page: Page): Promise<void> { async function test_deactivate_user(page: Page): Promise<void> {
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, {visible: true});
await page.waitForSelector(cordelia_user_row + " .fa-user-times"); await page.waitForSelector(cordelia_user_row + " .fa-user-times");
await page.click(cordelia_user_row + " .deactivate"); await page.click(cordelia_user_row + " .deactivate");
@ -62,7 +62,7 @@ async function test_deactivate_user(page: Page): Promise<void> {
} }
async function test_reactivate_user(page: Page): Promise<void> { async function test_reactivate_user(page: Page): Promise<void> {
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 + ".deactivated_user");
await page.waitForSelector(cordelia_user_row + " .fa-user-plus"); await page.waitForSelector(cordelia_user_row + " .fa-user-plus");
await page.click(cordelia_user_row + " .reactivate"); await page.click(cordelia_user_row + " .reactivate");
@ -70,12 +70,12 @@ async function test_reactivate_user(page: Page): Promise<void> {
await test_reactivation_confirmation_modal(page, common.fullname.cordelia); await test_reactivation_confirmation_modal(page, common.fullname.cordelia);
await page.waitForSelector(cordelia_user_row + ":not(.deactivated_user)", {visible: true}); 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"); await page.waitForSelector(cordelia_user_row + " .fa-user-times");
} }
async function test_deactivated_users_section(page: Page): Promise<void> { async function test_deactivated_users_section(page: Page): Promise<void> {
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); await test_deactivate_user(page);
// "Deactivated users" section doesn't render just deactivated users until reloaded. // "Deactivated users" section doesn't render just deactivated users until reloaded.