2024-10-09 00:25:41 +02:00
|
|
|
import assert from "node:assert/strict";
|
2020-08-15 20:42:39 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import type {Page} from "puppeteer";
|
2020-08-15 20:42:39 +02:00
|
|
|
|
2024-11-12 03:59:37 +01:00
|
|
|
import * as common from "./lib/common.ts";
|
2020-08-15 20:42:39 +02:00
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
async function wait_for_drafts_to_disappear(page: Page): Promise<void> {
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector("#draft_overlay.show", {hidden: true});
|
2020-08-15 20:42:39 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function wait_for_drafts_to_appear(page: Page): Promise<void> {
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector("#draft_overlay.show");
|
2020-08-15 20:42:39 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function get_drafts_count(page: Page): Promise<number> {
|
2023-06-09 21:53:24 +02:00
|
|
|
return await page.$$eval("#drafts_table .overlay-message-row", (drafts) => drafts.length);
|
2020-08-15 20:42:39 +02:00
|
|
|
}
|
|
|
|
|
2021-07-05 00:06:50 +02:00
|
|
|
const drafts_button = ".top_left_drafts";
|
2020-08-15 20:42:39 +02:00
|
|
|
const drafts_overlay = "#draft_overlay";
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_empty_drafts(page: Page): Promise<void> {
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.waitForSelector(drafts_button, {visible: true});
|
|
|
|
await page.click(drafts_button);
|
|
|
|
|
|
|
|
await wait_for_drafts_to_appear(page);
|
|
|
|
await page.waitForSelector(drafts_overlay, {visible: true});
|
|
|
|
assert.strictEqual(await common.get_text_from_selector(page, ".drafts-list"), "No drafts.");
|
|
|
|
|
|
|
|
await page.click(`${drafts_overlay} .exit`);
|
2022-02-08 00:13:33 +01:00
|
|
|
await wait_for_drafts_to_disappear(page);
|
2020-08-15 20:42:39 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function create_stream_message_draft(page: Page): Promise<void> {
|
2021-05-10 07:02:14 +02:00
|
|
|
console.log("Creating stream message draft");
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.keyboard.press("KeyC");
|
2023-04-18 05:13:50 +02:00
|
|
|
await page.waitForSelector("#stream_message_recipient_topic", {visible: true});
|
2023-05-07 14:45:04 +02:00
|
|
|
await common.select_stream_in_compose_via_dropdown(page, "Denmark");
|
2020-08-15 20:42:39 +02:00
|
|
|
await common.fill_form(page, "form#send_message_form", {
|
|
|
|
content: "Test stream message.",
|
|
|
|
});
|
2024-01-16 08:58:54 +01:00
|
|
|
await page.type("#stream_message_recipient_topic", "tests", {delay: 100});
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.click("#compose_close");
|
|
|
|
}
|
|
|
|
|
2021-05-26 20:51:28 +02:00
|
|
|
async function test_restore_stream_message_draft_by_opening_compose_box(page: Page): Promise<void> {
|
|
|
|
await page.click(".search_icon");
|
|
|
|
await page.waitForSelector("#search_query", {visible: true});
|
2024-04-29 15:10:05 +02:00
|
|
|
await common.clear_and_type(page, "#search_query", "stream:Denmark topic:tests");
|
2024-01-25 22:11:22 +01:00
|
|
|
await page.keyboard.press("Enter");
|
2024-04-29 15:10:05 +02:00
|
|
|
// Wait for narrow to complete.
|
|
|
|
const wait_for_change = true;
|
|
|
|
await common.get_current_msg_list_id(page, wait_for_change);
|
|
|
|
await page.keyboard.press("Enter");
|
2021-05-26 20:51:28 +02:00
|
|
|
|
|
|
|
await page.click("#left_bar_compose_reply_button_big");
|
|
|
|
await page.waitForSelector("#send_message_form", {visible: true});
|
|
|
|
|
|
|
|
await common.check_compose_state(page, {
|
2024-05-24 01:27:16 +02:00
|
|
|
stream_name: "Denmark",
|
2021-05-26 20:51:28 +02:00
|
|
|
topic: "tests",
|
2024-03-19 23:34:10 +01:00
|
|
|
content: "Test stream message. ",
|
2021-05-26 20:51:28 +02:00
|
|
|
});
|
|
|
|
await page.click("#compose_close");
|
|
|
|
await page.waitForSelector("#send_message_form", {visible: false});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function create_private_message_draft(page: Page): Promise<void> {
|
2023-06-16 13:52:33 +02:00
|
|
|
console.log("Creating direct message draft");
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.keyboard.press("KeyX");
|
|
|
|
await page.waitForSelector("#private_message_recipient", {visible: true});
|
2023-06-16 13:52:33 +02:00
|
|
|
await common.fill_form(page, "form#send_message_form", {content: "Test direct message."});
|
2020-08-15 20:42:39 +02:00
|
|
|
await common.pm_recipient.set(page, "cordelia@zulip.com");
|
|
|
|
await common.pm_recipient.set(page, "hamlet@zulip.com");
|
2021-05-26 20:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function test_restore_private_message_draft_by_opening_composebox(page: Page): Promise<void> {
|
|
|
|
await page.click("#left_bar_compose_reply_button_big");
|
|
|
|
await page.waitForSelector("#private_message_recipient", {visible: true});
|
|
|
|
|
|
|
|
await common.check_form_contents(page, "form#send_message_form", {
|
2024-03-19 23:34:10 +01:00
|
|
|
content: "Test direct message. ",
|
2021-05-26 20:51:28 +02:00
|
|
|
});
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.click("#compose_close");
|
2021-05-26 20:51:28 +02:00
|
|
|
await page.waitForSelector("#private_message_recipient", {visible: false});
|
2020-08-15 20:42:39 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function open_compose_markdown_preview(page: Page): Promise<void> {
|
2023-10-04 16:11:48 +02:00
|
|
|
const new_conversation_button = "#new_conversation_button";
|
|
|
|
await page.waitForSelector(new_conversation_button, {visible: true});
|
|
|
|
await page.click(new_conversation_button);
|
2020-08-15 20:42:39 +02:00
|
|
|
|
2021-04-20 19:50:01 +02:00
|
|
|
const markdown_preview_button = "#compose .markdown_preview"; // eye icon.
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.waitForSelector(markdown_preview_button, {visible: true});
|
|
|
|
await page.click(markdown_preview_button);
|
|
|
|
}
|
|
|
|
|
2021-11-12 06:00:12 +01:00
|
|
|
async function open_drafts_after_markdown_preview(page: Page): Promise<void> {
|
2020-08-15 20:42:39 +02:00
|
|
|
await open_compose_markdown_preview(page);
|
2021-11-12 06:00:12 +01:00
|
|
|
await page.waitForSelector(drafts_button, {visible: true});
|
|
|
|
await page.click(drafts_button);
|
2020-08-15 20:42:39 +02:00
|
|
|
await wait_for_drafts_to_appear(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_previously_created_drafts_rendered(page: Page): Promise<void> {
|
2020-08-15 20:42:39 +02:00
|
|
|
const drafts_count = await get_drafts_count(page);
|
|
|
|
assert.strictEqual(drafts_count, 2, "Drafts improperly loaded.");
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row .message_header_stream .stream_label",
|
2020-08-15 20:42:39 +02:00
|
|
|
),
|
2022-10-17 17:48:51 +02:00
|
|
|
"Denmark",
|
2020-08-15 20:42:39 +02:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row .message_header_stream .stream_topic",
|
2020-08-15 20:42:39 +02:00
|
|
|
),
|
|
|
|
"tests",
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-03-12 23:13:08 +01:00
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row:nth-last-child(2) .rendered_markdown.restore-overlay-message",
|
2021-03-12 23:13:08 +01:00
|
|
|
),
|
2023-06-16 13:52:33 +02:00
|
|
|
"Test direct message.",
|
2020-08-15 20:42:39 +02:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row .message_header_private_message .stream_label",
|
2020-08-15 20:42:39 +02:00
|
|
|
),
|
2024-05-22 14:56:57 +02:00
|
|
|
"You and Cordelia, Lear's daughter, King Hamlet",
|
2020-08-15 20:42:39 +02:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-03-12 23:13:08 +01:00
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row:last-child .rendered_markdown.restore-overlay-message",
|
2021-03-12 23:13:08 +01:00
|
|
|
),
|
2020-08-15 20:42:39 +02:00
|
|
|
"Test stream message.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-28 19:24:11 +02:00
|
|
|
async function test_restore_message_draft_via_draft_overlay(page: Page): Promise<void> {
|
2021-05-10 07:02:14 +02:00
|
|
|
console.log("Restoring stream message draft");
|
2023-06-09 21:53:24 +02:00
|
|
|
await page.click("#drafts_table .message_row:not(.private-message) .restore-overlay-message");
|
2022-02-08 00:13:33 +01:00
|
|
|
await wait_for_drafts_to_disappear(page);
|
2023-04-18 05:13:50 +02:00
|
|
|
await page.waitForSelector("#stream_message_recipient_topic", {visible: true});
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.waitForSelector("#preview_message_area", {hidden: true});
|
2023-01-19 03:38:14 +01:00
|
|
|
await common.check_compose_state(page, {
|
2023-08-04 06:46:35 +02:00
|
|
|
stream_name: "Denmark",
|
2023-01-19 03:38:14 +01:00
|
|
|
topic: "tests",
|
2020-08-15 20:42:39 +02:00
|
|
|
content: "Test stream message.",
|
|
|
|
});
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, "title"),
|
2022-10-17 17:48:51 +02:00
|
|
|
"#Denmark > tests - Zulip Dev - Zulip",
|
2020-08-15 20:42:39 +02:00
|
|
|
"Didn't narrow to the right topic.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function edit_stream_message_draft(page: Page): Promise<void> {
|
2023-05-07 14:45:04 +02:00
|
|
|
await common.select_stream_in_compose_via_dropdown(page, "Denmark");
|
2020-08-15 20:42:39 +02:00
|
|
|
await common.fill_form(page, "form#send_message_form", {
|
2021-05-10 07:02:14 +02:00
|
|
|
content: "Updated stream message",
|
2020-08-15 20:42:39 +02:00
|
|
|
});
|
|
|
|
await page.click("#compose_close");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_edited_draft_message(page: Page): Promise<void> {
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.waitForSelector(drafts_button, {visible: true});
|
|
|
|
await page.click(drafts_button);
|
|
|
|
|
|
|
|
await wait_for_drafts_to_appear(page);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row .message_header_stream .stream_label",
|
2020-08-15 20:42:39 +02:00
|
|
|
),
|
2022-10-17 17:48:51 +02:00
|
|
|
"Denmark",
|
2020-08-15 20:42:39 +02:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row .message_header_stream .stream_topic",
|
2020-08-15 20:42:39 +02:00
|
|
|
),
|
|
|
|
"tests",
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-03-12 23:13:08 +01:00
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row .message_row:not(.private-message) .rendered_markdown.restore-overlay-message",
|
2021-03-12 23:13:08 +01:00
|
|
|
),
|
2021-05-10 07:02:14 +02:00
|
|
|
"Updated stream message",
|
2020-08-15 20:42:39 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-28 19:24:11 +02:00
|
|
|
async function test_restore_private_message_draft_via_draft_overlay(page: Page): Promise<void> {
|
2023-06-16 13:52:33 +02:00
|
|
|
console.log("Restoring direct message draft.");
|
2023-06-09 21:53:24 +02:00
|
|
|
await page.click(".message_row.private-message .restore-overlay-message");
|
2022-02-08 00:13:33 +01:00
|
|
|
await wait_for_drafts_to_disappear(page);
|
2023-04-15 03:35:23 +02:00
|
|
|
await page.waitForSelector("#compose-direct-recipient", {visible: true});
|
2023-01-19 03:38:14 +01:00
|
|
|
await common.check_compose_state(page, {
|
2023-06-16 13:52:33 +02:00
|
|
|
content: "Test direct message.",
|
2020-08-15 20:42:39 +02:00
|
|
|
});
|
2024-05-31 01:16:21 +02:00
|
|
|
const cordelia_internal_email = await common.get_internal_email_from_name(
|
|
|
|
page,
|
|
|
|
common.fullname.cordelia,
|
|
|
|
);
|
|
|
|
const hamlet_internal_email = await common.get_internal_email_from_name(
|
|
|
|
page,
|
|
|
|
common.fullname.hamlet,
|
|
|
|
);
|
2024-06-10 20:14:45 +02:00
|
|
|
await common.pm_recipient.expect(page, `${cordelia_internal_email},${hamlet_internal_email}`);
|
2020-08-15 20:42:39 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, "title"),
|
2021-04-11 16:26:54 +02:00
|
|
|
"Cordelia, Lear's daughter, King Hamlet - Zulip Dev - Zulip",
|
2023-06-16 13:52:33 +02:00
|
|
|
"Didn't narrow to the direct messages with cordelia and hamlet",
|
2020-08-15 20:42:39 +02:00
|
|
|
);
|
|
|
|
await page.click("#compose_close");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_delete_draft(page: Page): Promise<void> {
|
2020-08-15 20:42:39 +02:00
|
|
|
console.log("Deleting draft");
|
|
|
|
await page.waitForSelector(drafts_button, {visible: true});
|
|
|
|
await page.click(drafts_button);
|
|
|
|
await wait_for_drafts_to_appear(page);
|
2023-06-09 21:53:24 +02:00
|
|
|
await page.click("#drafts_table .message_row.private-message .delete-overlay-message");
|
2020-08-15 20:42:39 +02:00
|
|
|
const drafts_count = await get_drafts_count(page);
|
|
|
|
assert.strictEqual(drafts_count, 1, "Draft not deleted.");
|
2021-02-20 05:58:35 +01:00
|
|
|
await page.waitForSelector("#drafts_table .message_row.private-message", {hidden: true});
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.click(`${drafts_overlay} .exit`);
|
2022-02-08 00:13:33 +01:00
|
|
|
await wait_for_drafts_to_disappear(page);
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.click("body");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_save_draft_by_reloading(page: Page): Promise<void> {
|
2020-08-15 20:42:39 +02:00
|
|
|
console.log("Saving draft by reloading.");
|
|
|
|
await page.keyboard.press("KeyX");
|
2023-04-15 03:35:23 +02:00
|
|
|
await page.waitForSelector("#compose-direct-recipient", {visible: true});
|
2020-08-15 20:42:39 +02:00
|
|
|
await common.fill_form(page, "form#send_message_form", {
|
2023-06-16 13:52:33 +02:00
|
|
|
content: "Test direct message draft.",
|
2020-08-15 20:42:39 +02:00
|
|
|
});
|
|
|
|
await common.pm_recipient.set(page, "cordelia@zulip.com");
|
|
|
|
await page.reload();
|
|
|
|
|
2023-06-16 13:52:33 +02:00
|
|
|
// Reloading into a direct messages narrow opens compose box.
|
2020-08-15 20:42:39 +02:00
|
|
|
await page.waitForSelector("#compose-textarea", {visible: true});
|
|
|
|
await page.click("#compose_close");
|
|
|
|
|
|
|
|
console.log("Reloading finished. Opening drafts again now.");
|
|
|
|
await page.waitForSelector(drafts_button, {visible: true});
|
|
|
|
await page.click(drafts_button);
|
|
|
|
|
|
|
|
console.log("Checking drafts survived after the reload");
|
|
|
|
await wait_for_drafts_to_appear(page);
|
|
|
|
const drafts_count = await get_drafts_count(page);
|
|
|
|
assert.strictEqual(drafts_count, 2, "All drafts aren't loaded.");
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row .message_header_private_message .stream_label",
|
2020-08-15 20:42:39 +02:00
|
|
|
),
|
2021-04-11 16:26:54 +02:00
|
|
|
"You and Cordelia, Lear's daughter",
|
2020-08-15 20:42:39 +02:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2021-03-12 23:13:08 +01:00
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
2023-06-09 21:53:24 +02:00
|
|
|
"#drafts_table .overlay-message-row:nth-last-child(2) .rendered_markdown.restore-overlay-message",
|
2021-03-12 23:13:08 +01:00
|
|
|
),
|
2023-06-16 13:52:33 +02:00
|
|
|
"Test direct message draft.",
|
2020-08-15 20:42:39 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-30 06:44:21 +02:00
|
|
|
async function test_delete_draft_on_clearing_text(page: Page): Promise<void> {
|
|
|
|
console.log("Deleting draft by clearing compose box textarea.");
|
|
|
|
await page.click("#drafts_table .message_row:not(.private-message) .restore-overlay-message");
|
|
|
|
await wait_for_drafts_to_disappear(page);
|
|
|
|
await page.waitForSelector("#send_message_form", {visible: true});
|
|
|
|
await common.fill_form(page, "form#send_message_form", {content: ""});
|
|
|
|
await page.click("#compose_close");
|
|
|
|
await page.waitForSelector("#send_message_form", {hidden: true});
|
|
|
|
await page.click(drafts_button);
|
|
|
|
await wait_for_drafts_to_appear(page);
|
|
|
|
const drafts_count = await get_drafts_count(page);
|
|
|
|
assert.strictEqual(drafts_count, 1, "Draft not deleted.");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function drafts_test(page: Page): Promise<void> {
|
2020-08-15 20:42:39 +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-08-16 10:57:57 +02:00
|
|
|
const message_list_id = await common.get_current_msg_list_id(page, true);
|
|
|
|
await page.waitForSelector(
|
|
|
|
`.message-list[data-message-list-id='${message_list_id}'] .message_row`,
|
|
|
|
{visible: true},
|
|
|
|
);
|
2020-08-15 20:42:39 +02:00
|
|
|
|
|
|
|
await test_empty_drafts(page);
|
|
|
|
|
|
|
|
await create_stream_message_draft(page);
|
2021-05-26 20:51:28 +02:00
|
|
|
await test_restore_stream_message_draft_by_opening_compose_box(page);
|
|
|
|
|
|
|
|
// Send a private message so that the draft we create is
|
|
|
|
// for an existing conversation.
|
|
|
|
await common.send_message(page, "private", {
|
|
|
|
recipient: "cordelia@zulip.com, hamlet@zulip.com",
|
|
|
|
content: "howdy doo",
|
|
|
|
});
|
2020-08-15 20:42:39 +02:00
|
|
|
await create_private_message_draft(page);
|
2024-03-06 13:12:08 +01:00
|
|
|
// Close and try restoring it by opening the composebox again.
|
2021-05-26 20:51:28 +02:00
|
|
|
await page.click("#compose_close");
|
|
|
|
await test_restore_private_message_draft_by_opening_composebox(page);
|
|
|
|
|
2021-11-12 06:00:12 +01:00
|
|
|
await open_drafts_after_markdown_preview(page);
|
2020-08-15 20:42:39 +02:00
|
|
|
await test_previously_created_drafts_rendered(page);
|
|
|
|
|
2021-05-28 19:24:11 +02:00
|
|
|
await test_restore_message_draft_via_draft_overlay(page);
|
2020-08-15 20:42:39 +02:00
|
|
|
await edit_stream_message_draft(page);
|
|
|
|
await test_edited_draft_message(page);
|
|
|
|
|
2021-05-28 19:24:11 +02:00
|
|
|
await test_restore_private_message_draft_via_draft_overlay(page);
|
2020-08-15 20:42:39 +02:00
|
|
|
await test_delete_draft(page);
|
|
|
|
await test_save_draft_by_reloading(page);
|
2022-08-30 06:44:21 +02:00
|
|
|
await test_delete_draft_on_clearing_text(page);
|
2020-08-15 20:42:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(drafts_test);
|