2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
const {
|
|
|
|
clear_buddy_list,
|
|
|
|
override_user_matches_narrow,
|
|
|
|
buddy_list_add_user_matching_view,
|
|
|
|
buddy_list_add_other_user,
|
|
|
|
stub_buddy_list_elements,
|
|
|
|
} = require("./lib/buddy_list");
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespace");
|
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");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $window_stub = $.create("window-stub");
|
|
|
|
set_global("to_$", () => $window_stub);
|
2023-12-14 23:51:33 +01:00
|
|
|
$(window).idle = noop;
|
2018-08-01 21:17:03 +02:00
|
|
|
|
|
|
|
const _document = {
|
2020-07-20 22:18:43 +02:00
|
|
|
hasFocus() {
|
2017-01-09 18:20:31 +01:00
|
|
|
return true;
|
|
|
|
},
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
2017-01-09 18:20:31 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const channel = mock_esm("../src/channel");
|
2024-10-01 00:04:14 +02:00
|
|
|
const electron_bridge = mock_esm("../src/electron_bridge");
|
2023-02-22 23:04:10 +01:00
|
|
|
const padded_widget = mock_esm("../src/padded_widget");
|
|
|
|
const pm_list = mock_esm("../src/pm_list");
|
|
|
|
const popovers = mock_esm("../src/popovers");
|
|
|
|
const resize = mock_esm("../src/resize");
|
2023-11-28 18:24:43 +01:00
|
|
|
const settings_data = mock_esm("../src/settings_data");
|
2023-09-28 11:08:09 +02:00
|
|
|
const sidebar_ui = mock_esm("../src/sidebar_ui");
|
2023-02-22 23:04:10 +01:00
|
|
|
const scroll_util = mock_esm("../src/scroll_util");
|
|
|
|
const watchdog = mock_esm("../src/watchdog");
|
2017-05-12 20:16:39 +02:00
|
|
|
|
2021-03-06 17:37:51 +01:00
|
|
|
set_global("document", _document);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
2024-06-11 21:39:15 +02:00
|
|
|
const direct_message_group_data = zrequire("direct_message_group_data");
|
2021-05-18 22:44:11 +02:00
|
|
|
const keydown_util = zrequire("keydown_util");
|
2021-06-27 21:38:26 +02:00
|
|
|
const muted_users = zrequire("muted_users");
|
2021-02-10 04:53:22 +01:00
|
|
|
const presence = zrequire("presence");
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2021-02-10 04:53:22 +01:00
|
|
|
const buddy_data = zrequire("buddy_data");
|
2021-02-28 01:13:13 +01:00
|
|
|
const {buddy_list} = zrequire("buddy_list");
|
2021-02-10 04:53:22 +01:00
|
|
|
const activity = zrequire("activity");
|
2023-10-05 10:20:16 +02:00
|
|
|
const activity_ui = zrequire("activity_ui");
|
2023-08-23 02:18:53 +02:00
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
const peer_data = zrequire("peer_data");
|
2024-02-05 19:03:29 +01:00
|
|
|
const message_lists = zrequire("message_lists");
|
2023-11-21 03:05:45 +01:00
|
|
|
const util = zrequire("util");
|
2023-08-23 02:18:53 +02:00
|
|
|
const {Filter} = zrequire("../src/filter");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {set_current_user, set_realm} = zrequire("state_data");
|
2024-10-09 08:44:21 +02:00
|
|
|
const {initialize_user_settings} = zrequire("user_settings");
|
|
|
|
|
2024-10-09 22:44:13 +02:00
|
|
|
const current_user = {};
|
|
|
|
set_current_user(current_user);
|
|
|
|
const realm = {};
|
|
|
|
set_realm(realm);
|
2024-10-09 08:44:21 +02:00
|
|
|
const user_settings = {};
|
|
|
|
initialize_user_settings({user_settings});
|
2016-11-11 19:30:04 +01:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "me@zulip.com",
|
2017-02-05 00:22:16 +01:00
|
|
|
user_id: 999,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Me Myself",
|
2017-02-05 00:22:16 +01:00
|
|
|
};
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@zulip.com",
|
2016-10-30 20:46:57 +01:00
|
|
|
user_id: 1,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice Smith",
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
2018-04-12 23:40:03 +02:00
|
|
|
const fred = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "fred@zulip.com",
|
2016-10-30 20:46:57 +01:00
|
|
|
user_id: 2,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: "Fred Flintstone",
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
2018-04-12 23:40:03 +02:00
|
|
|
const jill = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "jill@zulip.com",
|
2016-10-30 20:46:57 +01:00
|
|
|
user_id: 3,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Jill Hill",
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
2018-04-12 23:40:03 +02:00
|
|
|
const mark = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "mark@zulip.com",
|
2016-10-30 20:46:57 +01:00
|
|
|
user_id: 4,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Marky Mark",
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
2018-04-12 23:40:03 +02:00
|
|
|
const norbert = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "norbert@zulip.com",
|
2016-10-30 20:46:57 +01:00
|
|
|
user_id: 5,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Norbert Oswald",
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const zoe = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "zoe@example.com",
|
2017-03-31 00:18:04 +02:00
|
|
|
user_id: 6,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Zoe Yang",
|
2017-03-31 00:18:04 +02:00
|
|
|
};
|
2016-11-17 21:43:12 +01:00
|
|
|
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(alice);
|
|
|
|
people.add_active_user(fred);
|
|
|
|
people.add_active_user(jill);
|
|
|
|
people.add_active_user(mark);
|
|
|
|
people.add_active_user(norbert);
|
|
|
|
people.add_active_user(zoe);
|
|
|
|
people.add_active_user(me);
|
2017-03-31 00:18:04 +02:00
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
const $alice_stub = $.create("alice stub");
|
|
|
|
const $fred_stub = $.create("fred stub");
|
|
|
|
|
|
|
|
const rome_sub = {name: "Rome", subscribed: true, stream_id: 1001};
|
|
|
|
function add_sub_and_set_as_current_narrow(sub) {
|
|
|
|
stream_data.add_sub(sub);
|
2024-08-03 03:05:34 +02:00
|
|
|
const filter = new Filter([{operator: "stream", operand: sub.stream_id}]);
|
2024-02-05 19:03:29 +01:00
|
|
|
message_lists.set_current({
|
|
|
|
data: {
|
|
|
|
filter,
|
|
|
|
},
|
|
|
|
});
|
2021-05-18 21:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function test(label, f) {
|
2021-06-28 00:41:05 +02:00
|
|
|
run_test(label, (helpers) => {
|
2024-10-09 21:10:22 +02:00
|
|
|
helpers.override(user_settings, "presence_enabled", true);
|
2021-05-18 21:50:13 +02:00
|
|
|
// Simulate a small window by having the
|
|
|
|
// fill_screen_with_content render the entire
|
|
|
|
// list in one pass. We will do more refined
|
|
|
|
// testing in the buddy_list node tests.
|
2021-06-28 00:41:05 +02:00
|
|
|
helpers.override(buddy_list, "fill_screen_with_content", () => {
|
2021-05-18 21:50:13 +02:00
|
|
|
buddy_list.render_more({
|
|
|
|
chunk_size: 100,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
stub_buddy_list_elements();
|
|
|
|
helpers.override(buddy_list, "render_section_headers", noop);
|
|
|
|
helpers.override(buddy_list, "render_view_user_list_links", noop);
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
presence.presence_info.set(alice.user_id, {status: "active"});
|
|
|
|
presence.presence_info.set(fred.user_id, {status: "active"});
|
|
|
|
presence.presence_info.set(jill.user_id, {status: "active"});
|
|
|
|
presence.presence_info.set(mark.user_id, {status: "idle"});
|
|
|
|
presence.presence_info.set(norbert.user_id, {status: "active"});
|
|
|
|
presence.presence_info.set(zoe.user_id, {status: "active"});
|
|
|
|
presence.presence_info.set(me.user_id, {status: "active"});
|
2021-05-18 22:20:51 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
clear_buddy_list(buddy_list);
|
2021-06-27 21:38:26 +02:00
|
|
|
muted_users.set_muted_users([]);
|
2021-05-18 22:47:01 +02:00
|
|
|
|
|
|
|
activity.clear_for_testing();
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.set_cursor_and_filter();
|
2021-05-18 22:47:01 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
f(helpers);
|
2022-07-10 01:06:33 +02:00
|
|
|
|
|
|
|
presence.clear_internal_data();
|
2021-05-18 21:50:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-18 22:47:01 +02:00
|
|
|
run_test("reload_defaults", () => {
|
|
|
|
activity.clear_for_testing();
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.clear_for_testing();
|
2021-02-20 17:02:39 +01:00
|
|
|
blueslip.expect("warn", "get_filter_text() is called before initialization");
|
2023-10-05 10:20:16 +02:00
|
|
|
assert.equal(activity_ui.get_filter_text(), "");
|
2021-02-20 17:02:39 +01:00
|
|
|
});
|
|
|
|
|
2024-10-09 21:10:22 +02:00
|
|
|
test("get_status", ({override}) => {
|
2021-04-03 19:07:13 +02:00
|
|
|
page_params.realm_users = [];
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 999);
|
2021-04-03 19:07:13 +02:00
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
assert.equal(presence.get_status(current_user.user_id), "active");
|
2021-05-18 22:20:51 +02:00
|
|
|
assert.equal(presence.get_status(alice.user_id), "active");
|
|
|
|
assert.equal(presence.get_status(mark.user_id), "idle");
|
2017-04-13 04:28:15 +02:00
|
|
|
assert.equal(presence.get_status(fred.user_id), "active");
|
2021-05-18 22:20:51 +02:00
|
|
|
|
2024-10-09 21:10:22 +02:00
|
|
|
override(user_settings, "presence_enabled", false);
|
2024-02-13 02:08:16 +01:00
|
|
|
assert.equal(presence.get_status(current_user.user_id), "offline");
|
2024-10-09 21:10:22 +02:00
|
|
|
override(user_settings, "presence_enabled", true);
|
2024-02-13 02:08:16 +01:00
|
|
|
assert.equal(presence.get_status(current_user.user_id), "active");
|
2021-12-04 01:20:20 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
presence.presence_info.delete(zoe.user_id);
|
2017-10-12 18:08:42 +02:00
|
|
|
assert.equal(presence.get_status(zoe.user_id), "offline");
|
2021-05-18 22:20:51 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
presence.presence_info.set(alice.user_id, {status: "whatever"});
|
2021-05-18 22:20:51 +02:00
|
|
|
assert.equal(presence.get_status(alice.user_id), "whatever");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-13 04:28:15 +02:00
|
|
|
|
2021-05-18 21:50:13 +02:00
|
|
|
test("sort_users", () => {
|
2018-04-12 23:40:03 +02:00
|
|
|
const user_ids = [alice.user_id, fred.user_id, jill.user_id];
|
2013-08-09 14:42:49 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
presence.presence_info.delete(alice.user_id);
|
2021-05-18 22:20:51 +02:00
|
|
|
|
2024-10-02 07:09:29 +02:00
|
|
|
buddy_data.sort_users(user_ids, new Set());
|
2013-08-09 14:42:49 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(user_ids, [fred.user_id, jill.user_id, alice.user_id]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2024-06-11 21:39:15 +02:00
|
|
|
test("direct_message_group_data.process_loaded_messages", () => {
|
|
|
|
// TODO: move this to a module for just testing `direct_message_group_data`
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2024-06-11 21:45:05 +02:00
|
|
|
const direct_message_group1 = "jill@zulip.com,norbert@zulip.com";
|
2018-04-12 23:40:03 +02:00
|
|
|
const timestamp1 = 1382479029; // older
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2024-06-11 21:45:05 +02:00
|
|
|
const direct_message_group2 = "alice@zulip.com,fred@zulip.com";
|
2018-04-12 23:40:03 +02:00
|
|
|
const timestamp2 = 1382479033; // newer
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const old_timestamp = 1382479000;
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const messages = [
|
2017-02-05 00:22:16 +01:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2017-02-05 00:22:16 +01:00
|
|
|
display_recipient: [{id: jill.user_id}, {id: norbert.user_id}],
|
2016-12-03 23:17:57 +01:00
|
|
|
timestamp: timestamp1,
|
2013-10-23 20:44:31 +02:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2013-10-23 20:44:31 +02:00
|
|
|
},
|
2023-06-16 17:37:19 +02:00
|
|
|
// direct message to myself
|
2013-10-23 20:44:31 +02:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2023-06-16 17:37:19 +02:00
|
|
|
display_recipient: [{id: me.user_id}],
|
2013-10-23 20:44:31 +02:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2017-02-05 00:22:16 +01:00
|
|
|
display_recipient: [{id: alice.user_id}, {id: fred.user_id}],
|
2016-12-03 23:17:57 +01:00
|
|
|
timestamp: timestamp2,
|
2013-10-23 20:44:31 +02:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2017-02-05 00:22:16 +01:00
|
|
|
display_recipient: [{id: fred.user_id}, {id: alice.user_id}],
|
2016-12-03 23:17:57 +01:00
|
|
|
timestamp: old_timestamp,
|
|
|
|
},
|
2013-10-23 20:44:31 +02:00
|
|
|
];
|
|
|
|
|
2024-06-11 21:39:15 +02:00
|
|
|
direct_message_group_data.process_loaded_messages(messages);
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2024-06-11 21:45:05 +02:00
|
|
|
const user_ids_string1 = people.emails_strings_to_user_ids_string(direct_message_group1);
|
|
|
|
const user_ids_string2 = people.emails_strings_to_user_ids_string(direct_message_group2);
|
|
|
|
assert.deepEqual(direct_message_group_data.get_direct_message_groups(), [
|
|
|
|
user_ids_string2,
|
|
|
|
user_ids_string1,
|
|
|
|
]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
test("presence_list_full_update", ({override, mock_template}) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
override(padded_widget, "update_padding", noop);
|
2023-08-23 02:18:53 +02:00
|
|
|
let presence_rows = [];
|
2021-12-01 07:30:00 +01:00
|
|
|
mock_template("presence_rows.hbs", false, (data) => {
|
2023-08-23 02:18:53 +02:00
|
|
|
presence_rows = [...presence_rows, ...data.presence_rows];
|
2024-04-04 00:53:08 +02:00
|
|
|
return "<presence-rows-stub>";
|
2021-06-27 14:35:21 +02:00
|
|
|
});
|
|
|
|
|
2024-03-19 19:45:03 +01:00
|
|
|
$("input.user-list-filter").trigger("focus");
|
2018-04-22 17:46:20 +02:00
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
const user_ids = activity_ui.build_user_sidebar();
|
2018-07-14 14:06:30 +02:00
|
|
|
|
|
|
|
assert.deepEqual(user_ids, [
|
2018-12-18 18:50:58 +01:00
|
|
|
me.user_id,
|
2021-05-18 22:20:51 +02:00
|
|
|
alice.user_id,
|
2018-07-14 14:06:30 +02:00
|
|
|
fred.user_id,
|
|
|
|
jill.user_id,
|
|
|
|
norbert.user_id,
|
|
|
|
zoe.user_id,
|
|
|
|
mark.user_id,
|
2017-01-09 18:20:31 +01:00
|
|
|
]);
|
2023-08-23 02:18:53 +02:00
|
|
|
|
|
|
|
assert.equal(presence_rows.length, 7);
|
|
|
|
assert.equal(presence_rows[0].user_id, me.user_id);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-24 19:46:15 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
function simulate_right_column_buddy_list() {
|
2024-03-19 19:45:03 +01:00
|
|
|
$("input.user-list-filter").closest = (selector) => {
|
2018-04-21 14:59:03 +02:00
|
|
|
assert.equal(selector, ".app-main [class^='column-']");
|
2020-07-15 01:29:15 +02:00
|
|
|
return $.create("right-sidebar").addClass("column-right");
|
2018-04-21 14:59:03 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-16 17:37:19 +02:00
|
|
|
test("direct_message_update_dom_counts", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $count = $.create("alice-unread-count");
|
2018-04-12 23:40:03 +02:00
|
|
|
const pm_key = alice.user_id.toString();
|
2022-01-25 11:36:19 +01:00
|
|
|
const $li = $.create("alice stub");
|
2023-08-23 02:18:53 +02:00
|
|
|
buddy_list_add_user_matching_view(pm_key, $li);
|
2022-01-25 11:36:19 +01:00
|
|
|
$li.set_find_results(".unread_count", $count);
|
|
|
|
$count.set_parents_result("li", $li);
|
2017-05-24 19:46:15 +02:00
|
|
|
|
2020-02-03 09:39:58 +01:00
|
|
|
const counts = new Map();
|
2017-05-24 19:46:15 +02:00
|
|
|
counts.set(pm_key, 5);
|
2022-01-25 11:36:19 +01:00
|
|
|
$li.addClass("user_sidebar_entry");
|
2017-05-24 19:46:15 +02:00
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.update_dom_with_unread_counts({pm_count: counts});
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($count.text(), "5");
|
2017-05-24 19:46:15 +02:00
|
|
|
|
|
|
|
counts.set(pm_key, 0);
|
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.update_dom_with_unread_counts({pm_count: counts});
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($count.text(), "");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-24 19:46:15 +02:00
|
|
|
|
2023-11-21 03:05:45 +01:00
|
|
|
test("handlers", ({override, override_rewire, mock_template}) => {
|
2021-05-18 17:20:17 +02:00
|
|
|
let filter_key_handlers;
|
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
mock_template("presence_rows.hbs", false, () => "<presence-rows-stub>");
|
2021-06-27 14:35:21 +02:00
|
|
|
|
2021-05-18 17:20:17 +02:00
|
|
|
override(keydown_util, "handle", (opts) => {
|
|
|
|
filter_key_handlers = opts.handlers;
|
|
|
|
});
|
2023-12-14 23:51:33 +01:00
|
|
|
override(scroll_util, "scroll_element_into_container", noop);
|
|
|
|
override(padded_widget, "update_padding", noop);
|
|
|
|
override(popovers, "hide_all", noop);
|
|
|
|
override(sidebar_ui, "hide_all", noop);
|
|
|
|
override(sidebar_ui, "show_userlist_sidebar", noop);
|
|
|
|
override(resize, "resize_sidebars", noop);
|
2021-05-18 17:20:17 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
// This is kind of weak coverage; we are mostly making sure that
|
|
|
|
// keys and clicks got mapped to functions that don't crash.
|
2023-08-23 02:18:53 +02:00
|
|
|
const $me_li = $.create("me stub");
|
|
|
|
const $alice_li = $.create("alice stub");
|
|
|
|
const $fred_li = $.create("fred stub");
|
|
|
|
|
|
|
|
// Simulate a small window by having the
|
|
|
|
// fill_screen_with_content render the entire
|
|
|
|
// list in one pass. We will do more refined
|
|
|
|
// testing in the buddy_list node tests.
|
|
|
|
override(buddy_list, "fill_screen_with_content", () => {
|
|
|
|
buddy_list.render_more({
|
|
|
|
chunk_size: 100,
|
|
|
|
});
|
|
|
|
buddy_list_add_user_matching_view(me.user_id, $me_li);
|
|
|
|
buddy_list_add_user_matching_view(alice.user_id, $alice_li);
|
|
|
|
buddy_list_add_user_matching_view(fred.user_id, $fred_li);
|
|
|
|
});
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
let narrowed;
|
|
|
|
|
2023-11-21 03:05:45 +01:00
|
|
|
function narrow_by_email(email) {
|
2021-02-24 13:30:27 +01:00
|
|
|
assert.equal(email, "alice@zulip.com");
|
|
|
|
narrowed = true;
|
2023-11-21 03:05:45 +01:00
|
|
|
}
|
2021-02-24 13:30:27 +01:00
|
|
|
|
2018-07-16 15:16:33 +02:00
|
|
|
function init() {
|
2021-02-20 17:02:39 +01:00
|
|
|
$.clear_all_elements();
|
2023-08-23 02:18:53 +02:00
|
|
|
stub_buddy_list_elements();
|
2023-11-21 03:05:45 +01:00
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
buddy_list.start_scroll_handler = noop;
|
|
|
|
override_rewire(util, "call_function_periodically", noop);
|
|
|
|
override_rewire(activity, "send_presence_to_server", noop);
|
2023-11-21 03:05:45 +01:00
|
|
|
activity_ui.initialize({narrow_by_email});
|
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
buddy_list.populate({
|
|
|
|
all_user_ids: [me.user_id, alice.user_id, fred.user_id],
|
|
|
|
});
|
2018-07-16 15:16:33 +02:00
|
|
|
}
|
2018-07-14 18:08:13 +02:00
|
|
|
|
|
|
|
(function test_filter_keys() {
|
2018-07-16 15:16:33 +02:00
|
|
|
init();
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.user_cursor.go_to(alice.user_id);
|
2021-05-26 19:51:07 +02:00
|
|
|
filter_key_handlers.ArrowDown();
|
|
|
|
filter_key_handlers.ArrowUp();
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
(function test_click_filter() {
|
2018-07-16 15:16:33 +02:00
|
|
|
init();
|
2018-04-21 14:59:03 +02:00
|
|
|
const e = {
|
2022-11-17 23:33:43 +01:00
|
|
|
stopPropagation() {},
|
2018-02-12 23:31:17 +01:00
|
|
|
};
|
|
|
|
|
2024-03-19 19:45:03 +01:00
|
|
|
const handler = $("input.user-list-filter").get_on_handler("focus");
|
2018-04-21 14:59:03 +02:00
|
|
|
handler(e);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
(function test_click_header_filter() {
|
2018-07-16 15:16:33 +02:00
|
|
|
init();
|
2018-04-21 14:59:03 +02:00
|
|
|
const e = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
const handler = $("#userlist-header").get_on_handler("click");
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
simulate_right_column_buddy_list();
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
handler(e);
|
|
|
|
// and click again
|
|
|
|
handler(e);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-04-19 21:50:14 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
(function test_enter_key() {
|
2018-07-16 15:16:33 +02:00
|
|
|
init();
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2024-03-19 19:45:03 +01:00
|
|
|
$("input.user-list-filter").val("al");
|
2021-02-24 13:30:27 +01:00
|
|
|
narrowed = false;
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.user_cursor.go_to(alice.user_id);
|
2021-05-26 19:51:07 +02:00
|
|
|
filter_key_handlers.Enter();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(narrowed);
|
2018-04-21 14:59:03 +02:00
|
|
|
|
|
|
|
// get line coverage for cleared case
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.user_cursor.clear();
|
2021-05-26 19:51:07 +02:00
|
|
|
filter_key_handlers.Enter();
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-04-21 14:59:03 +02:00
|
|
|
|
|
|
|
(function test_click_handler() {
|
2018-07-16 15:16:33 +02:00
|
|
|
init();
|
2018-04-21 14:59:03 +02:00
|
|
|
// We wire up the click handler in click_handlers.js,
|
|
|
|
// so this just tests the called function.
|
2021-02-24 13:30:27 +01:00
|
|
|
narrowed = false;
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.narrow_for_user({$li: $alice_li});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(narrowed);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-04-21 14:59:03 +02:00
|
|
|
|
|
|
|
(function test_blur_filter() {
|
2018-07-16 15:16:33 +02:00
|
|
|
init();
|
2018-04-21 14:59:03 +02:00
|
|
|
const e = {};
|
2024-03-19 19:45:03 +01:00
|
|
|
const handler = $("input.user-list-filter").get_on_handler("blur");
|
2018-04-21 14:59:03 +02:00
|
|
|
handler(e);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
test("first/prev/next", ({override, override_rewire, mock_template}) => {
|
|
|
|
override_rewire(buddy_data, "user_matches_narrow", override_user_matches_narrow);
|
2024-04-04 00:53:08 +02:00
|
|
|
mock_template("presence_rows.hbs", false, () => "<presence-rows-stub>");
|
2023-12-14 23:51:33 +01:00
|
|
|
override(padded_widget, "update_padding", noop);
|
2023-08-23 02:18:53 +02:00
|
|
|
stub_buddy_list_elements();
|
2021-05-18 17:20:17 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
// empty list
|
2018-07-14 18:08:13 +02:00
|
|
|
assert.equal(buddy_list.first_key(), undefined);
|
2023-08-23 02:18:53 +02:00
|
|
|
blueslip.reset();
|
|
|
|
blueslip.expect("error", "Couldn't find key in buddy list");
|
2018-07-14 18:08:13 +02:00
|
|
|
assert.equal(buddy_list.prev_key(alice.user_id), undefined);
|
2023-08-23 02:18:53 +02:00
|
|
|
blueslip.reset();
|
|
|
|
blueslip.expect("error", "Couldn't find key in buddy list");
|
2018-07-14 18:08:13 +02:00
|
|
|
assert.equal(buddy_list.next_key(alice.user_id), undefined);
|
2023-08-23 02:18:53 +02:00
|
|
|
blueslip.reset();
|
2018-07-14 18:08:13 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
// one user matching the view
|
|
|
|
clear_buddy_list(buddy_list);
|
|
|
|
buddy_list_add_user_matching_view(alice.user_id, $alice_stub);
|
|
|
|
buddy_list.populate({
|
|
|
|
all_user_ids: [alice.user_id],
|
|
|
|
});
|
|
|
|
assert.equal(buddy_list.first_key(), alice.user_id);
|
|
|
|
assert.equal(buddy_list.prev_key(alice.user_id), undefined);
|
|
|
|
assert.equal(buddy_list.next_key(alice.user_id), undefined);
|
2018-07-14 18:08:13 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
// two users matching the view
|
|
|
|
clear_buddy_list(buddy_list);
|
|
|
|
buddy_list_add_user_matching_view(alice.user_id, $alice_stub);
|
|
|
|
buddy_list_add_user_matching_view(fred.user_id, $fred_stub);
|
|
|
|
buddy_list.populate({
|
|
|
|
all_user_ids: [alice.user_id, fred.user_id],
|
|
|
|
});
|
2018-07-14 18:08:13 +02:00
|
|
|
assert.equal(buddy_list.first_key(), alice.user_id);
|
|
|
|
assert.equal(buddy_list.prev_key(alice.user_id), undefined);
|
|
|
|
assert.equal(buddy_list.prev_key(fred.user_id), alice.user_id);
|
2023-08-23 02:18:53 +02:00
|
|
|
assert.equal(buddy_list.next_key(alice.user_id), fred.user_id);
|
|
|
|
assert.equal(buddy_list.next_key(fred.user_id), undefined);
|
|
|
|
|
|
|
|
// one other user
|
|
|
|
clear_buddy_list(buddy_list);
|
|
|
|
buddy_list_add_other_user(fred.user_id, $fred_stub);
|
|
|
|
buddy_list.populate({
|
|
|
|
all_user_ids: [fred.user_id],
|
|
|
|
});
|
|
|
|
assert.equal(buddy_list.first_key(), fred.user_id);
|
|
|
|
assert.equal(buddy_list.prev_key(fred.user_id), undefined);
|
|
|
|
assert.equal(buddy_list.next_key(fred.user_id), undefined);
|
2018-07-14 18:08:13 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
// two other users
|
|
|
|
clear_buddy_list(buddy_list);
|
|
|
|
buddy_list_add_other_user(alice.user_id, $alice_stub);
|
|
|
|
buddy_list_add_other_user(fred.user_id, $fred_stub);
|
|
|
|
buddy_list.populate({
|
|
|
|
all_user_ids: [alice.user_id, fred.user_id],
|
|
|
|
});
|
|
|
|
assert.equal(buddy_list.first_key(), alice.user_id);
|
|
|
|
assert.equal(buddy_list.prev_key(alice.user_id), undefined);
|
|
|
|
assert.equal(buddy_list.prev_key(fred.user_id), alice.user_id);
|
2018-07-14 18:08:13 +02:00
|
|
|
assert.equal(buddy_list.next_key(alice.user_id), fred.user_id);
|
|
|
|
assert.equal(buddy_list.next_key(fred.user_id), undefined);
|
2021-06-27 14:35:21 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
// one user matching the view, and one other user
|
|
|
|
clear_buddy_list(buddy_list);
|
|
|
|
buddy_list_add_user_matching_view(alice.user_id, $alice_stub);
|
|
|
|
buddy_list_add_other_user(alice.user_id, $fred_stub);
|
|
|
|
buddy_list.populate({
|
|
|
|
all_user_ids: [alice.user_id, fred.user_id],
|
|
|
|
});
|
|
|
|
assert.equal(buddy_list.first_key(), alice.user_id);
|
|
|
|
assert.equal(buddy_list.prev_key(alice.user_id), undefined);
|
|
|
|
assert.equal(buddy_list.prev_key(fred.user_id), alice.user_id);
|
|
|
|
assert.equal(buddy_list.next_key(alice.user_id), fred.user_id);
|
|
|
|
assert.equal(buddy_list.next_key(fred.user_id), undefined);
|
2018-07-14 18:08:13 +02:00
|
|
|
});
|
|
|
|
|
2023-08-16 15:58:46 +02:00
|
|
|
test("render_empty_user_list_message", ({override, mock_template}) => {
|
|
|
|
const empty_list_message = "No matching users.";
|
|
|
|
mock_template("empty_list_widget_for_list.hbs", false, (data) => {
|
|
|
|
assert.equal(data.empty_list_message, empty_list_message);
|
2024-04-04 00:53:08 +02:00
|
|
|
return "<empty-list-stub>";
|
2023-08-16 15:58:46 +02:00
|
|
|
});
|
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
let $appended_data;
|
2023-08-16 15:58:46 +02:00
|
|
|
override(buddy_list, "$container", {
|
2024-04-04 00:53:08 +02:00
|
|
|
append($data) {
|
|
|
|
$appended_data = $data;
|
2023-08-16 15:58:46 +02:00
|
|
|
},
|
2024-05-03 02:29:50 +02:00
|
|
|
attr(name) {
|
|
|
|
assert.equal(name, "data-search-results-empty");
|
2023-08-16 15:58:46 +02:00
|
|
|
return empty_list_message;
|
|
|
|
},
|
|
|
|
children: () => [],
|
|
|
|
});
|
|
|
|
|
|
|
|
activity_ui.render_empty_user_list_message_if_needed(buddy_list.$container);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.equal($appended_data.selector, "<empty-list-stub>");
|
2023-08-16 15:58:46 +02:00
|
|
|
});
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
test("insert_one_user_into_empty_list", ({override, mock_template}) => {
|
2024-10-09 21:10:22 +02:00
|
|
|
override(user_settings, "user_list_style", 2);
|
2023-08-23 02:18:53 +02:00
|
|
|
|
|
|
|
override(padded_widget, "update_padding", noop);
|
2021-12-01 07:30:00 +01:00
|
|
|
mock_template("presence_row.hbs", true, (data, html) => {
|
2021-06-27 14:35:21 +02:00
|
|
|
assert.deepEqual(data, {
|
2023-04-11 21:04:33 +02:00
|
|
|
href: "#narrow/dm/1-Alice-Smith",
|
2021-06-27 14:35:21 +02:00
|
|
|
name: "Alice Smith",
|
|
|
|
user_id: 1,
|
|
|
|
is_current_user: false,
|
|
|
|
num_unread: 0,
|
|
|
|
user_circle_class: "user_circle_green",
|
2021-06-27 19:04:17 +02:00
|
|
|
status_emoji_info: undefined,
|
2022-08-12 22:41:06 +02:00
|
|
|
status_text: undefined,
|
|
|
|
user_list_style: {
|
|
|
|
COMPACT: false,
|
|
|
|
WITH_STATUS: true,
|
|
|
|
WITH_AVATAR: false,
|
|
|
|
},
|
2023-09-13 19:30:52 +02:00
|
|
|
should_add_guest_user_indicator: false,
|
2021-06-27 14:35:21 +02:00
|
|
|
});
|
|
|
|
assert.ok(html.startsWith("<li data-user-id="));
|
|
|
|
return html;
|
|
|
|
});
|
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
let $users_matching_view_appended;
|
2024-09-18 08:28:12 +02:00
|
|
|
override(buddy_list.$users_matching_view_list, "append", ($element) => {
|
2024-04-04 00:53:08 +02:00
|
|
|
$users_matching_view_appended = $element;
|
2021-02-20 17:02:39 +01:00
|
|
|
});
|
2024-04-04 00:53:08 +02:00
|
|
|
let $other_users_appended;
|
2024-09-18 08:28:12 +02:00
|
|
|
override(buddy_list.$other_users_list, "append", ($element) => {
|
2024-04-04 00:53:08 +02:00
|
|
|
$other_users_appended = $element;
|
2023-08-23 02:18:53 +02:00
|
|
|
});
|
|
|
|
|
2024-07-09 18:59:01 +02:00
|
|
|
$.create("[data-presence-indicator-user-id]", {
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
to_$() {
|
|
|
|
return {
|
|
|
|
attr: () => 1,
|
|
|
|
removeClass() {
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
addClass: noop,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
add_sub_and_set_as_current_narrow(rome_sub);
|
|
|
|
|
|
|
|
buddy_list_add_user_matching_view(alice.user_id, $alice_stub);
|
|
|
|
peer_data.set_subscribers(rome_sub.stream_id, [alice.user_id]);
|
|
|
|
activity_ui.redraw_user(alice.user_id);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($users_matching_view_appended.selector.includes('data-user-id="1"'));
|
|
|
|
assert.ok($users_matching_view_appended.selector.includes("user_circle_green"));
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
clear_buddy_list(buddy_list);
|
|
|
|
buddy_list_add_other_user(alice.user_id, $alice_stub);
|
|
|
|
peer_data.set_subscribers(rome_sub.stream_id, []);
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user(alice.user_id);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($other_users_appended.selector.includes('data-user-id="1"'));
|
|
|
|
assert.ok($other_users_appended.selector.includes("user_circle_green"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2024-07-09 18:59:01 +02:00
|
|
|
test("insert_alice_then_fred", ({override, override_rewire, mock_template}) => {
|
2023-06-29 21:59:08 +02:00
|
|
|
mock_template("presence_row.hbs", true, (_data, html) => html);
|
2021-06-27 14:35:21 +02:00
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
let $other_users_appended;
|
2024-09-18 08:28:12 +02:00
|
|
|
override(buddy_list.$other_users_list, "append", ($element) => {
|
2024-04-04 00:53:08 +02:00
|
|
|
$other_users_appended = $element;
|
2021-02-20 17:02:39 +01:00
|
|
|
});
|
2023-12-14 23:51:33 +01:00
|
|
|
override(padded_widget, "update_padding", noop);
|
2024-07-09 18:59:01 +02:00
|
|
|
override_rewire(activity_ui, "update_presence_indicators", noop);
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user(alice.user_id);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($other_users_appended.selector.includes('data-user-id="1"'));
|
|
|
|
assert.ok($other_users_appended.selector.includes("user_circle_green"));
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user(fred.user_id);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($other_users_appended.selector.includes('data-user-id="2"'));
|
|
|
|
assert.ok($other_users_appended.selector.includes("user_circle_green"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
test("insert_fred_then_alice_then_rename, both as users matching view", ({
|
|
|
|
override,
|
2024-07-09 18:59:01 +02:00
|
|
|
override_rewire,
|
2023-08-23 02:18:53 +02:00
|
|
|
mock_template,
|
|
|
|
}) => {
|
2023-06-29 21:59:08 +02:00
|
|
|
mock_template("presence_row.hbs", true, (_data, html) => html);
|
2021-06-27 14:35:21 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
add_sub_and_set_as_current_narrow(rome_sub);
|
|
|
|
peer_data.set_subscribers(rome_sub.stream_id, [alice.user_id, fred.user_id]);
|
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
let $users_matching_view_appended;
|
2024-09-18 08:28:12 +02:00
|
|
|
override(buddy_list.$users_matching_view_list, "append", ($element) => {
|
2024-04-04 00:53:08 +02:00
|
|
|
$users_matching_view_appended = $element;
|
2021-02-20 17:02:39 +01:00
|
|
|
});
|
2023-12-14 23:51:33 +01:00
|
|
|
override(padded_widget, "update_padding", noop);
|
2024-07-09 18:59:01 +02:00
|
|
|
override_rewire(activity_ui, "update_presence_indicators", noop);
|
2023-08-23 02:18:53 +02:00
|
|
|
buddy_list_add_user_matching_view(alice.user_id, $alice_stub);
|
|
|
|
buddy_list_add_user_matching_view(fred.user_id, $fred_stub);
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user(fred.user_id);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($users_matching_view_appended.selector.includes('data-user-id="2"'));
|
|
|
|
assert.ok($users_matching_view_appended.selector.includes("user_circle_green"));
|
2018-07-14 14:06:30 +02:00
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
let $inserted;
|
|
|
|
$fred_stub.before = ($element) => {
|
|
|
|
$inserted = $element;
|
2017-05-25 01:49:39 +02:00
|
|
|
};
|
|
|
|
|
2021-02-25 16:07:04 +01:00
|
|
|
let fred_removed;
|
2022-01-25 11:36:19 +01:00
|
|
|
$fred_stub.remove = () => {
|
2021-02-25 16:07:04 +01:00
|
|
|
fred_removed = true;
|
|
|
|
};
|
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user(alice.user_id);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($inserted.selector.includes('data-user-id="1"'));
|
|
|
|
assert.ok($inserted.selector.includes("user_circle_green"));
|
2018-07-14 14:06:30 +02:00
|
|
|
|
|
|
|
// Next rename fred to Aaron.
|
|
|
|
const fred_with_new_name = {
|
|
|
|
email: fred.email,
|
|
|
|
user_id: fred.user_id,
|
|
|
|
full_name: "Aaron",
|
2017-05-25 01:49:39 +02:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(fred_with_new_name);
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
$alice_stub.before = ($element) => {
|
|
|
|
$inserted = $element;
|
2023-08-23 02:18:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
activity_ui.redraw_user(fred_with_new_name.user_id);
|
|
|
|
assert.ok(fred_removed);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($users_matching_view_appended.selector.includes('data-user-id="2"'));
|
2023-08-23 02:18:53 +02:00
|
|
|
|
|
|
|
// restore old Fred data
|
|
|
|
people.add_active_user(fred);
|
|
|
|
});
|
|
|
|
|
2024-07-09 18:59:01 +02:00
|
|
|
test("insert_fred_then_alice_then_rename, both as other users", ({
|
|
|
|
override,
|
|
|
|
override_rewire,
|
|
|
|
mock_template,
|
|
|
|
}) => {
|
2023-08-23 02:18:53 +02:00
|
|
|
mock_template("presence_row.hbs", true, (_data, html) => html);
|
|
|
|
|
|
|
|
add_sub_and_set_as_current_narrow(rome_sub);
|
|
|
|
peer_data.set_subscribers(rome_sub.stream_id, []);
|
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
let $other_users_appended;
|
2024-09-18 08:28:12 +02:00
|
|
|
override(buddy_list.$other_users_list, "append", ($element) => {
|
2024-04-04 00:53:08 +02:00
|
|
|
$other_users_appended = $element;
|
2023-08-23 02:18:53 +02:00
|
|
|
});
|
|
|
|
override(padded_widget, "update_padding", noop);
|
2024-07-09 18:59:01 +02:00
|
|
|
override_rewire(activity_ui, "update_presence_indicators", noop);
|
2023-08-23 02:18:53 +02:00
|
|
|
|
|
|
|
buddy_list_add_other_user(alice.user_id, $alice_stub);
|
|
|
|
buddy_list_add_other_user(fred.user_id, $fred_stub);
|
|
|
|
|
|
|
|
activity_ui.redraw_user(fred.user_id);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($other_users_appended.selector.includes('data-user-id="2"'));
|
|
|
|
assert.ok($other_users_appended.selector.includes("user_circle_green"));
|
2023-08-23 02:18:53 +02:00
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
let $inserted;
|
|
|
|
$fred_stub.before = ($element) => {
|
|
|
|
$inserted = $element;
|
2023-08-23 02:18:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let fred_removed;
|
|
|
|
$fred_stub.remove = () => {
|
|
|
|
fred_removed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
activity_ui.redraw_user(alice.user_id);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($inserted.selector.includes('data-user-id="1"'));
|
|
|
|
assert.ok($inserted.selector.includes("user_circle_green"));
|
2023-08-23 02:18:53 +02:00
|
|
|
|
|
|
|
// Next rename fred to Aaron.
|
|
|
|
const fred_with_new_name = {
|
|
|
|
email: fred.email,
|
|
|
|
user_id: fred.user_id,
|
|
|
|
full_name: "Aaron",
|
|
|
|
};
|
|
|
|
people.add_active_user(fred_with_new_name);
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2024-04-04 00:53:08 +02:00
|
|
|
$alice_stub.before = ($element) => {
|
|
|
|
$inserted = $element;
|
2018-07-14 14:06:30 +02:00
|
|
|
};
|
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user(fred_with_new_name.user_id);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(fred_removed);
|
2024-04-04 00:53:08 +02:00
|
|
|
assert.ok($other_users_appended.selector.includes('data-user-id="2"'));
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-07-14 14:06:30 +02:00
|
|
|
// restore old Fred data
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(fred);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2021-05-18 22:44:11 +02:00
|
|
|
test("insert_unfiltered_user_with_filter", () => {
|
2017-05-25 01:49:39 +02:00
|
|
|
// This test only tests that we do not explode when
|
|
|
|
// try to insert Fred into a list where he does not
|
|
|
|
// match the search filter.
|
2024-03-19 19:45:03 +01:00
|
|
|
const $user_filter = $("input.user-list-filter");
|
2022-01-25 11:36:19 +01:00
|
|
|
$user_filter.val("do-not-match-filter");
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user(fred.user_id);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
test("realm_presence_disabled", ({override}) => {
|
|
|
|
override(realm, "realm_presence_disabled", true);
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user();
|
|
|
|
activity_ui.build_user_sidebar();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2021-05-18 21:50:13 +02:00
|
|
|
test("redraw_muted_user", () => {
|
2021-06-27 21:38:26 +02:00
|
|
|
muted_users.add_muted_user(mark.user_id);
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.redraw_user(mark.user_id);
|
2023-08-23 07:54:50 +02:00
|
|
|
assert.equal($("#buddy-list-users-matching-view").html(), "never-been-set");
|
2021-04-23 17:30:00 +02:00
|
|
|
});
|
|
|
|
|
2024-07-09 18:59:01 +02:00
|
|
|
test("update_presence_info", ({override, override_rewire}) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
override(pm_list, "update_private_messages", noop);
|
2024-07-09 18:59:01 +02:00
|
|
|
override_rewire(activity_ui, "update_presence_indicators", noop);
|
2021-05-18 17:20:17 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_presence_disabled", false);
|
|
|
|
override(realm, "server_presence_ping_interval_seconds", 60);
|
|
|
|
override(realm, "server_presence_offline_threshold_seconds", 200);
|
2020-05-26 13:58:18 +02:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const server_time = 500;
|
|
|
|
const info = {
|
2017-06-24 15:15:37 +02:00
|
|
|
website: {
|
|
|
|
status: "active",
|
|
|
|
timestamp: server_time,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $alice_li = $.create("alice stub");
|
2023-08-23 02:18:53 +02:00
|
|
|
buddy_list_add_user_matching_view(alice.user_id, $alice_li);
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let inserted;
|
2021-05-18 23:03:28 +02:00
|
|
|
override(buddy_list, "insert_or_move", () => {
|
2018-04-20 16:13:39 +02:00
|
|
|
inserted = true;
|
2021-05-18 23:03:28 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2020-02-06 04:21:07 +01:00
|
|
|
presence.presence_info.delete(me.user_id);
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.update_presence_info(me.user_id, info, server_time);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(inserted);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.deepEqual(presence.presence_info.get(me.user_id).status, "active");
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2020-02-06 04:21:07 +01:00
|
|
|
presence.presence_info.delete(alice.user_id);
|
2023-10-05 10:20:16 +02:00
|
|
|
activity_ui.update_presence_info(alice.user_id, info, server_time);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(inserted);
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
const expected = {status: "active", last_active: 500};
|
2020-02-06 04:21:07 +01:00
|
|
|
assert.deepEqual(presence.presence_info.get(alice.user_id), expected);
|
2023-11-28 18:24:43 +01:00
|
|
|
|
|
|
|
// Test invalid and inaccessible user IDs.
|
|
|
|
const invalid_user_id = 99;
|
|
|
|
activity_ui.update_presence_info(invalid_user_id, info, server_time);
|
|
|
|
assert.equal(presence.presence_info.get(invalid_user_id), undefined);
|
|
|
|
|
|
|
|
const inaccessible_user_id = 10;
|
|
|
|
settings_data.user_can_access_all_other_users = () => false;
|
|
|
|
const inaccessible_user = people.make_user(
|
|
|
|
inaccessible_user_id,
|
|
|
|
"user10@zulipdev.com",
|
|
|
|
"Unknown user",
|
|
|
|
);
|
|
|
|
people._add_user(inaccessible_user);
|
|
|
|
activity_ui.update_presence_info(inaccessible_user_id, info, server_time);
|
|
|
|
assert.equal(presence.presence_info.get(inaccessible_user_id), undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2024-07-09 18:59:01 +02:00
|
|
|
test("initialize", ({override, override_rewire, mock_template}) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
override(pm_list, "update_private_messages", noop);
|
|
|
|
override(watchdog, "check_for_unsuspend", noop);
|
2023-08-23 02:18:53 +02:00
|
|
|
override(buddy_list, "fill_screen_with_content", noop);
|
2024-07-09 18:59:01 +02:00
|
|
|
override_rewire(activity_ui, "update_presence_indicators", noop);
|
2021-05-18 17:20:17 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
let payload;
|
|
|
|
override(channel, "post", (arg) => {
|
2022-11-09 11:09:28 +01:00
|
|
|
if (payload === undefined) {
|
|
|
|
// This "if" block is added such that we can execute "success"
|
|
|
|
// function when want_redraw is true.
|
|
|
|
payload = arg;
|
|
|
|
}
|
2021-02-24 13:30:27 +01:00
|
|
|
});
|
|
|
|
|
2019-04-18 19:28:25 +02:00
|
|
|
function clear() {
|
|
|
|
$.clear_all_elements();
|
2024-09-18 08:28:12 +02:00
|
|
|
buddy_list.$users_matching_view_list = $("#buddy-list-users-matching-view");
|
|
|
|
buddy_list.$users_matching_view_list.append = noop;
|
|
|
|
buddy_list.$other_users_list = $("#buddy-list-other-users");
|
|
|
|
buddy_list.$other_users_list.append = noop;
|
2023-08-23 02:18:53 +02:00
|
|
|
stub_buddy_list_elements();
|
2024-04-04 00:53:08 +02:00
|
|
|
mock_template("empty_list_widget_for_list.hbs", false, () => "<empty-list-stub>");
|
2023-08-23 02:18:53 +02:00
|
|
|
clear_buddy_list(buddy_list);
|
2020-02-06 03:58:06 +01:00
|
|
|
page_params.presences = {};
|
2019-04-18 19:28:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let scroll_handler_started;
|
2018-07-16 15:16:33 +02:00
|
|
|
buddy_list.start_scroll_handler = () => {
|
|
|
|
scroll_handler_started = true;
|
|
|
|
};
|
|
|
|
|
2021-05-18 21:29:06 +02:00
|
|
|
activity.mark_client_idle();
|
2019-04-18 19:28:25 +02:00
|
|
|
|
2020-07-21 09:44:41 +02:00
|
|
|
$(window).off("focus");
|
2022-11-09 11:09:28 +01:00
|
|
|
|
|
|
|
let set_timeout_function_called = false;
|
|
|
|
set_global("setTimeout", (func) => {
|
|
|
|
if (set_timeout_function_called) {
|
|
|
|
// This conditional is needed to avoid indefinite calls.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set_timeout_function_called = true;
|
|
|
|
func();
|
|
|
|
});
|
|
|
|
|
2018-05-07 03:30:13 +02:00
|
|
|
activity.initialize();
|
2023-11-21 03:05:45 +01:00
|
|
|
activity_ui.initialize({narrow_by_email() {}});
|
2021-05-18 22:47:01 +02:00
|
|
|
payload.success({
|
|
|
|
zephyr_mirror_active: true,
|
|
|
|
presences: {},
|
2023-10-18 20:01:05 +02:00
|
|
|
msg: "",
|
|
|
|
result: "success",
|
|
|
|
server_timestamp: 0,
|
2024-06-05 22:22:17 +02:00
|
|
|
presence_last_update_id: -1,
|
2021-05-18 22:47:01 +02:00
|
|
|
});
|
2020-07-21 06:16:05 +02:00
|
|
|
$(window).trigger("focus");
|
2019-04-18 19:28:25 +02:00
|
|
|
clear();
|
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(scroll_handler_started);
|
|
|
|
assert.ok(!activity.new_user_input);
|
|
|
|
assert.ok(!$("#zephyr-mirror-error").hasClass("show"));
|
2021-05-18 21:29:06 +02:00
|
|
|
assert.equal(activity.compute_active_status(), "active");
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
$(window).idle = (params) => {
|
2018-05-07 03:30:13 +02:00
|
|
|
params.onIdle();
|
|
|
|
};
|
2022-11-09 11:09:28 +01:00
|
|
|
payload = undefined;
|
|
|
|
set_timeout_function_called = false;
|
2018-05-07 03:30:13 +02:00
|
|
|
|
2020-07-21 09:44:41 +02:00
|
|
|
$(window).off("focus");
|
2018-05-07 03:30:13 +02:00
|
|
|
activity.initialize();
|
2023-11-21 03:05:45 +01:00
|
|
|
activity_ui.initialize({narrow_by_email() {}});
|
2021-02-24 13:30:27 +01:00
|
|
|
payload.success({
|
|
|
|
zephyr_mirror_active: false,
|
|
|
|
presences: {},
|
2023-10-18 20:01:05 +02:00
|
|
|
msg: "",
|
|
|
|
result: "success",
|
|
|
|
server_timestamp: 0,
|
2024-06-05 22:22:17 +02:00
|
|
|
presence_last_update_id: -1,
|
2021-02-24 13:30:27 +01:00
|
|
|
});
|
2019-04-18 19:28:25 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($("#zephyr-mirror-error").hasClass("show"));
|
|
|
|
assert.ok(!activity.new_user_input);
|
2021-05-18 21:29:06 +02:00
|
|
|
assert.equal(activity.compute_active_status(), "idle");
|
2018-05-07 03:30:13 +02:00
|
|
|
|
2021-02-22 16:35:19 +01:00
|
|
|
// Exercise the mousemove handler, which just
|
|
|
|
// sets a flag.
|
|
|
|
$("html").get_on_handler("mousemove")();
|
|
|
|
|
2019-04-18 19:28:25 +02:00
|
|
|
clear();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-12-19 18:41:47 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("electron_bridge", ({override_rewire}) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(activity, "send_presence_to_server", noop);
|
2021-05-18 21:29:06 +02:00
|
|
|
|
2021-05-19 16:35:02 +02:00
|
|
|
function with_bridge_idle(bridge_idle, f) {
|
2022-07-09 23:25:05 +02:00
|
|
|
with_overrides(({override}) => {
|
2024-10-01 00:04:14 +02:00
|
|
|
override(electron_bridge, "electron_bridge", {
|
2021-05-19 16:35:02 +02:00
|
|
|
get_idle_on_system: () => bridge_idle,
|
2022-07-09 23:25:05 +02:00
|
|
|
});
|
|
|
|
return f();
|
|
|
|
});
|
2021-05-19 16:35:02 +02:00
|
|
|
}
|
2021-05-18 21:29:06 +02:00
|
|
|
|
2021-05-19 16:35:02 +02:00
|
|
|
with_bridge_idle(true, () => {
|
|
|
|
activity.mark_client_idle();
|
|
|
|
assert.equal(activity.compute_active_status(), "idle");
|
|
|
|
activity.mark_client_active();
|
|
|
|
assert.equal(activity.compute_active_status(), "idle");
|
|
|
|
});
|
2019-03-29 00:13:07 +01:00
|
|
|
|
2022-07-09 23:25:05 +02:00
|
|
|
with_overrides(({override}) => {
|
2024-10-01 00:04:14 +02:00
|
|
|
override(electron_bridge, "electron_bridge", undefined);
|
2021-05-19 16:35:02 +02:00
|
|
|
activity.mark_client_idle();
|
|
|
|
assert.equal(activity.compute_active_status(), "idle");
|
|
|
|
activity.mark_client_active();
|
|
|
|
assert.equal(activity.compute_active_status(), "active");
|
|
|
|
});
|
2021-05-18 21:29:06 +02:00
|
|
|
|
2021-05-19 16:35:02 +02:00
|
|
|
with_bridge_idle(false, () => {
|
|
|
|
activity.mark_client_idle();
|
|
|
|
assert.equal(activity.compute_active_status(), "active");
|
|
|
|
activity.mark_client_active();
|
|
|
|
assert.equal(activity.compute_active_status(), "active");
|
|
|
|
});
|
2019-03-29 00:13:07 +01:00
|
|
|
});
|
2020-08-31 09:35:39 +02:00
|
|
|
|
2021-06-15 18:03:32 +02:00
|
|
|
test("test_send_or_receive_no_presence_for_spectator", () => {
|
|
|
|
page_params.is_spectator = true;
|
2020-09-24 07:50:36 +02:00
|
|
|
activity.send_presence_to_server();
|
2020-08-31 09:35:39 +02:00
|
|
|
});
|
2024-06-05 22:22:17 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
test("check_should_redraw_new_user", ({override}) => {
|
2024-06-05 22:22:17 +02:00
|
|
|
presence.presence_info.set(9999, {status: "active"});
|
|
|
|
|
|
|
|
// A user that wasn't yet known, but has presence info should be redrawn
|
|
|
|
// when being added.
|
|
|
|
assert.equal(activity_ui.check_should_redraw_new_user(9999), true);
|
|
|
|
|
|
|
|
// We don't even build the user sidebar if realm_presence_disabled is true,
|
|
|
|
// so nothing to redraw.
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_presence_disabled", true);
|
2024-06-05 22:22:17 +02:00
|
|
|
assert.equal(activity_ui.check_should_redraw_new_user(9999), false);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_presence_disabled", false);
|
2024-06-05 22:22:17 +02:00
|
|
|
// A new user that didn't have presence info should not be redrawn.
|
|
|
|
assert.equal(activity_ui.check_should_redraw_new_user(99999), false);
|
|
|
|
});
|