mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
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:
@@ -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 {
|
export function has_class_x(class_name: string): string {
|
||||||
return `contains(concat(" ", @class, " "), " ${class_name} ")`;
|
return `contains(concat(" ", @class, " "), " ${class_name} ")`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import type {Page} from "puppeteer";
|
|||||||
import * as common from "../puppeteer_lib/common";
|
import * as common from "../puppeteer_lib/common";
|
||||||
|
|
||||||
async function check_compose_form_empty(page: Page): Promise<void> {
|
async function check_compose_form_empty(page: Page): Promise<void> {
|
||||||
await common.check_form_contents(page, "#send_message_form", {
|
await common.check_compose_state(page, {
|
||||||
stream_message_recipient_stream: "",
|
stream: "",
|
||||||
stream_message_recipient_topic: "",
|
topic: "",
|
||||||
content: "",
|
content: "",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -57,9 +57,9 @@ async function test_reply_by_click_prepopulates_stream_topic_names(page: Page):
|
|||||||
assert.ok(stream_message !== null);
|
assert.ok(stream_message !== null);
|
||||||
// we chose only the last element make sure we don't click on any duplicates.
|
// we chose only the last element make sure we don't click on any duplicates.
|
||||||
await stream_message.click();
|
await stream_message.click();
|
||||||
await common.check_form_contents(page, "#send_message_form", {
|
await common.check_compose_state(page, {
|
||||||
stream_message_recipient_stream: "Verona",
|
stream: "Verona",
|
||||||
stream_message_recipient_topic: "Reply test",
|
topic: "Reply test",
|
||||||
content: "",
|
content: "",
|
||||||
});
|
});
|
||||||
await close_compose_box(page);
|
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.
|
// Now we go up and open compose box with r key.
|
||||||
await page.keyboard.press("KeyK");
|
await page.keyboard.press("KeyK");
|
||||||
await page.keyboard.press("KeyR");
|
await page.keyboard.press("KeyR");
|
||||||
await common.check_form_contents(page, "#send_message_form", {
|
await common.check_compose_state(page, {
|
||||||
stream_message_recipient_stream: "Verona",
|
stream: "Verona",
|
||||||
stream_message_recipient_topic: "Reply test",
|
topic: "Reply test",
|
||||||
content: "",
|
content: "",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,9 +116,9 @@ async function test_restore_message_draft_via_draft_overlay(page: Page): Promise
|
|||||||
await wait_for_drafts_to_disappear(page);
|
await wait_for_drafts_to_disappear(page);
|
||||||
await page.waitForSelector("#stream-message", {visible: true});
|
await page.waitForSelector("#stream-message", {visible: true});
|
||||||
await page.waitForSelector("#preview_message_area", {hidden: true});
|
await page.waitForSelector("#preview_message_area", {hidden: true});
|
||||||
await common.check_form_contents(page, "form#send_message_form", {
|
await common.check_compose_state(page, {
|
||||||
stream_message_recipient_stream: "Denmark",
|
stream: "Denmark",
|
||||||
stream_message_recipient_topic: "tests",
|
topic: "tests",
|
||||||
content: "Test stream message.",
|
content: "Test stream message.",
|
||||||
});
|
});
|
||||||
assert.strictEqual(
|
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 page.click(".message_row.private-message .restore-draft");
|
||||||
await wait_for_drafts_to_disappear(page);
|
await wait_for_drafts_to_disappear(page);
|
||||||
await page.waitForSelector("#private-message", {visible: true});
|
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.",
|
content: "Test private 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(page, "cordelia");
|
||||||
|
|||||||
Reference in New Issue
Block a user