mirror of https://github.com/zulip/zulip.git
node tests: Explicitly call make_stub.
This commit replaces all `with_stub` calls and explicitly calls `make_stub` instead. The `with_stub` helper does not add much clarity hence we now use scoped stub objects instead. This de-indents some blocks where scoping isn't required, for example when there is a single stub object inside a `run_test` function. With this change, we also need to explicitly assert `num_calls`.
This commit is contained in:
parent
a0d0b89adb
commit
0d770c32cc
|
@ -3,7 +3,7 @@
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||||
const {make_stub, with_stub} = require("../zjsunit/stub");
|
const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||||
|
|
||||||
|
@ -123,51 +123,59 @@ run_test("alert_words", (override) => {
|
||||||
|
|
||||||
run_test("attachments", (override) => {
|
run_test("attachments", (override) => {
|
||||||
const event = event_fixtures.attachment__add;
|
const event = event_fixtures.attachment__add;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
// attachments_ui is hard to test deeply
|
// attachments_ui is hard to test deeply
|
||||||
override(attachments_ui, "update_attachments", stub.f);
|
override(attachments_ui, "update_attachments", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
assert_same(stub.get_args("event").event, event);
|
assert_same(stub.get_args("event").event, event);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("user groups", (override) => {
|
run_test("user groups", (override) => {
|
||||||
let event = event_fixtures.user_group__add;
|
let event = event_fixtures.user_group__add;
|
||||||
override(settings_user_groups, "reload", noop);
|
override(settings_user_groups, "reload", noop);
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(user_groups, "add", stub.f);
|
override(user_groups, "add", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("group");
|
const args = stub.get_args("group");
|
||||||
assert_same(args.group, event.group);
|
assert_same(args.group, event.group);
|
||||||
});
|
}
|
||||||
|
|
||||||
event = event_fixtures.user_group__add_members;
|
event = event_fixtures.user_group__add_members;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(user_groups, "add_members", stub.f);
|
override(user_groups, "add_members", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("group_id", "user_ids");
|
const args = stub.get_args("group_id", "user_ids");
|
||||||
assert_same(args.group_id, event.group_id);
|
assert_same(args.group_id, event.group_id);
|
||||||
assert_same(args.user_ids, event.user_ids);
|
assert_same(args.user_ids, event.user_ids);
|
||||||
});
|
}
|
||||||
|
|
||||||
event = event_fixtures.user_group__remove_members;
|
event = event_fixtures.user_group__remove_members;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(user_groups, "remove_members", stub.f);
|
override(user_groups, "remove_members", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("group_id", "user_ids");
|
const args = stub.get_args("group_id", "user_ids");
|
||||||
assert_same(args.group_id, event.group_id);
|
assert_same(args.group_id, event.group_id);
|
||||||
assert_same(args.user_ids, event.user_ids);
|
assert_same(args.user_ids, event.user_ids);
|
||||||
});
|
}
|
||||||
|
|
||||||
event = event_fixtures.user_group__update;
|
event = event_fixtures.user_group__update;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(user_groups, "update", stub.f);
|
override(user_groups, "update", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("event");
|
const args = stub.get_args("event");
|
||||||
assert_same(args.event.group_id, event.group_id);
|
assert_same(args.event.group_id, event.group_id);
|
||||||
assert_same(args.event.data.name, event.data.name);
|
assert_same(args.event.data.name, event.data.name);
|
||||||
assert_same(args.event.data.description, event.data.description);
|
assert_same(args.event.data.description, event.data.description);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("custom profile fields", (override) => {
|
run_test("custom profile fields", (override) => {
|
||||||
|
@ -181,13 +189,13 @@ run_test("custom profile fields", (override) => {
|
||||||
run_test("default_streams", (override) => {
|
run_test("default_streams", (override) => {
|
||||||
const event = event_fixtures.default_streams;
|
const event = event_fixtures.default_streams;
|
||||||
override(settings_streams, "update_default_streams_table", noop);
|
override(settings_streams, "update_default_streams_table", noop);
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(stream_data, "set_realm_default_streams", stub.f);
|
override(stream_data, "set_realm_default_streams", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("realm_default_streams");
|
const args = stub.get_args("realm_default_streams");
|
||||||
assert_same(args.realm_default_streams, event.default_streams);
|
assert_same(args.realm_default_streams, event.default_streams);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("hotspots", (override) => {
|
run_test("hotspots", (override) => {
|
||||||
const event = event_fixtures.hotspots;
|
const event = event_fixtures.hotspots;
|
||||||
|
@ -198,54 +206,58 @@ run_test("hotspots", (override) => {
|
||||||
|
|
||||||
run_test("invites_changed", (override) => {
|
run_test("invites_changed", (override) => {
|
||||||
const event = event_fixtures.invites_changed;
|
const event = event_fixtures.invites_changed;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(settings_invites, "set_up", stub.f);
|
override(settings_invites, "set_up", stub.f);
|
||||||
dispatch(event); // stub automatically checks if stub.f is called once
|
dispatch(event);
|
||||||
});
|
assert.equal(stub.num_calls, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("muted_topics", (override) => {
|
run_test("muted_topics", (override) => {
|
||||||
const event = event_fixtures.muted_topics;
|
const event = event_fixtures.muted_topics;
|
||||||
|
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(muting_ui, "handle_topic_updates", stub.f);
|
override(muting_ui, "handle_topic_updates", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("muted_topics");
|
const args = stub.get_args("muted_topics");
|
||||||
assert_same(args.muted_topics, event.muted_topics);
|
assert_same(args.muted_topics, event.muted_topics);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("presence", (override) => {
|
run_test("presence", (override) => {
|
||||||
const event = event_fixtures.presence;
|
const event = event_fixtures.presence;
|
||||||
|
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(activity, "update_presence_info", stub.f);
|
override(activity, "update_presence_info", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("user_id", "presence", "server_time");
|
const args = stub.get_args("user_id", "presence", "server_time");
|
||||||
assert_same(args.user_id, event.user_id);
|
assert_same(args.user_id, event.user_id);
|
||||||
assert_same(args.presence, event.presence);
|
assert_same(args.presence, event.presence);
|
||||||
assert_same(args.server_time, event.server_timestamp);
|
assert_same(args.server_time, event.server_timestamp);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("reaction", (override) => {
|
run_test("reaction", (override) => {
|
||||||
let event = event_fixtures.reaction__add;
|
let event = event_fixtures.reaction__add;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(reactions, "add_reaction", stub.f);
|
override(reactions, "add_reaction", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("event");
|
const args = stub.get_args("event");
|
||||||
assert_same(args.event.emoji_name, event.emoji_name);
|
assert_same(args.event.emoji_name, event.emoji_name);
|
||||||
assert_same(args.event.message_id, event.message_id);
|
assert_same(args.event.message_id, event.message_id);
|
||||||
});
|
}
|
||||||
|
|
||||||
event = event_fixtures.reaction__remove;
|
event = event_fixtures.reaction__remove;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(reactions, "remove_reaction", stub.f);
|
override(reactions, "remove_reaction", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("event");
|
const args = stub.get_args("event");
|
||||||
assert_same(args.event.emoji_name, event.emoji_name);
|
assert_same(args.event.emoji_name, event.emoji_name);
|
||||||
assert_same(args.event.message_id, event.message_id);
|
assert_same(args.event.message_id, event.message_id);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("realm settings", (override) => {
|
run_test("realm settings", (override) => {
|
||||||
|
@ -387,33 +399,33 @@ run_test("realm settings", (override) => {
|
||||||
|
|
||||||
run_test("realm_bot add", (override) => {
|
run_test("realm_bot add", (override) => {
|
||||||
const event = event_fixtures.realm_bot__add;
|
const event = event_fixtures.realm_bot__add;
|
||||||
with_stub((bot_stub) => {
|
const bot_stub = make_stub();
|
||||||
with_stub((admin_stub) => {
|
const admin_stub = make_stub();
|
||||||
override(bot_data, "add", bot_stub.f);
|
override(bot_data, "add", bot_stub.f);
|
||||||
override(settings_users, "update_bot_data", admin_stub.f);
|
override(settings_users, "update_bot_data", admin_stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
|
||||||
|
assert.equal(bot_stub.num_calls, 1);
|
||||||
|
assert.equal(admin_stub.num_calls, 1);
|
||||||
const args = bot_stub.get_args("bot");
|
const args = bot_stub.get_args("bot");
|
||||||
assert_same(args.bot, event.bot);
|
assert_same(args.bot, event.bot);
|
||||||
|
|
||||||
admin_stub.get_args("update_user_id", "update_bot_data");
|
admin_stub.get_args("update_user_id", "update_bot_data");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
run_test("realm_bot remove", (override) => {
|
run_test("realm_bot remove", (override) => {
|
||||||
const event = event_fixtures.realm_bot__remove;
|
const event = event_fixtures.realm_bot__remove;
|
||||||
with_stub((bot_stub) => {
|
const bot_stub = make_stub();
|
||||||
with_stub((admin_stub) => {
|
const admin_stub = make_stub();
|
||||||
override(bot_data, "deactivate", bot_stub.f);
|
override(bot_data, "deactivate", bot_stub.f);
|
||||||
override(settings_users, "update_bot_data", admin_stub.f);
|
override(settings_users, "update_bot_data", admin_stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
|
||||||
|
assert.equal(bot_stub.num_calls, 1);
|
||||||
|
assert.equal(admin_stub.num_calls, 1);
|
||||||
const args = bot_stub.get_args("user_id");
|
const args = bot_stub.get_args("user_id");
|
||||||
assert_same(args.user_id, event.bot.user_id);
|
assert_same(args.user_id, event.bot.user_id);
|
||||||
|
|
||||||
admin_stub.get_args("update_user_id", "update_bot_data");
|
admin_stub.get_args("update_user_id", "update_bot_data");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
run_test("realm_bot delete", () => {
|
run_test("realm_bot delete", () => {
|
||||||
const event = event_fixtures.realm_bot__delete;
|
const event = event_fixtures.realm_bot__delete;
|
||||||
|
@ -423,13 +435,15 @@ run_test("realm_bot delete", () => {
|
||||||
|
|
||||||
run_test("realm_bot update", (override) => {
|
run_test("realm_bot update", (override) => {
|
||||||
const event = event_fixtures.realm_bot__update;
|
const event = event_fixtures.realm_bot__update;
|
||||||
with_stub((bot_stub) => {
|
const bot_stub = make_stub();
|
||||||
with_stub((admin_stub) => {
|
const admin_stub = make_stub();
|
||||||
override(bot_data, "update", bot_stub.f);
|
override(bot_data, "update", bot_stub.f);
|
||||||
override(settings_users, "update_bot_data", admin_stub.f);
|
override(settings_users, "update_bot_data", admin_stub.f);
|
||||||
|
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
|
||||||
|
assert.equal(bot_stub.num_calls, 1);
|
||||||
|
assert.equal(admin_stub.num_calls, 1);
|
||||||
let args = bot_stub.get_args("user_id", "bot");
|
let args = bot_stub.get_args("user_id", "bot");
|
||||||
assert_same(args.user_id, event.bot.user_id);
|
assert_same(args.user_id, event.bot.user_id);
|
||||||
assert_same(args.bot, event.bot);
|
assert_same(args.bot, event.bot);
|
||||||
|
@ -437,8 +451,6 @@ run_test("realm_bot update", (override) => {
|
||||||
args = admin_stub.get_args("update_user_id", "update_bot_data");
|
args = admin_stub.get_args("update_user_id", "update_bot_data");
|
||||||
assert_same(args.update_user_id, event.bot.user_id);
|
assert_same(args.update_user_id, event.bot.user_id);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
run_test("realm_emoji", (override) => {
|
run_test("realm_emoji", (override) => {
|
||||||
const event = event_fixtures.realm_emoji__update;
|
const event = event_fixtures.realm_emoji__update;
|
||||||
|
@ -521,30 +533,31 @@ run_test("realm_user", (override) => {
|
||||||
assert(!people.is_active_user_for_popover(event.person.user_id));
|
assert(!people.is_active_user_for_popover(event.person.user_id));
|
||||||
|
|
||||||
event = event_fixtures.realm_user__update;
|
event = event_fixtures.realm_user__update;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(user_events, "update_person", stub.f);
|
override(user_events, "update_person", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("person");
|
const args = stub.get_args("person");
|
||||||
assert_same(args.person, event.person);
|
assert_same(args.person, event.person);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("restart", (override) => {
|
run_test("restart", (override) => {
|
||||||
const event = event_fixtures.restart;
|
const event = event_fixtures.restart;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(reload, "initiate", stub.f);
|
override(reload, "initiate", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("options");
|
const args = stub.get_args("options");
|
||||||
assert.equal(args.options.save_pointer, true);
|
assert.equal(args.options.save_pointer, true);
|
||||||
assert.equal(args.options.immediate, true);
|
assert.equal(args.options.immediate, true);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("submessage", (override) => {
|
run_test("submessage", (override) => {
|
||||||
const event = event_fixtures.submessage;
|
const event = event_fixtures.submessage;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(submessage, "handle_event", stub.f);
|
override(submessage, "handle_event", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const submsg = stub.get_args("submsg").submsg;
|
const submsg = stub.get_args("submsg").submsg;
|
||||||
assert_same(submsg, {
|
assert_same(submsg, {
|
||||||
id: 99,
|
id: 99,
|
||||||
|
@ -554,26 +567,29 @@ run_test("submessage", (override) => {
|
||||||
content: "test",
|
content: "test",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// For subscriptions, see dispatch_subs.js
|
// For subscriptions, see dispatch_subs.js
|
||||||
|
|
||||||
run_test("typing", (override) => {
|
run_test("typing", (override) => {
|
||||||
let event = event_fixtures.typing__start;
|
let event = event_fixtures.typing__start;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(typing_events, "display_notification", stub.f);
|
override(typing_events, "display_notification", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("event");
|
const args = stub.get_args("event");
|
||||||
assert_same(args.event.sender.user_id, typing_person1.user_id);
|
assert_same(args.event.sender.user_id, typing_person1.user_id);
|
||||||
});
|
}
|
||||||
|
|
||||||
event = event_fixtures.typing__stop;
|
event = event_fixtures.typing__stop;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(typing_events, "hide_notification", stub.f);
|
override(typing_events, "hide_notification", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("event");
|
const args = stub.get_args("event");
|
||||||
assert_same(args.event.sender.user_id, typing_person1.user_id);
|
assert_same(args.event.sender.user_id, typing_person1.user_id);
|
||||||
});
|
}
|
||||||
|
|
||||||
page_params.user_id = typing_person1.user_id;
|
page_params.user_id = typing_person1.user_id;
|
||||||
event = event_fixtures.typing__start;
|
event = event_fixtures.typing__start;
|
||||||
|
@ -643,39 +659,47 @@ run_test("update_display_settings", (override) => {
|
||||||
|
|
||||||
override(realm_logo, "rerender", noop);
|
override(realm_logo, "rerender", noop);
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
event = event_fixtures.update_display_settings__color_scheme_dark;
|
event = event_fixtures.update_display_settings__color_scheme_dark;
|
||||||
page_params.color_scheme = 1;
|
page_params.color_scheme = 1;
|
||||||
override(night_mode, "enable", stub.f); // automatically checks if called
|
override(night_mode, "enable", stub.f); // automatically checks if called
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
assert(page_params.color_scheme, 2);
|
assert(page_params.color_scheme, 2);
|
||||||
});
|
}
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
event = event_fixtures.update_display_settings__color_scheme_light;
|
event = event_fixtures.update_display_settings__color_scheme_light;
|
||||||
page_params.color_scheme = 1;
|
page_params.color_scheme = 1;
|
||||||
override(night_mode, "disable", stub.f); // automatically checks if called
|
override(night_mode, "disable", stub.f); // automatically checks if called
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
assert(page_params.color_scheme, 3);
|
assert(page_params.color_scheme, 3);
|
||||||
});
|
}
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
event = event_fixtures.update_display_settings__color_scheme_automatic;
|
event = event_fixtures.update_display_settings__color_scheme_automatic;
|
||||||
page_params.color_scheme = 2;
|
page_params.color_scheme = 2;
|
||||||
override(night_mode, "default_preference_checker", stub.f); // automatically checks if called
|
override(night_mode, "default_preference_checker", stub.f); // automatically checks if called
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
assert(page_params.color_scheme, 1);
|
assert(page_params.color_scheme, 1);
|
||||||
});
|
}
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
event = event_fixtures.update_display_settings__emojiset;
|
event = event_fixtures.update_display_settings__emojiset;
|
||||||
called = false;
|
called = false;
|
||||||
override(settings_display, "report_emojiset_change", stub.f);
|
override(settings_display, "report_emojiset_change", stub.f);
|
||||||
page_params.emojiset = "text";
|
page_params.emojiset = "text";
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
assert_same(called, true);
|
assert_same(called, true);
|
||||||
assert_same(page_params.emojiset, "google");
|
assert_same(page_params.emojiset, "google");
|
||||||
});
|
}
|
||||||
|
|
||||||
override(starred_messages, "rerender_ui", noop);
|
override(starred_messages, "rerender_ui", noop);
|
||||||
event = event_fixtures.update_display_settings__starred_message_counts;
|
event = event_fixtures.update_display_settings__starred_message_counts;
|
||||||
|
@ -689,67 +713,69 @@ run_test("update_display_settings", (override) => {
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
assert_same(page_params.fluid_layout_width, true);
|
assert_same(page_params.fluid_layout_width, true);
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
event = event_fixtures.update_display_settings__demote_inactive_streams;
|
event = event_fixtures.update_display_settings__demote_inactive_streams;
|
||||||
override(stream_data, "set_filter_out_inactives", noop);
|
override(stream_data, "set_filter_out_inactives", noop);
|
||||||
override(stream_list, "update_streams_sidebar", stub.f);
|
override(stream_list, "update_streams_sidebar", stub.f);
|
||||||
page_params.demote_inactive_streams = 1;
|
page_params.demote_inactive_streams = 1;
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
assert_same(page_params.demote_inactive_streams, 2);
|
assert_same(page_params.demote_inactive_streams, 2);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("update_global_notifications", (override) => {
|
run_test("update_global_notifications", (override) => {
|
||||||
const event = event_fixtures.update_global_notifications;
|
const event = event_fixtures.update_global_notifications;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(notifications, "handle_global_notification_updates", stub.f);
|
override(notifications, "handle_global_notification_updates", stub.f);
|
||||||
override(settings_notifications, "update_page", noop);
|
override(settings_notifications, "update_page", noop);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("name", "setting");
|
const args = stub.get_args("name", "setting");
|
||||||
assert_same(args.name, event.notification_name);
|
assert_same(args.name, event.notification_name);
|
||||||
assert_same(args.setting, event.setting);
|
assert_same(args.setting, event.setting);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("update_message (read)", (override) => {
|
run_test("update_message (read)", (override) => {
|
||||||
const event = event_fixtures.update_message_flags__read;
|
const event = event_fixtures.update_message_flags__read;
|
||||||
|
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(unread_ops, "process_read_messages_event", stub.f);
|
override(unread_ops, "process_read_messages_event", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("message_ids");
|
const args = stub.get_args("message_ids");
|
||||||
assert_same(args.message_ids, [999]);
|
assert_same(args.message_ids, [999]);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("update_message (add star)", (override) => {
|
run_test("update_message (add star)", (override) => {
|
||||||
override(starred_messages, "rerender_ui", noop);
|
override(starred_messages, "rerender_ui", noop);
|
||||||
|
|
||||||
const event = event_fixtures.update_message_flags__starred_add;
|
const event = event_fixtures.update_message_flags__starred_add;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(ui, "update_starred_view", stub.f);
|
override(ui, "update_starred_view", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("message_id", "new_value");
|
const args = stub.get_args("message_id", "new_value");
|
||||||
assert_same(args.message_id, test_message.id);
|
assert_same(args.message_id, test_message.id);
|
||||||
assert_same(args.new_value, true); // for 'add'
|
assert_same(args.new_value, true); // for 'add'
|
||||||
const msg = message_store.get(test_message.id);
|
const msg = message_store.get(test_message.id);
|
||||||
assert.equal(msg.starred, true);
|
assert.equal(msg.starred, true);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("update_message (remove star)", (override) => {
|
run_test("update_message (remove star)", (override) => {
|
||||||
override(starred_messages, "rerender_ui", noop);
|
override(starred_messages, "rerender_ui", noop);
|
||||||
const event = event_fixtures.update_message_flags__starred_remove;
|
const event = event_fixtures.update_message_flags__starred_remove;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(ui, "update_starred_view", stub.f);
|
override(ui, "update_starred_view", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("message_id", "new_value");
|
const args = stub.get_args("message_id", "new_value");
|
||||||
assert_same(args.message_id, test_message.id);
|
assert_same(args.message_id, test_message.id);
|
||||||
assert_same(args.new_value, false);
|
assert_same(args.new_value, false);
|
||||||
const msg = message_store.get(test_message.id);
|
const msg = message_store.get(test_message.id);
|
||||||
assert.equal(msg.starred, false);
|
assert.equal(msg.starred, false);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
run_test("delete_message", (override) => {
|
run_test("delete_message", (override) => {
|
||||||
const event = event_fixtures.delete_message;
|
const event = event_fixtures.delete_message;
|
||||||
|
@ -784,39 +810,45 @@ run_test("delete_message", (override) => {
|
||||||
|
|
||||||
run_test("user_status", (override) => {
|
run_test("user_status", (override) => {
|
||||||
let event = event_fixtures.user_status__set_away;
|
let event = event_fixtures.user_status__set_away;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(activity, "on_set_away", stub.f);
|
override(activity, "on_set_away", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("user_id");
|
const args = stub.get_args("user_id");
|
||||||
assert_same(args.user_id, 55);
|
assert_same(args.user_id, 55);
|
||||||
});
|
}
|
||||||
|
|
||||||
event = event_fixtures.user_status__revoke_away;
|
event = event_fixtures.user_status__revoke_away;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(activity, "on_revoke_away", stub.f);
|
override(activity, "on_revoke_away", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("user_id");
|
const args = stub.get_args("user_id");
|
||||||
assert_same(args.user_id, 63);
|
assert_same(args.user_id, 63);
|
||||||
});
|
}
|
||||||
|
|
||||||
event = event_fixtures.user_status__set_status_text;
|
event = event_fixtures.user_status__set_status_text;
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(activity, "redraw_user", stub.f);
|
override(activity, "redraw_user", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("user_id");
|
const args = stub.get_args("user_id");
|
||||||
assert_same(args.user_id, test_user.user_id);
|
assert_same(args.user_id, test_user.user_id);
|
||||||
const status_text = user_status.get_status_text(test_user.user_id);
|
const status_text = user_status.get_status_text(test_user.user_id);
|
||||||
assert.equal(status_text, "out to lunch");
|
assert.equal(status_text, "out to lunch");
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("realm_export", (override) => {
|
run_test("realm_export", (override) => {
|
||||||
const event = event_fixtures.realm_export;
|
const event = event_fixtures.realm_export;
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(settings_exports, "populate_exports_table", stub.f);
|
override(settings_exports, "populate_exports_table", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("exports");
|
const args = stub.get_args("exports");
|
||||||
assert.equal(args.exports, event.exports);
|
assert.equal(args.exports, event.exports);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||||
const {make_stub, with_stub} = require("../zjsunit/stub");
|
const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
|
|
||||||
const events = require("./lib/events");
|
const events = require("./lib/events");
|
||||||
|
@ -62,14 +62,14 @@ test("add", (override) => {
|
||||||
name: sub.name,
|
name: sub.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
with_stub((subscription_stub) => {
|
const subscription_stub = make_stub();
|
||||||
override(stream_events, "mark_subscribed", subscription_stub.f);
|
override(stream_events, "mark_subscribed", subscription_stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(subscription_stub.num_calls, 1);
|
||||||
const args = subscription_stub.get_args("sub", "subscribers");
|
const args = subscription_stub.get_args("sub", "subscribers");
|
||||||
assert.deepEqual(args.sub.stream_id, stream_id);
|
assert.deepEqual(args.sub.stream_id, stream_id);
|
||||||
assert.deepEqual(args.subscribers, event.subscriptions[0].subscribers);
|
assert.deepEqual(args.subscribers, event.subscriptions[0].subscribers);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("peer add/remove", (override) => {
|
test("peer add/remove", (override) => {
|
||||||
let event = event_fixtures.subscription__peer_add;
|
let event = event_fixtures.subscription__peer_add;
|
||||||
|
@ -111,35 +111,37 @@ test("remove", (override) => {
|
||||||
|
|
||||||
stream_data.add_sub(sub);
|
stream_data.add_sub(sub);
|
||||||
|
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(stream_events, "mark_unsubscribed", stub.f);
|
override(stream_events, "mark_unsubscribed", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("sub");
|
const args = stub.get_args("sub");
|
||||||
assert.deepEqual(args.sub, sub);
|
assert.deepEqual(args.sub, sub);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("update", (override) => {
|
test("update", (override) => {
|
||||||
const event = event_fixtures.subscription__update;
|
const event = event_fixtures.subscription__update;
|
||||||
with_stub((stub) => {
|
|
||||||
|
const stub = make_stub();
|
||||||
override(stream_events, "update_property", stub.f);
|
override(stream_events, "update_property", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("stream_id", "property", "value");
|
const args = stub.get_args("stream_id", "property", "value");
|
||||||
assert.deepEqual(args.stream_id, event.stream_id);
|
assert.deepEqual(args.stream_id, event.stream_id);
|
||||||
assert.deepEqual(args.property, event.property);
|
assert.deepEqual(args.property, event.property);
|
||||||
assert.deepEqual(args.value, event.value);
|
assert.deepEqual(args.value, event.value);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("add error handling", (override) => {
|
test("add error handling", (override) => {
|
||||||
// test blueslip errors/warns
|
// test blueslip errors/warns
|
||||||
const event = event_fixtures.subscription__add;
|
const event = event_fixtures.subscription__add;
|
||||||
with_stub((stub) => {
|
|
||||||
|
const stub = make_stub();
|
||||||
override(blueslip, "error", stub.f);
|
override(blueslip, "error", stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
assert.deepEqual(stub.get_args("param").param, "Subscribing to unknown stream with ID 101");
|
assert.deepEqual(stub.get_args("param").param, "Subscribing to unknown stream with ID 101");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("peer event error handling (bad stream_ids/user_ids)", (override) => {
|
test("peer event error handling (bad stream_ids/user_ids)", (override) => {
|
||||||
override(compose_fade, "update_faded_users", () => {});
|
override(compose_fade, "update_faded_users", () => {});
|
||||||
|
@ -171,33 +173,34 @@ test("peer event error handling (bad stream_ids/user_ids)", (override) => {
|
||||||
test("stream update", (override) => {
|
test("stream update", (override) => {
|
||||||
const event = event_fixtures.stream__update;
|
const event = event_fixtures.stream__update;
|
||||||
|
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(stream_events, "update_property", stub.f);
|
override(stream_events, "update_property", stub.f);
|
||||||
override(settings_streams, "update_default_streams_table", noop);
|
override(settings_streams, "update_default_streams_table", noop);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("stream_id", "property", "value");
|
const args = stub.get_args("stream_id", "property", "value");
|
||||||
assert.equal(args.stream_id, event.stream_id);
|
assert.equal(args.stream_id, event.stream_id);
|
||||||
assert.equal(args.property, event.property);
|
assert.equal(args.property, event.property);
|
||||||
assert.equal(args.value, event.value);
|
assert.equal(args.value, event.value);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("stream create", (override) => {
|
test("stream create", (override) => {
|
||||||
const event = event_fixtures.stream__create;
|
const event = event_fixtures.stream__create;
|
||||||
with_stub((stub) => {
|
|
||||||
|
const stub = make_stub();
|
||||||
override(stream_data, "create_streams", stub.f);
|
override(stream_data, "create_streams", stub.f);
|
||||||
override(stream_data, "get_sub_by_id", noop);
|
override(stream_data, "get_sub_by_id", noop);
|
||||||
override(stream_data, "update_calculated_fields", noop);
|
override(stream_data, "update_calculated_fields", noop);
|
||||||
override(subs, "add_sub_to_table", noop);
|
override(subs, "add_sub_to_table", noop);
|
||||||
override(overlays, "streams_open", () => true);
|
override(overlays, "streams_open", () => true);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("streams");
|
const args = stub.get_args("streams");
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
args.streams.map((stream) => stream.stream_id),
|
args.streams.map((stream) => stream.stream_id),
|
||||||
[101, 102],
|
[101, 102],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("stream delete (normal)", (override) => {
|
test("stream delete (normal)", (override) => {
|
||||||
const event = event_fixtures.stream__delete;
|
const event = event_fixtures.stream__delete;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {set_global, with_overrides, zrequire} = require("../zjsunit/namespace");
|
const {set_global, with_overrides, zrequire} = require("../zjsunit/namespace");
|
||||||
const {with_stub} = require("../zjsunit/stub");
|
const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||||
|
|
||||||
|
@ -86,11 +86,10 @@ function return_false() {
|
||||||
|
|
||||||
function stubbing(module, func_name_to_stub, test_function) {
|
function stubbing(module, func_name_to_stub, test_function) {
|
||||||
with_overrides((override) => {
|
with_overrides((override) => {
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(module, func_name_to_stub, stub.f);
|
override(module, func_name_to_stub, stub.f);
|
||||||
test_function(stub);
|
test_function(stub);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("mappings", () => {
|
run_test("mappings", () => {
|
||||||
|
@ -192,8 +191,9 @@ run_test("basic_chars", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_mapping(c, module, func_name, shiftKey) {
|
function assert_mapping(c, module, func_name, shiftKey) {
|
||||||
stubbing(module, func_name, () => {
|
stubbing(module, func_name, (stub) => {
|
||||||
assert(process(c, shiftKey));
|
assert(process(c, shiftKey));
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,8 +406,9 @@ run_test("motion_keys", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_mapping(key_name, module, func_name, shiftKey, ctrlKey) {
|
function assert_mapping(key_name, module, func_name, shiftKey, ctrlKey) {
|
||||||
stubbing(module, func_name, () => {
|
stubbing(module, func_name, (stub) => {
|
||||||
assert(process(key_name, shiftKey, ctrlKey));
|
assert(process(key_name, shiftKey, ctrlKey));
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace");
|
const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace");
|
||||||
const {with_stub} = require("../zjsunit/stub");
|
const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
// These unit tests for static/js/message_list.js emphasize the model-ish
|
// These unit tests for static/js/message_list.js emphasize the model-ish
|
||||||
// aspects of the MessageList class. We have to stub out a few functions
|
// aspects of the MessageList class. We have to stub out a few functions
|
||||||
|
@ -316,54 +316,62 @@ run_test("bookend", (override) => {
|
||||||
override(stream_data, "is_subscribed", () => is_subscribed);
|
override(stream_data, "is_subscribed", () => is_subscribed);
|
||||||
override(stream_data, "get_sub", () => ({invite_only}));
|
override(stream_data, "get_sub", () => ({invite_only}));
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
list.view.render_trailing_bookend = stub.f;
|
list.view.render_trailing_bookend = stub.f;
|
||||||
list.update_trailing_bookend();
|
list.update_trailing_bookend();
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const bookend = stub.get_args("content", "subscribed", "show_button");
|
const bookend = stub.get_args("content", "subscribed", "show_button");
|
||||||
assert.equal(bookend.content, expected);
|
assert.equal(bookend.content, expected);
|
||||||
assert.equal(bookend.subscribed, true);
|
assert.equal(bookend.subscribed, true);
|
||||||
assert.equal(bookend.show_button, true);
|
assert.equal(bookend.show_button, true);
|
||||||
});
|
}
|
||||||
|
|
||||||
expected = "translated: You unsubscribed from stream IceCream";
|
expected = "translated: You unsubscribed from stream IceCream";
|
||||||
list.last_message_historical = false;
|
list.last_message_historical = false;
|
||||||
|
|
||||||
is_subscribed = false;
|
is_subscribed = false;
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
list.view.render_trailing_bookend = stub.f;
|
list.view.render_trailing_bookend = stub.f;
|
||||||
list.update_trailing_bookend();
|
list.update_trailing_bookend();
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const bookend = stub.get_args("content", "subscribed", "show_button");
|
const bookend = stub.get_args("content", "subscribed", "show_button");
|
||||||
assert.equal(bookend.content, expected);
|
assert.equal(bookend.content, expected);
|
||||||
assert.equal(bookend.subscribed, false);
|
assert.equal(bookend.subscribed, false);
|
||||||
assert.equal(bookend.show_button, true);
|
assert.equal(bookend.show_button, true);
|
||||||
});
|
}
|
||||||
|
|
||||||
// Test when the stream is privates (invite only)
|
// Test when the stream is privates (invite only)
|
||||||
expected = "translated: You unsubscribed from stream IceCream";
|
expected = "translated: You unsubscribed from stream IceCream";
|
||||||
|
|
||||||
invite_only = true;
|
invite_only = true;
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
list.view.render_trailing_bookend = stub.f;
|
list.view.render_trailing_bookend = stub.f;
|
||||||
list.update_trailing_bookend();
|
list.update_trailing_bookend();
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const bookend = stub.get_args("content", "subscribed", "show_button");
|
const bookend = stub.get_args("content", "subscribed", "show_button");
|
||||||
assert.equal(bookend.content, expected);
|
assert.equal(bookend.content, expected);
|
||||||
assert.equal(bookend.subscribed, false);
|
assert.equal(bookend.subscribed, false);
|
||||||
assert.equal(bookend.show_button, false);
|
assert.equal(bookend.show_button, false);
|
||||||
});
|
}
|
||||||
|
|
||||||
expected = "translated: You are not subscribed to stream IceCream";
|
expected = "translated: You are not subscribed to stream IceCream";
|
||||||
list.last_message_historical = true;
|
list.last_message_historical = true;
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
list.view.render_trailing_bookend = stub.f;
|
list.view.render_trailing_bookend = stub.f;
|
||||||
list.update_trailing_bookend();
|
list.update_trailing_bookend();
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const bookend = stub.get_args("content", "subscribed", "show_button");
|
const bookend = stub.get_args("content", "subscribed", "show_button");
|
||||||
assert.equal(bookend.content, expected);
|
assert.equal(bookend.content, expected);
|
||||||
assert.equal(bookend.subscribed, false);
|
assert.equal(bookend.subscribed, false);
|
||||||
assert.equal(bookend.show_button, true);
|
assert.equal(bookend.show_button, true);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("filter_muted_topic_messages", () => {
|
run_test("filter_muted_topic_messages", () => {
|
||||||
|
@ -414,11 +422,12 @@ run_test("add_remove_rerender", () => {
|
||||||
list.add_messages(messages);
|
list.add_messages(messages);
|
||||||
assert.equal(list.num_items(), 3);
|
assert.equal(list.num_items(), 3);
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
list.rerender = stub.f;
|
list.rerender = stub.f;
|
||||||
const message_ids = messages.map((msg) => msg.id);
|
const message_ids = messages.map((msg) => msg.id);
|
||||||
list.remove_and_rerender(message_ids);
|
list.remove_and_rerender(message_ids);
|
||||||
assert.equal(stub.num_calls, 1);
|
assert.equal(stub.num_calls, 1);
|
||||||
assert.equal(list.num_items(), 0);
|
assert.equal(list.num_items(), 0);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||||
const {with_stub} = require("../zjsunit/stub");
|
const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||||
|
|
||||||
|
@ -348,22 +348,26 @@ run_test("message_id_change", () => {
|
||||||
new_id: 402,
|
new_id: 402,
|
||||||
};
|
};
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
home_msg_list.change_message_id = stub.f;
|
home_msg_list.change_message_id = stub.f;
|
||||||
message_store.reify_message_id(opts);
|
message_store.reify_message_id(opts);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const msg_id = stub.get_args("old", "new");
|
const msg_id = stub.get_args("old", "new");
|
||||||
assert.equal(msg_id.old, 401);
|
assert.equal(msg_id.old, 401);
|
||||||
assert.equal(msg_id.new, 402);
|
assert.equal(msg_id.new, 402);
|
||||||
});
|
}
|
||||||
|
|
||||||
home_msg_list.view = {};
|
home_msg_list.view = {};
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
home_msg_list.view.change_message_id = stub.f;
|
home_msg_list.view.change_message_id = stub.f;
|
||||||
message_store.reify_message_id(opts);
|
message_store.reify_message_id(opts);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const msg_id = stub.get_args("old", "new");
|
const msg_id = stub.get_args("old", "new");
|
||||||
assert.equal(msg_id.old, 401);
|
assert.equal(msg_id.old, 401);
|
||||||
assert.equal(msg_id.new, 402);
|
assert.equal(msg_id.new, 402);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("errors", () => {
|
run_test("errors", () => {
|
||||||
|
|
|
@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {stub_templates} = require("../zjsunit/handlebars");
|
const {stub_templates} = require("../zjsunit/handlebars");
|
||||||
const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
|
const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
|
||||||
const {with_stub} = require("../zjsunit/stub");
|
const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||||
|
|
||||||
|
@ -264,9 +264,11 @@ run_test("sending", (override) => {
|
||||||
override(reactions, "add_reaction", () => {});
|
override(reactions, "add_reaction", () => {});
|
||||||
override(reactions, "remove_reaction", () => {});
|
override(reactions, "remove_reaction", () => {});
|
||||||
|
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
channel.del = stub.f;
|
channel.del = stub.f;
|
||||||
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("args").args;
|
const args = stub.get_args("args").args;
|
||||||
assert.equal(args.url, "/json/messages/1001/reactions");
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
||||||
assert.deepEqual(args.data, {
|
assert.deepEqual(args.data, {
|
||||||
|
@ -284,11 +286,13 @@ run_test("sending", (override) => {
|
||||||
return "XHR Error Message.";
|
return "XHR Error Message.";
|
||||||
};
|
};
|
||||||
args.error();
|
args.error();
|
||||||
});
|
}
|
||||||
emoji_name = "alien"; // not set yet
|
emoji_name = "alien"; // not set yet
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
channel.post = stub.f;
|
channel.post = stub.f;
|
||||||
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("args").args;
|
const args = stub.get_args("args").args;
|
||||||
assert.equal(args.url, "/json/messages/1001/reactions");
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
||||||
assert.deepEqual(args.data, {
|
assert.deepEqual(args.data, {
|
||||||
|
@ -296,16 +300,18 @@ run_test("sending", (override) => {
|
||||||
emoji_name: "alien",
|
emoji_name: "alien",
|
||||||
emoji_code: "1f47d",
|
emoji_code: "1f47d",
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
emoji_name = "inactive_realm_emoji";
|
emoji_name = "inactive_realm_emoji";
|
||||||
with_stub((stub) => {
|
{
|
||||||
// Test removing a deactivated realm emoji. An user can interact with a
|
// Test removing a deactivated realm emoji. An user can interact with a
|
||||||
// deactivated realm emoji only by clicking on a reaction, hence, only
|
// deactivated realm emoji only by clicking on a reaction, hence, only
|
||||||
// `process_reaction_click()` codepath supports deleting/adding a deactivated
|
// `process_reaction_click()` codepath supports deleting/adding a deactivated
|
||||||
// realm emoji.
|
// realm emoji.
|
||||||
|
const stub = make_stub();
|
||||||
channel.del = stub.f;
|
channel.del = stub.f;
|
||||||
reactions.process_reaction_click(message_id, "realm_emoji,992");
|
reactions.process_reaction_click(message_id, "realm_emoji,992");
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("args").args;
|
const args = stub.get_args("args").args;
|
||||||
assert.equal(args.url, "/json/messages/1001/reactions");
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
||||||
assert.deepEqual(args.data, {
|
assert.deepEqual(args.data, {
|
||||||
|
@ -313,12 +319,14 @@ run_test("sending", (override) => {
|
||||||
emoji_name: "inactive_realm_emoji",
|
emoji_name: "inactive_realm_emoji",
|
||||||
emoji_code: "992",
|
emoji_code: "992",
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
emoji_name = "zulip"; // Test adding zulip emoji.
|
emoji_name = "zulip"; // Test adding zulip emoji.
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
channel.post = stub.f;
|
channel.post = stub.f;
|
||||||
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
reactions.toggle_emoji_reaction(message_id, emoji_name);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("args").args;
|
const args = stub.get_args("args").args;
|
||||||
assert.equal(args.url, "/json/messages/1001/reactions");
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
||||||
assert.deepEqual(args.data, {
|
assert.deepEqual(args.data, {
|
||||||
|
@ -326,7 +334,7 @@ run_test("sending", (override) => {
|
||||||
emoji_name: "zulip",
|
emoji_name: "zulip",
|
||||||
emoji_code: "zulip",
|
emoji_code: "zulip",
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
emoji_name = "unknown-emoji"; // Test sending an emoji unknown to frontend.
|
emoji_name = "unknown-emoji"; // Test sending an emoji unknown to frontend.
|
||||||
blueslip.expect("warn", "Bad emoji name: " + emoji_name);
|
blueslip.expect("warn", "Bad emoji name: " + emoji_name);
|
||||||
|
@ -778,13 +786,15 @@ run_test("process_reaction_click", () => {
|
||||||
emoji_name: "smile",
|
emoji_name: "smile",
|
||||||
emoji_code: "1f642",
|
emoji_code: "1f642",
|
||||||
};
|
};
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
channel.del = stub.f;
|
channel.del = stub.f;
|
||||||
reactions.process_reaction_click(message_id, "unicode_emoji,1f642");
|
reactions.process_reaction_click(message_id, "unicode_emoji,1f642");
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("args").args;
|
const args = stub.get_args("args").args;
|
||||||
assert.equal(args.url, "/json/messages/1001/reactions");
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
||||||
assert.deepEqual(args.data, expected_reaction_info);
|
assert.deepEqual(args.data, expected_reaction_info);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("warnings", () => {
|
run_test("warnings", () => {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||||
const {make_stub, with_stub} = require("../zjsunit/stub");
|
const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||||
|
|
||||||
|
@ -89,24 +89,24 @@ run_test("update_property", (override) => {
|
||||||
|
|
||||||
// Test update color
|
// Test update color
|
||||||
{
|
{
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(stream_color, "update_stream_color", stub.f);
|
override(stream_color, "update_stream_color", stub.f);
|
||||||
stream_events.update_property(stream_id, "color", "blue");
|
stream_events.update_property(stream_id, "color", "blue");
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("sub", "val");
|
const args = stub.get_args("sub", "val");
|
||||||
assert.equal(args.sub.stream_id, stream_id);
|
assert.equal(args.sub.stream_id, stream_id);
|
||||||
assert.equal(args.val, "blue");
|
assert.equal(args.val, "blue");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test in home view
|
// Test in home view
|
||||||
{
|
{
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(stream_muting, "update_is_muted", stub.f);
|
override(stream_muting, "update_is_muted", stub.f);
|
||||||
stream_events.update_property(stream_id, "in_home_view", false);
|
stream_events.update_property(stream_id, "in_home_view", false);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("sub", "val");
|
const args = stub.get_args("sub", "val");
|
||||||
assert.equal(args.sub.stream_id, stream_id);
|
assert.equal(args.sub.stream_id, stream_id);
|
||||||
assert.equal(args.val, true);
|
assert.equal(args.val, true);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkbox_for(property) {
|
function checkbox_for(property) {
|
||||||
|
@ -145,26 +145,26 @@ run_test("update_property", (override) => {
|
||||||
|
|
||||||
// Test name change
|
// Test name change
|
||||||
{
|
{
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(subs, "update_stream_name", stub.f);
|
override(subs, "update_stream_name", stub.f);
|
||||||
stream_events.update_property(stream_id, "name", "the frontend");
|
stream_events.update_property(stream_id, "name", "the frontend");
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("sub", "val");
|
const args = stub.get_args("sub", "val");
|
||||||
assert.equal(args.sub.stream_id, stream_id);
|
assert.equal(args.sub.stream_id, stream_id);
|
||||||
assert.equal(args.val, "the frontend");
|
assert.equal(args.val, "the frontend");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test description change
|
// Test description change
|
||||||
{
|
{
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(subs, "update_stream_description", stub.f);
|
override(subs, "update_stream_description", stub.f);
|
||||||
stream_events.update_property(stream_id, "description", "we write code", {
|
stream_events.update_property(stream_id, "description", "we write code", {
|
||||||
rendered_description: "we write code",
|
rendered_description: "we write code",
|
||||||
});
|
});
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("sub", "val");
|
const args = stub.get_args("sub", "val");
|
||||||
assert.equal(args.sub.stream_id, stream_id);
|
assert.equal(args.sub.stream_id, stream_id);
|
||||||
assert.equal(args.val, "we write code");
|
assert.equal(args.val, "we write code");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test email address change
|
// Test email address change
|
||||||
|
@ -181,44 +181,44 @@ run_test("update_property", (override) => {
|
||||||
|
|
||||||
// Test stream privacy change event
|
// Test stream privacy change event
|
||||||
{
|
{
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(subs, "update_stream_privacy", stub.f);
|
override(subs, "update_stream_privacy", stub.f);
|
||||||
stream_events.update_property(stream_id, "invite_only", true, {
|
stream_events.update_property(stream_id, "invite_only", true, {
|
||||||
history_public_to_subscribers: true,
|
history_public_to_subscribers: true,
|
||||||
});
|
});
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("sub", "val");
|
const args = stub.get_args("sub", "val");
|
||||||
assert.equal(args.sub.stream_id, stream_id);
|
assert.equal(args.sub.stream_id, stream_id);
|
||||||
assert.deepEqual(args.val, {
|
assert.deepEqual(args.val, {
|
||||||
invite_only: true,
|
invite_only: true,
|
||||||
history_public_to_subscribers: true,
|
history_public_to_subscribers: true,
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test stream stream_post_policy change event
|
// Test stream stream_post_policy change event
|
||||||
{
|
{
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(subs, "update_stream_post_policy", stub.f);
|
override(subs, "update_stream_post_policy", stub.f);
|
||||||
stream_events.update_property(
|
stream_events.update_property(
|
||||||
stream_id,
|
stream_id,
|
||||||
"stream_post_policy",
|
"stream_post_policy",
|
||||||
stream_data.stream_post_policy_values.admins.code,
|
stream_data.stream_post_policy_values.admins.code,
|
||||||
);
|
);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("sub", "val");
|
const args = stub.get_args("sub", "val");
|
||||||
assert.equal(args.sub.stream_id, stream_id);
|
assert.equal(args.sub.stream_id, stream_id);
|
||||||
assert.equal(args.val, stream_data.stream_post_policy_values.admins.code);
|
assert.equal(args.val, stream_data.stream_post_policy_values.admins.code);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test stream message_retention_days change event
|
// Test stream message_retention_days change event
|
||||||
{
|
{
|
||||||
with_stub((stub) => {
|
const stub = make_stub();
|
||||||
override(subs, "update_message_retention_setting", stub.f);
|
override(subs, "update_message_retention_setting", stub.f);
|
||||||
stream_events.update_property(stream_id, "message_retention_days", 20);
|
stream_events.update_property(stream_id, "message_retention_days", 20);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("sub", "val");
|
const args = stub.get_args("sub", "val");
|
||||||
assert.equal(args.sub.stream_id, stream_id);
|
assert.equal(args.sub.stream_id, stream_id);
|
||||||
assert.equal(args.val, 20);
|
assert.equal(args.val, 20);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -298,14 +298,16 @@ run_test("marked_subscribed (color)", (override) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// narrow state is undefined
|
// narrow state is undefined
|
||||||
with_stub((stub) => {
|
{
|
||||||
|
const stub = make_stub();
|
||||||
override(subs, "set_color", stub.f);
|
override(subs, "set_color", stub.f);
|
||||||
stream_events.mark_subscribed(frontend, [], undefined);
|
stream_events.mark_subscribed(frontend, [], undefined);
|
||||||
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("id", "color");
|
const args = stub.get_args("id", "color");
|
||||||
assert.equal(args.id, frontend.stream_id);
|
assert.equal(args.id, frontend.stream_id);
|
||||||
assert.equal(args.color, "green");
|
assert.equal(args.color, "green");
|
||||||
assert.equal(warnings, 1);
|
assert.equal(warnings, 1);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("marked_subscribed (emails)", (override) => {
|
run_test("marked_subscribed (emails)", (override) => {
|
||||||
|
|
Loading…
Reference in New Issue