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-02-20 05:52:06 +01:00
|
|
|
import 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);
|
|
|
|
|
|
|
|
await page.waitForSelector("#settings_page", {visible: true});
|
2021-05-11 10:58:14 +02:00
|
|
|
await page.waitForFunction(() => location.href.includes("/#settings/")); // eslint-disable-line no-undef
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
// Hardcoded this instead of using `navigate_to`
|
2020-10-23 02:43:28 +02:00
|
|
|
// as Puppeteer cannot click hidden elements.
|
2021-02-20 06:51:39 +01:00
|
|
|
await page.evaluate(() => $("a[href='#message_feed_container]'").trigger("click"));
|
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);
|
2021-03-31 08:14:46 +02:00
|
|
|
await navigate_using_left_sidebar(page, "narrow/is/private", "message_feed_container");
|
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
|
2021-03-12 23:13:45 +01:00
|
|
|
await page.waitForXPath(
|
|
|
|
'//*[@id="message_view_header"]//*[@class="stream" and normalize-space()="Verona"]',
|
|
|
|
);
|
2020-08-05 19:38:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(navigation_tests);
|