2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
|
|
|
const {make_stub} = require("./lib/stub");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const blueslip = require("./lib/zblueslip");
|
|
|
|
const $ = require("./lib/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const color_data = mock_esm("../src/color_data");
|
2023-10-03 10:38:49 +02:00
|
|
|
const stream_color_events = mock_esm("../src/stream_color_events");
|
2023-02-22 23:04:10 +01:00
|
|
|
const stream_list = mock_esm("../src/stream_list");
|
|
|
|
const stream_muting = mock_esm("../src/stream_muting");
|
2023-10-05 23:35:50 +02:00
|
|
|
const stream_settings_api = mock_esm("../src/stream_settings_api");
|
2023-02-22 23:04:10 +01:00
|
|
|
const stream_settings_ui = mock_esm("../src/stream_settings_ui", {
|
2021-03-07 13:57:14 +01:00
|
|
|
update_settings_for_subscribed: noop,
|
2023-03-25 14:10:45 +01:00
|
|
|
update_empty_left_panel_message: noop,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const unread_ui = mock_esm("../src/unread_ui");
|
|
|
|
const message_lists = mock_esm("../src/message_lists", {
|
2024-02-05 19:03:29 +01:00
|
|
|
current: undefined,
|
2021-03-30 02:21:21 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const message_view_header = mock_esm("../src/message_view_header", {
|
2022-07-10 01:06:33 +02:00
|
|
|
maybe_rerender_title_area_for_stream() {},
|
|
|
|
});
|
2023-09-06 23:14:37 +02:00
|
|
|
mock_esm("../src/recent_view_ui", {
|
2022-11-17 23:33:43 +01:00
|
|
|
complete_rerender() {},
|
2021-03-06 17:37:51 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/settings_notifications", {
|
2022-11-17 23:33:43 +01:00
|
|
|
update_page() {},
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-07-29 02:37:35 +02:00
|
|
|
mock_esm("../src/overlays", {
|
|
|
|
streams_open: () => true,
|
|
|
|
});
|
2023-09-21 06:25:07 +02:00
|
|
|
const user_profile = mock_esm("../src/user_profile");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
const {Filter} = zrequire("../src/filter");
|
2023-11-17 01:32:35 +01:00
|
|
|
const activity_ui = zrequire("activity_ui");
|
|
|
|
const {buddy_list} = zrequire("buddy_list");
|
2021-03-07 13:57:14 +01:00
|
|
|
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");
|
2023-10-04 22:48:28 +02:00
|
|
|
const settings_config = zrequire("settings_config");
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
const stream_events = zrequire("stream_events");
|
2023-03-31 06:27:36 +02:00
|
|
|
const compose_recipient = zrequire("compose_recipient");
|
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"}]);
|
2024-02-13 03:44:04 +01:00
|
|
|
message_lists.current = {
|
|
|
|
data: {
|
|
|
|
filter,
|
|
|
|
},
|
|
|
|
};
|
2021-03-14 14:56:28 +01:00
|
|
|
}
|
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
|
|
|
|
2023-02-09 21:45:47 +01:00
|
|
|
test("update_property", ({override, override_rewire}) => {
|
2023-05-07 14:45:04 +02:00
|
|
|
override_rewire(compose_recipient, "possibly_update_stream_name_in_compose", noop);
|
|
|
|
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
|
2023-02-09 21:45:47 +01:00
|
|
|
|
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();
|
2023-10-03 10:38:49 +02:00
|
|
|
override(stream_color_events, "update_stream_color", stub.f);
|
2021-02-13 03:46:14 +01:00
|
|
|
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
|
|
|
|
2022-08-15 12:04:55 +02:00
|
|
|
// Test in home view (code coverage; until event/property removed)
|
|
|
|
{
|
|
|
|
stream_events.update_property(stream_id, "in_home_view", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test is muted
|
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);
|
2022-08-15 12:04:55 +02:00
|
|
|
stream_events.update_property(stream_id, "is_muted", true);
|
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, 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",
|
2023-10-04 22:48:28 +02:00
|
|
|
settings_config.stream_post_policy_values.admins.code,
|
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);
|
2023-10-04 22:48:28 +02:00
|
|
|
assert.equal(args.val, settings_config.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
|
|
|
}
|
2022-12-29 18:36:06 +01:00
|
|
|
|
2023-07-12 12:57:57 +02:00
|
|
|
// Test stream can_remove_subscribers_group change event
|
2022-12-29 18:36:06 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
|
|
|
override(stream_settings_ui, "update_can_remove_subscribers_group_id", stub.f);
|
2023-07-12 12:57:57 +02:00
|
|
|
stream_events.update_property(stream_id, "can_remove_subscribers_group", 3);
|
2022-12-29 18:36:06 +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, 3);
|
|
|
|
}
|
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
|
|
|
});
|
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
test("marked_subscribed (normal)", ({override}) => {
|
2021-03-14 14:56:28 +01:00
|
|
|
const sub = {...frontend};
|
|
|
|
stream_data.add_sub(sub);
|
2023-10-03 10:38:49 +02:00
|
|
|
override(stream_color_events, "update_stream_color", noop);
|
2023-11-17 01:32:35 +01:00
|
|
|
override(buddy_list, "populate", noop);
|
|
|
|
activity_ui.set_cursor_and_filter();
|
2021-02-11 15:44:42 +01:00
|
|
|
|
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 list_updated = false;
|
|
|
|
|
|
|
|
const stream_list_stub = make_stub();
|
|
|
|
const message_view_header_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);
|
2022-08-15 21:32:10 +02:00
|
|
|
override(stream_list, "update_subscribe_to_more_streams_link", noop);
|
2022-10-25 01:31:19 +02:00
|
|
|
override(unread_ui, "update_unread_counts", noop);
|
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;
|
|
|
|
});
|
2023-07-29 02:37:35 +02:00
|
|
|
override(user_profile, "update_user_profile_streams_list_for_users", noop);
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
|
2023-03-25 14:10:45 +01:00
|
|
|
|
2021-03-14 14:56:28 +01:00
|
|
|
stream_events.mark_subscribed(sub, [], "blue");
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2022-10-25 01:31:19 +02:00
|
|
|
const 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");
|
2024-02-13 03:44:04 +01:00
|
|
|
message_lists.current = undefined;
|
2021-02-11 15:44:42 +01:00
|
|
|
});
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
test("marked_subscribed (color)", ({override}) => {
|
2021-02-11 15:44:42 +01:00
|
|
|
override(stream_list, "add_sidebar_row", noop);
|
2022-08-15 21:32:10 +02:00
|
|
|
override(stream_list, "update_subscribe_to_more_streams_link", noop);
|
2022-10-25 01:31:19 +02:00
|
|
|
override(unread_ui, "update_unread_counts", noop);
|
2021-02-11 15:44:42 +01:00
|
|
|
|
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");
|
2023-07-29 02:37:35 +02:00
|
|
|
override(user_profile, "update_user_profile_streams_list_for_users", noop);
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
|
2023-03-25 14:10:45 +01: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();
|
2023-10-05 23:35:50 +02:00
|
|
|
override(stream_settings_api, "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
|
|
|
});
|
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
test("marked_subscribed (emails)", ({override}) => {
|
2021-03-14 14:56:28 +01:00
|
|
|
const sub = {...frontend};
|
|
|
|
stream_data.add_sub(sub);
|
2023-10-03 10:38:49 +02:00
|
|
|
override(stream_color_events, "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(stream_list, "add_sidebar_row", noop);
|
2022-08-15 21:32:10 +02:00
|
|
|
override(stream_list, "update_subscribe_to_more_streams_link", noop);
|
2022-10-25 01:31:19 +02:00
|
|
|
override(unread_ui, "update_unread_counts", 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);
|
2023-07-29 02:37:35 +02:00
|
|
|
override(user_profile, "update_user_profile_streams_list_for_users", noop);
|
2017-07-03 21:55:03 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
|
2023-03-25 14:10:45 +01: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
|
|
|
|
2023-05-07 14:45:04 +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);
|
2022-08-15 21:32:10 +02:00
|
|
|
override(stream_list, "update_subscribe_to_more_streams_link", noop);
|
2022-10-25 01:31:19 +02:00
|
|
|
override(unread_ui, "update_unread_counts", noop);
|
2023-07-29 02:37:35 +02:00
|
|
|
override(user_profile, "update_user_profile_streams_list_for_users", noop);
|
2017-07-03 22:17:16 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
|
2023-03-25 14:10:45 +01: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
|
|
|
|
2023-05-07 14:45:04 +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);
|
2022-08-15 21:32:10 +02:00
|
|
|
override(stream_list, "update_subscribe_to_more_streams_link", noop);
|
2022-10-25 01:31:19 +02:00
|
|
|
override(unread_ui, "update_unread_counts", noop);
|
2023-04-11 23:36:11 +02:00
|
|
|
override(unread_ui, "hide_unread_banner", noop);
|
2023-07-29 02:37:35 +02:00
|
|
|
override(user_profile, "update_user_profile_streams_list_for_users", noop);
|
2023-11-17 01:32:35 +01:00
|
|
|
override(buddy_list, "populate", noop);
|
2017-07-06 15:43:41 +02:00
|
|
|
|
2023-04-18 04:45:32 +02:00
|
|
|
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
|
2023-03-25 14:10:45 +01: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
|
|
|
|
2024-02-13 03:44:04 +01:00
|
|
|
message_lists.current = undefined;
|
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
|
|
|
});
|
2022-10-11 14:20:27 +02:00
|
|
|
|
2023-11-17 01:32:35 +01:00
|
|
|
test("process_subscriber_update", ({override, override_rewire}) => {
|
2022-10-11 14:20:27 +02:00
|
|
|
const subsStub = make_stub();
|
|
|
|
stream_settings_ui.update_subscribers_ui = subsStub.f;
|
|
|
|
|
2023-11-17 01:32:35 +01:00
|
|
|
let build_user_sidebar_called = false;
|
|
|
|
override_rewire(activity_ui, "build_user_sidebar", () => {
|
|
|
|
build_user_sidebar_called = true;
|
|
|
|
});
|
2023-07-29 02:37:35 +02:00
|
|
|
override(user_profile, "update_user_profile_streams_list_for_users", noop);
|
|
|
|
// Sample user IDs
|
|
|
|
const userIds = [104, 2, 3];
|
2022-10-11 14:20:27 +02:00
|
|
|
// Sample stream IDs
|
|
|
|
const streamIds = [1, 2, 3];
|
|
|
|
|
|
|
|
// Call the function being tested
|
2023-07-29 02:37:35 +02:00
|
|
|
stream_events.process_subscriber_update(userIds, streamIds);
|
2022-10-11 14:20:27 +02:00
|
|
|
|
|
|
|
// Assert that update_subscribers_ui is called for each stream ID
|
|
|
|
assert.equal(subsStub.num_calls, streamIds.length);
|
2023-11-17 01:32:35 +01:00
|
|
|
|
|
|
|
assert.ok(!build_user_sidebar_called);
|
|
|
|
|
|
|
|
// For a stream the user is currently viewing, we rebuild the user sidebar
|
|
|
|
// when someone subscribes to that stream.
|
|
|
|
override_rewire(narrow_state, "stream_id", () => 1);
|
|
|
|
stream_events.process_subscriber_update(userIds, streamIds);
|
|
|
|
assert.ok(build_user_sidebar_called);
|
2022-10-11 14:20:27 +02:00
|
|
|
});
|