2021-02-20 05:52:06 +01:00
|
|
|
import {strict as assert} from "assert";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2022-09-12 01:20:51 +02:00
|
|
|
import type {Page} from "puppeteer";
|
2020-06-19 21:20:53 +02:00
|
|
|
|
2023-02-22 23:04:11 +01:00
|
|
|
import * as common from "./lib/common";
|
2020-06-19 21:20:53 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function check_compose_form_empty(page: Page): Promise<void> {
|
2023-01-19 03:38:14 +01:00
|
|
|
await common.check_compose_state(page, {
|
|
|
|
stream: "",
|
|
|
|
topic: "",
|
2020-06-19 21:20:53 +02:00
|
|
|
content: "",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function close_compose_box(page: Page): Promise<void> {
|
2023-04-18 05:13:50 +02:00
|
|
|
const recipient_dropdown_visible =
|
|
|
|
(await page.$("#compose_select_recipient_widget .open")) !== null;
|
2022-10-21 00:44:55 +02:00
|
|
|
|
2023-04-18 05:13:50 +02:00
|
|
|
if (recipient_dropdown_visible) {
|
2022-10-21 00:44:55 +02:00
|
|
|
await page.keyboard.press("Escape");
|
2023-04-18 05:13:50 +02:00
|
|
|
await page.waitForSelector("#id_compose_select_recipient.open", {hidden: true});
|
2022-10-21 00:44:55 +02:00
|
|
|
}
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.keyboard.press("Escape");
|
|
|
|
await page.waitForSelector("#compose-textarea", {hidden: true});
|
|
|
|
}
|
|
|
|
|
2022-09-10 05:37:50 +02:00
|
|
|
function get_message_selector(text: string): string {
|
2022-09-12 00:13:48 +02:00
|
|
|
return `xpath/(//p[text()='${text}'])[last()]`;
|
2020-06-19 21:20:53 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_send_messages(page: Page): Promise<void> {
|
2021-03-27 04:40:48 +01:00
|
|
|
const initial_msgs_count = (await page.$$("#zhome .message_row")).length;
|
2020-06-19 21:20:53 +02:00
|
|
|
|
|
|
|
await common.send_multiple_messages(page, [
|
|
|
|
{stream: "Verona", topic: "Reply test", content: "Compose stream reply test"},
|
|
|
|
{recipient: "cordelia@zulip.com", content: "Compose private message reply test"},
|
|
|
|
]);
|
|
|
|
|
2021-03-27 04:40:48 +01:00
|
|
|
assert.equal((await page.$$("#zhome .message_row")).length, initial_msgs_count + 2);
|
2020-06-19 21:20:53 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_stream_compose_keyboard_shortcut(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.keyboard.press("KeyC");
|
2023-04-18 05:13:50 +02:00
|
|
|
await page.waitForSelector("#stream_message_recipient_topic", {visible: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
await check_compose_form_empty(page);
|
|
|
|
await close_compose_box(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_private_message_compose_shortcut(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.keyboard.press("KeyX");
|
|
|
|
await page.waitForSelector("#private_message_recipient", {visible: true});
|
|
|
|
await common.pm_recipient.expect(page, "");
|
|
|
|
await close_compose_box(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_keyboard_shortcuts(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
await test_stream_compose_keyboard_shortcut(page);
|
|
|
|
await test_private_message_compose_shortcut(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_reply_by_click_prepopulates_stream_topic_names(page: Page): Promise<void> {
|
2022-09-10 05:37:50 +02:00
|
|
|
const stream_message_selector = get_message_selector("Compose stream reply test");
|
|
|
|
const stream_message = await page.waitForSelector(stream_message_selector, {visible: true});
|
2022-09-12 01:20:51 +02:00
|
|
|
assert.ok(stream_message !== null);
|
2020-06-19 21:20:53 +02:00
|
|
|
// we chose only the last element make sure we don't click on any duplicates.
|
2022-09-12 01:20:51 +02:00
|
|
|
await stream_message.click();
|
2023-01-19 03:38:14 +01:00
|
|
|
await common.check_compose_state(page, {
|
|
|
|
stream: "Verona",
|
|
|
|
topic: "Reply test",
|
2020-06-19 21:20:53 +02:00
|
|
|
content: "",
|
|
|
|
});
|
|
|
|
await close_compose_box(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_reply_by_click_prepopulates_private_message_recipient(
|
|
|
|
page: Page,
|
|
|
|
): Promise<void> {
|
2022-09-10 05:37:50 +02:00
|
|
|
const private_message = await page.$(
|
|
|
|
get_message_selector("Compose private message reply test"),
|
2020-06-19 21:20:53 +02:00
|
|
|
);
|
2022-09-12 01:20:51 +02:00
|
|
|
assert.ok(private_message !== null);
|
|
|
|
await private_message.click();
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.waitForSelector("#private_message_recipient", {visible: true});
|
|
|
|
await common.pm_recipient.expect(
|
|
|
|
page,
|
|
|
|
await common.get_internal_email_from_name(page, "cordelia"),
|
|
|
|
);
|
|
|
|
await close_compose_box(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_reply_with_r_shortcut(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
// The last message(private) in the narrow is currently selected as a result of previous tests.
|
|
|
|
// Now we go up and open compose box with r key.
|
|
|
|
await page.keyboard.press("KeyK");
|
|
|
|
await page.keyboard.press("KeyR");
|
2023-01-19 03:38:14 +01:00
|
|
|
await common.check_compose_state(page, {
|
|
|
|
stream: "Verona",
|
|
|
|
topic: "Reply test",
|
2020-06-19 21:20:53 +02:00
|
|
|
content: "",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_open_close_compose_box(page: Page): Promise<void> {
|
2023-04-18 05:13:50 +02:00
|
|
|
await page.waitForSelector("#stream_message_recipient_topic", {visible: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
await close_compose_box(page);
|
2023-04-18 05:13:50 +02:00
|
|
|
await page.waitForSelector("#stream_message_recipient_topic", {hidden: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
|
|
|
|
await page.keyboard.press("KeyX");
|
2023-04-15 03:35:23 +02:00
|
|
|
await page.waitForSelector("#compose-direct-recipient", {visible: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
await close_compose_box(page);
|
2023-04-15 03:35:23 +02:00
|
|
|
await page.waitForSelector("#compose-direct-recipient", {hidden: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_narrow_to_private_messages_with_cordelia(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
const you_and_cordelia_selector =
|
2023-05-01 22:57:25 +02:00
|
|
|
'*[data-tippy-content="Go to direct messages with Cordelia, Lear\'s daughter"]';
|
2020-06-19 21:20:53 +02:00
|
|
|
// For some unknown reason page.click() isn't working here.
|
|
|
|
await page.evaluate(
|
2021-02-20 05:52:06 +01:00
|
|
|
(selector: string) => document.querySelector<HTMLElement>(selector)!.click(),
|
2020-06-19 21:20:53 +02:00
|
|
|
you_and_cordelia_selector,
|
|
|
|
);
|
2021-04-11 16:26:54 +02:00
|
|
|
const cordelia_user_id = await common.get_user_id_from_name(page, "Cordelia, Lear's daughter");
|
2022-09-13 13:15:57 +02:00
|
|
|
const pm_list_selector = `li[data-user-ids-string="${cordelia_user_id}"].pm-list-item.active-sub-filter`;
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.waitForSelector(pm_list_selector, {visible: true});
|
|
|
|
await close_compose_box(page);
|
|
|
|
|
|
|
|
await page.keyboard.press("KeyC");
|
|
|
|
await page.waitForSelector("#compose", {visible: true});
|
2023-04-18 05:13:50 +02:00
|
|
|
await page.waitForSelector(".compose_table #id_compose_select_recipient.open", {
|
2021-03-27 04:40:48 +01:00
|
|
|
visible: true,
|
|
|
|
});
|
2020-06-19 21:20:53 +02:00
|
|
|
await close_compose_box(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_send_multirecipient_pm_from_cordelia_pm_narrow(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
const recipients = ["cordelia@zulip.com", "othello@zulip.com"];
|
|
|
|
const multiple_recipients_pm = "A huddle to check spaces";
|
|
|
|
await common.send_message(page, "private", {
|
|
|
|
recipient: recipients.join(", "),
|
|
|
|
outside_view: true,
|
|
|
|
content: multiple_recipients_pm,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Go back to all messages view and make sure all messages are loaded.
|
2020-09-20 10:14:24 +02:00
|
|
|
await page.click(".top_left_all_messages");
|
2020-06-19 21:20:53 +02:00
|
|
|
|
|
|
|
await page.waitForSelector("#zhome .message_row", {visible: true});
|
2021-03-27 04:40:48 +01:00
|
|
|
const pm = await page.waitForSelector(
|
|
|
|
`xpath/(//*[${common.has_class_x(
|
|
|
|
"messagebox",
|
2022-09-12 00:13:48 +02:00
|
|
|
)} and contains(normalize-space(), "${multiple_recipients_pm}") and count(.//*[${common.has_class_x(
|
|
|
|
"star",
|
|
|
|
)}])>0])[last()]`,
|
2021-03-27 04:40:48 +01:00
|
|
|
);
|
|
|
|
assert.ok(pm !== null);
|
|
|
|
await pm.click();
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.waitForSelector("#compose-textarea", {visible: true});
|
|
|
|
const recipient_internal_emails = [
|
|
|
|
await common.get_internal_email_from_name(page, "othello"),
|
|
|
|
await common.get_internal_email_from_name(page, "cordelia"),
|
|
|
|
].join(",");
|
|
|
|
await common.pm_recipient.expect(page, recipient_internal_emails);
|
|
|
|
}
|
|
|
|
|
2021-04-20 19:50:01 +02:00
|
|
|
const markdown_preview_button = "#compose .markdown_preview";
|
|
|
|
const markdown_preview_hide_button = "#compose .undo_markdown_preview";
|
2020-06-19 21:20:53 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_markdown_preview_buttons_visibility(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.waitForSelector(markdown_preview_button, {visible: true});
|
2020-08-11 01:48:53 +02:00
|
|
|
await page.waitForSelector(markdown_preview_hide_button, {hidden: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
// verify if Markdown preview button works.
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.click(markdown_preview_button);
|
2020-08-11 01:48:53 +02:00
|
|
|
await page.waitForSelector(markdown_preview_button, {hidden: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.waitForSelector(markdown_preview_hide_button, {visible: true});
|
|
|
|
|
2021-04-07 19:41:02 +02:00
|
|
|
// verify if hide button works.
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.click(markdown_preview_hide_button);
|
|
|
|
await page.waitForSelector(markdown_preview_button, {visible: true});
|
2020-08-11 01:48:53 +02:00
|
|
|
await page.waitForSelector(markdown_preview_hide_button, {hidden: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_markdown_preview_without_any_content(page: Page): Promise<void> {
|
2021-04-20 19:50:01 +02:00
|
|
|
await page.click("#compose .markdown_preview");
|
|
|
|
await page.waitForSelector("#compose .undo_markdown_preview", {visible: true});
|
|
|
|
const markdown_preview_element = await page.$("#compose .preview_content");
|
2022-07-06 05:28:39 +02:00
|
|
|
assert.ok(markdown_preview_element);
|
2020-06-19 21:20:53 +02:00
|
|
|
assert.equal(
|
2021-02-20 05:52:06 +01:00
|
|
|
await page.evaluate((element: Element) => element.textContent, markdown_preview_element),
|
2020-06-19 21:20:53 +02:00
|
|
|
"Nothing to preview",
|
|
|
|
);
|
2021-04-20 19:50:01 +02:00
|
|
|
await page.click("#compose .undo_markdown_preview");
|
2020-06-19 21:20:53 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_markdown_rendering(page: Page): Promise<void> {
|
2021-04-20 19:50:01 +02:00
|
|
|
await page.waitForSelector("#compose .markdown_preview", {visible: true});
|
2021-03-27 04:40:48 +01:00
|
|
|
assert.equal(await common.get_text_from_selector(page, "#compose .preview_content"), "");
|
2020-06-19 21:20:53 +02:00
|
|
|
await common.fill_form(page, 'form[action^="/json/messages"]', {
|
2020-08-11 01:47:54 +02:00
|
|
|
content: "**Markdown preview** >> Test for Markdown preview",
|
2020-06-19 21:20:53 +02:00
|
|
|
});
|
2021-04-20 19:50:01 +02:00
|
|
|
await page.click("#compose .markdown_preview");
|
2022-09-12 01:20:51 +02:00
|
|
|
const preview_content = await page.waitForSelector(
|
2021-03-27 04:40:48 +01:00
|
|
|
`xpath///*[@id="compose"]//*[${common.has_class_x(
|
|
|
|
"preview_content",
|
|
|
|
)} and normalize-space()!=""]`,
|
|
|
|
{visible: true},
|
2022-09-12 01:20:51 +02:00
|
|
|
);
|
|
|
|
assert.ok(preview_content !== null);
|
2020-06-19 21:20:53 +02:00
|
|
|
const expected_markdown_html =
|
2020-08-11 01:47:54 +02:00
|
|
|
"<p><strong>Markdown preview</strong> >> Test for Markdown preview</p>";
|
2020-06-19 21:20:53 +02:00
|
|
|
assert.equal(
|
2021-03-27 04:40:48 +01:00
|
|
|
await (await preview_content.getProperty("innerHTML")).jsonValue(),
|
2020-06-19 21:20:53 +02:00
|
|
|
expected_markdown_html,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_markdown_preview(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
await test_markdown_preview_buttons_visibility(page);
|
|
|
|
await test_markdown_preview_without_any_content(page);
|
|
|
|
await test_markdown_rendering(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function compose_tests(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +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-06-19 21:20:53 +02:00
|
|
|
await test_send_messages(page);
|
|
|
|
await test_keyboard_shortcuts(page);
|
|
|
|
await test_reply_by_click_prepopulates_stream_topic_names(page);
|
|
|
|
await test_reply_by_click_prepopulates_private_message_recipient(page);
|
|
|
|
await test_reply_with_r_shortcut(page);
|
|
|
|
await test_open_close_compose_box(page);
|
|
|
|
await test_narrow_to_private_messages_with_cordelia(page);
|
|
|
|
await test_send_multirecipient_pm_from_cordelia_pm_narrow(page);
|
|
|
|
await test_markdown_preview(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(compose_tests);
|