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-02-20 05:52:06 +01:00
|
|
|
async function navigate_to(page: Page, click_target: string, tab: string): Promise<void> {
|
2020-08-05 19:38:08 +02:00
|
|
|
console.log("Visiting #" + click_target);
|
2021-02-03 23:23:32 +01:00
|
|
|
await page.click(`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);
|
|
|
|
|
|
|
|
const settings_selector = "a[href^='#settings']";
|
|
|
|
await page.waitForSelector(settings_selector, {visible: true});
|
|
|
|
await page.click(settings_selector);
|
|
|
|
|
|
|
|
await page.waitForSelector("#settings_page", {visible: true});
|
|
|
|
|
|
|
|
await page.click("#settings_page .content-wrapper .exit");
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
const manage_streams_selector = 'a[href^="#streams"]';
|
|
|
|
await page.waitForSelector(manage_streams_selector, {visible: true});
|
|
|
|
await page.click(manage_streams_selector);
|
|
|
|
|
|
|
|
await page.waitForSelector("#subscription_overlay", {visible: true});
|
|
|
|
await page.waitForSelector("#subscriptions_table", {visible: true});
|
|
|
|
|
|
|
|
await page.click("#subscription_overlay .exit");
|
|
|
|
}
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
async function test_reload_hash(page: Page): Promise<void> {
|
2020-08-05 19:38:08 +02:00
|
|
|
const initial_page_load_time = await page.evaluate(() => page_params.page_load_time);
|
|
|
|
console.log("initial load time: " + initial_page_load_time);
|
|
|
|
|
|
|
|
const initial_hash = await page.evaluate(() => window.location.hash);
|
|
|
|
|
2021-02-10 04:51:11 +01:00
|
|
|
await page.evaluate(() => {
|
|
|
|
const reload = window.require("./static/js/reload");
|
|
|
|
reload.initiate({immediate: true});
|
|
|
|
});
|
2020-08-05 19:38:08 +02:00
|
|
|
await page.waitForSelector("#zfilt", {visible: true});
|
|
|
|
|
|
|
|
const page_load_time = await page.evaluate(() => page_params.page_load_time);
|
|
|
|
assert(page_load_time > initial_page_load_time, "Page not reloaded.");
|
|
|
|
|
|
|
|
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-02-10 04:51:11 +01:00
|
|
|
const verona_id = await page.evaluate(() => {
|
|
|
|
const stream_data = window.require("./static/js/stream_data");
|
|
|
|
return stream_data.get_stream_id("Verona");
|
|
|
|
});
|
2020-08-05 19:38:08 +02:00
|
|
|
const verona_narrow = `narrow/stream/${verona_id}-Verona`;
|
|
|
|
|
|
|
|
await navigate_to(page, verona_narrow, "message_feed_container");
|
|
|
|
|
|
|
|
// 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);
|
2020-09-20 10:14:24 +02:00
|
|
|
await navigate_to(page, "all_messages", "message_feed_container");
|
2020-08-05 19:38:08 +02:00
|
|
|
await navigate_to_settings(page);
|
|
|
|
await navigate_to(page, "narrow/is/private", "message_feed_container");
|
|
|
|
await navigate_to_subscriptions(page);
|
|
|
|
await navigate_to(page, verona_narrow, "message_feed_container");
|
|
|
|
|
|
|
|
await test_reload_hash(page);
|
|
|
|
|
|
|
|
// Verify that we're narrowed to the target stream
|
|
|
|
await common.wait_for_text(page, "#message_view_header .stream", "Verona");
|
|
|
|
|
|
|
|
await common.log_out(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(navigation_tests);
|