2021-03-27 04:40:48 +01:00
|
|
|
import {strict as assert} from "assert";
|
|
|
|
|
2022-09-12 01:20:51 +02:00
|
|
|
import type {Page} from "puppeteer";
|
2020-07-31 22:26:41 +02:00
|
|
|
|
2023-02-22 23:04:11 +01:00
|
|
|
import * as common from "./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> {
|
2024-01-17 07:53:40 +01:00
|
|
|
const msg = (await page.$$(".message-list .message_row")).at(-1);
|
2022-09-12 01:20:51 +02:00
|
|
|
assert.ok(msg !== undefined);
|
2021-03-27 04:40:48 +01:00
|
|
|
const id = await (await msg.getProperty("id")).jsonValue();
|
|
|
|
await msg.hover();
|
|
|
|
const info = await page.waitForSelector(
|
|
|
|
`#${CSS.escape(id)} .message_control_button.actions_hover`,
|
|
|
|
{visible: true},
|
|
|
|
);
|
|
|
|
assert.ok(info !== null);
|
|
|
|
await info.click();
|
|
|
|
await page.waitForSelector(".popover_edit_message", {visible: true});
|
|
|
|
await page.click(".popover_edit_message");
|
2020-07-31 22:26:41 +02:00
|
|
|
await page.waitForSelector(".message_edit_content", {visible: true});
|
|
|
|
}
|
|
|
|
|
2022-10-01 13:50:44 +02:00
|
|
|
async function edit_stream_message(page: Page, 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_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);
|
|
|
|
}
|
|
|
|
|
2024-01-17 07:53:40 +01:00
|
|
|
async function test_stream_message_edit(page: Page, message_list_id: number): Promise<void> {
|
2020-07-31 22:26:41 +02:00
|
|
|
await common.send_message(page, "stream", {
|
2023-08-04 06:46:35 +02:00
|
|
|
stream_name: "Verona",
|
2020-07-31 22:26:41 +02:00
|
|
|
topic: "edits",
|
|
|
|
content: "test editing",
|
|
|
|
});
|
|
|
|
|
2022-10-01 13:50:44 +02:00
|
|
|
await edit_stream_message(page, "test edited");
|
2020-07-31 22:26:41 +02:00
|
|
|
|
2024-01-17 07:53:40 +01:00
|
|
|
await common.check_messages_sent(page, message_list_id, [["Verona > edits", ["test edited"]]]);
|
2020-07-31 22:26:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_edit_message_with_slash_me(page: Page): Promise<void> {
|
2024-01-17 07:53:40 +01:00
|
|
|
const last_message_xpath = `(//*[${common.has_class_x("message-list")}]//*[${common.has_class_x(
|
|
|
|
"messagebox",
|
|
|
|
)}])[last()]`;
|
2021-03-27 04:40:48 +01:00
|
|
|
|
2020-07-31 22:26:41 +02:00
|
|
|
await common.send_message(page, "stream", {
|
2023-08-04 06:46:35 +02:00
|
|
|
stream_name: "Verona",
|
2020-07-31 22:26:41 +02:00
|
|
|
topic: "edits",
|
|
|
|
content: "/me test editing a message with me",
|
|
|
|
});
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector(
|
|
|
|
`xpath/${last_message_xpath}//*[${common.has_class_x(
|
|
|
|
"status-message",
|
|
|
|
)} and text()="test editing a message with me"]`,
|
2020-07-31 22:26:41 +02:00
|
|
|
);
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector(
|
|
|
|
`xpath/${last_message_xpath}//*[${common.has_class_x(
|
2023-06-14 20:40:08 +02:00
|
|
|
"sender_name",
|
2021-03-27 04:40:48 +01:00
|
|
|
)} and normalize-space()="Desdemona"]`,
|
2020-07-31 22:26:41 +02:00
|
|
|
);
|
|
|
|
|
2022-10-01 13:50:44 +02:00
|
|
|
await edit_stream_message(page, "/me test edited a message with me");
|
2020-07-31 22:26:41 +02:00
|
|
|
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector(
|
|
|
|
`xpath/${last_message_xpath}//*[${common.has_class_x(
|
|
|
|
"status-message",
|
|
|
|
)} and text()="test edited a message with me"]`,
|
2020-07-31 22:26:41 +02:00
|
|
|
);
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector(
|
|
|
|
`xpath/${last_message_xpath}//*[${common.has_class_x(
|
2023-06-14 20:40:08 +02:00
|
|
|
"sender_name",
|
2021-03-27 04:40:48 +01:00
|
|
|
)} and normalize-space()="Desdemona"]`,
|
2020-07-31 22:26:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-17 07:53:40 +01:00
|
|
|
async function test_edit_private_message(page: Page, message_list_id: number): 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");
|
|
|
|
|
2024-01-17 07:53:40 +01:00
|
|
|
await common.check_messages_sent(page, message_list_id, [
|
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);
|
2023-10-11 19:08:42 +02:00
|
|
|
await page.click("#left-sidebar-navigation-list .top_left_all_messages");
|
2024-01-17 07:53:40 +01:00
|
|
|
await page.waitForSelector(".message-list .message_row", {visible: true});
|
|
|
|
const message_list_id = await common.get_current_msg_list_id(page, true);
|
2020-07-31 22:26:41 +02:00
|
|
|
|
2024-01-17 07:53:40 +01:00
|
|
|
await test_stream_message_edit(page, message_list_id);
|
2020-07-31 22:26:41 +02:00
|
|
|
await test_edit_message_with_slash_me(page);
|
2024-01-17 07:53:40 +01:00
|
|
|
await test_edit_private_message(page, message_list_id);
|
2020-07-31 22:26:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(edit_tests);
|