2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-06-16 15:58:34 +02:00
|
|
|
const {mock_esm, 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-03-16 23:38:59 +01:00
|
|
|
const blueslip = require("../zjsunit/zblueslip");
|
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 = () => {};
|
2021-03-11 05:43:45 +01:00
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
const color_data = mock_esm("../../static/js/color_data");
|
|
|
|
const message_util = mock_esm("../../static/js/message_util");
|
|
|
|
const stream_color = mock_esm("../../static/js/stream_color");
|
|
|
|
const stream_list = mock_esm("../../static/js/stream_list");
|
|
|
|
const stream_muting = mock_esm("../../static/js/stream_muting");
|
2021-07-09 15:51:31 +02:00
|
|
|
const stream_settings_ui = mock_esm("../../static/js/stream_settings_ui", {
|
2021-03-07 13:57:14 +01:00
|
|
|
update_settings_for_subscribed: noop,
|
|
|
|
});
|
|
|
|
|
2021-03-30 06:23:09 +02:00
|
|
|
mock_esm("../../static/js/all_messages_data", {
|
|
|
|
all_messages_data: {
|
2020-12-01 23:21:38 +01:00
|
|
|
all_messages() {
|
|
|
|
return ["msg"];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-03-30 02:21:21 +02:00
|
|
|
const message_lists = mock_esm("../../static/js/message_lists", {
|
|
|
|
current: {},
|
|
|
|
});
|
2022-07-10 01:06:33 +02:00
|
|
|
const message_view_header = mock_esm("../../static/js/message_view_header", {
|
|
|
|
maybe_rerender_title_area_for_stream() {},
|
|
|
|
});
|
2021-06-10 14:18:46 +02:00
|
|
|
mock_esm("../../static/js/recent_topics_ui", {
|
2021-03-06 17:37:51 +01:00
|
|
|
complete_rerender: () => {},
|
|
|
|
});
|
2021-03-10 06:10:32 +01:00
|
|
|
mock_esm("../../static/js/settings_notifications", {
|
2021-03-07 13:57:14 +01:00
|
|
|
update_page: () => {},
|
|
|
|
});
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
mock_esm("../../static/js/overlays", {streams_open: () => true});
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2021-03-07 13:57:14 +01:00
|
|
|
const {Filter} = zrequire("../js/filter");
|
|
|
|
const narrow_state = zrequire("narrow_state");
|
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");
|
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
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
const dev_help = {
|
|
|
|
subscribed: true,
|
|
|
|
color: "blue",
|
|
|
|
name: "dev help",
|
|
|
|
stream_id: 2,
|
|
|
|
is_muted: true,
|
|
|
|
invite_only: false,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
function narrow_to_frontend() {
|
|
|
|
const filter = new Filter([{operator: "stream", operand: "frontend"}]);
|
|
|
|
narrow_state.set_current_filter(filter);
|
|
|
|
}
|
2017-07-01 22:17:22 +02:00
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2021-03-14 14:56:28 +01:00
|
|
|
stream_data.clear_subscriptions();
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-03-14 14:56:28 +01:00
|
|
|
});
|
|
|
|
}
|
2020-06-23 16:19:55 +02:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("update_property", ({override}) => {
|
2021-03-14 14:56:28 +01:00
|
|
|
const sub = {...frontend};
|
|
|
|
stream_data.add_sub(sub);
|
2020-06-23 16:19:55 +02:00
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
const stream_id = sub.stream_id;
|
2021-02-04 18:25:22 +01:00
|
|
|
|
2017-07-01 22:17:22 +02:00
|
|
|
// Invoke error for non-existent stream/property
|
2020-07-26 17:04:39 +02:00
|
|
|
{
|
2021-03-16 23:55:01 +01:00
|
|
|
blueslip.expect("warn", "Update for an unknown subscription");
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_events.update_property(99, "color", "blue");
|
2021-03-16 23:55:01 +01:00
|
|
|
blueslip.reset();
|
2017-07-01 22:17:22 +02:00
|
|
|
|
2021-03-16 23:55:01 +01:00
|
|
|
blueslip.expect("warn", "Unexpected subscription property type");
|
2021-02-04 18:25:22 +01:00
|
|
|
stream_events.update_property(stream_id, "not_real", 42);
|
2021-03-16 23:55:01 +01:00
|
|
|
blueslip.reset();
|
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);
|
2022-02-20 21:32:14 +01:00
|
|
|
override(stream_list, "refresh_muted_or_unmuted_stream", noop);
|
2021-02-13 03:46:14 +01:00
|
|
|
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);
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(sub.desktop_notifications, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
let $checkbox = checkbox_for("desktop_notifications");
|
|
|
|
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);
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(sub.audible_notifications, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
$checkbox = checkbox_for("audible_notifications");
|
|
|
|
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);
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(sub.push_notifications, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
$checkbox = checkbox_for("push_notifications");
|
|
|
|
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);
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(sub.email_notifications, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
$checkbox = checkbox_for("email_notifications");
|
|
|
|
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);
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(sub.wildcard_mentions_notify, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
$checkbox = checkbox_for("wildcard_mentions_notify");
|
|
|
|
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();
|
2021-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "update_stream_name", stub.f);
|
2021-02-13 03:46:14 +01:00
|
|
|
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();
|
2021-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "update_stream_description", stub.f);
|
2021-02-13 03:46:14 +01:00
|
|
|
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");
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(sub.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);
|
2022-01-25 11:36:19 +01:00
|
|
|
$checkbox = checkbox_for("pin_to_top");
|
|
|
|
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();
|
2021-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "update_stream_privacy", stub.f);
|
2021-02-13 03:46:14 +01:00
|
|
|
stream_events.update_property(stream_id, "invite_only", true, {
|
|
|
|
history_public_to_subscribers: true,
|
2020-11-10 15:57:14 +01:00
|
|
|
is_web_public: false,
|
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.deepEqual(args.val, {
|
|
|
|
invite_only: true,
|
|
|
|
history_public_to_subscribers: true,
|
2020-11-10 15:57:14 +01:00
|
|
|
is_web_public: false,
|
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();
|
2021-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "update_stream_post_policy", stub.f);
|
2021-02-13 03:46:14 +01:00
|
|
|
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();
|
2021-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "update_message_retention_setting", stub.f);
|
2021-02-13 03:46:14 +01:00
|
|
|
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-03-14 14:56:28 +01:00
|
|
|
test("marked_unsubscribed (code coverage)", () => {
|
2021-02-11 15:44:42 +01:00
|
|
|
// We don't error for unsubscribed streams for some reason.
|
|
|
|
stream_events.mark_unsubscribed(undefined);
|
|
|
|
});
|
2020-07-26 13:32:02 +02:00
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
test("marked_(un)subscribed (early return)", () => {
|
2021-02-11 15:44:42 +01:00
|
|
|
// 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-03-16 23:55:01 +01:00
|
|
|
test("marked_subscribed (error)", () => {
|
2021-02-11 15:44:42 +01:00
|
|
|
// Test undefined error
|
2021-03-16 23:55:01 +01:00
|
|
|
blueslip.expect("error", "Undefined sub passed to mark_subscribed");
|
2021-02-11 15:44:42 +01:00
|
|
|
stream_events.mark_subscribed(undefined, [], "yellow");
|
2021-03-16 23:55:01 +01:00
|
|
|
blueslip.reset();
|
2021-02-11 15:44:42 +01:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("marked_subscribed (normal)", ({override}) => {
|
2021-03-14 14:56:28 +01:00
|
|
|
const sub = {...frontend};
|
|
|
|
stream_data.add_sub(sub);
|
2021-02-11 15:44:42 +01:00
|
|
|
override(stream_color, "update_stream_color", noop);
|
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
narrow_to_frontend();
|
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);
|
2022-07-10 01:06:33 +02:00
|
|
|
override(
|
|
|
|
message_view_header,
|
|
|
|
"maybe_rerender_title_area_for_stream",
|
|
|
|
message_view_header_stub.f,
|
|
|
|
);
|
2021-03-30 02:21:21 +02:00
|
|
|
override(message_lists.current, "update_trailing_bookend", () => {
|
2021-02-11 15:44:42 +01:00
|
|
|
list_updated = true;
|
|
|
|
});
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
stream_events.mark_subscribed(sub, [], "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");
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(args.sub.stream_id, sub.stream_id);
|
2021-02-11 15:44:42 +01:00
|
|
|
assert.equal(message_view_header_stub.num_calls, 1);
|
|
|
|
|
|
|
|
assert.equal(list_updated, true);
|
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(sub.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
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("marked_subscribed (color)", ({override}) => {
|
2021-02-11 15:44:42 +01:00
|
|
|
override(message_util, "do_unread_count_updates", noop);
|
|
|
|
override(stream_list, "add_sidebar_row", noop);
|
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
const sub = {
|
|
|
|
subscribed: false,
|
|
|
|
name: "production help",
|
|
|
|
stream_id: 201,
|
|
|
|
is_muted: true,
|
|
|
|
invite_only: false,
|
|
|
|
};
|
2022-07-10 01:06:33 +02:00
|
|
|
stream_data.add_sub(sub);
|
2021-03-14 14:56:28 +01:00
|
|
|
|
2021-02-11 15:44:42 +01:00
|
|
|
override(color_data, "pick_color", () => "green");
|
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-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "set_color", stub.f);
|
2021-03-16 23:55:01 +01:00
|
|
|
blueslip.expect("warn", "Frontend needed to pick a color in mark_subscribed");
|
2021-03-14 14:56:28 +01:00
|
|
|
stream_events.mark_subscribed(sub, [], 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");
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.equal(args.id, sub.stream_id);
|
2021-02-11 15:44:42 +01:00
|
|
|
assert.equal(args.color, "green");
|
2021-03-16 23:55:01 +01:00
|
|
|
blueslip.reset();
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2021-02-11 15:44:42 +01:00
|
|
|
});
|
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("marked_subscribed (emails)", ({override}) => {
|
2021-03-14 14:56:28 +01:00
|
|
|
const sub = {...frontend};
|
|
|
|
stream_data.add_sub(sub);
|
2021-02-11 15:44:42 +01:00
|
|
|
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();
|
2021-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "update_settings_for_subscribed", subs_stub.f);
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2021-11-23 00:37:45 +01:00
|
|
|
assert.ok(!stream_data.is_subscribed_by_name(sub.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];
|
2021-03-14 14:56:28 +01:00
|
|
|
stream_events.mark_subscribed(sub, user_ids, "");
|
|
|
|
assert.deepEqual(new Set(peer_data.get_subscribers(sub.stream_id)), new Set(user_ids));
|
2021-11-23 00:37:45 +01:00
|
|
|
assert.ok(stream_data.is_subscribed_by_name(sub.name));
|
2021-02-11 15:44:42 +01:00
|
|
|
|
|
|
|
const args = subs_stub.get_args("sub");
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.deepEqual(sub, args.sub);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("mark_unsubscribed (update_settings_for_unsubscribed)", ({override}) => {
|
2021-02-11 15:44:42 +01:00
|
|
|
// Test unsubscribe
|
2021-03-14 14:56:28 +01:00
|
|
|
const sub = {...dev_help};
|
2022-07-10 01:06:33 +02:00
|
|
|
stream_data.add_sub(sub);
|
|
|
|
stream_data.subscribe_myself(sub);
|
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-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "update_settings_for_unsubscribed", stub.f);
|
2021-02-11 15:44:42 +01:00
|
|
|
override(stream_list, "remove_sidebar_row", noop);
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
stream_events.mark_unsubscribed(sub);
|
2021-02-11 15:44:42 +01:00
|
|
|
const args = stub.get_args("sub");
|
2021-03-14 14:56:28 +01:00
|
|
|
assert.deepEqual(args.sub, sub);
|
2021-02-11 15:44:42 +01:00
|
|
|
});
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("mark_unsubscribed (render_title_area)", ({override}) => {
|
2021-03-14 14:56:28 +01:00
|
|
|
const sub = {...frontend, subscribed: true};
|
|
|
|
stream_data.add_sub(sub);
|
|
|
|
|
2017-07-03 22:17:16 +02:00
|
|
|
// Test update bookend and remove done event
|
2021-03-14 14:56:28 +01:00
|
|
|
narrow_to_frontend();
|
2021-02-11 15:44:42 +01:00
|
|
|
const message_view_header_stub = make_stub();
|
2022-07-10 01:06:33 +02:00
|
|
|
override(
|
|
|
|
message_view_header,
|
|
|
|
"maybe_rerender_title_area_for_stream",
|
|
|
|
message_view_header_stub.f,
|
|
|
|
);
|
2021-07-09 15:51:31 +02:00
|
|
|
override(stream_settings_ui, "update_settings_for_unsubscribed", noop);
|
2021-03-30 02:21:21 +02:00
|
|
|
override(message_lists.current, "update_trailing_bookend", noop);
|
2021-02-11 15:44:42 +01:00
|
|
|
override(stream_list, "remove_sidebar_row", noop);
|
2017-07-06 15:43:41 +02:00
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
stream_events.mark_unsubscribed(sub);
|
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
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
test("remove_deactivated_user_from_all_streams", () => {
|
|
|
|
stream_data.add_sub(dev_help);
|
2020-12-01 00:06:06 +01:00
|
|
|
const subs_stub = make_stub();
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.update_subscribers_ui = subs_stub.f;
|
2018-08-04 19:44:31 +02:00
|
|
|
|
2021-01-12 16:05:24 +01:00
|
|
|
// assert starting state
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!stream_data.is_user_subscribed(dev_help.stream_id, george.user_id));
|
2021-01-12 16:05:24 +01:00
|
|
|
|
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-06-10 08:32:54 +02:00
|
|
|
assert.ok(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
|
|
|
});
|