2024-10-09 00:25:41 +02:00
|
|
|
import assert from "node:assert/strict";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2022-03-18 16:18:44 +01:00
|
|
|
import type {Page} from "puppeteer";
|
2020-07-07 18:19:41 +02:00
|
|
|
|
2023-02-22 23:04:11 +01:00
|
|
|
import * as common from "./lib/common";
|
2020-07-07 18:19:41 +02:00
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
async function user_row_selector(page: Page, name: string): Promise<string> {
|
2020-07-07 18:19:41 +02:00
|
|
|
const user_id = await common.get_user_id_from_name(page, name);
|
2022-02-08 18:56:40 +01:00
|
|
|
const selector = `.remove_potential_subscriber[data-user-id="${user_id}"]`;
|
|
|
|
return selector;
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
async function await_user_visible(page: Page, name: string): Promise<void> {
|
|
|
|
const selector = await user_row_selector(page, name);
|
|
|
|
await page.waitForSelector(selector, {visible: true});
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
async function await_user_hidden(page: Page, name: string): Promise<void> {
|
|
|
|
const selector = await user_row_selector(page, name);
|
|
|
|
await page.waitForSelector(selector, {hidden: true});
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
async function add_user_to_stream(page: Page, name: string): Promise<void> {
|
|
|
|
const user_id = await common.get_user_id_from_name(page, name);
|
2024-06-10 21:11:41 +02:00
|
|
|
assert(user_id !== undefined);
|
2024-05-04 00:31:56 +02:00
|
|
|
await page.evaluate((user_id) => {
|
|
|
|
zulip_test.add_user_id_to_new_stream(user_id);
|
|
|
|
}, user_id);
|
2022-02-08 18:56:40 +01:00
|
|
|
await await_user_visible(page, name);
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function stream_name_error(page: Page): Promise<string> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForSelector("#stream_name_error", {visible: true});
|
|
|
|
return await common.get_text_from_selector(page, "#stream_name_error");
|
|
|
|
}
|
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
async function click_create_new_stream(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.click("#add_new_subscription .create_stream_button");
|
2024-03-24 22:17:18 +01:00
|
|
|
await page.type("#create_stream_name", "Test Stream 1");
|
|
|
|
await page.click("#stream_creation_go_to_subscribers");
|
2022-03-18 15:24:39 +01:00
|
|
|
await page.waitForSelector(".finalize_create_stream", {visible: true});
|
|
|
|
|
|
|
|
// sanity check that desdemona is the initial subsscriber
|
2022-02-08 18:56:40 +01:00
|
|
|
await await_user_visible(page, "desdemona");
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function clear_ot_filter_with_backspace(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.click(".add-user-list-filter");
|
|
|
|
await page.keyboard.press("Backspace");
|
|
|
|
await page.keyboard.press("Backspace");
|
|
|
|
}
|
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
async function test_user_filter_ui(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForSelector("form#stream_creation_form", {visible: true});
|
2022-02-08 18:56:40 +01:00
|
|
|
// Desdemona should be there by default
|
|
|
|
await await_user_visible(page, "desdemona");
|
|
|
|
|
2024-05-31 01:16:21 +02:00
|
|
|
await add_user_to_stream(page, common.fullname.cordelia);
|
|
|
|
await add_user_to_stream(page, common.fullname.othello);
|
2020-07-07 18:19:41 +02:00
|
|
|
|
2021-05-11 15:14:51 +02:00
|
|
|
await page.type(`form#stream_creation_form [name="user_list_filter"]`, "ot", {delay: 100});
|
2022-02-08 18:56:40 +01:00
|
|
|
await page.waitForSelector("#create_stream_subscribers", {visible: true});
|
2021-05-11 15:14:51 +02:00
|
|
|
// Wait until filtering is completed.
|
|
|
|
await page.waitForFunction(
|
2022-02-08 18:56:40 +01:00
|
|
|
() =>
|
|
|
|
document.querySelectorAll("#create_stream_subscribers .remove_potential_subscriber")
|
|
|
|
.length === 1,
|
2021-05-11 15:14:51 +02:00
|
|
|
);
|
|
|
|
|
2024-05-31 01:16:21 +02:00
|
|
|
await await_user_hidden(page, common.fullname.cordelia);
|
2022-02-08 18:56:40 +01:00
|
|
|
await await_user_hidden(page, "desdemona");
|
2024-05-31 01:16:21 +02:00
|
|
|
await await_user_visible(page, common.fullname.othello);
|
2020-07-07 18:19:41 +02:00
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
// Clear the filter.
|
2020-07-07 18:19:41 +02:00
|
|
|
await clear_ot_filter_with_backspace(page);
|
2022-02-08 18:56:40 +01:00
|
|
|
|
2024-05-31 01:16:21 +02:00
|
|
|
await await_user_visible(page, common.fullname.cordelia);
|
2022-02-08 18:56:40 +01:00
|
|
|
await await_user_visible(page, "desdemona");
|
2024-05-31 01:16:21 +02:00
|
|
|
await await_user_visible(page, common.fullname.othello);
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function create_stream(page: Page): Promise<void> {
|
2024-03-24 22:17:18 +01:00
|
|
|
await page.click("#stream_creation_go_to_configure_channel_settings");
|
|
|
|
await page.waitForSelector('xpath///*[text()="Configure new channel settings"]', {
|
|
|
|
visible: true,
|
|
|
|
});
|
|
|
|
|
2020-07-07 18:19:41 +02:00
|
|
|
await common.fill_form(page, "form#stream_creation_form", {
|
|
|
|
stream_name: "Puppeteer",
|
2020-10-23 02:43:28 +02:00
|
|
|
stream_description: "Everything Puppeteer",
|
2020-07-07 18:19:41 +02:00
|
|
|
});
|
2024-03-24 22:17:18 +01:00
|
|
|
await page.click("#stream_creation_go_to_subscribers");
|
|
|
|
await page.type("#create_stream_name", "Test Stream 2");
|
2022-02-15 21:16:10 +01:00
|
|
|
await page.click("form#stream_creation_form .finalize_create_stream");
|
2024-04-04 13:58:27 +02:00
|
|
|
// an explanatory modal is shown for the first stream created
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
await page.click(".dialog_submit_button");
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
2024-11-07 02:05:55 +01:00
|
|
|
|
|
|
|
// We redirect to the channel message view.
|
|
|
|
await page.waitForSelector("#subscription_overlay", {hidden: true});
|
|
|
|
await page.waitForSelector(
|
|
|
|
`xpath///*[${common.has_class_x("message-header-navbar-title")} and text()="Puppeteer"]`,
|
|
|
|
);
|
|
|
|
|
2024-04-04 13:58:27 +02:00
|
|
|
await page.waitForSelector(".message-header-stream-settings-button");
|
|
|
|
await page.click(".message-header-stream-settings-button");
|
|
|
|
await page.waitForSelector(".stream_section");
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector(
|
2024-11-07 02:05:55 +01:00
|
|
|
`xpath///*[${common.has_class_x("stream-name-title")} and text()="Puppeteer"]`,
|
|
|
|
{visible: true},
|
2021-03-27 04:40:48 +01:00
|
|
|
);
|
2020-07-07 18:19:41 +02:00
|
|
|
const stream_name = await common.get_text_from_selector(
|
|
|
|
page,
|
2021-07-05 11:26:23 +02:00
|
|
|
".stream-header .stream-name .sub-stream-name",
|
2020-07-07 18:19:41 +02:00
|
|
|
);
|
|
|
|
const stream_description = await common.get_text_from_selector(
|
|
|
|
page,
|
2021-07-05 11:26:23 +02:00
|
|
|
".stream-description .sub-stream-description",
|
2020-07-07 18:19:41 +02:00
|
|
|
);
|
|
|
|
assert.strictEqual(stream_name, "Puppeteer");
|
2020-10-23 02:43:28 +02:00
|
|
|
assert.strictEqual(stream_description, "Everything Puppeteer");
|
2020-07-07 18:19:41 +02:00
|
|
|
|
2022-02-08 18:56:40 +01:00
|
|
|
// Assert subscriber count becomes 3 (cordelia, desdemona, othello)
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.waitForSelector(
|
|
|
|
`xpath///*[@data-stream-name="Puppeteer"]//*[${common.has_class_x(
|
|
|
|
"subscriber-count",
|
|
|
|
)} and normalize-space()="3"]`,
|
2020-07-07 18:19:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_streams_with_empty_names_cannot_be_created(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.click("#add_new_subscription .create_stream_button");
|
|
|
|
await page.waitForSelector("form#stream_creation_form", {visible: true});
|
|
|
|
await common.fill_form(page, "form#stream_creation_form", {stream_name: " "});
|
2024-03-24 22:17:18 +01:00
|
|
|
await page.click("form#stream_creation_form button#stream_creation_go_to_subscribers");
|
2024-04-18 16:26:11 +02:00
|
|
|
assert.strictEqual(await stream_name_error(page), "Choose a name for the new channel.");
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_streams_with_duplicate_names_cannot_be_created(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await common.fill_form(page, "form#stream_creation_form", {stream_name: "Puppeteer"});
|
2024-03-24 22:17:18 +01:00
|
|
|
await page.click("form#stream_creation_form button#stream_creation_go_to_subscribers");
|
2024-04-18 16:26:11 +02:00
|
|
|
assert.strictEqual(await stream_name_error(page), "A channel with this name already exists.");
|
2020-07-07 18:19:41 +02:00
|
|
|
|
2024-03-24 22:17:18 +01:00
|
|
|
const cancel_button_selector = "form#stream_creation_form button.create_stream_cancel";
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.click(cancel_button_selector);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_stream_creation(page: Page): Promise<void> {
|
2022-02-08 18:56:40 +01:00
|
|
|
await click_create_new_stream(page);
|
|
|
|
await test_user_filter_ui(page);
|
2020-07-07 18:19:41 +02:00
|
|
|
await create_stream(page);
|
|
|
|
await test_streams_with_empty_names_cannot_be_created(page);
|
|
|
|
await test_streams_with_duplicate_names_cannot_be_created(page);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_streams_search_feature(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
assert.strictEqual(await common.get_text_from_selector(page, "#search_stream_name"), "");
|
|
|
|
const hidden_streams_selector = ".stream-row.notdisplayed .stream-name";
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
|
|
|
'.stream-row[data-stream-name="Verona"] .stream-name',
|
|
|
|
),
|
|
|
|
"Verona",
|
|
|
|
);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(
|
2020-07-07 18:19:41 +02:00
|
|
|
!(await common.get_text_from_selector(page, hidden_streams_selector)).includes("Verona"),
|
|
|
|
"#Verona is hidden",
|
|
|
|
);
|
|
|
|
|
|
|
|
await page.type('#stream_filter input[type="text"]', "Puppeteer");
|
2021-04-29 17:22:48 +02:00
|
|
|
await page.waitForSelector(".stream-row[data-stream-name='core team']", {hidden: true});
|
2020-07-07 18:19:41 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, ".stream-row:not(.notdisplayed) .stream-name"),
|
|
|
|
"Puppeteer",
|
|
|
|
);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(
|
2020-07-07 18:19:41 +02:00
|
|
|
(await common.get_text_from_selector(page, hidden_streams_selector)).includes("Verona"),
|
|
|
|
"#Verona is not hidden",
|
|
|
|
);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(
|
2020-07-07 18:19:41 +02:00
|
|
|
!(await common.get_text_from_selector(page, hidden_streams_selector)).includes("Puppeteer"),
|
|
|
|
"Puppeteer is hidden after searching.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function subscriptions_tests(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await common.log_in(page);
|
2022-03-18 16:18:44 +01:00
|
|
|
await common.open_streams_modal(page);
|
2020-07-07 18:19:41 +02:00
|
|
|
await test_stream_creation(page);
|
|
|
|
await test_streams_search_feature(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(subscriptions_tests);
|