mirror of https://github.com/zulip/zulip.git
zulip_test: Convert module to TypeScript.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
fd8b2c557f
commit
d507706371
|
@ -290,7 +290,7 @@ EXEMPT_FILES = make_set(
|
||||||
"web/src/zcommand.ts",
|
"web/src/zcommand.ts",
|
||||||
"web/src/zform.js",
|
"web/src/zform.js",
|
||||||
"web/src/zulip.js",
|
"web/src/zulip.js",
|
||||||
"web/src/zulip_test.js",
|
"web/src/zulip_test.ts",
|
||||||
"web/tests/lib/mdiff.js",
|
"web/tests/lib/mdiff.js",
|
||||||
"web/tests/lib/real_jquery.js",
|
"web/tests/lib/real_jquery.js",
|
||||||
"web/tests/lib/zjquery_element.js",
|
"web/tests/lib/zjquery_element.js",
|
||||||
|
|
|
@ -78,10 +78,9 @@ async function test_reply_by_click_prepopulates_private_message_recipient(
|
||||||
assert.ok(private_message !== null);
|
assert.ok(private_message !== null);
|
||||||
await private_message.click();
|
await private_message.click();
|
||||||
await page.waitForSelector("#private_message_recipient", {visible: true});
|
await page.waitForSelector("#private_message_recipient", {visible: true});
|
||||||
await common.pm_recipient.expect(
|
const email = await common.get_internal_email_from_name(page, "cordelia");
|
||||||
page,
|
assert(email !== undefined);
|
||||||
await common.get_internal_email_from_name(page, "cordelia"),
|
await common.pm_recipient.expect(page, email);
|
||||||
);
|
|
||||||
await close_compose_box(page);
|
await close_compose_box(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const is_firefox = process.env.PUPPETEER_PRODUCT === "firefox";
|
||||||
let realm_url = "http://zulip.zulipdev.com:9981/";
|
let realm_url = "http://zulip.zulipdev.com:9981/";
|
||||||
const gps = new StackTraceGPS({ajax: async (url) => (await fetch(url)).text()});
|
const gps = new StackTraceGPS({ajax: async (url) => (await fetch(url)).text()});
|
||||||
|
|
||||||
let last_current_msg_list_id: number | null = null;
|
let last_current_msg_list_id: number | undefined;
|
||||||
|
|
||||||
export const pm_recipient = {
|
export const pm_recipient = {
|
||||||
async set(page: Page, recipient: string): Promise<void> {
|
async set(page: Page, recipient: string): Promise<void> {
|
||||||
|
@ -231,27 +231,30 @@ export function has_class_x(class_name: string): string {
|
||||||
return `contains(concat(" ", @class, " "), " ${class_name} ")`;
|
return `contains(concat(" ", @class, " "), " ${class_name} ")`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_stream_id(page: Page, stream_name: string): Promise<number> {
|
export async function get_stream_id(page: Page, stream_name: string): Promise<number | undefined> {
|
||||||
return await page.evaluate(
|
return await page.evaluate(
|
||||||
(stream_name: string) => zulip_test.get_stream_id(stream_name),
|
(stream_name: string) => zulip_test.get_stream_id(stream_name),
|
||||||
stream_name,
|
stream_name,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_user_id_from_name(page: Page, name: string): Promise<number> {
|
export async function get_user_id_from_name(page: Page, name: string): Promise<number | undefined> {
|
||||||
if (fullname[name] !== undefined) {
|
if (fullname[name] !== undefined) {
|
||||||
name = fullname[name];
|
name = fullname[name];
|
||||||
}
|
}
|
||||||
return await page.evaluate((name: string) => zulip_test.get_user_id_from_name(name), name);
|
return await page.evaluate((name: string) => zulip_test.get_user_id_from_name(name), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_internal_email_from_name(page: Page, name: string): Promise<string> {
|
export async function get_internal_email_from_name(
|
||||||
|
page: Page,
|
||||||
|
name: string,
|
||||||
|
): Promise<string | undefined> {
|
||||||
if (fullname[name] !== undefined) {
|
if (fullname[name] !== undefined) {
|
||||||
name = fullname[name];
|
name = fullname[name];
|
||||||
}
|
}
|
||||||
return await page.evaluate((fullname: string) => {
|
return await page.evaluate((fullname: string) => {
|
||||||
const user_id = zulip_test.get_user_id_from_name(fullname);
|
const user_id = zulip_test.get_user_id_from_name(fullname);
|
||||||
return zulip_test.get_person_by_user_id(user_id).email;
|
return user_id === undefined ? undefined : zulip_test.get_person_by_user_id(user_id).email;
|
||||||
}, name);
|
}, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +362,7 @@ export async function wait_for_fully_processed_message(page: Page, content: stri
|
||||||
- does it look to have been
|
- does it look to have been
|
||||||
re-rendered based on server info?
|
re-rendered based on server info?
|
||||||
*/
|
*/
|
||||||
const last_msg = zulip_test.current_msg_list.last();
|
const last_msg = zulip_test.current_msg_list?.last();
|
||||||
if (last_msg === undefined) {
|
if (last_msg === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -463,7 +466,9 @@ export async function send_message(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the compose box after sending the message.
|
// Close the compose box after sending the message.
|
||||||
await page.evaluate(() => zulip_test.cancel_compose());
|
await page.evaluate(() => {
|
||||||
|
zulip_test.cancel_compose();
|
||||||
|
});
|
||||||
// Make sure the compose box is closed.
|
// Make sure the compose box is closed.
|
||||||
await page.waitForSelector("#compose-textarea", {hidden: true});
|
await page.waitForSelector("#compose-textarea", {hidden: true});
|
||||||
}
|
}
|
||||||
|
@ -731,12 +736,18 @@ export async function get_current_msg_list_id(
|
||||||
// NOTE: This only checks if the current message list id changed from the last call to this function,
|
// NOTE: This only checks if the current message list id changed from the last call to this function,
|
||||||
// so, make sure to have a call to this function before changing to the narrow that you want to check.
|
// so, make sure to have a call to this function before changing to the narrow that you want to check.
|
||||||
await page.waitForFunction(
|
await page.waitForFunction(
|
||||||
(last_current_msg_list_id) =>
|
(last_current_msg_list_id) => {
|
||||||
zulip_test.current_msg_list.id !== last_current_msg_list_id,
|
const current_msg_list = zulip_test.current_msg_list;
|
||||||
|
return (
|
||||||
|
current_msg_list !== undefined &&
|
||||||
|
current_msg_list.id !== last_current_msg_list_id
|
||||||
|
);
|
||||||
|
},
|
||||||
{},
|
{},
|
||||||
last_current_msg_list_id,
|
last_current_msg_list_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
last_current_msg_list_id = await page.evaluate(() => zulip_test.current_msg_list.id);
|
last_current_msg_list_id = await page.evaluate(() => zulip_test.current_msg_list?.id);
|
||||||
return last_current_msg_list_id!;
|
assert(last_current_msg_list_id !== undefined);
|
||||||
|
return last_current_msg_list_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ async function test_mention(page: Page): Promise<void> {
|
||||||
|
|
||||||
console.log("Checking for all everyone warning");
|
console.log("Checking for all everyone warning");
|
||||||
const stream_size = await page.evaluate(() =>
|
const stream_size = await page.evaluate(() =>
|
||||||
zulip_test.get_subscriber_count(zulip_test.get_sub("Verona").stream_id),
|
zulip_test.get_subscriber_count(zulip_test.get_sub("Verona")!.stream_id),
|
||||||
);
|
);
|
||||||
const threshold = await page.evaluate(() => {
|
const threshold = await page.evaluate(() => {
|
||||||
zulip_test.set_wildcard_mention_threshold(5);
|
zulip_test.set_wildcard_mention_threshold(5);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as common from "./lib/common";
|
||||||
|
|
||||||
async function get_stream_li(page: Page, stream_name: string): Promise<string> {
|
async function get_stream_li(page: Page, stream_name: string): Promise<string> {
|
||||||
const stream_id = await common.get_stream_id(page, stream_name);
|
const stream_id = await common.get_stream_id(page, stream_name);
|
||||||
|
assert(stream_id !== undefined);
|
||||||
return `#stream_filters [data-stream-id="${CSS.escape(stream_id.toString())}"]`;
|
return `#stream_filters [data-stream-id="${CSS.escape(stream_id.toString())}"]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,12 +64,15 @@ async function navigate_to_private_messages(page: Page): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function test_reload_hash(page: Page): Promise<void> {
|
async function test_reload_hash(page: Page): Promise<void> {
|
||||||
const initial_page_load_time = await page.evaluate((): number => zulip_test.page_load_time);
|
const initial_page_load_time = await page.evaluate(() => zulip_test.page_load_time);
|
||||||
|
assert(initial_page_load_time !== undefined);
|
||||||
console.log(`initial load time: ${initial_page_load_time}`);
|
console.log(`initial load time: ${initial_page_load_time}`);
|
||||||
|
|
||||||
const initial_hash = await page.evaluate(() => window.location.hash);
|
const initial_hash = await page.evaluate(() => window.location.hash);
|
||||||
|
|
||||||
await page.evaluate(() => zulip_test.initiate_reload({immediate: true}));
|
await page.evaluate(() => {
|
||||||
|
zulip_test.initiate_reload({immediate: true});
|
||||||
|
});
|
||||||
await page.waitForNavigation();
|
await page.waitForNavigation();
|
||||||
const message_list_id = await common.get_current_msg_list_id(page, true);
|
const message_list_id = await common.get_current_msg_list_id(page, true);
|
||||||
await page.waitForSelector(`.message-list[data-message-list-id='${message_list_id}']`, {
|
await page.waitForSelector(`.message-list[data-message-list-id='${message_list_id}']`, {
|
||||||
|
@ -77,6 +80,7 @@ async function test_reload_hash(page: Page): Promise<void> {
|
||||||
});
|
});
|
||||||
|
|
||||||
const page_load_time = await page.evaluate(() => zulip_test.page_load_time);
|
const page_load_time = await page.evaluate(() => zulip_test.page_load_time);
|
||||||
|
assert(page_load_time !== undefined);
|
||||||
assert.ok(page_load_time > initial_page_load_time, "Page not reloaded.");
|
assert.ok(page_load_time > initial_page_load_time, "Page not reloaded.");
|
||||||
|
|
||||||
const hash = await page.evaluate(() => window.location.hash);
|
const hash = await page.evaluate(() => window.location.hash);
|
||||||
|
@ -88,7 +92,7 @@ async function navigation_tests(page: Page): Promise<void> {
|
||||||
|
|
||||||
await navigate_to_settings(page);
|
await navigate_to_settings(page);
|
||||||
|
|
||||||
const verona_id = await page.evaluate((): number => zulip_test.get_stream_id("Verona"));
|
const verona_id = await page.evaluate(() => zulip_test.get_stream_id("Verona"));
|
||||||
const verona_narrow = `narrow/stream/${verona_id}-Verona`;
|
const verona_narrow = `narrow/stream/${verona_id}-Verona`;
|
||||||
|
|
||||||
await navigate_using_left_sidebar(page, verona_narrow);
|
await navigate_using_left_sidebar(page, verona_narrow);
|
||||||
|
|
|
@ -22,7 +22,9 @@ async function await_user_hidden(page: Page, name: string): Promise<void> {
|
||||||
|
|
||||||
async function add_user_to_stream(page: Page, name: string): Promise<void> {
|
async function add_user_to_stream(page: Page, name: string): Promise<void> {
|
||||||
const user_id = await common.get_user_id_from_name(page, name);
|
const user_id = await common.get_user_id_from_name(page, name);
|
||||||
await page.evaluate((user_id) => zulip_test.add_user_id_to_new_stream(user_id), user_id);
|
await page.evaluate((user_id) => {
|
||||||
|
zulip_test.add_user_id_to_new_stream(user_id);
|
||||||
|
}, user_id);
|
||||||
await await_user_visible(page, name);
|
await await_user_visible(page, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ async function navigate_to_user_list(page: Page): Promise<void> {
|
||||||
|
|
||||||
async function user_row(page: Page, name: string): Promise<string> {
|
async function user_row(page: Page, name: string): Promise<string> {
|
||||||
const user_id = await common.get_user_id_from_name(page, name);
|
const user_id = await common.get_user_id_from_name(page, name);
|
||||||
|
assert(user_id !== undefined);
|
||||||
return `.user_row[data-user-id="${CSS.escape(user_id.toString())}"]`;
|
return `.user_row[data-user-id="${CSS.escape(user_id.toString())}"]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
// These declarations tell the TypeScript compiler about the existence
|
|
||||||
// of the global variables for our untyped JavaScript modules. Please
|
|
||||||
// remove each declaration when the corresponding module is migrated
|
|
||||||
// to TS.
|
|
||||||
|
|
||||||
/// <reference types="spectrum" />
|
/// <reference types="spectrum" />
|
||||||
|
|
||||||
export {};
|
import type * as zulip_test_module from "./zulip_test";
|
||||||
|
|
||||||
type JQueryCaretRange = {
|
type JQueryCaretRange = {
|
||||||
start: number;
|
start: number;
|
||||||
|
@ -23,7 +18,7 @@ type JQueryIdleOptions = Partial<{
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
let zulip_test: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
const zulip_test: typeof zulip_test_module;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
namespace JQueryValidation {
|
namespace JQueryValidation {
|
||||||
|
|
|
@ -48,6 +48,7 @@ export type MessageList = {
|
||||||
messages: Message[],
|
messages: Message[],
|
||||||
append_opts: {messages_are_new: boolean},
|
append_opts: {messages_are_new: boolean},
|
||||||
) => RenderInfo | undefined;
|
) => RenderInfo | undefined;
|
||||||
|
last: () => Message | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export let current: MessageList | undefined;
|
export let current: MessageList | undefined;
|
||||||
|
|
|
@ -115,6 +115,7 @@ export type Message = (
|
||||||
clean_reactions: Map<string, MessageCleanReaction>;
|
clean_reactions: Map<string, MessageCleanReaction>;
|
||||||
|
|
||||||
locally_echoed?: boolean;
|
locally_echoed?: boolean;
|
||||||
|
raw_content?: string;
|
||||||
|
|
||||||
// Added in `message_helper.process_new_message`.
|
// Added in `message_helper.process_new_message`.
|
||||||
sent_by_me: boolean;
|
sent_by_me: boolean;
|
||||||
|
|
|
@ -10,7 +10,9 @@ export {get_by_user_id as get_person_by_user_id, get_user_id_from_name} from "./
|
||||||
export {last_visible as last_visible_row, id as row_id} from "./rows";
|
export {last_visible as last_visible_row, id as row_id} from "./rows";
|
||||||
export {cancel as cancel_compose} from "./compose_actions";
|
export {cancel as cancel_compose} from "./compose_actions";
|
||||||
export {page_params, page_params_parse_time} from "./base_page_params";
|
export {page_params, page_params_parse_time} from "./base_page_params";
|
||||||
|
// @ts-expect-error We haven't converted reload.js yet
|
||||||
export {initiate as initiate_reload} from "./reload";
|
export {initiate as initiate_reload} from "./reload";
|
||||||
export {page_load_time} from "./setup";
|
export {page_load_time} from "./setup";
|
||||||
export {current_user, realm} from "./state_data";
|
export {current_user, realm} from "./state_data";
|
||||||
|
// @ts-expect-error We haven't converted stream_create_subscribers.js yet
|
||||||
export {add_user_id_to_new_stream} from "./stream_create_subscribers";
|
export {add_user_id_to_new_stream} from "./stream_create_subscribers";
|
Loading…
Reference in New Issue