2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-03-11 05:43:45 +01:00
|
|
|
const {mock_cjs, mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace");
|
2021-02-13 03:46:14 +01:00
|
|
|
const {make_stub} = require("../zjsunit/stub");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-06-20 21:14:09 +02:00
|
|
|
const blueslip = require("../zjsunit/zblueslip");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2021-03-25 22:35:45 +01:00
|
|
|
const {page_params} = require("../zjsunit/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
const noop = () => {};
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2020-08-29 04:08:14 +02:00
|
|
|
const events = require("./lib/events");
|
2020-06-12 20:26:04 +02:00
|
|
|
|
|
|
|
const event_fixtures = events.fixtures;
|
|
|
|
const test_message = events.test_message;
|
|
|
|
const test_user = events.test_user;
|
2020-07-25 22:58:18 +02:00
|
|
|
const typing_person1 = events.typing_person1;
|
2020-06-12 20:26:04 +02:00
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
set_global("setTimeout", (func) => func());
|
2018-08-19 01:34:26 +02:00
|
|
|
|
2021-03-11 05:43:45 +01:00
|
|
|
mock_cjs("jquery", $);
|
2021-03-10 06:10:32 +01:00
|
|
|
const activity = mock_esm("../../static/js/activity");
|
|
|
|
const alert_words_ui = mock_esm("../../static/js/alert_words_ui");
|
|
|
|
const attachments_ui = mock_esm("../../static/js/attachments_ui");
|
|
|
|
const bot_data = mock_esm("../../static/js/bot_data");
|
|
|
|
const composebox_typeahead = mock_esm("../../static/js/composebox_typeahead");
|
|
|
|
const emoji_picker = mock_esm("../../static/js/emoji_picker");
|
|
|
|
const hotspots = mock_esm("../../static/js/hotspots");
|
|
|
|
const markdown = mock_esm("../../static/js/markdown");
|
|
|
|
const message_edit = mock_esm("../../static/js/message_edit");
|
|
|
|
const message_events = mock_esm("../../static/js/message_events");
|
|
|
|
const message_list = mock_esm("../../static/js/message_list");
|
2021-03-30 02:21:21 +02:00
|
|
|
const message_lists = mock_esm("../../static/js/message_lists");
|
2021-03-10 06:10:32 +01:00
|
|
|
const muting_ui = mock_esm("../../static/js/muting_ui");
|
|
|
|
const night_mode = mock_esm("../../static/js/night_mode");
|
|
|
|
const notifications = mock_esm("../../static/js/notifications");
|
|
|
|
const reactions = mock_esm("../../static/js/reactions");
|
|
|
|
const realm_icon = mock_esm("../../static/js/realm_icon");
|
|
|
|
const realm_logo = mock_esm("../../static/js/realm_logo");
|
|
|
|
const reload = mock_esm("../../static/js/reload");
|
|
|
|
const scroll_bar = mock_esm("../../static/js/scroll_bar");
|
|
|
|
const settings_account = mock_esm("../../static/js/settings_account");
|
|
|
|
const settings_bots = mock_esm("../../static/js/settings_bots");
|
|
|
|
const settings_display = mock_esm("../../static/js/settings_display");
|
|
|
|
const settings_emoji = mock_esm("../../static/js/settings_emoji");
|
|
|
|
const settings_exports = mock_esm("../../static/js/settings_exports");
|
|
|
|
const settings_invites = mock_esm("../../static/js/settings_invites");
|
|
|
|
const settings_linkifiers = mock_esm("../../static/js/settings_linkifiers");
|
|
|
|
const settings_notifications = mock_esm("../../static/js/settings_notifications");
|
|
|
|
const settings_org = mock_esm("../../static/js/settings_org");
|
|
|
|
const settings_profile_fields = mock_esm("../../static/js/settings_profile_fields");
|
|
|
|
const settings_streams = mock_esm("../../static/js/settings_streams");
|
|
|
|
const settings_user_groups = mock_esm("../../static/js/settings_user_groups");
|
|
|
|
const settings_users = mock_esm("../../static/js/settings_users");
|
|
|
|
const stream_data = mock_esm("../../static/js/stream_data");
|
|
|
|
const stream_events = mock_esm("../../static/js/stream_events");
|
|
|
|
const submessage = mock_esm("../../static/js/submessage");
|
|
|
|
const typing_events = mock_esm("../../static/js/typing_events");
|
|
|
|
const ui = mock_esm("../../static/js/ui");
|
|
|
|
const unread_ops = mock_esm("../../static/js/unread_ops");
|
|
|
|
const user_events = mock_esm("../../static/js/user_events");
|
|
|
|
const user_groups = mock_esm("../../static/js/user_groups");
|
|
|
|
mock_esm("../../static/js/compose");
|
2021-03-10 14:44:11 +01:00
|
|
|
|
|
|
|
const electron_bridge = set_global("electron_bridge", {});
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current = {};
|
|
|
|
message_lists.home = {};
|
2021-02-28 00:42:57 +01:00
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
// page_params is highly coupled to dispatching now
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.test_suite = false;
|
|
|
|
page_params.is_admin = true;
|
|
|
|
page_params.realm_description = "already set description";
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2020-02-26 23:53:46 +01:00
|
|
|
// For data-oriented modules, just use them, don't stub them.
|
2021-02-10 04:53:22 +01:00
|
|
|
const alert_words = zrequire("alert_words");
|
2021-02-11 01:23:23 +01:00
|
|
|
const stream_topic_history = zrequire("stream_topic_history");
|
|
|
|
const stream_list = zrequire("stream_list");
|
2021-03-28 17:57:53 +02:00
|
|
|
const message_helper = zrequire("message_helper");
|
2021-02-10 04:53:22 +01:00
|
|
|
const message_store = zrequire("message_store");
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2021-02-11 01:23:23 +01:00
|
|
|
const starred_messages = zrequire("starred_messages");
|
2021-02-10 04:53:22 +01:00
|
|
|
const user_status = zrequire("user_status");
|
2020-07-15 01:29:15 +02:00
|
|
|
|
zjsunit: Remove rewiremock dependency.
We now just use a module._load hook to inject
stubs into our code.
For conversion purposes I temporarily maintain
the API of rewiremock, apart from the enable/disable
pieces, but I will make a better wrapper in an
upcoming commit.
We can detect when rewiremock is called after
zrequire now, and I fix all the violations in
this commit, mostly by using override.
We can also detect when a mock is needlessly
created, and I fix all the violations in this
commit.
The one minor nuisance that this commit introduces
is that you can only stub out modules in the Zulip
source tree, which is now static/js. This should
not really be a problem--there are usually better
techniques to deal with third party depenencies.
In the prior commit I show a typical workaround,
which is to create a one-line wrapper in your
test code. It's often the case that you can simply
use override(), as well.
In passing I kill off `reset_modules`, and I
eliminated the second argument to zrequire,
which dates back to pre-es6 days.
2021-03-06 12:47:54 +01:00
|
|
|
const emoji = zrequire("../shared/js/emoji");
|
2020-07-25 00:12:17 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const server_events_dispatch = zrequire("server_events_dispatch");
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
function dispatch(ev) {
|
2019-01-25 20:03:10 +01:00
|
|
|
server_events_dispatch.dispatch_normal_event(ev);
|
2016-08-05 21:44:51 +02:00
|
|
|
}
|
|
|
|
|
2019-01-25 20:03:10 +01:00
|
|
|
people.init();
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(test_user);
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2021-03-28 17:57:53 +02:00
|
|
|
message_helper.process_new_message(test_message);
|
2019-01-26 18:49:10 +01:00
|
|
|
|
2020-07-25 23:59:49 +02:00
|
|
|
const realm_emoji = {};
|
zjsunit: Remove rewiremock dependency.
We now just use a module._load hook to inject
stubs into our code.
For conversion purposes I temporarily maintain
the API of rewiremock, apart from the enable/disable
pieces, but I will make a better wrapper in an
upcoming commit.
We can detect when rewiremock is called after
zrequire now, and I fix all the violations in
this commit, mostly by using override.
We can also detect when a mock is needlessly
created, and I fix all the violations in this
commit.
The one minor nuisance that this commit introduces
is that you can only stub out modules in the Zulip
source tree, which is now static/js. This should
not really be a problem--there are usually better
techniques to deal with third party depenencies.
In the prior commit I show a typical workaround,
which is to create a one-line wrapper in your
test code. It's often the case that you can simply
use override(), as well.
In passing I kill off `reset_modules`, and I
eliminated the second argument to zrequire,
which dates back to pre-es6 days.
2021-03-06 12:47:54 +01:00
|
|
|
const emoji_codes = zrequire("../generated/emoji/emoji_codes.json");
|
2020-07-25 23:59:49 +02:00
|
|
|
|
|
|
|
emoji.initialize({realm_emoji, emoji_codes});
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
function assert_same(actual, expected) {
|
|
|
|
// This helper prevents us from getting false positives
|
|
|
|
// where actual and expected are both undefined.
|
2019-01-26 19:28:39 +01:00
|
|
|
assert(expected !== undefined);
|
2016-08-05 21:44:51 +02:00
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
}
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("alert_words", (override) => {
|
2021-03-10 14:30:51 +01:00
|
|
|
alert_words.initialize({alert_words: []});
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(!alert_words.has_alert_word("fire"));
|
|
|
|
assert(!alert_words.has_alert_word("lunch"));
|
2020-02-26 23:53:46 +01:00
|
|
|
|
2021-02-11 01:23:23 +01:00
|
|
|
override(alert_words_ui, "render_alert_words_ui", noop);
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.alert_words;
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(alert_words.get_word_list(), ["fire", "lunch"]);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(alert_words.has_alert_word("fire"));
|
|
|
|
assert(alert_words.has_alert_word("lunch"));
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("attachments", (override) => {
|
2020-08-05 19:04:42 +02:00
|
|
|
const event = event_fixtures.attachment__add;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
// attachments_ui is hard to test deeply
|
|
|
|
override(attachments_ui, "update_attachments", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
assert_same(stub.get_args("event").event, event);
|
2018-08-19 00:02:08 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("user groups", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.user_group__add;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_user_groups, "reload", noop);
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(user_groups, "add", stub.f);
|
2018-04-15 21:26:58 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("group");
|
2018-04-15 21:26:58 +02:00
|
|
|
assert_same(args.group, event.group);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-04-15 21:26:58 +02:00
|
|
|
|
2021-03-26 18:25:36 +01:00
|
|
|
event = event_fixtures.user_group__remove;
|
|
|
|
{
|
|
|
|
const stub = make_stub();
|
|
|
|
override(user_groups, "get_user_group_from_id", stub.f);
|
|
|
|
override(user_groups, "remove", noop);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("group_id");
|
|
|
|
assert_same(args.group_id, event.group_id);
|
|
|
|
}
|
|
|
|
|
2018-04-15 21:26:58 +02:00
|
|
|
event = event_fixtures.user_group__add_members;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(user_groups, "add_members", stub.f);
|
2018-04-15 21:26:58 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("group_id", "user_ids");
|
2018-04-15 21:26:58 +02:00
|
|
|
assert_same(args.group_id, event.group_id);
|
|
|
|
assert_same(args.user_ids, event.user_ids);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-04-15 21:26:58 +02:00
|
|
|
|
|
|
|
event = event_fixtures.user_group__remove_members;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(user_groups, "remove_members", stub.f);
|
2018-04-15 21:26:58 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("group_id", "user_ids");
|
2018-04-15 21:26:58 +02:00
|
|
|
assert_same(args.group_id, event.group_id);
|
|
|
|
assert_same(args.user_ids, event.user_ids);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-04-15 21:26:58 +02:00
|
|
|
|
|
|
|
event = event_fixtures.user_group__update;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(user_groups, "update", stub.f);
|
2018-04-15 21:26:58 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("event");
|
2018-04-15 21:26:58 +02:00
|
|
|
assert_same(args.event.group_id, event.group_id);
|
|
|
|
assert_same(args.event.data.name, event.data.name);
|
|
|
|
assert_same(args.event.data.description, event.data.description);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-04-15 21:26:58 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("custom profile fields", (override) => {
|
2021-03-26 09:51:43 +01:00
|
|
|
const event = event_fixtures.custom_profile_fields;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_profile_fields, "populate_profile_fields", noop);
|
|
|
|
override(settings_account, "add_custom_profile_fields_to_settings", noop);
|
2017-12-14 05:51:45 +01:00
|
|
|
dispatch(event);
|
2020-12-01 00:57:57 +01:00
|
|
|
assert_same(page_params.custom_profile_fields, event.fields);
|
2017-12-14 05:51:45 +01:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("default_streams", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.default_streams;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_streams, "update_default_streams_table", noop);
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(stream_data, "set_realm_default_streams", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("realm_default_streams");
|
|
|
|
assert_same(args.realm_default_streams, event.default_streams);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("hotspots", (override) => {
|
2021-03-10 14:30:51 +01:00
|
|
|
page_params.hotspots = [];
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.hotspots;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(hotspots, "load_new", noop);
|
2017-05-31 06:34:53 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.hotspots, event.hotspots);
|
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("invites_changed", (override) => {
|
2021-02-22 17:01:29 +01:00
|
|
|
$.create("#admin-invites-list", {children: ["stub"]});
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.invites_changed;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(settings_invites, "set_up", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
2018-08-19 00:02:08 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("muted_topics", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.muted_topics;
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(muting_ui, "handle_topic_updates", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("muted_topics");
|
|
|
|
assert_same(args.muted_topics, event.muted_topics);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("presence", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.presence;
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(activity, "update_presence_info", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("user_id", "presence", "server_time");
|
|
|
|
assert_same(args.user_id, event.user_id);
|
|
|
|
assert_same(args.presence, event.presence);
|
|
|
|
assert_same(args.server_time, event.server_timestamp);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("reaction", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.reaction__add;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(reactions, "add_reaction", stub.f);
|
2017-05-31 06:37:52 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("event");
|
2017-05-31 06:37:52 +02:00
|
|
|
assert_same(args.event.emoji_name, event.emoji_name);
|
|
|
|
assert_same(args.event.message_id, event.message_id);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2017-05-31 06:37:52 +02:00
|
|
|
|
|
|
|
event = event_fixtures.reaction__remove;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(reactions, "remove_reaction", stub.f);
|
2017-05-31 06:37:52 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("event");
|
2017-05-31 06:37:52 +02:00
|
|
|
assert_same(args.event.emoji_name, event.emoji_name);
|
|
|
|
assert_same(args.event.message_id, event.message_id);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2017-05-31 06:37:52 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("realm settings", (override) => {
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_org, "sync_realm_settings", noop);
|
|
|
|
override(settings_bots, "update_bot_permissions_ui", noop);
|
|
|
|
override(notifications, "redraw_title", noop);
|
2020-07-26 12:20:40 +02:00
|
|
|
|
2021-03-10 14:44:11 +01:00
|
|
|
function test_electron_dispatch(event, fake_send_event) {
|
|
|
|
let called = false;
|
|
|
|
|
|
|
|
with_field(electron_bridge, "send_event", fake_send_event, () => {
|
|
|
|
dispatch(event);
|
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
assert(called);
|
|
|
|
}
|
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
// realm
|
|
|
|
function test_realm_boolean(event, parameter_name) {
|
|
|
|
page_params[parameter_name] = true;
|
2020-07-16 22:40:18 +02:00
|
|
|
event = {...event};
|
2016-08-05 21:44:51 +02:00
|
|
|
event.value = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], false);
|
2020-07-16 22:40:18 +02:00
|
|
|
event = {...event};
|
2016-08-05 21:44:51 +02:00
|
|
|
event.value = true;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], true);
|
|
|
|
}
|
|
|
|
|
2020-04-01 08:54:56 +02:00
|
|
|
function test_realm_integer(event, parameter_name) {
|
|
|
|
page_params[parameter_name] = 1;
|
|
|
|
event = {...event};
|
|
|
|
event.value = 2;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], 2);
|
|
|
|
|
|
|
|
event = {...event};
|
|
|
|
event.value = 3;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], 3);
|
|
|
|
|
|
|
|
event = {...event};
|
|
|
|
event.value = 1;
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(page_params[parameter_name], 1);
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.realm__update__create_stream_policy;
|
2020-07-15 01:29:15 +02:00
|
|
|
test_realm_integer(event, "realm_create_stream_policy");
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2019-04-08 19:23:00 +02:00
|
|
|
event = event_fixtures.realm__update__invite_to_stream_policy;
|
2020-07-15 01:29:15 +02:00
|
|
|
test_realm_integer(event, "realm_invite_to_stream_policy");
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2020-04-03 02:31:43 +02:00
|
|
|
event = event_fixtures.realm__update__bot_creation_policy;
|
2020-07-15 01:29:15 +02:00
|
|
|
test_realm_integer(event, "realm_bot_creation_policy");
|
2020-04-03 02:31:43 +02:00
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
event = event_fixtures.realm__update__invite_required;
|
2020-07-15 01:29:15 +02:00
|
|
|
test_realm_boolean(event, "realm_invite_required");
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.realm__update__name;
|
|
|
|
|
2021-03-10 14:44:11 +01:00
|
|
|
test_electron_dispatch(event, (key, val) => {
|
|
|
|
assert_same(key, "realm_name");
|
|
|
|
assert_same(val, "new_realm_name");
|
2019-07-25 09:13:22 +02:00
|
|
|
});
|
2021-03-10 14:44:11 +01:00
|
|
|
assert_same(page_params.realm_name, "new_realm_name");
|
2018-08-19 01:34:26 +02:00
|
|
|
|
2018-07-27 23:26:29 +02:00
|
|
|
event = event_fixtures.realm__update__emails_restricted_to_domains;
|
2020-07-15 01:29:15 +02:00
|
|
|
test_realm_boolean(event, "realm_emails_restricted_to_domains");
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2018-03-05 19:19:19 +01:00
|
|
|
event = event_fixtures.realm__update__disallow_disposable_email_addresses;
|
2020-07-15 01:29:15 +02:00
|
|
|
test_realm_boolean(event, "realm_disallow_disposable_email_addresses");
|
2018-03-05 19:19:19 +01:00
|
|
|
|
2020-07-29 13:19:47 +02:00
|
|
|
event = event_fixtures.realm__update__default_twenty_four_hour_time;
|
2020-07-15 01:29:15 +02:00
|
|
|
test_realm_boolean(event, "realm_default_twenty_four_hour_time");
|
2020-04-30 21:47:41 +02:00
|
|
|
|
2020-03-08 18:45:44 +01:00
|
|
|
event = event_fixtures.realm__update__email_addresses_visibility;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_email_address_visibility, 3);
|
|
|
|
|
2020-07-29 13:19:47 +02:00
|
|
|
event = event_fixtures.realm__update__notifications_stream_id;
|
2018-08-19 01:34:26 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_notifications_stream_id, 42);
|
2020-07-16 23:29:01 +02:00
|
|
|
page_params.realm_notifications_stream_id = -1; // make sure to reset for future tests
|
2018-08-19 01:34:26 +02:00
|
|
|
|
2020-07-29 13:19:47 +02:00
|
|
|
event = event_fixtures.realm__update__signup_notifications_stream_id;
|
2018-08-19 01:34:26 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_signup_notifications_stream_id, 41);
|
|
|
|
page_params.realm_signup_notifications_stream_id = -1; // make sure to reset for future tests
|
|
|
|
|
2020-07-29 13:19:47 +02:00
|
|
|
event = event_fixtures.realm__update__default_code_block_language;
|
2020-04-10 09:38:55 +02:00
|
|
|
dispatch(event);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_same(page_params.realm_default_code_block_language, "javascript");
|
2020-04-10 09:38:55 +02:00
|
|
|
|
2016-08-05 21:44:51 +02:00
|
|
|
event = event_fixtures.realm__update_dict__default;
|
|
|
|
page_params.realm_allow_message_editing = false;
|
|
|
|
page_params.realm_message_content_edit_limit_seconds = 0;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_org, "populate_auth_methods", noop);
|
|
|
|
override(message_edit, "update_message_topic_editing_pencil", noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_allow_message_editing, true);
|
|
|
|
assert_same(page_params.realm_message_content_edit_limit_seconds, 5);
|
2018-08-19 01:34:26 +02:00
|
|
|
assert_same(page_params.realm_authentication_methods, {Google: true});
|
|
|
|
|
|
|
|
event = event_fixtures.realm__update_dict__icon;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(realm_icon, "rerender", noop);
|
2018-08-19 01:34:26 +02:00
|
|
|
|
2021-03-10 14:44:11 +01:00
|
|
|
test_electron_dispatch(event, (key, val) => {
|
|
|
|
assert_same(key, "realm_icon_url");
|
|
|
|
assert_same(val, "icon.png");
|
2019-07-25 09:13:22 +02:00
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_same(page_params.realm_icon_url, "icon.png");
|
|
|
|
assert_same(page_params.realm_icon_source, "U");
|
2018-08-19 01:34:26 +02:00
|
|
|
|
2021-02-11 01:23:23 +01:00
|
|
|
override(realm_logo, "rerender", noop);
|
2021-02-11 16:36:12 +01:00
|
|
|
|
|
|
|
event = event_fixtures.realm__update_dict__logo;
|
2019-01-25 20:35:55 +01:00
|
|
|
dispatch(event);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_same(page_params.realm_logo_url, "logo.png");
|
|
|
|
assert_same(page_params.realm_logo_source, "U");
|
2019-01-25 20:35:55 +01:00
|
|
|
|
2019-01-27 08:25:10 +01:00
|
|
|
event = event_fixtures.realm__update_dict__night_logo;
|
|
|
|
dispatch(event);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_same(page_params.realm_night_logo_url, "night_logo.png");
|
|
|
|
assert_same(page_params.realm_night_logo_source, "U");
|
2019-01-27 08:25:10 +01:00
|
|
|
|
2018-08-19 01:34:26 +02:00
|
|
|
event = event_fixtures.realm__deactivated;
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("location", {});
|
2018-08-19 01:34:26 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(window.location.href, "/accounts/deactivated/");
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2021-02-11 16:36:12 +01:00
|
|
|
run_test("realm_bot add", (override) => {
|
|
|
|
const event = event_fixtures.realm_bot__add;
|
2021-02-13 03:46:14 +01:00
|
|
|
const bot_stub = make_stub();
|
|
|
|
const admin_stub = make_stub();
|
|
|
|
override(bot_data, "add", bot_stub.f);
|
2021-03-21 17:22:14 +01:00
|
|
|
override(settings_bots, "eventually_render_bots", () => {});
|
2021-02-13 03:46:14 +01:00
|
|
|
override(settings_users, "update_bot_data", admin_stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
|
|
|
|
assert.equal(bot_stub.num_calls, 1);
|
|
|
|
assert.equal(admin_stub.num_calls, 1);
|
|
|
|
const args = bot_stub.get_args("bot");
|
|
|
|
assert_same(args.bot, event.bot);
|
|
|
|
admin_stub.get_args("update_user_id", "update_bot_data");
|
2021-02-11 16:36:12 +01:00
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2021-02-11 16:36:12 +01:00
|
|
|
run_test("realm_bot remove", (override) => {
|
|
|
|
const event = event_fixtures.realm_bot__remove;
|
2021-02-13 03:46:14 +01:00
|
|
|
const bot_stub = make_stub();
|
|
|
|
const admin_stub = make_stub();
|
|
|
|
override(bot_data, "deactivate", bot_stub.f);
|
2021-03-21 17:22:14 +01:00
|
|
|
override(settings_bots, "eventually_render_bots", () => {});
|
2021-02-13 03:46:14 +01:00
|
|
|
override(settings_users, "update_bot_data", admin_stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
|
|
|
|
assert.equal(bot_stub.num_calls, 1);
|
|
|
|
assert.equal(admin_stub.num_calls, 1);
|
|
|
|
const args = bot_stub.get_args("user_id");
|
|
|
|
assert_same(args.user_id, event.bot.user_id);
|
|
|
|
admin_stub.get_args("update_user_id", "update_bot_data");
|
2021-02-11 16:36:12 +01:00
|
|
|
});
|
2018-03-08 16:28:37 +01:00
|
|
|
|
2021-02-11 16:36:12 +01:00
|
|
|
run_test("realm_bot delete", () => {
|
|
|
|
const event = event_fixtures.realm_bot__delete;
|
2020-05-28 22:29:52 +02:00
|
|
|
// We don't handle live updates for delete events, this is a noop.
|
|
|
|
dispatch(event);
|
2021-02-11 16:36:12 +01:00
|
|
|
});
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2021-02-11 16:36:12 +01:00
|
|
|
run_test("realm_bot update", (override) => {
|
|
|
|
const event = event_fixtures.realm_bot__update;
|
2021-02-13 03:46:14 +01:00
|
|
|
const bot_stub = make_stub();
|
|
|
|
const admin_stub = make_stub();
|
|
|
|
override(bot_data, "update", bot_stub.f);
|
2021-03-21 17:22:14 +01:00
|
|
|
override(settings_bots, "eventually_render_bots", () => {});
|
2021-02-13 03:46:14 +01:00
|
|
|
override(settings_users, "update_bot_data", admin_stub.f);
|
2017-03-11 19:18:57 +01:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
dispatch(event);
|
2017-03-11 19:18:57 +01:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(bot_stub.num_calls, 1);
|
|
|
|
assert.equal(admin_stub.num_calls, 1);
|
|
|
|
let args = bot_stub.get_args("user_id", "bot");
|
|
|
|
assert_same(args.user_id, event.bot.user_id);
|
|
|
|
assert_same(args.bot, event.bot);
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
args = admin_stub.get_args("update_user_id", "update_bot_data");
|
|
|
|
assert_same(args.update_user_id, event.bot.user_id);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("realm_emoji", (override) => {
|
2020-08-05 19:04:27 +02:00
|
|
|
const event = event_fixtures.realm_emoji__update;
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2020-07-25 14:27:39 +02:00
|
|
|
const ui_func_names = [
|
2021-02-11 01:23:23 +01:00
|
|
|
[settings_emoji, "populate_emoji"],
|
|
|
|
[emoji_picker, "rebuild_catalog"],
|
|
|
|
[composebox_typeahead, "update_emoji_data"],
|
2020-07-25 14:27:39 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
const ui_stubs = [];
|
|
|
|
|
2021-02-11 01:23:23 +01:00
|
|
|
for (const [module, func_name] of ui_func_names) {
|
2020-12-01 00:06:06 +01:00
|
|
|
const ui_stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(module, func_name, ui_stub.f);
|
2020-07-25 14:27:39 +02:00
|
|
|
ui_stubs.push(ui_stub);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we start with nothing...
|
2021-03-10 14:30:51 +01:00
|
|
|
emoji.update_emojis([]);
|
2020-07-25 14:27:39 +02:00
|
|
|
assert.equal(emoji.get_realm_emoji_url("spain"), undefined);
|
|
|
|
|
|
|
|
dispatch(event);
|
|
|
|
|
|
|
|
// Now emoji.js knows about the spain emoji.
|
|
|
|
assert_same(emoji.get_realm_emoji_url("spain"), "/some/path/to/spain.png");
|
|
|
|
|
|
|
|
// Make sure our UI modules all got dispatched the same simple way.
|
|
|
|
for (const stub of ui_stubs) {
|
|
|
|
assert(stub.num_calls, 1);
|
|
|
|
assert.equal(stub.last_call_args.length, 0);
|
|
|
|
}
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2021-03-13 18:15:14 +01:00
|
|
|
run_test("linkifier", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.realm_filters;
|
2016-08-05 21:44:51 +02:00
|
|
|
page_params.realm_filters = [];
|
2021-03-13 18:15:14 +01:00
|
|
|
override(settings_linkifiers, "populate_linkifiers", noop);
|
|
|
|
override(markdown, "update_linkifier_rules", noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_filters, event.realm_filters);
|
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("realm_domains", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.realm_domains__add;
|
2017-05-31 07:02:00 +02:00
|
|
|
page_params.realm_domains = [];
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_org, "populate_realm_domains", noop);
|
2017-05-31 07:02:00 +02:00
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_domains, [event.realm_domain]);
|
|
|
|
|
2020-10-15 14:42:15 +02:00
|
|
|
override(settings_org, "populate_realm_domains", noop);
|
2017-05-31 07:02:00 +02:00
|
|
|
event = event_fixtures.realm_domains__change;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_domains, [event.realm_domain]);
|
|
|
|
|
2020-10-15 14:42:15 +02:00
|
|
|
override(settings_org, "populate_realm_domains", noop);
|
2017-05-31 07:02:00 +02:00
|
|
|
event = event_fixtures.realm_domains__remove;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.realm_domains, []);
|
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("realm_user", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.realm_user__add;
|
2020-08-14 02:45:53 +02:00
|
|
|
dispatch({...event});
|
2020-02-05 14:30:59 +01:00
|
|
|
const added_person = people.get_by_user_id(event.person.user_id);
|
2020-08-14 02:45:53 +02:00
|
|
|
// sanity check a few individual fields
|
2020-07-25 22:15:45 +02:00
|
|
|
assert.equal(added_person.full_name, "Test User");
|
2020-10-27 01:41:00 +01:00
|
|
|
assert.equal(added_person.timezone, "America/New_York");
|
2020-08-14 02:45:53 +02:00
|
|
|
|
|
|
|
// ...but really the whole struct gets copied without any
|
|
|
|
// manipulation
|
|
|
|
assert.deepEqual(added_person, event.person);
|
|
|
|
|
2019-01-25 20:03:10 +01:00
|
|
|
assert(people.is_active_user_for_popover(event.person.user_id));
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.realm_user__remove;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(stream_events, "remove_deactivated_user_from_all_streams", noop);
|
2019-01-25 20:03:10 +01:00
|
|
|
dispatch(event);
|
|
|
|
|
|
|
|
// We don't actually remove the person, we just deactivate them.
|
2020-02-05 14:30:59 +01:00
|
|
|
const removed_person = people.get_by_user_id(event.person.user_id);
|
2020-07-25 22:15:45 +02:00
|
|
|
assert.equal(removed_person.full_name, "Test User");
|
2019-01-25 20:03:10 +01:00
|
|
|
assert(!people.is_active_user_for_popover(event.person.user_id));
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.realm_user__update;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(user_events, "update_person", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("person");
|
|
|
|
assert_same(args.person, event.person);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("restart", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.restart;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(reload, "initiate", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("options");
|
|
|
|
assert.equal(args.options.save_pointer, true);
|
|
|
|
assert.equal(args.options.immediate, true);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("submessage", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.submessage;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(submessage, "handle_event", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const submsg = stub.get_args("submsg").submsg;
|
|
|
|
assert_same(submsg, {
|
|
|
|
id: 99,
|
|
|
|
sender_id: 42,
|
|
|
|
msg_type: "stream",
|
|
|
|
message_id: 56,
|
|
|
|
content: "test",
|
2018-08-19 00:02:08 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-12 22:27:49 +02:00
|
|
|
// For subscriptions, see dispatch_subs.js
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("typing", (override) => {
|
2021-03-10 14:30:51 +01:00
|
|
|
// Simulate that we are not typing.
|
|
|
|
page_params.user_id = typing_person1.user_id + 1;
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.typing__start;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(typing_events, "display_notification", stub.f);
|
2017-05-31 07:48:38 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("event");
|
2020-07-25 22:58:18 +02:00
|
|
|
assert_same(args.event.sender.user_id, typing_person1.user_id);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2017-05-31 07:48:38 +02:00
|
|
|
|
|
|
|
event = event_fixtures.typing__stop;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(typing_events, "hide_notification", stub.f);
|
2017-05-31 07:48:38 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("event");
|
2020-07-25 22:58:18 +02:00
|
|
|
assert_same(args.event.sender.user_id, typing_person1.user_id);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-08-18 23:26:21 +02:00
|
|
|
|
2021-03-10 14:30:51 +01:00
|
|
|
// Get line coverage--we ignore our own typing events.
|
2020-07-25 22:58:18 +02:00
|
|
|
page_params.user_id = typing_person1.user_id;
|
|
|
|
event = event_fixtures.typing__start;
|
2021-03-10 14:30:51 +01:00
|
|
|
dispatch(event);
|
2017-05-31 07:48:38 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("update_display_settings", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.update_display_settings__default_language;
|
2020-07-15 01:29:15 +02:00
|
|
|
page_params.default_language = "en";
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_display, "update_page", noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
dispatch(event);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_same(page_params.default_language, "fr");
|
2016-08-05 21:44:51 +02:00
|
|
|
|
|
|
|
event = event_fixtures.update_display_settings__left_side_userlist;
|
|
|
|
page_params.left_side_userlist = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.left_side_userlist, true);
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
// We alias message_list.narrowed to message_lists.current
|
2020-07-26 14:31:16 +02:00
|
|
|
// to make sure we get line coverage on re-rendering
|
|
|
|
// the current message list. The actual code tests
|
|
|
|
// that these two objects are equal. It is possible
|
|
|
|
// we want a better strategy for that, or at least
|
|
|
|
// a helper.
|
2021-03-30 02:21:21 +02:00
|
|
|
message_list.narrowed = message_lists.current;
|
2020-07-26 14:31:16 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let called = false;
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.rerender = () => {
|
2018-08-19 01:59:34 +02:00
|
|
|
called = true;
|
|
|
|
};
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
override(message_lists.home, "rerender", noop);
|
2016-08-05 21:44:51 +02:00
|
|
|
event = event_fixtures.update_display_settings__twenty_four_hour_time;
|
|
|
|
page_params.twenty_four_hour_time = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.twenty_four_hour_time, true);
|
2018-08-19 01:59:34 +02:00
|
|
|
assert_same(called, true);
|
2016-08-05 21:44:51 +02:00
|
|
|
|
2018-01-15 19:36:32 +01:00
|
|
|
event = event_fixtures.update_display_settings__translate_emoticons;
|
|
|
|
page_params.translate_emoticons = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.translate_emoticons, true);
|
2018-08-19 01:59:34 +02:00
|
|
|
|
|
|
|
event = event_fixtures.update_display_settings__high_contrast_mode;
|
|
|
|
page_params.high_contrast_mode = false;
|
2019-11-02 00:06:25 +01:00
|
|
|
let toggled = [];
|
2018-08-19 01:59:34 +02:00
|
|
|
$("body").toggleClass = (cls) => {
|
|
|
|
toggled.push(cls);
|
|
|
|
};
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.high_contrast_mode, true);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_same(toggled, ["high-contrast"]);
|
2018-08-19 01:59:34 +02:00
|
|
|
|
|
|
|
event = event_fixtures.update_display_settings__dense_mode;
|
|
|
|
page_params.dense_mode = false;
|
|
|
|
toggled = [];
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.dense_mode, true);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_same(toggled, ["less_dense_mode", "more_dense_mode"]);
|
2018-08-19 01:59:34 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("body").fadeOut = (secs) => {
|
|
|
|
assert_same(secs, 300);
|
|
|
|
};
|
|
|
|
$("body").fadeIn = (secs) => {
|
|
|
|
assert_same(secs, 300);
|
|
|
|
};
|
2018-08-19 01:59:34 +02:00
|
|
|
|
2021-02-11 16:36:12 +01:00
|
|
|
override(realm_logo, "rerender", noop);
|
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-05-16 13:13:59 +02:00
|
|
|
event = event_fixtures.update_display_settings__color_scheme_dark;
|
|
|
|
page_params.color_scheme = 1;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(night_mode, "enable", stub.f); // automatically checks if called
|
2018-08-19 01:59:34 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-05-16 13:13:59 +02:00
|
|
|
assert(page_params.color_scheme, 2);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-08-19 01:59:34 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-05-16 13:13:59 +02:00
|
|
|
event = event_fixtures.update_display_settings__color_scheme_light;
|
|
|
|
page_params.color_scheme = 1;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(night_mode, "disable", stub.f); // automatically checks if called
|
2020-05-16 13:13:59 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-05-16 13:13:59 +02:00
|
|
|
assert(page_params.color_scheme, 3);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2020-05-16 13:13:59 +02:00
|
|
|
|
2021-03-10 13:56:10 +01:00
|
|
|
{
|
|
|
|
event = event_fixtures.update_display_settings__default_view_recent_topics;
|
|
|
|
page_params.default_view = "all_messages";
|
|
|
|
dispatch(event);
|
|
|
|
assert(page_params.default_view, "recent_topics");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
event = event_fixtures.update_display_settings__default_view_all_messages;
|
|
|
|
page_params.default_view = "recent_topics";
|
|
|
|
dispatch(event);
|
|
|
|
assert(page_params.default_view, "all_messages");
|
|
|
|
}
|
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-05-16 13:13:59 +02:00
|
|
|
event = event_fixtures.update_display_settings__color_scheme_automatic;
|
|
|
|
page_params.color_scheme = 2;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(night_mode, "default_preference_checker", stub.f); // automatically checks if called
|
2018-08-19 01:59:34 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-05-16 13:13:59 +02:00
|
|
|
assert(page_params.color_scheme, 1);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-08-19 01:59:34 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2018-08-19 01:59:34 +02:00
|
|
|
event = event_fixtures.update_display_settings__emojiset;
|
|
|
|
called = false;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(settings_display, "report_emojiset_change", stub.f);
|
2020-07-15 01:29:15 +02:00
|
|
|
page_params.emojiset = "text";
|
2018-08-19 01:59:34 +02:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2018-08-19 01:59:34 +02:00
|
|
|
assert_same(called, true);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_same(page_params.emojiset, "google");
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2019-01-25 21:33:02 +01:00
|
|
|
|
2021-02-11 01:23:23 +01:00
|
|
|
override(starred_messages, "rerender_ui", noop);
|
2019-01-25 21:33:02 +01:00
|
|
|
event = event_fixtures.update_display_settings__starred_message_counts;
|
|
|
|
page_params.starred_message_counts = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.starred_message_counts, true);
|
2019-04-16 18:46:17 +02:00
|
|
|
|
2021-02-11 01:23:23 +01:00
|
|
|
override(scroll_bar, "set_layout_width", noop);
|
2019-04-16 18:46:17 +02:00
|
|
|
event = event_fixtures.update_display_settings__fluid_layout_width;
|
|
|
|
page_params.fluid_layout_width = false;
|
|
|
|
dispatch(event);
|
|
|
|
assert_same(page_params.fluid_layout_width, true);
|
2019-03-17 14:48:51 +01:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2019-03-17 14:48:51 +01:00
|
|
|
event = event_fixtures.update_display_settings__demote_inactive_streams;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(stream_data, "set_filter_out_inactives", noop);
|
|
|
|
override(stream_list, "update_streams_sidebar", stub.f);
|
2019-03-17 14:48:51 +01:00
|
|
|
page_params.demote_inactive_streams = 1;
|
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2019-03-17 14:48:51 +01:00
|
|
|
assert_same(page_params.demote_inactive_streams, 2);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("update_global_notifications", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.update_global_notifications;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(notifications, "handle_global_notification_updates", stub.f);
|
|
|
|
override(settings_notifications, "update_page", noop);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("name", "setting");
|
|
|
|
assert_same(args.name, event.notification_name);
|
|
|
|
assert_same(args.setting, event.setting);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("update_message (read)", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.update_message_flags__read;
|
2017-03-11 19:18:57 +01:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(unread_ops, "process_read_messages_event", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("message_ids");
|
|
|
|
assert_same(args.message_ids, [999]);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
|
|
|
|
2021-02-11 16:36:12 +01:00
|
|
|
run_test("update_message (add star)", (override) => {
|
2021-02-11 01:23:23 +01:00
|
|
|
override(starred_messages, "rerender_ui", noop);
|
2019-01-26 19:28:39 +01:00
|
|
|
|
2021-02-11 16:36:12 +01:00
|
|
|
const event = event_fixtures.update_message_flags__starred_add;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(ui, "update_starred_view", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("message_id", "new_value");
|
|
|
|
assert_same(args.message_id, test_message.id);
|
|
|
|
assert_same(args.new_value, true); // for 'add'
|
|
|
|
const msg = message_store.get(test_message.id);
|
|
|
|
assert.equal(msg.starred, true);
|
2021-02-11 16:36:12 +01:00
|
|
|
});
|
2019-01-26 19:28:39 +01:00
|
|
|
|
2021-02-11 16:36:12 +01:00
|
|
|
run_test("update_message (remove star)", (override) => {
|
|
|
|
override(starred_messages, "rerender_ui", noop);
|
|
|
|
const event = event_fixtures.update_message_flags__starred_remove;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(ui, "update_starred_view", stub.f);
|
|
|
|
dispatch(event);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("message_id", "new_value");
|
|
|
|
assert_same(args.message_id, test_message.id);
|
|
|
|
assert_same(args.new_value, false);
|
|
|
|
const msg = message_store.get(test_message.id);
|
|
|
|
assert.equal(msg.starred, false);
|
2016-08-05 21:44:51 +02:00
|
|
|
});
|
2017-05-31 07:20:28 +02:00
|
|
|
|
2021-03-20 08:33:28 +01:00
|
|
|
run_test("update_message (wrong data)", (override) => {
|
|
|
|
override(starred_messages, "rerender_ui", noop);
|
|
|
|
const event = event_fixtures.update_message_flags__starred_add;
|
|
|
|
// message does not exist
|
|
|
|
event.messages = [0];
|
|
|
|
dispatch(event);
|
|
|
|
// update_starred_view never gets invoked, early return is successful
|
|
|
|
});
|
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("delete_message", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.delete_message;
|
2018-02-16 23:41:38 +01:00
|
|
|
|
2021-02-11 01:23:23 +01:00
|
|
|
override(stream_list, "update_streams_sidebar", noop);
|
2021-02-11 16:36:12 +01:00
|
|
|
|
|
|
|
const message_events_stub = make_stub();
|
|
|
|
override(message_events, "remove_messages", message_events_stub.f);
|
|
|
|
|
|
|
|
const unread_ops_stub = make_stub();
|
|
|
|
override(unread_ops, "process_read_messages_event", unread_ops_stub.f);
|
|
|
|
|
|
|
|
const stream_topic_history_stub = make_stub();
|
|
|
|
override(stream_topic_history, "remove_messages", stream_topic_history_stub.f);
|
|
|
|
|
|
|
|
dispatch(event);
|
|
|
|
|
|
|
|
let args;
|
|
|
|
|
|
|
|
args = message_events_stub.get_args("message_ids");
|
|
|
|
assert_same(args.message_ids, [1337]);
|
|
|
|
|
|
|
|
args = unread_ops_stub.get_args("message_ids");
|
|
|
|
assert_same(args.message_ids, [1337]);
|
|
|
|
|
|
|
|
args = stream_topic_history_stub.get_args("opts");
|
|
|
|
assert_same(args.opts.stream_id, 99);
|
|
|
|
assert_same(args.opts.topic_name, "topic1");
|
|
|
|
assert_same(args.opts.num_messages, 1);
|
|
|
|
assert_same(args.opts.max_removed_msg_id, 1337);
|
2017-05-31 07:20:28 +02:00
|
|
|
});
|
2018-12-19 18:41:47 +01:00
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("user_status", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = event_fixtures.user_status__set_away;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(activity, "on_set_away", stub.f);
|
2018-12-19 18:41:47 +01:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("user_id");
|
2018-12-19 18:41:47 +01:00
|
|
|
assert_same(args.user_id, 55);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-12-19 18:41:47 +01:00
|
|
|
|
|
|
|
event = event_fixtures.user_status__revoke_away;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(activity, "on_revoke_away", stub.f);
|
2018-12-19 18:41:47 +01:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("user_id");
|
2018-12-19 18:41:47 +01:00
|
|
|
assert_same(args.user_id, 63);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2019-01-26 19:29:06 +01:00
|
|
|
|
|
|
|
event = event_fixtures.user_status__set_status_text;
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 01:23:23 +01:00
|
|
|
override(activity, "redraw_user", stub.f);
|
2019-01-26 19:29:06 +01:00
|
|
|
dispatch(event);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("user_id");
|
2019-01-26 19:29:06 +01:00
|
|
|
assert_same(args.user_id, test_user.user_id);
|
2019-11-02 00:06:25 +01:00
|
|
|
const status_text = user_status.get_status_text(test_user.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(status_text, "out to lunch");
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2018-12-19 18:41:47 +01:00
|
|
|
});
|
2019-04-09 21:49:07 +02:00
|
|
|
|
2020-07-26 18:21:06 +02:00
|
|
|
run_test("realm_export", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = event_fixtures.realm_export;
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(settings_exports, "populate_exports_table", stub.f);
|
|
|
|
dispatch(event);
|
2019-04-09 21:49:07 +02:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("exports");
|
|
|
|
assert.equal(args.exports, event.exports);
|
2019-04-09 21:49:07 +02:00
|
|
|
});
|
2020-06-20 21:14:09 +02:00
|
|
|
|
2020-10-16 04:28:43 +02:00
|
|
|
run_test("server_event_dispatch_op_errors", (override) => {
|
2020-06-20 21:14:09 +02:00
|
|
|
blueslip.expect("error", "Unexpected event type subscription/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({type: "subscription", op: "other"});
|
2021-03-24 13:20:01 +01:00
|
|
|
blueslip.expect("error", "Unexpected event type reaction/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({type: "reaction", op: "other"});
|
2020-10-15 13:51:21 +02:00
|
|
|
blueslip.expect("error", "Unexpected event type realm/update_dict/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({
|
|
|
|
type: "realm",
|
|
|
|
op: "update_dict",
|
|
|
|
property: "other",
|
|
|
|
});
|
2020-10-15 14:11:54 +02:00
|
|
|
blueslip.expect("error", "Unexpected event type realm_bot/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({type: "realm_bot", op: "other"});
|
2020-10-15 16:34:13 +02:00
|
|
|
blueslip.expect("error", "Unexpected event type realm_domains/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({type: "realm_domains", op: "other"});
|
2020-10-16 03:55:11 +02:00
|
|
|
blueslip.expect("error", "Unexpected event type realm_user/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({type: "realm_user", op: "other"});
|
2020-10-16 04:13:38 +02:00
|
|
|
blueslip.expect("error", "Unexpected event type stream/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({type: "stream", op: "other"});
|
2020-10-16 04:28:43 +02:00
|
|
|
blueslip.expect("error", "Unexpected event type typing/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({
|
|
|
|
type: "typing",
|
|
|
|
sender: {user_id: 5},
|
|
|
|
op: "other",
|
|
|
|
});
|
|
|
|
override(settings_user_groups, "reload", noop);
|
|
|
|
blueslip.expect("error", "Unexpected event type user_group/other");
|
|
|
|
server_events_dispatch.dispatch_normal_event({type: "user_group", op: "other"});
|
2020-06-20 21:14:09 +02:00
|
|
|
});
|