2021-02-20 05:52:06 +01:00
|
|
|
import type {Page} from "puppeteer";
|
2020-07-31 22:26:41 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import common from "../puppeteer_lib/common";
|
2020-07-31 22:26:41 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function trigger_edit_last_message(page: Page): Promise<void> {
|
2020-07-31 22:26:41 +02:00
|
|
|
await page.evaluate(() => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $msg = $("#zhome .message_row").last();
|
|
|
|
$msg.find(".message_control_button.actions_hover").trigger("click");
|
2020-07-31 22:26:41 +02:00
|
|
|
$(".popover_edit_message").trigger("click");
|
|
|
|
});
|
|
|
|
await page.waitForSelector(".message_edit_content", {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function edit_stream_message(page: Page, topic: string, content: string): Promise<void> {
|
2020-07-31 22:26:41 +02:00
|
|
|
await trigger_edit_last_message(page);
|
|
|
|
|
2021-03-06 21:16:35 +01:00
|
|
|
await common.clear_and_type(page, ".message_edit_topic", topic);
|
|
|
|
await common.clear_and_type(page, ".message_edit_content", content);
|
2020-07-31 22:26:41 +02:00
|
|
|
await page.click(".message_edit_save");
|
|
|
|
|
|
|
|
await common.wait_for_fully_processed_message(page, content);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_stream_message_edit(page: Page): Promise<void> {
|
2020-07-31 22:26:41 +02:00
|
|
|
await common.send_message(page, "stream", {
|
|
|
|
stream: "Verona",
|
|
|
|
topic: "edits",
|
|
|
|
content: "test editing",
|
|
|
|
});
|
|
|
|
|
|
|
|
await edit_stream_message(page, "edited", "test edited");
|
|
|
|
|
|
|
|
await common.check_messages_sent(page, "zhome", [["Verona > edited", ["test edited"]]]);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_edit_message_with_slash_me(page: Page): Promise<void> {
|
2020-07-31 22:26:41 +02:00
|
|
|
await common.send_message(page, "stream", {
|
|
|
|
stream: "Verona",
|
|
|
|
topic: "edits",
|
|
|
|
content: "/me test editing a message with me",
|
|
|
|
});
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => $(".last_message .status-message").text() === "test editing a message with me",
|
|
|
|
);
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => $(".last_message .sender_name-in-status").text().trim() === "Desdemona",
|
|
|
|
);
|
|
|
|
|
|
|
|
await edit_stream_message(page, "edited", "/me test edited a message with me");
|
|
|
|
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => $(".last_message .status-message").text() === "test edited a message with me",
|
|
|
|
);
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => $(".last_message .sender_name-in-status").text().trim() === "Desdemona",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_edit_private_message(page: Page): Promise<void> {
|
2020-07-31 22:26:41 +02:00
|
|
|
await common.send_message(page, "private", {
|
|
|
|
recipient: "cordelia@zulip.com",
|
|
|
|
content: "test editing pm",
|
|
|
|
});
|
|
|
|
await trigger_edit_last_message(page);
|
|
|
|
|
2021-03-06 21:16:35 +01:00
|
|
|
await common.clear_and_type(page, ".message_edit_content", "test edited pm");
|
2020-07-31 22:26:41 +02:00
|
|
|
await page.click(".message_edit_save");
|
|
|
|
await common.wait_for_fully_processed_message(page, "test edited pm");
|
|
|
|
|
|
|
|
await common.check_messages_sent(page, "zhome", [
|
2021-04-11 16:26:54 +02:00
|
|
|
["You and Cordelia, Lear's daughter", ["test edited pm"]],
|
2020-07-31 22:26:41 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function edit_tests(page: Page): Promise<void> {
|
2020-07-31 22:26:41 +02:00
|
|
|
await common.log_in(page);
|
2020-09-20 10:14:24 +02:00
|
|
|
await page.click(".top_left_all_messages");
|
|
|
|
await page.waitForSelector("#zhome .message_row", {visible: true});
|
2020-07-31 22:26:41 +02:00
|
|
|
|
|
|
|
await test_stream_message_edit(page);
|
|
|
|
await test_edit_message_with_slash_me(page);
|
|
|
|
await test_edit_private_message(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(edit_tests);
|