2021-02-20 05:52:06 +01:00
|
|
|
import {strict as assert} from "assert";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-03-27 04:40:48 +01:00
|
|
|
import type {ElementHandle, Page} from "puppeteer";
|
2020-07-13 19:48:12 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import {test_credentials} from "../../var/puppeteer/test_credentials";
|
2023-02-22 23:04:11 +01:00
|
|
|
|
|
|
|
import * as common from "./lib/common";
|
2020-07-13 19:48:12 +02:00
|
|
|
|
|
|
|
const OUTGOING_WEBHOOK_BOT_TYPE = "3";
|
|
|
|
const GENERIC_BOT_TYPE = "1";
|
|
|
|
|
2021-05-09 22:29:53 +02:00
|
|
|
const zuliprc_regex =
|
|
|
|
/^data:application\/octet-stream;charset=utf-8,\[api]\nemail=.+\nkey=.+\nsite=.+\n$/;
|
2020-07-13 19:48:12 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function get_decoded_url_in_selector(page: Page, selector: string): Promise<string> {
|
2021-03-27 04:40:48 +01:00
|
|
|
const a = (await page.$(selector)) as ElementHandle<HTMLAnchorElement>;
|
|
|
|
return decodeURIComponent(await (await a.getProperty("href")).jsonValue());
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function open_settings(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
const menu_selector = "#settings-dropdown";
|
|
|
|
await page.waitForSelector(menu_selector, {visible: true});
|
|
|
|
await page.click(menu_selector);
|
|
|
|
|
2021-03-31 08:57:11 +02:00
|
|
|
const settings_selector = '.dropdown-menu a[href="#settings"]';
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.waitForSelector(settings_selector, {visible: true});
|
|
|
|
await page.click(settings_selector);
|
|
|
|
|
2021-06-17 18:42:31 +02:00
|
|
|
await page.waitForSelector("#settings_content .profile-settings-form", {visible: true});
|
2021-03-01 06:38:03 +01:00
|
|
|
const page_url = await common.page_url_with_fragment(page);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(
|
|
|
|
page_url.includes("/#settings/"),
|
|
|
|
`Page url: ${page_url} does not contain /#settings/`,
|
|
|
|
);
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_change_full_name(page: Page): Promise<void> {
|
2021-06-17 18:42:31 +02:00
|
|
|
await page.click("#full_name");
|
2020-07-13 19:48:12 +02:00
|
|
|
|
|
|
|
const full_name_input_selector = 'input[name="full_name"]';
|
2021-06-17 18:42:31 +02:00
|
|
|
await common.clear_and_type(page, full_name_input_selector, "New name");
|
|
|
|
|
|
|
|
await page.click("#settings_content .profile-settings-form");
|
2022-09-13 14:12:32 +02:00
|
|
|
await page.waitForSelector(".full-name-change-container .alert-success", {visible: true});
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForFunction(
|
|
|
|
() => document.querySelector<HTMLInputElement>("#full_name")?.value === "New name",
|
|
|
|
);
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2022-03-03 15:37:48 +01:00
|
|
|
async function test_change_password(page: Page): Promise<void> {
|
|
|
|
await page.click("#change_password");
|
|
|
|
|
|
|
|
const change_password_button_selector = "#change_password_modal .dialog_submit_button";
|
|
|
|
await page.waitForSelector(change_password_button_selector, {visible: true});
|
|
|
|
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
await page.type("#old_password", test_credentials.default_user.password);
|
|
|
|
test_credentials.default_user.password = "new_password";
|
|
|
|
await page.type("#new_password", test_credentials.default_user.password);
|
|
|
|
await page.click(change_password_button_selector);
|
|
|
|
|
|
|
|
// On success the change password modal gets closed.
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_get_api_key(page: Page): Promise<void> {
|
2022-02-25 17:37:50 +01:00
|
|
|
await page.click('[data-section="account-and-privacy"]');
|
2020-07-13 19:48:12 +02:00
|
|
|
const show_change_api_key_selector = "#api_key_button";
|
|
|
|
await page.click(show_change_api_key_selector);
|
|
|
|
|
|
|
|
const get_api_key_button_selector = "#get_api_key_button";
|
|
|
|
await page.waitForSelector(get_api_key_button_selector, {visible: true});
|
2021-07-20 14:52:50 +02:00
|
|
|
await common.wait_for_micromodal_to_open(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
await common.fill_form(page, "#api_key_form", {
|
|
|
|
password: test_credentials.default_user.password,
|
|
|
|
});
|
2021-03-06 21:14:31 +01:00
|
|
|
|
|
|
|
// When typing the password in Firefox, it shows "Not Secure" warning
|
2021-05-10 07:02:14 +02:00
|
|
|
// which was hiding the Get API key button.
|
2021-03-06 21:14:31 +01:00
|
|
|
// You can see the screenshot of it in https://github.com/zulip/zulip/pull/17136.
|
|
|
|
// Focusing on it will remove the warning.
|
|
|
|
await page.focus(get_api_key_button_selector);
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click(get_api_key_button_selector);
|
|
|
|
|
|
|
|
await page.waitForSelector("#show_api_key", {visible: true});
|
|
|
|
const api_key = await common.get_text_from_selector(page, "#api_key_value");
|
2021-06-08 04:57:40 +02:00
|
|
|
assert.match(api_key, /[\dA-Za-z]{32}/, "Incorrect API key format.");
|
2020-07-13 19:48:12 +02:00
|
|
|
|
|
|
|
const download_zuliprc_selector = "#download_zuliprc";
|
|
|
|
await page.click(download_zuliprc_selector);
|
|
|
|
const zuliprc_decoded_url = await get_decoded_url_in_selector(page, download_zuliprc_selector);
|
2021-06-08 04:57:40 +02:00
|
|
|
assert.match(zuliprc_decoded_url, zuliprc_regex, "Incorrect zuliprc file");
|
2021-07-20 14:52:50 +02:00
|
|
|
await page.click("#api_key_modal .modal__close");
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_webhook_bot_creation(page: Page): Promise<void> {
|
2022-09-15 14:07:39 +02:00
|
|
|
await page.click("#bot-settings .add-a-new-bot");
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, ".dialog_heading"),
|
|
|
|
"Add a new bot",
|
|
|
|
"Unexpected title for deactivate user modal",
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, "#dialog_widget_modal .dialog_submit_button"),
|
|
|
|
"Add",
|
|
|
|
"Deactivate button has incorrect text.",
|
|
|
|
);
|
2020-07-13 19:48:12 +02:00
|
|
|
await common.fill_form(page, "#create_bot_form", {
|
|
|
|
bot_name: "Bot 1",
|
|
|
|
bot_short_name: "1",
|
|
|
|
bot_type: OUTGOING_WEBHOOK_BOT_TYPE,
|
|
|
|
payload_url: "http://hostname.example.com/bots/followup",
|
|
|
|
});
|
2022-09-15 14:07:39 +02:00
|
|
|
await page.click("#dialog_widget_modal .dialog_submit_button");
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
|
|
|
|
const bot_email = "1-bot@zulip.testserver";
|
2021-02-03 23:23:32 +01:00
|
|
|
const download_zuliprc_selector = `.download_bot_zuliprc[data-email="${CSS.escape(
|
|
|
|
bot_email,
|
|
|
|
)}"]`;
|
2021-05-09 22:29:53 +02:00
|
|
|
const outgoing_webhook_zuliprc_regex =
|
|
|
|
/^data:application\/octet-stream;charset=utf-8,\[api]\nemail=.+\nkey=.+\nsite=.+\ntoken=.+\n$/;
|
2020-07-13 19:48:12 +02:00
|
|
|
|
|
|
|
await page.waitForSelector(download_zuliprc_selector, {visible: true});
|
|
|
|
await page.click(download_zuliprc_selector);
|
|
|
|
|
|
|
|
const zuliprc_decoded_url = await get_decoded_url_in_selector(page, download_zuliprc_selector);
|
2021-06-08 04:57:40 +02:00
|
|
|
assert.match(
|
|
|
|
zuliprc_decoded_url,
|
|
|
|
outgoing_webhook_zuliprc_regex,
|
2022-02-08 00:13:33 +01:00
|
|
|
"Incorrect outgoing webhook bot zuliprc format",
|
2020-07-13 19:48:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_normal_bot_creation(page: Page): Promise<void> {
|
2022-09-15 14:07:39 +02:00
|
|
|
await page.click("#bot-settings .add-a-new-bot");
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, ".dialog_heading"),
|
|
|
|
"Add a new bot",
|
|
|
|
"Unexpected title for deactivate user modal",
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, "#dialog_widget_modal .dialog_submit_button"),
|
|
|
|
"Add",
|
|
|
|
"Deactivate button has incorrect text.",
|
|
|
|
);
|
2020-07-13 19:48:12 +02:00
|
|
|
await common.fill_form(page, "#create_bot_form", {
|
|
|
|
bot_name: "Bot 2",
|
|
|
|
bot_short_name: "2",
|
|
|
|
bot_type: GENERIC_BOT_TYPE,
|
|
|
|
});
|
2022-09-15 14:07:39 +02:00
|
|
|
await page.click("#dialog_widget_modal .dialog_submit_button");
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
|
|
|
|
const bot_email = "2-bot@zulip.testserver";
|
2021-02-03 23:23:32 +01:00
|
|
|
const download_zuliprc_selector = `.download_bot_zuliprc[data-email="${CSS.escape(
|
|
|
|
bot_email,
|
|
|
|
)}"]`;
|
2020-07-13 19:48:12 +02:00
|
|
|
|
|
|
|
await page.waitForSelector(download_zuliprc_selector, {visible: true});
|
|
|
|
await page.click(download_zuliprc_selector);
|
|
|
|
const zuliprc_decoded_url = await get_decoded_url_in_selector(page, download_zuliprc_selector);
|
2021-06-08 04:57:40 +02:00
|
|
|
assert.match(zuliprc_decoded_url, zuliprc_regex, "Incorrect zuliprc format for bot.");
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_botserverrc(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click("#download_botserverrc");
|
|
|
|
await page.waitForSelector('#download_botserverrc[href^="data:application"]', {visible: true});
|
|
|
|
const botserverrc_decoded_url = await get_decoded_url_in_selector(
|
|
|
|
page,
|
|
|
|
"#download_botserverrc",
|
|
|
|
);
|
2021-05-09 22:29:53 +02:00
|
|
|
const botserverrc_regex =
|
|
|
|
/^data:application\/octet-stream;charset=utf-8,\[]\nemail=.+\nkey=.+\nsite=.+\ntoken=.+\n$/;
|
2021-06-08 04:57:40 +02:00
|
|
|
assert.match(botserverrc_decoded_url, botserverrc_regex, "Incorrect botserverrc format.");
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_edit_bot_form(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
const bot1_email = "1-bot@zulip.testserver";
|
2021-02-03 23:23:32 +01:00
|
|
|
const bot1_edit_btn = `.open_edit_bot_form[data-email="${CSS.escape(bot1_email)}"]`;
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click(bot1_edit_btn);
|
|
|
|
|
2022-07-11 12:23:59 +02:00
|
|
|
const edit_form_selector = `#bot-edit-form[data-email="${CSS.escape(bot1_email)}"]`;
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.waitForSelector(edit_form_selector, {visible: true});
|
2022-07-11 12:23:59 +02:00
|
|
|
const name_field_selector = edit_form_selector + " [name=full_name]";
|
2021-06-08 20:40:18 +02:00
|
|
|
assert.equal(
|
|
|
|
await page.$eval(name_field_selector, (el) => (el as HTMLInputElement).value),
|
|
|
|
"Bot 1",
|
|
|
|
);
|
2020-07-13 19:48:12 +02:00
|
|
|
|
2022-07-11 12:23:59 +02:00
|
|
|
await common.fill_form(page, edit_form_selector, {full_name: "Bot one"});
|
2021-07-18 08:43:09 +02:00
|
|
|
const save_btn_selector = "#edit_bot_modal .dialog_submit_button";
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click(save_btn_selector);
|
|
|
|
|
|
|
|
// The form gets closed on saving. So, assert it's closed by waiting for it to be hidden.
|
2020-08-11 01:48:53 +02:00
|
|
|
await page.waitForSelector("#edit_bot_modal", {hidden: true});
|
2020-07-13 19:48:12 +02:00
|
|
|
|
2022-09-10 05:37:50 +02:00
|
|
|
await page.waitForSelector(
|
2021-03-27 04:20:49 +01:00
|
|
|
`xpath///*[${common.has_class_x(
|
|
|
|
"open_edit_bot_form",
|
|
|
|
)} and @data-email="${bot1_email}"]/ancestor::*[${common.has_class_x(
|
|
|
|
"details",
|
|
|
|
)}]/*[${common.has_class_x("name")} and text()="Bot one"]`,
|
2020-07-13 19:48:12 +02:00
|
|
|
);
|
2020-11-24 21:04:16 +01:00
|
|
|
|
2021-07-18 08:43:09 +02:00
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 11:56:12 +01:00
|
|
|
// Disabled the below test due to non-deterministic failures.
|
|
|
|
// The test often fails to close the modal.
|
|
|
|
// TODO: Debug this and re-enable with a fix.
|
2021-04-12 21:14:40 +02:00
|
|
|
async function test_invalid_edit_bot_form(page: Page): Promise<void> {
|
2022-01-17 11:56:12 +01:00
|
|
|
return;
|
2021-04-12 21:14:40 +02:00
|
|
|
const bot1_email = "1-bot@zulip.testserver";
|
|
|
|
const bot1_edit_btn = `.open_edit_bot_form[data-email="${CSS.escape(bot1_email)}"]`;
|
|
|
|
await page.click(bot1_edit_btn);
|
|
|
|
|
2022-07-11 12:23:59 +02:00
|
|
|
const edit_form_selector = `#bot-edit-form[data-email="${CSS.escape(bot1_email)}"]`;
|
2021-04-12 21:14:40 +02:00
|
|
|
await page.waitForSelector(edit_form_selector, {visible: true});
|
2022-07-11 12:23:59 +02:00
|
|
|
const name_field_selector = edit_form_selector + " [name=full_name]";
|
2021-06-08 20:40:18 +02:00
|
|
|
assert.equal(
|
|
|
|
await page.$eval(name_field_selector, (el) => (el as HTMLInputElement).value),
|
|
|
|
"Bot one",
|
|
|
|
);
|
2021-04-12 21:14:40 +02:00
|
|
|
|
2022-07-11 12:23:59 +02:00
|
|
|
await common.fill_form(page, edit_form_selector, {full_name: "Bot 2"});
|
2021-07-18 08:43:09 +02:00
|
|
|
const save_btn_selector = "#edit_bot_modal .dialog_submit_button";
|
2021-04-12 21:14:40 +02:00
|
|
|
await page.click(save_btn_selector);
|
|
|
|
|
|
|
|
// The form should not get closed on saving. Errors should be visible on the form.
|
2021-12-02 14:42:52 +01:00
|
|
|
await common.wait_for_micromodal_to_open(page);
|
2022-07-11 12:23:59 +02:00
|
|
|
await page.waitForSelector("#dialog_error", {visible: true});
|
2021-04-12 21:14:40 +02:00
|
|
|
assert.strictEqual(
|
2022-07-11 12:23:59 +02:00
|
|
|
await common.get_text_from_selector(page, "#dialog_error"),
|
|
|
|
"Failed: Name is already in use!",
|
2021-04-12 21:14:40 +02:00
|
|
|
);
|
2021-12-15 04:15:13 +01:00
|
|
|
|
|
|
|
const cancel_button_selector = "#edit_bot_modal .dialog_cancel_button";
|
|
|
|
await page.waitForFunction(
|
|
|
|
(cancel_button_selector: string) =>
|
|
|
|
!document.querySelector(cancel_button_selector)?.hasAttribute("disabled"),
|
2022-07-06 05:28:39 +02:00
|
|
|
{},
|
|
|
|
cancel_button_selector,
|
2021-12-15 04:15:13 +01:00
|
|
|
);
|
|
|
|
await page.click(cancel_button_selector);
|
2022-09-10 05:37:50 +02:00
|
|
|
await page.waitForSelector(
|
2021-03-27 04:20:49 +01:00
|
|
|
`xpath///*[${common.has_class_x(
|
|
|
|
"open_edit_bot_form",
|
|
|
|
)} and @data-email="${bot1_email}"]/ancestor::*[${common.has_class_x(
|
|
|
|
"details",
|
|
|
|
)}]/*[${common.has_class_x("name")} and text()="Bot one"]`,
|
2021-04-12 21:14:40 +02:00
|
|
|
);
|
|
|
|
|
2021-07-18 08:43:09 +02:00
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2021-04-12 21:14:40 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_your_bots_section(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click('[data-section="your-bots"]');
|
|
|
|
await test_webhook_bot_creation(page);
|
|
|
|
await test_normal_bot_creation(page);
|
|
|
|
await test_botserverrc(page);
|
|
|
|
await test_edit_bot_form(page);
|
2021-04-12 21:14:40 +02:00
|
|
|
await test_invalid_edit_bot_form(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const alert_word_status_selector = "#alert_word_status";
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function add_alert_word(page: Page, word: string): Promise<void> {
|
2022-07-21 06:24:16 +02:00
|
|
|
await page.click("#open-add-alert-word-modal");
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
|
|
|
|
await page.type("#add-alert-word-name", word);
|
|
|
|
await page.click("#add-alert-word .dialog_submit_button");
|
|
|
|
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function check_alert_word_added(page: Page, word: string): Promise<void> {
|
2021-02-03 23:23:32 +01:00
|
|
|
const added_alert_word_selector = `.alert-word-item[data-word='${CSS.escape(word)}']`;
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.waitForSelector(added_alert_word_selector, {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function get_alert_words_status_text(page: Page): Promise<string> {
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.waitForSelector(alert_word_status_selector, {visible: true});
|
|
|
|
const status_text = await common.get_text_from_selector(page, ".alert_word_status_text");
|
|
|
|
return status_text;
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function close_alert_words_status(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
const status_close_btn = ".close-alert-word-status";
|
|
|
|
await page.click(status_close_btn);
|
2020-08-11 01:48:53 +02:00
|
|
|
await page.waitForSelector(alert_word_status_selector, {hidden: true});
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_duplicate_alert_words_cannot_be_added(
|
|
|
|
page: Page,
|
|
|
|
duplicate_word: string,
|
|
|
|
): Promise<void> {
|
2022-07-21 06:24:16 +02:00
|
|
|
await page.click("#open-add-alert-word-modal");
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
|
|
|
|
await page.type("#add-alert-word-name", duplicate_word);
|
|
|
|
await page.click("#add-alert-word .dialog_submit_button");
|
|
|
|
|
|
|
|
const alert_word_status_selector = "#dialog_error";
|
|
|
|
await page.waitForSelector(alert_word_status_selector, {visible: true});
|
|
|
|
const status_text = await common.get_text_from_selector(page, alert_word_status_selector);
|
2020-07-13 19:48:12 +02:00
|
|
|
assert.strictEqual(status_text, "Alert word already exists!");
|
2022-07-21 06:24:16 +02:00
|
|
|
|
|
|
|
await page.click("#add-alert-word .dialog_cancel_button");
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function delete_alert_word(page: Page, word: string): Promise<void> {
|
2021-02-03 23:23:32 +01:00
|
|
|
const delete_btn_selector = `.remove-alert-word[data-word="${CSS.escape(word)}"]`;
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click(delete_btn_selector);
|
2021-02-20 05:58:35 +01:00
|
|
|
await page.waitForSelector(delete_btn_selector, {hidden: true});
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_alert_word_deletion(page: Page, word: string): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
await delete_alert_word(page, word);
|
|
|
|
const status_text = await get_alert_words_status_text(page);
|
2022-11-20 22:12:05 +01:00
|
|
|
assert.strictEqual(status_text, `Alert word "${word}" removed successfully!`);
|
2020-07-13 19:48:12 +02:00
|
|
|
await close_alert_words_status(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_alert_words_section(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click('[data-section="alert-words"]');
|
|
|
|
const word = "puppeteer";
|
|
|
|
await add_alert_word(page, word);
|
|
|
|
await check_alert_word_added(page, word);
|
|
|
|
await test_duplicate_alert_words_cannot_be_added(page, word);
|
|
|
|
await test_alert_word_deletion(page, word);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function change_language(page: Page, language_data_code: string): Promise<void> {
|
2022-05-02 11:15:25 +02:00
|
|
|
await page.waitForSelector("#user-display-settings .language_selection_button", {
|
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
await page.click("#user-display-settings .language_selection_button");
|
2021-07-18 15:33:16 +02:00
|
|
|
await common.wait_for_micromodal_to_open(page);
|
2021-02-03 23:23:32 +01:00
|
|
|
const language_selector = `a[data-code="${CSS.escape(language_data_code)}"]`;
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click(language_selector);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function check_language_setting_status(page: Page): Promise<void> {
|
2023-03-04 14:49:02 +01:00
|
|
|
await page.waitForSelector("#user-display-settings .general-settings-status .reload_link", {
|
2021-08-09 12:01:13 +02:00
|
|
|
visible: true,
|
|
|
|
});
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function assert_language_changed_to_chinese(page: Page): Promise<void> {
|
2022-05-02 11:15:25 +02:00
|
|
|
await page.waitForSelector("#user-display-settings .language_selection_button", {
|
|
|
|
visible: true,
|
|
|
|
});
|
2021-08-09 12:01:13 +02:00
|
|
|
const default_language = await common.get_text_from_selector(
|
|
|
|
page,
|
2022-05-02 11:15:25 +02:00
|
|
|
"#user-display-settings .language_selection_button",
|
2021-08-09 12:01:13 +02:00
|
|
|
);
|
2020-07-13 19:48:12 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
default_language,
|
|
|
|
"简体中文",
|
|
|
|
"Default language has not been changed to Chinese.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_i18n_language_precedence(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
const settings_url_for_german = "http://zulip.zulipdev.com:9981/de/#settings";
|
|
|
|
await page.goto(settings_url_for_german);
|
2020-08-28 15:50:29 +02:00
|
|
|
await page.waitForSelector("#settings-change-box", {visible: true});
|
2020-07-13 19:48:12 +02:00
|
|
|
const page_language_code = await page.evaluate(() => document.documentElement.lang);
|
|
|
|
assert.strictEqual(page_language_code, "de");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_default_language_setting(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
const display_settings_section = '[data-section="display-settings"]';
|
|
|
|
await page.click(display_settings_section);
|
|
|
|
|
|
|
|
const chinese_language_data_code = "zh-hans";
|
|
|
|
await change_language(page, chinese_language_data_code);
|
2021-01-20 09:04:29 +01:00
|
|
|
// Check that the saved indicator appears
|
|
|
|
await check_language_setting_status(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click(".reload_link");
|
2022-05-02 11:15:25 +02:00
|
|
|
await page.waitForSelector("#user-display-settings .language_selection_button", {
|
|
|
|
visible: true,
|
|
|
|
});
|
2020-07-13 19:48:12 +02:00
|
|
|
await assert_language_changed_to_chinese(page);
|
|
|
|
await test_i18n_language_precedence(page);
|
2020-08-28 16:03:38 +02:00
|
|
|
await page.waitForSelector(display_settings_section, {visible: true});
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click(display_settings_section);
|
|
|
|
|
|
|
|
// Change the language back to English so that subsequent tests pass.
|
|
|
|
await change_language(page, "en");
|
|
|
|
|
2021-01-20 09:04:29 +01:00
|
|
|
// Check that the saved indicator appears
|
|
|
|
await check_language_setting_status(page);
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.goto("http://zulip.zulipdev.com:9981/#settings"); // get back to normal language.
|
2020-08-28 15:50:29 +02:00
|
|
|
await page.waitForSelector(display_settings_section, {visible: true});
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click(display_settings_section);
|
2023-03-04 14:49:02 +01:00
|
|
|
await page.waitForSelector("#user-display-settings .general-settings-status", {
|
2021-11-09 12:36:40 +01:00
|
|
|
visible: true,
|
|
|
|
});
|
2022-05-02 11:15:25 +02:00
|
|
|
await page.waitForSelector("#user-display-settings .language_selection_button", {
|
|
|
|
visible: true,
|
|
|
|
});
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_notifications_section(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.click('[data-section="notifications"]');
|
|
|
|
// At the beginning, "PMs, mentions, and alerts"(checkbox name=enable_sounds) audio will be on
|
|
|
|
// and "Streams"(checkbox name=enable_stream_audible_notifications) audio will be off by default.
|
|
|
|
|
2021-09-16 20:29:59 +02:00
|
|
|
const notification_sound_enabled =
|
|
|
|
"#user-notification-settings .setting_notification_sound:enabled";
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.waitForSelector(notification_sound_enabled, {visible: true});
|
|
|
|
|
2021-09-16 20:29:59 +02:00
|
|
|
await common.fill_form(page, "#user-notification-settings .notification-settings-form", {
|
2020-07-13 19:48:12 +02:00
|
|
|
enable_stream_audible_notifications: true,
|
|
|
|
enable_sounds: false,
|
|
|
|
});
|
|
|
|
await page.waitForSelector(notification_sound_enabled, {visible: true});
|
|
|
|
|
2021-09-16 20:29:59 +02:00
|
|
|
await common.fill_form(page, "#user-notification-settings .notification-settings-form", {
|
2020-07-13 19:48:12 +02:00
|
|
|
enable_stream_audible_notifications: true,
|
|
|
|
});
|
|
|
|
/*
|
|
|
|
Usually notifications sound dropdown gets disabled on disabling
|
|
|
|
all audio notifications. But this seems flaky in tests.
|
|
|
|
TODO: Find the right fix and enable this.
|
|
|
|
|
2021-08-10 12:56:28 +02:00
|
|
|
const notification_sound_disabled = ".setting_notification_sound:disabled";
|
2020-07-13 19:48:12 +02:00
|
|
|
await page.waitForSelector(notification_sound_disabled);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function settings_tests(page: Page): Promise<void> {
|
2020-07-13 19:48:12 +02:00
|
|
|
await common.log_in(page);
|
|
|
|
await open_settings(page);
|
|
|
|
await test_change_full_name(page);
|
|
|
|
await test_alert_words_section(page);
|
|
|
|
await test_your_bots_section(page);
|
|
|
|
await test_default_language_setting(page);
|
|
|
|
await test_notifications_section(page);
|
2022-03-03 15:37:48 +01:00
|
|
|
await test_get_api_key(page);
|
|
|
|
await test_change_password(page);
|
|
|
|
// test_change_password should be the very last test, because it
|
|
|
|
// replaces your session, which can lead to some nondeterministic
|
|
|
|
// failures in test code after it, involving `GET /events`
|
|
|
|
// returning a 401. (We reset the test database after each file).
|
2020-07-13 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(settings_tests);
|