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 {ElementHandle, Page} from "puppeteer";
|
2020-07-07 18:19:41 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import common from "../puppeteer_lib/common";
|
2020-07-07 18:19:41 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function user_checkbox(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);
|
2021-04-22 23:40:09 +02:00
|
|
|
return `#user_checkbox_${CSS.escape(user_id.toString())}`;
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function user_span(page: Page, name: string): Promise<string> {
|
2021-04-22 23:40:09 +02:00
|
|
|
return (await user_checkbox(page, name)) + " span";
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function stream_checkbox(page: Page, stream_name: string): Promise<string> {
|
2020-07-07 18:19:41 +02:00
|
|
|
const stream_id = await common.get_stream_id(page, stream_name);
|
2021-02-20 05:52:06 +01:00
|
|
|
return `#stream-checkboxes [data-stream-id="${CSS.escape(stream_id.toString())}"]`;
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function stream_span(page: Page, stream_name: string): Promise<string> {
|
2020-07-07 18:19:41 +02:00
|
|
|
return (await stream_checkbox(page, stream_name)) + " input ~ span";
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function wait_for_checked(page: Page, user_name: string, is_checked: boolean): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
const selector = await user_checkbox(page, user_name);
|
|
|
|
await page.waitForFunction(
|
2021-02-20 05:52:06 +01:00
|
|
|
(selector: string, is_checked: boolean) =>
|
2021-04-22 23:40:09 +02:00
|
|
|
$(selector).find("input").prop("checked") === is_checked,
|
2020-07-07 18:19:41 +02:00
|
|
|
{},
|
|
|
|
selector,
|
|
|
|
is_checked,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function open_streams_modal(page: Page): Promise<void> {
|
2021-03-31 08:57:11 +02:00
|
|
|
const all_streams_selector = "#add-stream-link";
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForSelector(all_streams_selector, {visible: true});
|
|
|
|
await page.click(all_streams_selector);
|
|
|
|
|
|
|
|
await page.waitForSelector("#subscription_overlay.new-style", {visible: true});
|
2021-03-01 06:38:03 +01:00
|
|
|
const url = await common.page_url_with_fragment(page);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(url.includes("#streams/all"));
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 18:37:45 +01:00
|
|
|
async function test_subscription_button(page: Page): Promise<void> {
|
|
|
|
const stream_selector = "[data-stream-name='Venice']";
|
|
|
|
const button_selector = `${stream_selector} .sub_unsub_button`;
|
2021-02-18 15:54:19 +01:00
|
|
|
const subscribed_selector = `${button_selector}.checked`;
|
|
|
|
const unsubscribed_selector = `${button_selector}:not(.checked)`;
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function subscribed(): Promise<ElementHandle | null> {
|
2021-02-18 15:54:19 +01:00
|
|
|
return await page.waitForSelector(subscribed_selector, {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function unsubscribed(): Promise<ElementHandle | null> {
|
2021-02-18 15:54:19 +01:00
|
|
|
return await page.waitForSelector(unsubscribed_selector, {visible: true});
|
|
|
|
}
|
|
|
|
|
2022-02-09 18:37:45 +01:00
|
|
|
// Make sure that Venice is even in our list of streams.
|
|
|
|
await page.waitForSelector(stream_selector, {visible: true});
|
|
|
|
await page.waitForSelector(button_selector, {visible: true});
|
|
|
|
|
2021-02-18 15:54:19 +01:00
|
|
|
// Note that we intentionally re-find the button after each click, since
|
|
|
|
// the live-update code may replace the whole row.
|
|
|
|
let button;
|
|
|
|
|
2022-02-09 18:37:45 +01:00
|
|
|
// We assume Venice is already subscribed, so the first line here
|
2021-02-18 15:54:19 +01:00
|
|
|
// should happen immediately.
|
|
|
|
button = await subscribed();
|
2021-09-22 22:52:53 +02:00
|
|
|
await button!.click();
|
2021-02-18 15:54:19 +01:00
|
|
|
button = await unsubscribed();
|
2021-09-22 22:52:53 +02:00
|
|
|
await button!.click();
|
2021-02-18 15:54:19 +01:00
|
|
|
button = await subscribed();
|
2021-09-22 22:52:53 +02:00
|
|
|
await button!.click();
|
2021-02-18 15:54:19 +01:00
|
|
|
button = await unsubscribed();
|
2021-09-22 22:52:53 +02:00
|
|
|
await button!.click();
|
2021-02-18 15:54:19 +01:00
|
|
|
button = await subscribed();
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function click_create_new_stream(
|
|
|
|
page: Page,
|
|
|
|
cordelia_checkbox: string,
|
|
|
|
othello_checkbox: string,
|
|
|
|
): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.click("#add_new_subscription .create_stream_button");
|
|
|
|
await page.waitForSelector(cordelia_checkbox, {visible: true});
|
|
|
|
await page.waitForSelector(othello_checkbox, {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function open_copy_from_stream_dropdown(
|
|
|
|
page: Page,
|
|
|
|
scotland_checkbox: string,
|
|
|
|
rome_checkbox: string,
|
|
|
|
): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.click("#copy-from-stream-expand-collapse .control-label");
|
|
|
|
await page.waitForSelector(scotland_checkbox, {visible: true});
|
|
|
|
await page.waitForSelector(rome_checkbox, {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-04-22 23:40:09 +02:00
|
|
|
async function verify_check_all_only_affects_visible_users(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await wait_for_checked(page, "cordelia", false);
|
|
|
|
await wait_for_checked(page, "othello", true);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function verify_filtered_users_are_visible_again(
|
|
|
|
page: Page,
|
|
|
|
cordelia_checkbox: string,
|
|
|
|
othello_checkbox: string,
|
|
|
|
): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForSelector(cordelia_checkbox, {visible: true});
|
|
|
|
await page.waitForSelector(othello_checkbox, {visible: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function test_user_filter_ui(
|
2021-02-20 05:52:06 +01:00
|
|
|
page: Page,
|
|
|
|
cordelia_checkbox: string,
|
|
|
|
othello_checkbox: string,
|
|
|
|
scotland_checkbox: string,
|
|
|
|
rome_checkbox: string,
|
|
|
|
): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForSelector("form#stream_creation_form", {visible: true});
|
2021-04-22 23:40:09 +02:00
|
|
|
// Desdemona should be checked by default
|
|
|
|
await wait_for_checked(page, "desdemona", true);
|
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});
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForSelector("#user-checkboxes", {visible: true});
|
2021-05-11 15:14:51 +02:00
|
|
|
// Wait until filtering is completed.
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => document.querySelectorAll("#user-checkboxes label").length === 1,
|
|
|
|
);
|
|
|
|
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForSelector(cordelia_checkbox, {hidden: true});
|
|
|
|
await page.waitForSelector(othello_checkbox, {visible: true});
|
|
|
|
|
2020-08-11 01:47:44 +02:00
|
|
|
// Filter shouldn't affect streams.
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForSelector(scotland_checkbox, {visible: true});
|
|
|
|
await page.waitForSelector(rome_checkbox, {visible: true});
|
|
|
|
|
2021-04-22 23:40:09 +02:00
|
|
|
// Test check all
|
|
|
|
await page.click(".subs_set_all_users");
|
2021-04-30 07:39:36 +02:00
|
|
|
await wait_for_checked(page, "othello", true);
|
2020-07-07 18:19:41 +02:00
|
|
|
await clear_ot_filter_with_backspace(page);
|
|
|
|
await verify_filtered_users_are_visible_again(page, cordelia_checkbox, othello_checkbox);
|
2021-04-22 23:40:09 +02:00
|
|
|
await verify_check_all_only_affects_visible_users(page);
|
|
|
|
|
|
|
|
// Test unset all
|
|
|
|
await page.click(".subs_unset_all_users");
|
|
|
|
await verify_filtered_users_are_visible_again(page, cordelia_checkbox, othello_checkbox);
|
|
|
|
await wait_for_checked(page, "cordelia", false);
|
|
|
|
await wait_for_checked(page, "othello", false);
|
2020-07-07 18:19:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function create_stream(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForXPath('//*[text()="Create stream"]', {visible: true});
|
|
|
|
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
|
|
|
});
|
|
|
|
await page.click(await stream_span(page, "Scotland")); // Subscribes all users from Scotland
|
|
|
|
await page.click(await user_span(page, "cordelia")); // Add cordelia.
|
2021-04-22 23:40:09 +02:00
|
|
|
await page.click(await user_span(page, "desdemona")); // Add cordelia.
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.click(await user_span(page, "othello")); // Remove othello who was selected from Scotland.
|
2021-04-22 23:40:09 +02:00
|
|
|
await wait_for_checked(page, "cordelia", true);
|
|
|
|
await wait_for_checked(page, "desdemona", true); // Add desdemona back as we did unset all in last test.
|
2020-07-07 18:19:41 +02:00
|
|
|
await wait_for_checked(page, "othello", false);
|
|
|
|
await page.click("form#stream_creation_form button.button.sea-green");
|
|
|
|
await page.waitForFunction(() => $(".stream-name").is(':contains("Puppeteer")'));
|
|
|
|
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
|
|
|
);
|
|
|
|
const subscriber_count_selector = "[data-stream-name='Puppeteer'] .subscriber-count";
|
|
|
|
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
|
|
|
|
2020-12-22 15:46:00 +01:00
|
|
|
// Assert subscriber count becomes 6(scotland(+5), cordelia(+1), othello(-1), Desdemona(+1)).
|
2020-07-07 18:19:41 +02:00
|
|
|
await page.waitForFunction(
|
2020-12-22 15:46:00 +01:00
|
|
|
(subscriber_count_selector: string) => $(subscriber_count_selector).text().trim() === "6",
|
2020-07-07 18:19:41 +02:00
|
|
|
{},
|
|
|
|
subscriber_count_selector,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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: " "});
|
|
|
|
await page.click("form#stream_creation_form button.button.sea-green");
|
|
|
|
assert.strictEqual(await stream_name_error(page), "A stream needs to have a name");
|
|
|
|
}
|
|
|
|
|
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"});
|
|
|
|
await page.click("form#stream_creation_form button.button.sea-green");
|
|
|
|
assert.strictEqual(await stream_name_error(page), "A stream with this name already exists");
|
|
|
|
|
|
|
|
const cancel_button_selector = "form#stream_creation_form button.button.white";
|
|
|
|
await page.click(cancel_button_selector);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_stream_creation(page: Page): Promise<void> {
|
2020-07-07 18:19:41 +02:00
|
|
|
const cordelia_checkbox = await user_checkbox(page, "cordelia");
|
|
|
|
const othello_checkbox = await user_checkbox(page, "othello");
|
|
|
|
const scotland_checkbox = await stream_checkbox(page, "Scotland");
|
|
|
|
const rome_checkbox = await stream_checkbox(page, "Rome");
|
|
|
|
|
|
|
|
await click_create_new_stream(page, cordelia_checkbox, othello_checkbox);
|
|
|
|
await open_copy_from_stream_dropdown(page, scotland_checkbox, rome_checkbox);
|
|
|
|
await test_user_filter_ui(
|
|
|
|
page,
|
|
|
|
cordelia_checkbox,
|
|
|
|
othello_checkbox,
|
|
|
|
scotland_checkbox,
|
|
|
|
rome_checkbox,
|
|
|
|
);
|
|
|
|
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);
|
|
|
|
await open_streams_modal(page);
|
2022-02-09 18:37:45 +01:00
|
|
|
await test_subscription_button(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);
|