2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-02-28 00:52:39 +01:00
|
|
|
const rewiremock = require("rewiremock/node");
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, 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");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
const noop = () => {};
|
2020-04-01 20:10:12 +02:00
|
|
|
const _settings_notifications = {
|
|
|
|
update_page: () => {},
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("settings_notifications", _settings_notifications);
|
2017-07-01 22:17:22 +02:00
|
|
|
|
2021-02-28 00:52:39 +01:00
|
|
|
const color_data = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/color_data").with(color_data);
|
2020-07-26 14:06:28 +02:00
|
|
|
set_global("current_msg_list", {});
|
2021-02-10 04:53:22 +01:00
|
|
|
const message_util = set_global("message_util", {});
|
2021-02-28 00:53:05 +01:00
|
|
|
const stream_color = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/stream_color").with(stream_color);
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_list = set_global("stream_list", {});
|
2021-02-28 00:54:52 +01:00
|
|
|
const stream_muting = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/stream_muting").with(stream_muting);
|
2021-02-10 04:53:22 +01:00
|
|
|
let subs = set_global("subs", {});
|
2020-12-05 09:27:33 +01:00
|
|
|
set_global("recent_topics", {
|
|
|
|
complete_rerender: () => {},
|
|
|
|
});
|
2020-12-01 23:21:38 +01:00
|
|
|
|
|
|
|
set_global("message_list", {
|
|
|
|
all: {
|
|
|
|
all_messages() {
|
|
|
|
return ["msg"];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
subs = set_global("subs", {update_settings_for_subscribed: noop});
|
2021-02-28 01:03:46 +01:00
|
|
|
rewiremock("../../static/js/overlays").with({streams_open: () => true});
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2021-02-28 00:52:39 +01:00
|
|
|
rewiremock.enable();
|
|
|
|
|
2021-01-12 21:38:01 +01:00
|
|
|
const peer_data = zrequire("peer_data");
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
const stream_events = zrequire("stream_events");
|
2021-02-28 00:45:40 +01:00
|
|
|
const {Filter} = zrequire("Filter", "js/filter");
|
2021-02-10 04:53:22 +01:00
|
|
|
const narrow_state = zrequire("narrow_state");
|
2021-02-11 01:23:23 +01:00
|
|
|
const message_view_header = zrequire("message_view_header");
|
2020-06-22 23:17:23 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const george = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "george@zulip.com",
|
|
|
|
full_name: "George",
|
2018-08-04 19:44:31 +02:00
|
|
|
user_id: 103,
|
|
|
|
};
|
2021-02-11 15:44:42 +01:00
|
|
|
const me = {
|
|
|
|
email: "me@zulip.com",
|
|
|
|
full_name: "Me Myself",
|
|
|
|
user_id: 104,
|
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(george);
|
2021-02-11 15:44:42 +01:00
|
|
|
people.add_active_user(me);
|
|
|
|
people.initialize_current_user(me.user_id);
|
2018-08-04 19:44:31 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const frontend = {
|
2017-07-03 21:55:03 +02:00
|
|
|
subscribed: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "yellow",
|
|
|
|
name: "frontend",
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_id: 101,
|
2019-05-15 08:54:25 +02:00
|
|
|
is_muted: true,
|
2017-07-01 22:17:22 +02:00
|
|
|
invite_only: false,
|
|
|
|
};
|
2018-08-04 19:44:31 +02:00
|
|
|
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(frontend);
|
2017-07-01 22:17:22 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const frontend_filter_terms = [{operator: "stream", operand: "frontend"}];
|
2020-06-23 16:19:55 +02:00
|
|
|
|
|
|
|
const frontend_filter = new Filter(frontend_filter_terms);
|
|
|
|
|
2020-07-26 17:04:39 +02:00
|
|
|
run_test("update_property", (override) => {
|
2021-02-04 18:25:22 +01:00
|
|
|
const stream_id = frontend.stream_id;
|
|
|
|
|
2017-07-01 22:17:22 +02:00
|
|
|
// Invoke error for non-existent stream/property
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2019-11-02 00:06:25 +01:00
|
|
|
let errors = 0;
|
2021-02-11 01:23:23 +01:00
|
|
|
override(blueslip, "warn", () => {
|
2017-07-01 22:17:22 +02:00
|
|
|
errors += 1;
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(99, "color", "blue");
|
2017-07-01 22:17:22 +02:00
|
|
|
assert.equal(errors, 1);
|
|
|
|
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "not_real", 42);
|
2017-07-01 22:17:22 +02:00
|
|
|
assert.equal(errors, 2);
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2017-07-01 22:17:22 +02:00
|
|
|
|
|
|
|
// Test update color
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(stream_color, "update_stream_color", stub.f);
|
|
|
|
stream_events.update_property(stream_id, "color", "blue");
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("sub", "val");
|
|
|
|
assert.equal(args.sub.stream_id, stream_id);
|
|
|
|
assert.equal(args.val, "blue");
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2017-07-01 22:17:22 +02:00
|
|
|
|
|
|
|
// Test in home view
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(stream_muting, "update_is_muted", stub.f);
|
|
|
|
stream_events.update_property(stream_id, "in_home_view", false);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("sub", "val");
|
|
|
|
assert.equal(args.sub.stream_id, stream_id);
|
|
|
|
assert.equal(args.val, true);
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2017-07-03 19:57:24 +02:00
|
|
|
|
2021-02-04 18:25:22 +01:00
|
|
|
function checkbox_for(property) {
|
2021-02-03 23:23:32 +01:00
|
|
|
return $(`#${CSS.escape(property)}_${CSS.escape(stream_id)}`);
|
2021-02-04 18:25:22 +01:00
|
|
|
}
|
|
|
|
|
2017-07-03 19:57:24 +02:00
|
|
|
// Test desktop notifications
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "desktop_notifications", true);
|
2017-07-03 19:57:24 +02:00
|
|
|
assert.equal(frontend.desktop_notifications, true);
|
2021-02-04 18:25:22 +01:00
|
|
|
let checkbox = checkbox_for("desktop_notifications");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(checkbox.prop("checked"), true);
|
2017-07-03 19:57:24 +02:00
|
|
|
|
|
|
|
// Tests audible notifications
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "audible_notifications", true);
|
2017-07-03 19:57:24 +02:00
|
|
|
assert.equal(frontend.audible_notifications, true);
|
2021-02-04 18:25:22 +01:00
|
|
|
checkbox = checkbox_for("audible_notifications");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(checkbox.prop("checked"), true);
|
2017-07-03 19:57:24 +02:00
|
|
|
|
2017-08-17 16:55:32 +02:00
|
|
|
// Tests push notifications
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "push_notifications", true);
|
2017-08-17 16:55:32 +02:00
|
|
|
assert.equal(frontend.push_notifications, true);
|
2021-02-04 18:25:22 +01:00
|
|
|
checkbox = checkbox_for("push_notifications");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(checkbox.prop("checked"), true);
|
2017-08-17 16:55:32 +02:00
|
|
|
|
2017-11-21 05:58:26 +01:00
|
|
|
// Tests email notifications
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "email_notifications", true);
|
2017-11-21 05:58:26 +01:00
|
|
|
assert.equal(frontend.email_notifications, true);
|
2021-02-04 18:25:22 +01:00
|
|
|
checkbox = checkbox_for("email_notifications");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(checkbox.prop("checked"), true);
|
2017-11-21 05:58:26 +01:00
|
|
|
|
2019-11-26 02:37:12 +01:00
|
|
|
// Tests wildcard_mentions_notify notifications
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "wildcard_mentions_notify", true);
|
2019-11-26 02:37:12 +01:00
|
|
|
assert.equal(frontend.wildcard_mentions_notify, true);
|
2021-02-04 18:25:22 +01:00
|
|
|
checkbox = checkbox_for("wildcard_mentions_notify");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(checkbox.prop("checked"), true);
|
2019-11-26 02:37:12 +01:00
|
|
|
|
2017-07-03 19:57:24 +02:00
|
|
|
// Test name change
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(subs, "update_stream_name", stub.f);
|
|
|
|
stream_events.update_property(stream_id, "name", "the frontend");
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("sub", "val");
|
|
|
|
assert.equal(args.sub.stream_id, stream_id);
|
|
|
|
assert.equal(args.val, "the frontend");
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2017-07-03 19:57:24 +02:00
|
|
|
|
|
|
|
// Test description change
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(subs, "update_stream_description", stub.f);
|
|
|
|
stream_events.update_property(stream_id, "description", "we write code", {
|
|
|
|
rendered_description: "we write code",
|
2017-07-03 19:57:24 +02:00
|
|
|
});
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("sub", "val");
|
|
|
|
assert.equal(args.sub.stream_id, stream_id);
|
|
|
|
assert.equal(args.val, "we write code");
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2017-07-03 19:57:24 +02:00
|
|
|
|
|
|
|
// Test email address change
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "email_address", "zooly@zulip.com");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(frontend.email_address, "zooly@zulip.com");
|
2017-07-03 19:57:24 +02:00
|
|
|
|
|
|
|
// Test pin to top
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-02-11 01:23:23 +01:00
|
|
|
override(stream_list, "refresh_pinned_or_unpinned_stream", noop);
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "pin_to_top", true);
|
|
|
|
checkbox = checkbox_for("pin_to_top");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(checkbox.prop("checked"), true);
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2019-05-02 19:43:27 +02:00
|
|
|
// Test stream privacy change event
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(subs, "update_stream_privacy", stub.f);
|
|
|
|
stream_events.update_property(stream_id, "invite_only", true, {
|
|
|
|
history_public_to_subscribers: true,
|
|
|
|
});
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("sub", "val");
|
|
|
|
assert.equal(args.sub.stream_id, stream_id);
|
|
|
|
assert.deepEqual(args.val, {
|
|
|
|
invite_only: true,
|
|
|
|
history_public_to_subscribers: true,
|
2019-05-02 19:43:27 +02:00
|
|
|
});
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2019-05-02 19:43:27 +02:00
|
|
|
|
2020-02-04 21:50:55 +01:00
|
|
|
// Test stream stream_post_policy change event
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(subs, "update_stream_post_policy", stub.f);
|
|
|
|
stream_events.update_property(
|
|
|
|
stream_id,
|
|
|
|
"stream_post_policy",
|
|
|
|
stream_data.stream_post_policy_values.admins.code,
|
|
|
|
);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("sub", "val");
|
|
|
|
assert.equal(args.sub.stream_id, stream_id);
|
|
|
|
assert.equal(args.val, stream_data.stream_post_policy_values.admins.code);
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2020-06-15 17:00:00 +02:00
|
|
|
|
|
|
|
// Test stream message_retention_days change event
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
override(subs, "update_message_retention_setting", stub.f);
|
|
|
|
stream_events.update_property(stream_id, "message_retention_days", 20);
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
const args = stub.get_args("sub", "val");
|
|
|
|
assert.equal(args.sub.stream_id, stream_id);
|
|
|
|
assert.equal(args.val, 20);
|
2020-07-26 17:04:39 +02:00
|
|
|
}
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
run_test("marked_unsubscribed (code coverage)", () => {
|
|
|
|
// We don't error for unsubscribed streams for some reason.
|
|
|
|
stream_events.mark_unsubscribed(undefined);
|
|
|
|
});
|
2020-07-26 13:32:02 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
run_test("marked_(un)subscribed (early return)", () => {
|
|
|
|
// The early-return prevents us from exploding or needing
|
|
|
|
// to override functions with side effects
|
|
|
|
stream_events.mark_subscribed({subscribed: true});
|
|
|
|
stream_events.mark_unsubscribed({subscribed: false});
|
|
|
|
});
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
run_test("marked_subscribed (error)", (override) => {
|
|
|
|
// Test undefined error
|
|
|
|
let errors = 0;
|
|
|
|
override(blueslip, "error", () => {
|
|
|
|
errors += 1;
|
2017-07-03 21:55:03 +02:00
|
|
|
});
|
2021-02-11 15:44:42 +01:00
|
|
|
stream_events.mark_subscribed(undefined, [], "yellow");
|
|
|
|
assert.equal(errors, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test("marked_subscribed (normal)", (override) => {
|
|
|
|
override(stream_data, "subscribe_myself", noop);
|
|
|
|
override(stream_data, "update_calculated_fields", noop);
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
override(stream_color, "update_stream_color", noop);
|
|
|
|
|
2020-06-23 16:19:55 +02:00
|
|
|
narrow_state.set_current_filter(frontend_filter);
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
let args;
|
|
|
|
let list_updated = false;
|
|
|
|
|
|
|
|
const stream_list_stub = make_stub();
|
|
|
|
const message_view_header_stub = make_stub();
|
|
|
|
const message_util_stub = make_stub();
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
override(stream_list, "add_sidebar_row", stream_list_stub.f);
|
|
|
|
override(message_util, "do_unread_count_updates", message_util_stub.f);
|
|
|
|
override(message_view_header, "render_title_area", message_view_header_stub.f);
|
|
|
|
override(current_msg_list, "update_trailing_bookend", () => {
|
|
|
|
list_updated = true;
|
|
|
|
});
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
stream_events.mark_subscribed(frontend, [], "blue");
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
args = message_util_stub.get_args("messages");
|
|
|
|
assert.deepEqual(args.messages, ["msg"]);
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
args = stream_list_stub.get_args("sub");
|
|
|
|
assert.equal(args.sub.stream_id, frontend.stream_id);
|
|
|
|
assert.equal(message_view_header_stub.num_calls, 1);
|
|
|
|
|
|
|
|
assert.equal(list_updated, true);
|
|
|
|
|
|
|
|
assert.equal(frontend.color, "blue");
|
2020-06-23 16:19:55 +02:00
|
|
|
narrow_state.reset_current_filter();
|
2021-02-11 15:44:42 +01:00
|
|
|
});
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
run_test("marked_subscribed (color)", (override) => {
|
|
|
|
override(stream_data, "subscribe_myself", noop);
|
|
|
|
override(stream_data, "update_calculated_fields", noop);
|
|
|
|
override(message_util, "do_unread_count_updates", noop);
|
|
|
|
override(stream_list, "add_sidebar_row", noop);
|
|
|
|
|
|
|
|
frontend.color = undefined;
|
|
|
|
override(color_data, "pick_color", () => "green");
|
|
|
|
let warnings = 0;
|
|
|
|
override(blueslip, "warn", () => {
|
|
|
|
warnings += 1;
|
|
|
|
});
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
// narrow state is undefined
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2021-02-11 15:44:42 +01:00
|
|
|
override(subs, "set_color", stub.f);
|
|
|
|
stream_events.mark_subscribed(frontend, [], undefined);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2021-02-11 15:44:42 +01:00
|
|
|
const args = stub.get_args("id", "color");
|
|
|
|
assert.equal(args.id, frontend.stream_id);
|
|
|
|
assert.equal(args.color, "green");
|
|
|
|
assert.equal(warnings, 1);
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2021-02-11 15:44:42 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
run_test("marked_subscribed (emails)", (override) => {
|
|
|
|
override(stream_data, "update_calculated_fields", noop);
|
|
|
|
override(stream_color, "update_stream_color", noop);
|
2017-07-03 21:55:03 +02:00
|
|
|
|
|
|
|
// Test assigning subscriber emails
|
2020-06-23 16:19:55 +02:00
|
|
|
// narrow state is undefined
|
2021-02-11 15:44:42 +01:00
|
|
|
override(message_util, "do_unread_count_updates", noop);
|
|
|
|
override(stream_list, "add_sidebar_row", noop);
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
const subs_stub = make_stub();
|
|
|
|
override(subs, "update_settings_for_subscribed", subs_stub.f);
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
assert(!stream_data.is_subscribed(frontend.name));
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
const user_ids = [15, 20, 25, me.user_id];
|
|
|
|
stream_events.mark_subscribed(frontend, user_ids, "");
|
|
|
|
assert.deepEqual(new Set(peer_data.get_subscribers(frontend.stream_id)), new Set(user_ids));
|
|
|
|
assert(stream_data.is_subscribed(frontend.name));
|
|
|
|
|
|
|
|
const args = subs_stub.get_args("sub");
|
|
|
|
assert.deepEqual(frontend, args.sub);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
run_test("mark_unsubscribed (update_settings_for_unsubscribed)", (override) => {
|
2021-02-11 01:23:23 +01:00
|
|
|
override(stream_data, "update_calculated_fields", noop);
|
2020-07-26 17:04:39 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
// Test unsubscribe
|
|
|
|
frontend.subscribed = true;
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
const stub = make_stub();
|
2020-07-26 13:32:02 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
override(subs, "update_settings_for_unsubscribed", stub.f);
|
|
|
|
override(stream_list, "remove_sidebar_row", noop);
|
|
|
|
override(stream_data, "unsubscribe_myself", noop);
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
stream_events.mark_unsubscribed(frontend);
|
|
|
|
const args = stub.get_args("sub");
|
|
|
|
assert.deepEqual(args.sub, frontend);
|
|
|
|
});
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
run_test("mark_unsubscribed (render_title_area)", (override) => {
|
|
|
|
override(stream_data, "update_calculated_fields", noop);
|
2017-07-03 22:17:16 +02:00
|
|
|
|
|
|
|
// Test update bookend and remove done event
|
2020-06-23 16:19:55 +02:00
|
|
|
narrow_state.set_current_filter(frontend_filter);
|
2021-02-11 15:44:42 +01:00
|
|
|
const message_view_header_stub = make_stub();
|
|
|
|
override(message_view_header, "render_title_area", message_view_header_stub.f);
|
|
|
|
override(stream_data, "unsubscribe_myself", noop);
|
|
|
|
override(subs, "update_settings_for_unsubscribed", noop);
|
|
|
|
override(current_msg_list, "update_trailing_bookend", noop);
|
|
|
|
override(stream_list, "remove_sidebar_row", noop);
|
2017-07-06 15:43:41 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
stream_events.mark_unsubscribed(frontend);
|
2017-07-06 15:43:41 +02:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
assert.equal(message_view_header_stub.num_calls, 1);
|
2020-06-22 23:17:23 +02:00
|
|
|
|
2020-06-23 16:19:55 +02:00
|
|
|
narrow_state.reset_current_filter();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-08-04 19:44:31 +02:00
|
|
|
|
|
|
|
stream_data.clear_subscriptions();
|
2019-11-02 00:06:25 +01:00
|
|
|
const dev_help = {
|
2018-08-04 19:44:31 +02:00
|
|
|
subscribed: true,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
|
|
|
name: "dev help",
|
2018-08-04 19:44:31 +02:00
|
|
|
stream_id: 2,
|
2019-05-15 08:54:25 +02:00
|
|
|
is_muted: true,
|
2018-08-04 19:44:31 +02:00
|
|
|
invite_only: false,
|
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(dev_help);
|
2018-08-04 19:44:31 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("remove_deactivated_user_from_all_streams", () => {
|
2020-12-01 00:06:06 +01:00
|
|
|
const subs_stub = make_stub();
|
2020-06-22 23:17:23 +02:00
|
|
|
subs.update_subscribers_ui = subs_stub.f;
|
2018-08-04 19:44:31 +02:00
|
|
|
|
|
|
|
dev_help.can_access_subscribers = true;
|
|
|
|
|
2021-01-12 16:05:24 +01:00
|
|
|
// assert starting state
|
|
|
|
assert(!stream_data.is_user_subscribed(dev_help.stream_id, george.user_id));
|
|
|
|
|
2018-08-04 19:44:31 +02:00
|
|
|
// verify that deactivating user should unsubscribe user from all streams
|
2021-01-29 17:17:32 +01:00
|
|
|
peer_data.add_subscriber(dev_help.stream_id, george.user_id);
|
2021-01-12 16:05:24 +01:00
|
|
|
assert(stream_data.is_user_subscribed(dev_help.stream_id, george.user_id));
|
2018-08-04 19:44:31 +02:00
|
|
|
|
|
|
|
stream_events.remove_deactivated_user_from_all_streams(george.user_id);
|
|
|
|
|
2020-06-22 23:17:23 +02:00
|
|
|
// verify that we issue a call to update subscriber count/list UI
|
|
|
|
assert.equal(subs_stub.num_calls, 1);
|
2018-08-04 19:44:31 +02:00
|
|
|
});
|
2021-02-28 00:52:39 +01:00
|
|
|
rewiremock.disable();
|