2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-02-21 00:20:39 +01:00
|
|
|
const rewiremock = require("rewiremock/node");
|
|
|
|
|
2020-12-01 00:19:42 +01:00
|
|
|
const {stub_templates} = require("../zjsunit/handlebars");
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2018-12-26 19:56:19 +01:00
|
|
|
/*
|
|
|
|
This test suite is designed to find errors
|
|
|
|
in our initialization sequence. It doesn't
|
|
|
|
really validate any behavior, other than just
|
|
|
|
making sure things don't fail. For more
|
|
|
|
directed testing of individual modules, you
|
|
|
|
should create dedicated test suites.
|
|
|
|
|
|
|
|
Also, we stub a lot of initialization here that
|
|
|
|
is tricky to test due to dependencies on things
|
|
|
|
like jQuery. A good project is to work through
|
|
|
|
ignore_modules and try to make this test more
|
|
|
|
complete.
|
|
|
|
|
|
|
|
Also, it's good to be alert here for things
|
|
|
|
that can be cleaned up in the code--for example,
|
|
|
|
not everything needs to happen in `initialization`--
|
|
|
|
some things can happen later in a `launch` method.
|
|
|
|
|
|
|
|
*/
|
2021-02-21 15:38:51 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("document", {
|
2018-12-26 19:56:19 +01:00
|
|
|
location: {
|
2020-07-15 01:29:15 +02:00
|
|
|
protocol: "http",
|
2018-12-26 19:56:19 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("csrf_token", "whatever");
|
2018-12-26 19:56:19 +01:00
|
|
|
|
2021-02-28 00:57:20 +01:00
|
|
|
const resize = {
|
|
|
|
__esModule: true,
|
2020-12-01 23:21:38 +01:00
|
|
|
handler: () => {},
|
2021-02-28 00:57:20 +01:00
|
|
|
};
|
|
|
|
rewiremock("../../static/js/resize").with(resize);
|
2021-02-23 03:54:07 +01:00
|
|
|
const page_params = set_global("page_params", {});
|
2018-12-26 19:56:19 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
page_params.realm_default_streams = [];
|
|
|
|
page_params.subscriptions = [];
|
|
|
|
page_params.unsubscribed = [];
|
|
|
|
page_params.never_subscribed = [];
|
|
|
|
page_params.realm_notifications_stream_id = -1;
|
|
|
|
page_params.unread_msgs = {
|
|
|
|
huddles: [],
|
|
|
|
pms: [],
|
|
|
|
streams: [],
|
|
|
|
mentions: [],
|
|
|
|
};
|
|
|
|
page_params.recent_private_conversations = [];
|
|
|
|
page_params.user_status = {};
|
|
|
|
page_params.realm_emoji = {};
|
|
|
|
page_params.realm_users = [];
|
|
|
|
page_params.realm_non_active_users = [];
|
|
|
|
page_params.cross_realm_bots = [];
|
|
|
|
page_params.muted_topics = [];
|
|
|
|
page_params.realm_user_groups = [];
|
|
|
|
page_params.realm_bots = [];
|
|
|
|
page_params.realm_filters = [];
|
|
|
|
page_params.starred_messages = [];
|
|
|
|
page_params.presences = [];
|
|
|
|
|
2021-02-24 23:00:26 +01:00
|
|
|
set_global("activity", {initialize() {}});
|
2021-02-28 01:00:56 +01:00
|
|
|
rewiremock("../../static/js/click_handlers").with({initialize() {}});
|
2021-02-28 00:38:58 +01:00
|
|
|
rewiremock("../../static/js/compose_pm_pill").with({initialize() {}});
|
2021-02-28 00:37:57 +01:00
|
|
|
rewiremock("../../static/js/drafts").with({initialize() {}});
|
2021-02-24 23:00:26 +01:00
|
|
|
set_global("emoji_picker", {initialize() {}});
|
|
|
|
set_global("gear_menu", {initialize() {}});
|
|
|
|
set_global("hashchange", {initialize() {}});
|
|
|
|
set_global("hotspots", {initialize() {}});
|
|
|
|
// Accesses home_msg_list, which is a lot of complexity to set up
|
|
|
|
set_global("message_fetch", {initialize() {}});
|
2021-02-28 00:59:17 +01:00
|
|
|
rewiremock("../../static/js/message_scroll").with({initialize() {}});
|
2021-02-28 00:42:00 +01:00
|
|
|
const message_viewport = {
|
|
|
|
__esModule: true,
|
|
|
|
initialize() {},
|
|
|
|
};
|
|
|
|
rewiremock("../../static/js/message_viewport").with(message_viewport);
|
2021-02-24 23:00:26 +01:00
|
|
|
set_global("panels", {initialize() {}});
|
|
|
|
set_global("popovers", {initialize() {}});
|
2021-02-28 00:48:40 +01:00
|
|
|
rewiremock("../../static/js/reload").with({initialize() {}});
|
2021-02-24 23:00:26 +01:00
|
|
|
set_global("scroll_bar", {initialize() {}});
|
|
|
|
const server_events = set_global("server_events", {initialize() {}});
|
|
|
|
set_global("settings_sections", {initialize() {}});
|
2021-02-28 01:01:14 +01:00
|
|
|
rewiremock("../../static/js/settings_panel_menu").with({initialize() {}});
|
2021-02-28 01:01:33 +01:00
|
|
|
rewiremock("../../static/js/settings_toggle").with({initialize() {}});
|
2021-02-24 23:00:26 +01:00
|
|
|
set_global("subs", {initialize() {}});
|
|
|
|
set_global("timerender", {initialize() {}});
|
|
|
|
const ui = set_global("ui", {initialize() {}});
|
2021-02-28 00:40:18 +01:00
|
|
|
rewiremock("../../static/js/unread_ui").with({initialize() {}});
|
2018-12-26 19:56:19 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
server_events.home_view_loaded = () => true;
|
|
|
|
|
|
|
|
resize.watch_manual_resize = () => {};
|
|
|
|
|
2021-02-24 22:31:50 +01:00
|
|
|
rewiremock("../../static/js/favicon").with({});
|
|
|
|
rewiremock("../../static/js/emojisets").with({
|
|
|
|
initialize: () => {},
|
|
|
|
});
|
|
|
|
|
|
|
|
rewiremock.enable();
|
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const util = zrequire("util");
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("hash_util");
|
|
|
|
zrequire("overlays");
|
2020-07-08 23:44:01 +02:00
|
|
|
zrequire("message_view_header");
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("presence");
|
|
|
|
zrequire("search_pill_widget");
|
|
|
|
zrequire("unread");
|
|
|
|
zrequire("bot_data");
|
2021-02-10 04:53:22 +01:00
|
|
|
const upload = zrequire("upload");
|
|
|
|
const compose = zrequire("compose");
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("composebox_typeahead");
|
|
|
|
zrequire("narrow");
|
|
|
|
zrequire("search_suggestion");
|
|
|
|
zrequire("search");
|
2021-02-24 22:31:50 +01:00
|
|
|
zrequire("notifications");
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("stream_list");
|
|
|
|
zrequire("starred_messages");
|
2020-07-05 12:19:09 +02:00
|
|
|
zrequire("recent_topics");
|
2020-02-21 00:20:39 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("initialize_everything", () => {
|
2021-02-21 14:35:54 +01:00
|
|
|
util.is_mobile = () => false;
|
|
|
|
stub_templates(() => "some-html");
|
|
|
|
ui.get_scroll_element = (element) => element;
|
|
|
|
|
|
|
|
const document_stub = $.create("document-stub");
|
|
|
|
document.to_$ = () => document_stub;
|
|
|
|
document_stub.idle = () => {};
|
|
|
|
|
|
|
|
const window_stub = $.create("window-stub");
|
|
|
|
set_global("to_$", () => window_stub);
|
|
|
|
window_stub.idle = () => {};
|
2020-12-01 23:21:38 +01:00
|
|
|
window_stub.on = () => window_stub;
|
2021-02-21 14:35:54 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
message_viewport.message_pane = $(".app");
|
2021-02-21 14:35:54 +01:00
|
|
|
|
|
|
|
const $message_view_header = $.create("#message_view_header");
|
|
|
|
$message_view_header.append = () => {};
|
2021-02-28 00:52:20 +01:00
|
|
|
upload.__Rewire__("setup_upload", () => {});
|
2021-02-21 14:35:54 +01:00
|
|
|
|
|
|
|
$("#stream_message_recipient_stream").typeahead = () => {};
|
|
|
|
$("#stream_message_recipient_topic").typeahead = () => {};
|
|
|
|
$("#private_message_recipient").typeahead = () => {};
|
|
|
|
$("#compose-textarea").typeahead = () => {};
|
|
|
|
$("#search_query").typeahead = () => {};
|
|
|
|
|
|
|
|
const value_stub = $.create("value");
|
|
|
|
const count_stub = $.create("count");
|
|
|
|
count_stub.set_find_results(".value", value_stub);
|
|
|
|
$(".top_left_starred_messages").set_find_results(".count", count_stub);
|
|
|
|
|
|
|
|
$("#message_view_header .stream").length = 0;
|
|
|
|
|
|
|
|
// set find results doesn't work here since we call .empty() in the code.
|
|
|
|
$message_view_header.find = () => false;
|
|
|
|
|
2021-02-28 00:51:57 +01:00
|
|
|
compose.__Rewire__("compute_show_video_chat_button", () => {});
|
2021-02-21 14:35:54 +01:00
|
|
|
$("#below-compose-content .video_link").toggle = () => {};
|
|
|
|
|
2021-02-22 17:01:29 +01:00
|
|
|
$("<audio>")[0] = "stub";
|
|
|
|
|
2021-02-24 22:31:50 +01:00
|
|
|
zrequire("ui_init");
|
2018-12-26 19:56:19 +01:00
|
|
|
});
|
2021-02-24 22:31:50 +01:00
|
|
|
|
|
|
|
rewiremock.disable();
|