puppeteer: Check compose form contents in a new distinct function.

This is a prep commit for a future where we check the stream name
from a different field that isn't in the form, so that we only
have to change code in this single place.
This commit is contained in:
evykassirer
2023-01-18 18:38:14 -08:00
committed by Tim Abbott
parent d3164016f5
commit 56c9b4f8c1
3 changed files with 27 additions and 13 deletions

View File

@@ -186,6 +186,20 @@ export async function check_form_contents(
}
}
export async function check_compose_state(
page: Page,
params: Record<string, string>,
): Promise<void> {
const form_params: Record<string, string> = {content: params.content};
if (params.stream) {
form_params.stream_message_recipient_stream = params.stream;
}
if (params.topic) {
form_params.stream_message_recipient_topic = params.topic;
}
await check_form_contents(page, "form#send_message_form", form_params);
}
export function has_class_x(class_name: string): string {
return `contains(concat(" ", @class, " "), " ${class_name} ")`;
}

View File

@@ -5,9 +5,9 @@ import type {Page} from "puppeteer";
import * as common from "../puppeteer_lib/common";
async function check_compose_form_empty(page: Page): Promise<void> {
await common.check_form_contents(page, "#send_message_form", {
stream_message_recipient_stream: "",
stream_message_recipient_topic: "",
await common.check_compose_state(page, {
stream: "",
topic: "",
content: "",
});
}
@@ -57,9 +57,9 @@ async function test_reply_by_click_prepopulates_stream_topic_names(page: Page):
assert.ok(stream_message !== null);
// we chose only the last element make sure we don't click on any duplicates.
await stream_message.click();
await common.check_form_contents(page, "#send_message_form", {
stream_message_recipient_stream: "Verona",
stream_message_recipient_topic: "Reply test",
await common.check_compose_state(page, {
stream: "Verona",
topic: "Reply test",
content: "",
});
await close_compose_box(page);
@@ -86,9 +86,9 @@ async function test_reply_with_r_shortcut(page: Page): Promise<void> {
// Now we go up and open compose box with r key.
await page.keyboard.press("KeyK");
await page.keyboard.press("KeyR");
await common.check_form_contents(page, "#send_message_form", {
stream_message_recipient_stream: "Verona",
stream_message_recipient_topic: "Reply test",
await common.check_compose_state(page, {
stream: "Verona",
topic: "Reply test",
content: "",
});
}

View File

@@ -116,9 +116,9 @@ async function test_restore_message_draft_via_draft_overlay(page: Page): Promise
await wait_for_drafts_to_disappear(page);
await page.waitForSelector("#stream-message", {visible: true});
await page.waitForSelector("#preview_message_area", {hidden: true});
await common.check_form_contents(page, "form#send_message_form", {
stream_message_recipient_stream: "Denmark",
stream_message_recipient_topic: "tests",
await common.check_compose_state(page, {
stream: "Denmark",
topic: "tests",
content: "Test stream message.",
});
assert.strictEqual(
@@ -170,7 +170,7 @@ async function test_restore_private_message_draft_via_draft_overlay(page: Page):
await page.click(".message_row.private-message .restore-draft");
await wait_for_drafts_to_disappear(page);
await page.waitForSelector("#private-message", {visible: true});
await common.check_form_contents(page, "form#send_message_form", {
await common.check_compose_state(page, {
content: "Test private message.",
});
const cordelia_internal_email = await common.get_internal_email_from_name(page, "cordelia");