2024-10-09 00:25:41 +02:00
|
|
|
import assert from "node:assert/strict";
|
2020-08-07 22:05:18 +02:00
|
|
|
|
2023-10-25 02:19:36 +02:00
|
|
|
import type {Page} from "puppeteer";
|
2020-08-07 22:05:18 +02:00
|
|
|
|
2024-11-12 03:59:37 +01:00
|
|
|
import * as common from "./lib/common.ts";
|
2020-08-07 22:05:18 +02:00
|
|
|
|
2024-02-07 12:13:02 +01:00
|
|
|
async function submit_announcements_stream_settings(page: Page): Promise<void> {
|
2022-12-07 13:10:53 +01:00
|
|
|
await page.waitForSelector('#org-notifications .save-button[data-status="unsaved"]', {
|
|
|
|
visible: true,
|
|
|
|
});
|
2020-08-07 22:05:18 +02:00
|
|
|
|
2022-12-07 13:10:53 +01:00
|
|
|
const save_button = "#org-notifications .save-button";
|
2020-08-07 22:05:18 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, save_button),
|
|
|
|
"Save changes",
|
|
|
|
"Save button has incorrect text.",
|
|
|
|
);
|
|
|
|
await page.click(save_button);
|
|
|
|
|
2022-12-07 13:10:53 +01:00
|
|
|
await page.waitForSelector('#org-notifications .save-button[data-status="saved"]', {
|
|
|
|
visible: true,
|
|
|
|
});
|
2020-08-07 22:05:18 +02:00
|
|
|
assert.strictEqual(
|
2022-12-07 13:10:53 +01:00
|
|
|
await common.get_text_from_selector(page, "#org-notifications .save-button"),
|
2020-08-07 22:05:18 +02:00
|
|
|
"Saved",
|
|
|
|
"Saved text didn't appear after saving new stream notifications setting",
|
|
|
|
);
|
|
|
|
|
2022-12-07 13:10:53 +01:00
|
|
|
await page.waitForSelector("#org-notifications .save-button", {hidden: true});
|
2020-08-07 22:05:18 +02:00
|
|
|
}
|
|
|
|
|
2024-02-07 12:13:02 +01:00
|
|
|
async function test_change_new_stream_announcements_stream(page: Page): Promise<void> {
|
|
|
|
await page.click("#realm_new_stream_announcements_stream_id_widget.dropdown-widget-button");
|
2023-07-19 16:14:00 +02:00
|
|
|
await page.waitForSelector(".dropdown-list-container", {
|
2020-08-07 22:05:18 +02:00
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
|
2023-07-19 16:14:00 +02:00
|
|
|
await page.type(".dropdown-list-search-input", "rome");
|
2020-08-19 18:58:10 +02:00
|
|
|
|
2022-09-10 05:37:50 +02:00
|
|
|
const rome_in_dropdown = await page.waitForSelector(
|
2023-07-19 16:14:00 +02:00
|
|
|
`xpath///*[${common.has_class_x("list-item")}][normalize-space()="Rome"]`,
|
2021-03-12 23:13:45 +01:00
|
|
|
{visible: true},
|
|
|
|
);
|
2022-09-09 14:51:32 +02:00
|
|
|
assert.ok(rome_in_dropdown);
|
2022-09-10 05:37:50 +02:00
|
|
|
await rome_in_dropdown.click();
|
2020-08-19 18:58:10 +02:00
|
|
|
|
2024-02-07 12:13:02 +01:00
|
|
|
await submit_announcements_stream_settings(page);
|
2020-08-07 22:05:18 +02:00
|
|
|
}
|
|
|
|
|
2024-02-07 17:11:43 +01:00
|
|
|
async function test_change_signup_announcements_stream(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
console.log('Changing signup notifications stream to Verona by filtering with "verona"');
|
|
|
|
|
2024-02-07 17:11:43 +01:00
|
|
|
await page.click("#realm_signup_announcements_stream_id_widget");
|
2023-07-19 16:14:00 +02:00
|
|
|
await page.waitForSelector(".dropdown-list-search-input", {visible: true});
|
2020-08-07 22:05:18 +02:00
|
|
|
|
2023-07-19 16:14:00 +02:00
|
|
|
await page.type(".dropdown-list-search-input", "verona");
|
|
|
|
await page.waitForSelector(".dropdown-list .list-item", {visible: true});
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.keyboard.press("ArrowDown");
|
|
|
|
await page.keyboard.press("Enter");
|
2024-02-07 12:13:02 +01:00
|
|
|
await submit_announcements_stream_settings(page);
|
2020-08-07 22:05:18 +02:00
|
|
|
}
|
|
|
|
|
2024-01-26 14:45:37 +01:00
|
|
|
async function test_change_zulip_update_announcements_stream(page: Page): Promise<void> {
|
|
|
|
await page.click("#realm_zulip_update_announcements_stream_id_widget.dropdown-widget-button");
|
|
|
|
await page.waitForSelector(".dropdown-list-container", {
|
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.type(".dropdown-list-search-input", "rome");
|
|
|
|
|
|
|
|
const rome_in_dropdown = await page.waitForSelector(
|
|
|
|
`xpath///*[${common.has_class_x("list-item")}][normalize-space()="Rome"]`,
|
|
|
|
{visible: true},
|
|
|
|
);
|
|
|
|
assert.ok(rome_in_dropdown);
|
|
|
|
await rome_in_dropdown.click();
|
|
|
|
|
|
|
|
await submit_announcements_stream_settings(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_permissions_change_save_worked(page: Page): Promise<void> {
|
2022-12-07 13:10:53 +01:00
|
|
|
const saved_status = '#org-stream-permissions .save-button[data-status="saved"]';
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.waitForSelector(saved_status, {
|
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
await page.waitForSelector(saved_status, {hidden: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function submit_stream_permissions_change(page: Page): Promise<void> {
|
2022-12-07 13:10:53 +01:00
|
|
|
const save_button = "#org-stream-permissions .save-button";
|
2020-09-05 18:00:00 +02:00
|
|
|
await page.waitForSelector(save_button, {visible: true});
|
2020-08-07 22:05:18 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, save_button),
|
|
|
|
"Save changes",
|
|
|
|
"Save button didn't appear for permissions change.",
|
|
|
|
);
|
|
|
|
await page.click(save_button);
|
|
|
|
|
|
|
|
await test_permissions_change_save_worked(page);
|
|
|
|
}
|
|
|
|
|
2021-06-19 16:53:48 +02:00
|
|
|
async function test_changing_create_streams_and_invite_to_stream_policies(
|
|
|
|
page: Page,
|
|
|
|
): Promise<void> {
|
|
|
|
const policies = {
|
|
|
|
"invite to stream": "#id_realm_invite_to_stream_policy",
|
|
|
|
};
|
|
|
|
const policy_values = {
|
|
|
|
"admins only": 2,
|
|
|
|
"members and admins": 1,
|
|
|
|
"full members": 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const [policy, selector] of Object.entries(policies)) {
|
|
|
|
for (const [policy_value_name, policy_value] of Object.entries(policy_values)) {
|
|
|
|
console.log(`Test setting ${policy} policy to '${policy_value_name}'.`);
|
|
|
|
await page.waitForSelector(selector, {visible: true});
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.select(selector, `${policy_value}`);
|
2021-06-19 16:53:48 +02:00
|
|
|
await submit_stream_permissions_change(page);
|
|
|
|
}
|
|
|
|
}
|
2020-08-07 22:05:18 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_save_joining_organization_change_worked(page: Page): Promise<void> {
|
2022-12-07 13:10:53 +01:00
|
|
|
const saved_status = '#org-join-settings .save-button[data-status="saved"]';
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.waitForSelector(saved_status, {
|
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
await page.waitForSelector(saved_status, {hidden: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function submit_joining_organization_change(page: Page): Promise<void> {
|
2022-12-07 13:10:53 +01:00
|
|
|
const save_button = "#org-join-settings .save-button";
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.waitForSelector(save_button, {visible: true});
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, save_button),
|
|
|
|
"Save changes",
|
|
|
|
"Save button didn't appear for permissions change.",
|
|
|
|
);
|
|
|
|
await page.waitForSelector(save_button, {visible: true});
|
|
|
|
await page.click(save_button);
|
|
|
|
|
|
|
|
await test_save_joining_organization_change_worked(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_set_new_user_threshold_to_three_days(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
console.log("Test setting new user threshold to three days.");
|
2022-12-13 12:32:01 +01:00
|
|
|
await page.waitForSelector("#id_realm_waiting_period_threshold", {visible: true});
|
2022-12-12 18:21:08 +01:00
|
|
|
await page.select("#id_realm_waiting_period_threshold", "3");
|
2020-08-07 22:05:18 +02:00
|
|
|
await submit_joining_organization_change(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_set_new_user_threshold_to_N_days(page: Page): Promise<void> {
|
2023-03-04 02:09:45 +01:00
|
|
|
console.log("Test setting new user threshold to N days.");
|
2022-12-13 12:32:01 +01:00
|
|
|
await page.waitForSelector("#id_realm_waiting_period_threshold", {visible: true});
|
|
|
|
await page.select("#id_realm_waiting_period_threshold", "custom_period");
|
2020-08-07 22:05:18 +02:00
|
|
|
|
2021-03-27 04:40:48 +01:00
|
|
|
const N = "10";
|
2022-12-13 12:32:01 +01:00
|
|
|
await common.clear_and_type(page, "#id_realm_waiting_period_threshold_custom_input", N);
|
2020-08-07 22:05:18 +02:00
|
|
|
await submit_joining_organization_change(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_organization_permissions(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.click("li[data-section='organization-permissions']");
|
|
|
|
|
2024-02-07 18:39:39 +01:00
|
|
|
// Test temporarily disabled 2024-02-07 due to nondeterminsitic failures.
|
2024-06-06 21:48:31 +02:00
|
|
|
// See https://chat.zulip.org/#narrow/channel/43-automated-testing/topic/main.20failing/near/1733342
|
2024-02-07 18:39:39 +01:00
|
|
|
console.log("Skipping", test_changing_create_streams_and_invite_to_stream_policies);
|
2020-08-07 22:05:18 +02:00
|
|
|
|
2024-02-25 19:05:14 +01:00
|
|
|
// Test temporarily disabled 2024-02-25 due to nondeterminsitic failures.
|
2024-06-06 21:48:31 +02:00
|
|
|
// See https://chat.zulip.org/#narrow/channel/43-automated-testing/topic/main.20failing/near/1743361
|
2024-02-25 19:05:14 +01:00
|
|
|
console.log("Skipping", test_set_new_user_threshold_to_three_days);
|
|
|
|
console.log("Skipping", test_set_new_user_threshold_to_N_days);
|
2020-08-07 22:05:18 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_add_emoji(page: Page): Promise<void> {
|
2022-03-29 18:46:59 +02:00
|
|
|
await common.fill_form(page, "#add-custom-emoji-form", {name: "zulip logo"});
|
2020-08-07 22:05:18 +02:00
|
|
|
|
2023-10-25 02:19:36 +02:00
|
|
|
const emoji_upload_handle = await page.$("input#emoji_file_input");
|
2022-08-04 22:16:39 +02:00
|
|
|
assert.ok(emoji_upload_handle);
|
2023-10-25 02:19:36 +02:00
|
|
|
await emoji_upload_handle.uploadFile("static/images/logo/zulip-icon-128x128.png");
|
2022-03-29 18:46:59 +02:00
|
|
|
await page.click("#add-custom-emoji-modal .dialog_submit_button");
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2020-08-07 22:05:18 +02:00
|
|
|
|
|
|
|
await page.waitForSelector("tr#emoji_zulip_logo", {visible: true});
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, "tr#emoji_zulip_logo .emoji_name"),
|
|
|
|
"zulip logo",
|
|
|
|
"Emoji name incorrectly saved.",
|
|
|
|
);
|
|
|
|
await page.waitForSelector("tr#emoji_zulip_logo img", {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_delete_emoji(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.click("tr#emoji_zulip_logo button.delete");
|
|
|
|
|
2022-09-06 15:26:07 +02:00
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
await page.click("#confirm_deactivate_custom_emoji_modal .dialog_submit_button");
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
|
|
|
|
2020-08-07 22:05:18 +02:00
|
|
|
// assert the emoji is deleted.
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector("tr#emoji_zulip_logo", {hidden: true});
|
2020-08-07 22:05:18 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_custom_realm_emoji(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.click("li[data-section='emoji-settings']");
|
2022-03-29 18:46:59 +02:00
|
|
|
await page.click("#add-custom-emoji-button");
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
2020-08-07 22:05:18 +02:00
|
|
|
|
|
|
|
await test_add_emoji(page);
|
|
|
|
await test_delete_emoji(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_upload_realm_icon_image(page: Page): Promise<void> {
|
2023-10-25 02:19:36 +02:00
|
|
|
const upload_handle = await page.$("#realm-icon-upload-widget input.image_file_input");
|
2022-08-04 22:16:39 +02:00
|
|
|
assert.ok(upload_handle);
|
2023-10-25 02:19:36 +02:00
|
|
|
await upload_handle.uploadFile("static/images/logo/zulip-icon-128x128.png");
|
2020-08-07 22:05:18 +02:00
|
|
|
|
|
|
|
await page.waitForSelector("#realm-icon-upload-widget .upload-spinner-background", {
|
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
await page.waitForSelector("#realm-icon-upload-widget .upload-spinner-background", {
|
2021-03-11 22:48:43 +01:00
|
|
|
hidden: true,
|
2020-08-07 22:05:18 +02:00
|
|
|
});
|
|
|
|
await page.waitForSelector(
|
|
|
|
'#realm-icon-upload-widget .image-block[src^="/user_avatars/2/realm/icon.png?version=2"]',
|
|
|
|
{visible: true},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function delete_realm_icon(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.click("li[data-section='organization-profile']");
|
|
|
|
await page.click("#realm-icon-upload-widget .image-delete-button");
|
|
|
|
|
2021-03-11 22:48:43 +01:00
|
|
|
await page.waitForSelector("#realm-icon-upload-widget .image-delete-button", {hidden: true});
|
2020-08-07 22:05:18 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_organization_profile(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.click("li[data-section='organization-profile']");
|
|
|
|
const gravatar_selctor =
|
|
|
|
'#realm-icon-upload-widget .image-block[src^="https://secure.gravatar.com/avatar/"]';
|
|
|
|
await page.waitForSelector(gravatar_selctor, {visible: true});
|
2021-03-11 22:48:43 +01:00
|
|
|
await page.waitForSelector("#realm-icon-upload-widget .image-delete-button", {hidden: true});
|
2020-08-07 22:05:18 +02:00
|
|
|
|
|
|
|
await test_upload_realm_icon_image(page);
|
|
|
|
await page.waitForSelector("#realm-icon-upload-widget .image-delete-button", {visible: true});
|
|
|
|
|
|
|
|
await delete_realm_icon(page);
|
2021-03-11 22:48:43 +01:00
|
|
|
await page.waitForSelector("#realm-icon-upload-widget .image-delete-button", {hidden: true});
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.waitForSelector(gravatar_selctor, {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_authentication_methods(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
await page.click("li[data-section='auth-methods']");
|
|
|
|
await page.waitForSelector(".method_row[data-method='Google'] input[type='checkbox'] + span", {
|
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.click(".method_row[data-method='Google'] input[type='checkbox'] + span");
|
2022-12-07 13:10:53 +01:00
|
|
|
const save_button = "#org-auth_settings .save-button";
|
2020-08-07 22:05:18 +02:00
|
|
|
assert.strictEqual(await common.get_text_from_selector(page, save_button), "Save changes");
|
|
|
|
await page.click(save_button);
|
|
|
|
|
|
|
|
// Leave the page and return.
|
|
|
|
const settings_dropdown = "#settings-dropdown";
|
|
|
|
await page.click(settings_dropdown);
|
|
|
|
|
|
|
|
await common.manage_organization(page);
|
|
|
|
await page.click("li[data-section='auth-methods']");
|
|
|
|
|
|
|
|
// Test setting was saved.
|
|
|
|
await page.waitForSelector(".method_row[data-method='Google'] input[type='checkbox'] + span", {
|
|
|
|
visible: true,
|
|
|
|
});
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector(
|
|
|
|
".method_row[data-method='Google'] input[type='checkbox']:not(:checked)",
|
2020-08-07 22:05:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function admin_test(page: Page): Promise<void> {
|
2020-08-07 22:05:18 +02:00
|
|
|
await common.log_in(page);
|
|
|
|
|
|
|
|
await common.manage_organization(page);
|
2024-02-07 12:13:02 +01:00
|
|
|
await test_change_new_stream_announcements_stream(page);
|
2024-02-07 17:11:43 +01:00
|
|
|
await test_change_signup_announcements_stream(page);
|
2024-01-26 14:45:37 +01:00
|
|
|
await test_change_zulip_update_announcements_stream(page);
|
2020-08-07 22:05:18 +02:00
|
|
|
|
|
|
|
await test_organization_permissions(page);
|
2021-03-03 05:52:03 +01:00
|
|
|
// Currently, Firefox (with puppeteer) does not support file upload:
|
|
|
|
// https://github.com/puppeteer/puppeteer/issues/6688.
|
|
|
|
// Until that is resolved upstream, we need to skip the tests that involve
|
|
|
|
// doing file upload on Firefox.
|
|
|
|
if (!common.is_firefox) {
|
|
|
|
await test_custom_realm_emoji(page);
|
|
|
|
await test_organization_profile(page);
|
|
|
|
}
|
2020-08-07 22:05:18 +02:00
|
|
|
await test_authentication_methods(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(admin_test);
|