2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
|
|
|
const return_true = function () { return true; };
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("$", global.make_zjquery());
|
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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("people");
|
|
|
|
zrequire("stream_data");
|
|
|
|
zrequire("stream_events");
|
|
|
|
zrequire("Filter", "js/filter");
|
|
|
|
zrequire("narrow_state");
|
|
|
|
zrequire("tab_bar");
|
2020-06-22 23:17:23 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const with_overrides = global.with_overrides;
|
2017-07-01 22:17:22 +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,
|
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(george);
|
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",
|
2017-07-01 22:17:22 +02:00
|
|
|
stream_id: 1,
|
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-06-23 16:19:55 +02:00
|
|
|
|
|
|
|
const frontend_filter_terms = [
|
2020-07-15 01:29:15 +02:00
|
|
|
{ operator: "stream", operand: "frontend" },
|
2020-06-23 16:19:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
const frontend_filter = new Filter(frontend_filter_terms);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("update_property", () => {
|
2017-07-01 22:17:22 +02:00
|
|
|
// Invoke error for non-existent stream/property
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let errors = 0;
|
2020-07-15 01:29:15 +02: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);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(1, "not_real", 42);
|
2017-07-01 22:17:22 +02:00
|
|
|
assert.equal(errors, 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test update color
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_color.update_stream_color", stub.f);
|
|
|
|
stream_events.update_property(1, "color", "blue");
|
|
|
|
const args = stub.get_args("sub", "val");
|
2017-07-01 22:17:22 +02:00
|
|
|
assert.equal(args.sub.stream_id, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(args.val, "blue");
|
2017-07-01 22:17:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test in home view
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_muting.update_is_muted", stub.f);
|
|
|
|
stream_events.update_property(1, "in_home_view", false);
|
|
|
|
const args = stub.get_args("sub", "val");
|
2017-07-01 22:17:22 +02:00
|
|
|
assert.equal(args.sub.stream_id, 1);
|
|
|
|
assert.equal(args.val, true);
|
|
|
|
});
|
|
|
|
});
|
2017-07-03 19:57:24 +02:00
|
|
|
|
|
|
|
// Test desktop notifications
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(1, "desktop_notifications", true);
|
2017-07-03 19:57:24 +02:00
|
|
|
assert.equal(frontend.desktop_notifications, true);
|
2019-11-02 00:06:25 +01:00
|
|
|
let checkbox = $("#desktop_notifications_1");
|
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
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(1, "audible_notifications", true);
|
2017-07-03 19:57:24 +02:00
|
|
|
assert.equal(frontend.audible_notifications, true);
|
2019-06-14 19:29:48 +02:00
|
|
|
checkbox = $("#audible_notifications_1");
|
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
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(1, "push_notifications", true);
|
2017-08-17 16:55:32 +02:00
|
|
|
assert.equal(frontend.push_notifications, true);
|
2019-06-14 19:29:48 +02:00
|
|
|
checkbox = $("#push_notifications_1");
|
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
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(1, "email_notifications", true);
|
2017-11-21 05:58:26 +01:00
|
|
|
assert.equal(frontend.email_notifications, true);
|
2019-06-14 19:29:48 +02:00
|
|
|
checkbox = $("#email_notifications_1");
|
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
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(1, "wildcard_mentions_notify", true);
|
2019-11-26 02:37:12 +01:00
|
|
|
assert.equal(frontend.wildcard_mentions_notify, true);
|
|
|
|
checkbox = $("#wildcard_mentions_notify_1");
|
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-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("subs.update_stream_name", stub.f);
|
|
|
|
stream_events.update_property(1, "name", "the frontend");
|
|
|
|
const args = stub.get_args("sub", "val");
|
2017-07-03 19:57:24 +02:00
|
|
|
assert.equal(args.sub.stream_id, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(args.val, "the frontend");
|
2017-07-03 19:57:24 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test description change
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("subs.update_stream_description", stub.f);
|
|
|
|
stream_events.update_property(1, "description", "we write code", {rendered_description: "we write code"});
|
|
|
|
const args = stub.get_args("sub", "val");
|
2017-07-03 19:57:24 +02:00
|
|
|
assert.equal(args.sub.stream_id, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(args.val, "we write code");
|
2017-07-03 19:57:24 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test email address change
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(1, "email_address", "zooly@zulip.com");
|
|
|
|
assert.equal(frontend.email_address, "zooly@zulip.com");
|
2017-07-03 19:57:24 +02:00
|
|
|
|
|
|
|
// Test pin to top
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_list.refresh_pinned_or_unpinned_stream", noop);
|
|
|
|
stream_events.update_property(1, "pin_to_top", true);
|
2019-06-14 19:29:48 +02:00
|
|
|
checkbox = $("#pin_to_top_1");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(checkbox.prop("checked"), true);
|
2017-07-03 19:57:24 +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-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("subs.update_stream_privacy", stub.f);
|
|
|
|
stream_events.update_property(1, "invite_only", true, {
|
2019-05-02 19:43:27 +02:00
|
|
|
history_public_to_subscribers: true,
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("sub", "val");
|
2019-05-02 19:43:27 +02:00
|
|
|
assert.equal(args.sub.stream_id, 1);
|
|
|
|
assert.deepEqual(args.val, {
|
|
|
|
invite_only: true,
|
|
|
|
history_public_to_subscribers: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-04 21:50:55 +01:00
|
|
|
// Test stream stream_post_policy change event
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("subs.update_stream_post_policy", stub.f);
|
|
|
|
stream_events.update_property(1, "stream_post_policy", stream_data.stream_post_policy_values.admins.code);
|
|
|
|
const args = stub.get_args("sub", "val");
|
2019-05-02 19:43:27 +02:00
|
|
|
assert.equal(args.sub.stream_id, 1);
|
2020-02-04 21:50:55 +01:00
|
|
|
assert.equal(args.val, stream_data.stream_post_policy_values.admins.code);
|
2019-05-02 19:43:27 +02:00
|
|
|
});
|
|
|
|
});
|
2020-06-15 17:00:00 +02:00
|
|
|
|
|
|
|
// Test stream message_retention_days change event
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("subs.update_message_retention_setting", stub.f);
|
|
|
|
stream_events.update_property(1, "message_retention_days", 20);
|
|
|
|
const args = stub.get_args("sub", "val");
|
2020-06-15 17:00:00 +02:00
|
|
|
assert.equal(args.sub.stream_id, 1);
|
|
|
|
assert.equal(args.val, 20);
|
|
|
|
});
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("marked_subscribed", () => {
|
2017-07-03 21:55:03 +02:00
|
|
|
// Test undefined error
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let errors = 0;
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_color.update_stream_color", noop);
|
|
|
|
override("blueslip.error", () => {
|
2017-07-03 21:55:03 +02:00
|
|
|
errors += 1;
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.mark_subscribed(undefined, [], "yellow");
|
2017-07-03 21:55:03 +02:00
|
|
|
assert.equal(errors, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test early return if subscribed
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let completed = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
override("message_util.do_unread_count_updates", () => {
|
2017-07-03 21:55:03 +02:00
|
|
|
completed = true; // This gets run if we continue and don't early return
|
|
|
|
});
|
2019-11-02 00:06:25 +01:00
|
|
|
const subscribed = {subscribed: true};
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.mark_subscribed(subscribed, [], "yellow");
|
2017-07-03 21:55:03 +02:00
|
|
|
assert.equal(completed, false);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("message_list", {
|
2017-07-03 21:55:03 +02:00
|
|
|
all: {
|
2020-07-15 01:29:15 +02:00
|
|
|
all_messages: function () { return ["msg"]; },
|
2017-07-03 21:55:03 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-08-04 19:44:31 +02:00
|
|
|
stream_data.subscribe_myself = noop;
|
|
|
|
stream_data.set_subscribers = noop;
|
|
|
|
stream_data.get_colors = noop;
|
|
|
|
stream_data.update_calculated_fields = noop;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("subs", { update_settings_for_subscribed: noop });
|
|
|
|
set_global("overlays", { streams_open: return_true });
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2020-06-18 13:53:44 +02:00
|
|
|
// Test basic dispatching and updating stream color
|
2020-06-23 16:19:55 +02:00
|
|
|
narrow_state.set_current_filter(frontend_filter);
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2020-06-18 13:53:44 +02:00
|
|
|
let args;
|
|
|
|
let list_updated = false;
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2020-06-18 13:53:44 +02:00
|
|
|
const stream_list_stub = global.make_stub();
|
2020-06-22 23:17:23 +02:00
|
|
|
const tab_bar_stub = global.make_stub();
|
2020-06-18 13:53:44 +02:00
|
|
|
const message_util_stub = global.make_stub();
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_color.update_stream_color", noop);
|
|
|
|
override("stream_list.add_sidebar_row", stream_list_stub.f);
|
|
|
|
override("message_util.do_unread_count_updates", message_util_stub.f);
|
|
|
|
override("tab_bar.render_title_area", tab_bar_stub.f);
|
|
|
|
override("current_msg_list.update_trailing_bookend", () => {
|
2020-06-18 13:53:44 +02:00
|
|
|
list_updated = true;
|
2017-07-03 21:55:03 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.mark_subscribed(frontend, [], "blue");
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
args = message_util_stub.get_args("messages");
|
|
|
|
assert.deepEqual(args.messages, ["msg"]);
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
args = stream_list_stub.get_args("sub");
|
2020-06-18 13:53:44 +02:00
|
|
|
assert.equal(args.sub.stream_id, 1);
|
2020-06-22 23:17:23 +02:00
|
|
|
assert.equal(tab_bar_stub.num_calls, 1);
|
2020-06-18 13:53:44 +02:00
|
|
|
|
|
|
|
assert.equal(list_updated, true);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(frontend.color, "blue");
|
2018-11-10 01:57:10 +01:00
|
|
|
});
|
2020-06-23 16:19:55 +02:00
|
|
|
narrow_state.reset_current_filter();
|
2017-07-03 21:55:03 +02:00
|
|
|
|
|
|
|
// Test assigning generated color
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2017-07-03 21:55:03 +02:00
|
|
|
frontend.color = undefined;
|
2020-07-15 01:29:15 +02:00
|
|
|
override("color_data.pick_color", () => "green");
|
2019-11-02 00:06:25 +01:00
|
|
|
let warnings = 0;
|
2020-07-15 01:29:15 +02:00
|
|
|
override("blueslip.warn", () => {
|
2017-07-03 21:55:03 +02:00
|
|
|
warnings += 1;
|
|
|
|
});
|
|
|
|
|
2020-06-23 16:19:55 +02:00
|
|
|
// narrow state is undefined
|
2020-07-02 01:45:54 +02:00
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("message_util.do_unread_count_updates", noop);
|
|
|
|
override("stream_list.add_sidebar_row", noop);
|
|
|
|
override("stream_color.update_stream_color", noop);
|
|
|
|
override("subs.set_color", stub.f);
|
2017-07-03 21:55:03 +02:00
|
|
|
stream_events.mark_subscribed(frontend, [], undefined);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("id", "color");
|
2017-07-03 21:55:03 +02:00
|
|
|
assert.equal(args.id, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(args.color, "green");
|
2017-07-03 21:55:03 +02:00
|
|
|
assert.equal(warnings, 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test assigning subscriber emails
|
2020-06-23 16:19:55 +02:00
|
|
|
// narrow state is undefined
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_color.update_stream_color", noop);
|
|
|
|
override("message_util.do_unread_count_updates", noop);
|
|
|
|
override("stream_list.add_sidebar_row", noop);
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_data.set_subscribers", stub.f);
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_ids = [15, 20, 25];
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.mark_subscribed(frontend, user_ids, "");
|
|
|
|
const args = stub.get_args("sub", "subscribers");
|
2017-07-03 21:55:03 +02:00
|
|
|
assert.deepEqual(frontend, args.sub);
|
2017-10-07 16:00:39 +02:00
|
|
|
assert.deepEqual(user_ids, args.subscribers);
|
2017-07-03 21:55:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// assign self as well
|
2020-07-02 01:45:54 +02:00
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_data.subscribe_myself", stub.f);
|
|
|
|
stream_events.mark_subscribed(frontend, [], "");
|
|
|
|
const args = stub.get_args("sub");
|
2017-07-03 21:55:03 +02:00
|
|
|
assert.deepEqual(frontend, args.sub);
|
|
|
|
});
|
|
|
|
|
|
|
|
// and finally update subscriber settings
|
2020-07-02 01:45:54 +02:00
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("subs.update_settings_for_subscribed", stub.f);
|
|
|
|
stream_events.mark_subscribed(frontend, [], "");
|
|
|
|
const args = stub.get_args("sub");
|
2017-07-03 21:55:03 +02:00
|
|
|
assert.deepEqual(frontend, args.sub);
|
|
|
|
});
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("mark_unsubscribed", () => {
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2020-06-18 13:53:44 +02:00
|
|
|
let removed_sub = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_list.remove_sidebar_row", () => {
|
2020-06-18 13:53:44 +02:00
|
|
|
removed_sub = true;
|
|
|
|
});
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2020-06-18 13:53:44 +02:00
|
|
|
// take no action if no sub specified
|
|
|
|
stream_events.mark_unsubscribed();
|
|
|
|
assert.equal(removed_sub, false);
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2020-06-18 13:53:44 +02:00
|
|
|
// take no action if already unsubscribed
|
|
|
|
frontend.subscribed = false;
|
|
|
|
stream_events.mark_unsubscribed(frontend);
|
|
|
|
assert.equal(removed_sub, false);
|
|
|
|
});
|
2017-07-03 22:17:16 +02:00
|
|
|
|
|
|
|
// Test unsubscribe
|
|
|
|
frontend.subscribed = true;
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_data.unsubscribe_myself", stub.f);
|
|
|
|
override("subs.update_settings_for_unsubscribed", noop);
|
|
|
|
override("stream_list.remove_sidebar_row", noop);
|
2017-07-03 22:17:16 +02:00
|
|
|
stream_events.mark_unsubscribed(frontend);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("sub");
|
2017-07-03 22:17:16 +02:00
|
|
|
assert.deepEqual(args.sub, frontend);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test update settings after unsubscribe
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
|
|
|
global.with_stub((stub) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
override("subs.update_settings_for_unsubscribed", stub.f);
|
|
|
|
override("stream_data.unsubscribe_myself", noop);
|
|
|
|
override("stream_list.remove_sidebar_row", noop);
|
2017-07-03 22:17:16 +02:00
|
|
|
stream_events.mark_unsubscribed(frontend);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("sub");
|
2017-07-03 22:17:16 +02:00
|
|
|
assert.deepEqual(args.sub, frontend);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test update bookend and remove done event
|
2020-06-23 16:19:55 +02:00
|
|
|
narrow_state.set_current_filter(frontend_filter);
|
2020-07-02 01:45:54 +02:00
|
|
|
with_overrides((override) => {
|
2020-06-22 23:17:23 +02:00
|
|
|
const tab_bar_stub = global.make_stub();
|
2020-07-15 01:29:15 +02:00
|
|
|
override("tab_bar.render_title_area", tab_bar_stub.f);
|
|
|
|
override("stream_data.unsubscribe_myself", noop);
|
|
|
|
override("subs.update_settings_for_unsubscribed", noop);
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let updated = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
override("current_msg_list.update_trailing_bookend", () => {
|
2017-07-06 15:43:41 +02:00
|
|
|
updated = true;
|
2017-07-03 22:17:16 +02:00
|
|
|
});
|
2017-07-06 15:43:41 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let event_triggered = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
override("stream_list.remove_sidebar_row", (stream_id) => {
|
2020-06-18 13:53:44 +02:00
|
|
|
assert.equal(stream_id, frontend.stream_id);
|
2017-07-06 15:43:41 +02:00
|
|
|
event_triggered = true;
|
2020-06-18 13:53:44 +02:00
|
|
|
});
|
2017-07-06 15:43:41 +02:00
|
|
|
|
|
|
|
stream_events.mark_unsubscribed(frontend);
|
2020-06-22 23:17:23 +02:00
|
|
|
|
|
|
|
assert.equal(tab_bar_stub.num_calls, 1);
|
2017-07-06 15:43:41 +02:00
|
|
|
assert.equal(updated, true);
|
|
|
|
assert.equal(event_triggered, true);
|
2017-07-03 22:17:16 +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-06-22 23:17:23 +02:00
|
|
|
const subs_stub = global.make_stub();
|
|
|
|
subs.update_subscribers_ui = subs_stub.f;
|
2018-08-04 19:44:31 +02:00
|
|
|
|
|
|
|
dev_help.can_access_subscribers = true;
|
|
|
|
|
|
|
|
// verify that deactivating user should unsubscribe user from all streams
|
2020-06-20 21:35:41 +02:00
|
|
|
assert(stream_data.add_subscriber(dev_help.stream_id, george.user_id));
|
2018-08-04 19:44:31 +02:00
|
|
|
assert(dev_help.subscribers.has(george.user_id));
|
|
|
|
|
|
|
|
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
|
|
|
});
|