2024-10-09 00:25:41 +02:00
|
|
|
import assert from "node:assert/strict";
|
2020-08-14 20:20:53 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import type {Page} from "puppeteer";
|
2020-08-14 20:20:53 +02:00
|
|
|
|
2023-02-22 23:04:11 +01:00
|
|
|
import * as common from "./lib/common";
|
2020-08-14 20:20:53 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function navigate_to_user_list(page: Page): Promise<void> {
|
2020-08-14 20:20:53 +02:00
|
|
|
const menu_selector = "#settings-dropdown";
|
|
|
|
await page.waitForSelector(menu_selector, {visible: true});
|
|
|
|
await page.click(menu_selector);
|
2023-10-13 12:51:35 +02:00
|
|
|
|
|
|
|
const organization_settings = '.link-item a[href="#organization"]';
|
|
|
|
await page.waitForSelector(organization_settings, {visible: true});
|
|
|
|
await page.click(organization_settings);
|
|
|
|
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector("#settings_overlay_container.show", {visible: true});
|
2024-06-12 10:59:52 +02:00
|
|
|
await page.click("li[data-section='users']");
|
2024-05-30 11:28:49 +02:00
|
|
|
await page.waitForSelector("#admin-user-list.show", {visible: true});
|
2020-08-14 20:20:53 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function user_row(page: Page, name: string): Promise<string> {
|
2020-08-14 20:20:53 +02:00
|
|
|
const user_id = await common.get_user_id_from_name(page, name);
|
2024-05-04 00:31:56 +02:00
|
|
|
assert(user_id !== undefined);
|
2021-02-20 05:52:06 +01:00
|
|
|
return `.user_row[data-user-id="${CSS.escape(user_id.toString())}"]`;
|
2020-08-14 20:20:53 +02:00
|
|
|
}
|
|
|
|
|
2022-03-20 12:45:39 +01:00
|
|
|
async function test_reactivation_confirmation_modal(page: Page, fullname: string): Promise<void> {
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, ".dialog_heading"),
|
|
|
|
"Reactivate " + fullname,
|
2022-04-27 17:38:57 +02:00
|
|
|
"Unexpected title for reactivate user modal",
|
2022-03-20 12:45:39 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2024-05-15 08:38:06 +02:00
|
|
|
await common.get_text_from_selector(page, ".micromodal .dialog_submit_button"),
|
2022-03-20 12:45:39 +01:00
|
|
|
"Confirm",
|
|
|
|
"Reactivate button has incorrect text.",
|
|
|
|
);
|
2024-05-15 08:38:06 +02:00
|
|
|
await page.click(".micromodal .dialog_submit_button");
|
2022-03-20 12:45:39 +01:00
|
|
|
await common.wait_for_micromodal_to_close(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_deactivate_user(page: Page): Promise<void> {
|
2024-05-31 01:16:21 +02:00
|
|
|
const cordelia_user_row = await user_row(page, common.fullname.cordelia);
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector(cordelia_user_row, {visible: true});
|
|
|
|
await page.waitForSelector(cordelia_user_row + " .fa-user-times");
|
|
|
|
await page.click(cordelia_user_row + " .deactivate");
|
2021-07-04 08:47:08 +02:00
|
|
|
await common.wait_for_micromodal_to_open(page);
|
2020-08-14 20:20:53 +02:00
|
|
|
|
|
|
|
assert.strictEqual(
|
2021-07-05 12:41:37 +02:00
|
|
|
await common.get_text_from_selector(page, ".dialog_heading"),
|
2022-07-26 20:52:40 +02:00
|
|
|
"Deactivate " + common.fullname.cordelia + "?",
|
2022-04-27 17:38:57 +02:00
|
|
|
"Unexpected title for deactivate user modal",
|
2020-08-14 20:20:53 +02:00
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2024-05-15 08:38:06 +02:00
|
|
|
await common.get_text_from_selector(page, ".micromodal .dialog_submit_button"),
|
2022-07-26 21:16:08 +02:00
|
|
|
"Deactivate",
|
2020-08-14 20:20:53 +02:00
|
|
|
"Deactivate button has incorrect text.",
|
|
|
|
);
|
2024-05-15 08:38:06 +02:00
|
|
|
await page.click(".micromodal .dialog_submit_button");
|
2021-07-04 08:47:08 +02:00
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2020-08-14 20:20:53 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_reactivate_user(page: Page): Promise<void> {
|
2024-05-31 01:16:21 +02:00
|
|
|
let cordelia_user_row = await user_row(page, common.fullname.cordelia);
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector(cordelia_user_row + ".deactivated_user");
|
|
|
|
await page.waitForSelector(cordelia_user_row + " .fa-user-plus");
|
|
|
|
await page.click(cordelia_user_row + " .reactivate");
|
|
|
|
|
2022-03-20 12:45:39 +01:00
|
|
|
await test_reactivation_confirmation_modal(page, common.fullname.cordelia);
|
|
|
|
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector(cordelia_user_row + ":not(.deactivated_user)", {visible: true});
|
2024-05-31 01:16:21 +02:00
|
|
|
cordelia_user_row = await user_row(page, common.fullname.cordelia);
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector(cordelia_user_row + " .fa-user-times");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_deactivated_users_section(page: Page): Promise<void> {
|
2024-05-31 01:16:21 +02:00
|
|
|
const cordelia_user_row = await user_row(page, common.fullname.cordelia);
|
2020-08-14 20:20:53 +02:00
|
|
|
await test_deactivate_user(page);
|
|
|
|
|
|
|
|
// "Deactivated users" section doesn't render just deactivated users until reloaded.
|
|
|
|
await page.reload();
|
2024-05-30 11:28:49 +02:00
|
|
|
await page.waitForSelector("#admin-user-list.show", {visible: true});
|
|
|
|
const deactivated_users_section = ".tab-container .ind-tab[data-tab-key='deactivated']";
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector(deactivated_users_section, {visible: true});
|
|
|
|
await page.click(deactivated_users_section);
|
|
|
|
|
2022-08-17 03:45:42 +02:00
|
|
|
// Instead of waiting for reactivate button using the `waitForSelector` function,
|
|
|
|
// we wait until the input is focused because the `waitForSelector` function
|
|
|
|
// doesn't guarantee that element is interactable.
|
|
|
|
await page.waitForSelector("input[aria-label='Filter deactivated users']", {visible: true});
|
|
|
|
await page.click("input[aria-label='Filter deactivated users']");
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => document.activeElement?.classList?.contains("search") === true,
|
2020-08-14 20:20:53 +02:00
|
|
|
);
|
|
|
|
await page.click("#admin_deactivated_users_table " + cordelia_user_row + " .reactivate");
|
2022-03-20 12:45:39 +01:00
|
|
|
|
|
|
|
await test_reactivation_confirmation_modal(page, common.fullname.cordelia);
|
|
|
|
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector(
|
|
|
|
"#admin_deactivated_users_table " + cordelia_user_row + " button:not(.reactivate)",
|
|
|
|
{visible: true},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_bot_deactivation_and_reactivation(page: Page): Promise<void> {
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.click("li[data-section='bot-list-admin']");
|
|
|
|
|
|
|
|
const default_bot_user_row = await user_row(page, "Zulip Default Bot");
|
|
|
|
|
|
|
|
await page.click(default_bot_user_row + " .deactivate");
|
2022-04-20 15:12:47 +02:00
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, ".dialog_heading"),
|
2022-07-26 19:58:38 +02:00
|
|
|
"Deactivate Zulip Default Bot?",
|
2022-04-20 15:12:47 +02:00
|
|
|
"Unexpected title for deactivate bot modal",
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2024-05-15 08:38:06 +02:00
|
|
|
await common.get_text_from_selector(page, ".micromodal .dialog_submit_button"),
|
2022-07-26 21:16:08 +02:00
|
|
|
"Deactivate",
|
2022-04-20 15:12:47 +02:00
|
|
|
"Deactivate button has incorrect text.",
|
|
|
|
);
|
2024-05-15 08:38:06 +02:00
|
|
|
await page.click(".micromodal .dialog_submit_button");
|
2022-04-20 15:12:47 +02:00
|
|
|
await common.wait_for_micromodal_to_close(page);
|
|
|
|
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector(default_bot_user_row + ".deactivated_user", {visible: true});
|
|
|
|
await page.waitForSelector(default_bot_user_row + " .fa-user-plus");
|
|
|
|
|
|
|
|
await page.click(default_bot_user_row + " .reactivate");
|
2022-03-20 12:45:39 +01:00
|
|
|
await test_reactivation_confirmation_modal(page, "Zulip Default Bot");
|
2020-08-14 20:20:53 +02:00
|
|
|
await page.waitForSelector(default_bot_user_row + ":not(.deactivated_user)", {visible: true});
|
|
|
|
await page.waitForSelector(default_bot_user_row + " .fa-user-times");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function user_deactivation_test(page: Page): Promise<void> {
|
2020-08-14 20:20:53 +02:00
|
|
|
await common.log_in(page);
|
|
|
|
await navigate_to_user_list(page);
|
|
|
|
await test_deactivate_user(page);
|
|
|
|
await test_reactivate_user(page);
|
|
|
|
await test_deactivated_users_section(page);
|
|
|
|
await test_bot_deactivation_and_reactivation(page);
|
|
|
|
}
|
|
|
|
|
2022-08-17 03:45:42 +02:00
|
|
|
common.run_test(user_deactivation_test);
|