2021-02-20 05:52:06 +01:00
|
|
|
import {strict as assert} from "assert";
|
2020-08-05 19:38:08 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import type {Page} from "puppeteer";
|
2020-08-05 19:38:08 +02:00
|
|
|
|
2021-03-27 03:52:16 +01:00
|
|
|
import * as common from "../puppeteer_lib/common";
|
2020-08-05 19:38:08 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function wait_for_tab(page: Page, tab: string): Promise<void> {
|
2020-09-20 10:14:24 +02:00
|
|
|
const tab_slector = `#${CSS.escape(tab)}.tab-pane`;
|
2020-08-05 19:38:08 +02:00
|
|
|
await page.waitForSelector(tab_slector, {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-03-31 08:14:46 +02:00
|
|
|
async function navigate_using_left_sidebar(
|
|
|
|
page: Page,
|
|
|
|
click_target: string,
|
|
|
|
tab: string,
|
|
|
|
): Promise<void> {
|
2020-08-05 19:38:08 +02:00
|
|
|
console.log("Visiting #" + click_target);
|
2021-03-31 08:14:46 +02:00
|
|
|
await page.click(`#left-sidebar a[href='#${CSS.escape(click_target)}']`);
|
2020-08-05 19:38:08 +02:00
|
|
|
|
|
|
|
await wait_for_tab(page, tab);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function open_menu(page: Page): Promise<void> {
|
2020-08-05 19:38:08 +02:00
|
|
|
const menu_selector = "#settings-dropdown";
|
|
|
|
await page.waitForSelector(menu_selector, {visible: true});
|
|
|
|
await page.click(menu_selector);
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function navigate_to_settings(page: Page): Promise<void> {
|
2020-08-05 19:38:08 +02:00
|
|
|
console.log("Navigating to settings");
|
|
|
|
|
|
|
|
await open_menu(page);
|
|
|
|
|
2021-03-31 08:57:11 +02:00
|
|
|
const settings_selector = ".dropdown-menu a[href^='#settings']";
|
2020-08-05 19:38:08 +02:00
|
|
|
await page.waitForSelector(settings_selector, {visible: true});
|
|
|
|
await page.click(settings_selector);
|
|
|
|
|
2022-08-17 03:50:29 +02:00
|
|
|
const profile_section_tab_selector = "li[data-section='profile']";
|
|
|
|
await page.waitForSelector(profile_section_tab_selector, {visible: true});
|
|
|
|
await page.click(profile_section_tab_selector);
|
|
|
|
await page.waitForFunction(
|
|
|
|
() => document.activeElement?.getAttribute("data-section") === "profile",
|
|
|
|
);
|
2020-08-05 19:38:08 +02:00
|
|
|
|
|
|
|
await page.click("#settings_page .content-wrapper .exit");
|
2021-03-12 12:30:25 +01:00
|
|
|
// Wait until the overlay is completely closed.
|
|
|
|
await page.waitForSelector("#settings_overlay_container", {hidden: true});
|
2020-08-05 19:38:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function navigate_to_subscriptions(page: Page): Promise<void> {
|
2020-08-05 19:38:08 +02:00
|
|
|
console.log("Navigate to subscriptions");
|
|
|
|
|
|
|
|
await open_menu(page);
|
|
|
|
|
2021-03-31 08:57:11 +02:00
|
|
|
const manage_streams_selector = '.dropdown-menu a[href^="#streams"]';
|
2020-08-05 19:38:08 +02:00
|
|
|
await page.waitForSelector(manage_streams_selector, {visible: true});
|
|
|
|
await page.click(manage_streams_selector);
|
|
|
|
|
|
|
|
await page.waitForSelector("#subscription_overlay", {visible: true});
|
2021-12-21 19:41:13 +01:00
|
|
|
await page.waitForSelector("#manage_streams_container", {visible: true});
|
2020-08-05 19:38:08 +02:00
|
|
|
|
|
|
|
await page.click("#subscription_overlay .exit");
|
2021-03-12 12:30:25 +01:00
|
|
|
// Wait until the overlay is completely closed.
|
2021-03-12 22:26:39 +01:00
|
|
|
await page.waitForSelector("#subscription_overlay", {hidden: true});
|
2020-08-05 19:38:08 +02:00
|
|
|
}
|
|
|
|
|
2022-09-13 13:15:57 +02:00
|
|
|
async function navigate_to_private_messages(page: Page): Promise<void> {
|
|
|
|
console.log("Navigate to private messages");
|
|
|
|
|
|
|
|
const all_private_messages_icon = "#show_all_private_messages";
|
|
|
|
await page.waitForSelector(all_private_messages_icon, {visible: true});
|
|
|
|
await page.click(all_private_messages_icon);
|
|
|
|
|
|
|
|
await page.waitForSelector("#message_view_header .fa-envelope", {visible: true});
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_reload_hash(page: Page): Promise<void> {
|
2021-09-23 00:25:31 +02:00
|
|
|
const initial_page_load_time = await page.evaluate(
|
|
|
|
(): number => zulip_test.page_params.page_load_time,
|
|
|
|
);
|
2021-09-22 23:34:58 +02:00
|
|
|
console.log(`initial load time: ${initial_page_load_time}`);
|
2020-08-05 19:38:08 +02:00
|
|
|
|
|
|
|
const initial_hash = await page.evaluate(() => window.location.hash);
|
|
|
|
|
2021-03-01 23:33:52 +01:00
|
|
|
await page.evaluate(() => zulip_test.initiate_reload({immediate: true}));
|
2021-03-03 05:51:58 +01:00
|
|
|
await page.waitForNavigation();
|
2020-08-05 19:38:08 +02:00
|
|
|
await page.waitForSelector("#zfilt", {visible: true});
|
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
const page_load_time = await page.evaluate(() => zulip_test.page_params.page_load_time);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(page_load_time > initial_page_load_time, "Page not reloaded.");
|
2020-08-05 19:38:08 +02:00
|
|
|
|
|
|
|
const hash = await page.evaluate(() => window.location.hash);
|
|
|
|
assert.strictEqual(hash, initial_hash, "Hash not preserved.");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function navigation_tests(page: Page): Promise<void> {
|
2020-08-05 19:38:08 +02:00
|
|
|
await common.log_in(page);
|
|
|
|
|
|
|
|
await navigate_to_settings(page);
|
|
|
|
|
2021-09-23 00:25:31 +02:00
|
|
|
const verona_id = await page.evaluate((): number => zulip_test.get_stream_id("Verona"));
|
2020-08-05 19:38:08 +02:00
|
|
|
const verona_narrow = `narrow/stream/${verona_id}-Verona`;
|
|
|
|
|
2021-03-31 08:14:46 +02:00
|
|
|
await navigate_using_left_sidebar(page, verona_narrow, "message_feed_container");
|
2020-08-05 19:38:08 +02:00
|
|
|
|
2021-03-27 04:40:48 +01:00
|
|
|
await page.click(".home-link");
|
2020-08-05 19:38:08 +02:00
|
|
|
await wait_for_tab(page, "message_feed_container");
|
|
|
|
|
|
|
|
await navigate_to_subscriptions(page);
|
2021-03-31 08:14:46 +02:00
|
|
|
await navigate_using_left_sidebar(page, "all_messages", "message_feed_container");
|
2020-08-05 19:38:08 +02:00
|
|
|
await navigate_to_settings(page);
|
2022-09-13 13:15:57 +02:00
|
|
|
await navigate_to_private_messages(page);
|
2020-08-05 19:38:08 +02:00
|
|
|
await navigate_to_subscriptions(page);
|
2021-03-31 08:14:46 +02:00
|
|
|
await navigate_using_left_sidebar(page, verona_narrow, "message_feed_container");
|
2020-08-05 19:38:08 +02:00
|
|
|
|
|
|
|
await test_reload_hash(page);
|
|
|
|
|
|
|
|
// Verify that we're narrowed to the target stream
|
2022-09-10 05:37:50 +02:00
|
|
|
await page.waitForSelector(
|
2021-03-27 04:20:49 +01:00
|
|
|
`xpath///*[@id="message_view_header"]//*[${common.has_class_x(
|
|
|
|
"stream",
|
|
|
|
)} and normalize-space()="Verona"]`,
|
2021-03-12 23:13:45 +01:00
|
|
|
);
|
2020-08-05 19:38:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(navigation_tests);
|