2021-02-20 05:52:06 +01:00
|
|
|
import {strict as assert} from "assert";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import type {Page} from "puppeteer";
|
2020-06-19 21:20:53 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import common from "../puppeteer_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> {
|
2020-06-19 21:20:53 +02:00
|
|
|
await common.check_form_contents(page, "#send_message_form", {
|
|
|
|
stream_message_recipient_stream: "",
|
|
|
|
stream_message_recipient_topic: "",
|
|
|
|
content: "",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function close_compose_box(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
await page.keyboard.press("Escape");
|
|
|
|
await page.waitForSelector("#compose-textarea", {hidden: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
function get_message_xpath(text: string): string {
|
2020-06-19 21:20:53 +02:00
|
|
|
return `//p[text()='${text}']`;
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
function get_last_element<T>(array: T[]): T {
|
2020-06-19 21:20:53 +02:00
|
|
|
return array.slice(-1)[0];
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_send_messages(page: Page): Promise<void> {
|
2020-06-19 21:20:53 +02:00
|
|
|
const initial_msgs_count = await page.evaluate(() => $("#zhome .message_row").length);
|
|
|
|
|
|
|
|
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"},
|
|
|
|
]);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
await page.evaluate(() => $("#zhome .message_row").length),
|
|
|
|
initial_msgs_count + 2,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
await page.waitForSelector("#stream-message", {visible: true});
|
|
|
|
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> {
|
2021-03-12 12:30:25 +01:00
|
|
|
const stream_message_xpath = get_message_xpath("Compose stream reply test");
|
|
|
|
await page.waitForXPath(stream_message_xpath, {visible: true});
|
|
|
|
const stream_message = get_last_element(await page.$x(stream_message_xpath));
|
2020-06-19 21:20:53 +02:00
|
|
|
// we chose only the last element make sure we don't click on any duplicates.
|
|
|
|
await stream_message.click();
|
|
|
|
await common.check_form_contents(page, "#send_message_form", {
|
|
|
|
stream_message_recipient_stream: "Verona",
|
|
|
|
stream_message_recipient_topic: "Reply test",
|
|
|
|
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> {
|
2020-06-19 21:20:53 +02:00
|
|
|
const private_message = get_last_element(
|
|
|
|
await page.$x(get_message_xpath("Compose private message reply test")),
|
|
|
|
);
|
|
|
|
await private_message.click();
|
|
|
|
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");
|
|
|
|
await common.check_form_contents(page, "#send_message_form", {
|
|
|
|
stream_message_recipient_stream: "Verona",
|
|
|
|
stream_message_recipient_topic: "Reply test",
|
|
|
|
content: "",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_open_close_compose_box(page: Page): Promise<void> {
|
2020-08-11 18:08:47 +02:00
|
|
|
await page.waitForSelector("#stream-message", {visible: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
await close_compose_box(page);
|
|
|
|
await page.waitForSelector("#stream-message", {hidden: true});
|
|
|
|
|
|
|
|
await page.keyboard.press("KeyX");
|
2020-08-11 18:08:47 +02:00
|
|
|
await page.waitForSelector("#private-message", {visible: true});
|
2020-06-19 21:20:53 +02:00
|
|
|
await close_compose_box(page);
|
|
|
|
await page.waitForSelector("#private-message", {hidden: true});
|
|
|
|
}
|
|
|
|
|
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 =
|
2021-04-11 16:26:54 +02:00
|
|
|
'*[title="Narrow to your private 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");
|
2020-06-19 21:20:53 +02:00
|
|
|
const pm_list_selector = `li[data-user-ids-string="${cordelia_user_id}"].expanded_private_message.active-sub-filter`;
|
|
|
|
await page.waitForSelector(pm_list_selector, {visible: true});
|
|
|
|
await close_compose_box(page);
|
|
|
|
|
|
|
|
await page.keyboard.press("KeyC");
|
|
|
|
await page.waitForSelector("#compose", {visible: true});
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => document.activeElement === $(".compose_table #stream_message_recipient_stream")[0],
|
|
|
|
);
|
|
|
|
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";
|
2021-02-03 23:23:32 +01:00
|
|
|
const pm_selector = `.messagebox:contains('${CSS.escape(multiple_recipients_pm)}')`;
|
2020-06-19 21:20:53 +02:00
|
|
|
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-02-20 05:52:06 +01:00
|
|
|
await page.waitForFunction((selector: string) => $(selector).length !== 0, {}, pm_selector);
|
|
|
|
await page.evaluate((selector: string) => {
|
2020-06-19 21:20:53 +02:00
|
|
|
$(selector).slice(-1)[0].click();
|
|
|
|
}, pm_selector);
|
|
|
|
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
|
|
|
|
|
|
|
// verify if markdowm preview button works.
|
|
|
|
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");
|
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});
|
|
|
|
let markdown_preview_element = await page.$("#compose .preview_content");
|
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
|
|
|
"",
|
|
|
|
);
|
|
|
|
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");
|
|
|
|
await page.waitForSelector("#compose .preview_content", {visible: true});
|
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>";
|
2021-04-20 19:50:01 +02:00
|
|
|
await page.waitForFunction(() => $("#compose .preview_content").html() !== "");
|
|
|
|
markdown_preview_element = await page.$("#compose .preview_content");
|
2020-06-19 21:20:53 +02:00
|
|
|
assert.equal(
|
2021-02-20 05:52:06 +01:00
|
|
|
await page.evaluate((element: Element) => element.innerHTML, markdown_preview_element),
|
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);
|