2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-07-25 02:02:35 +02:00
|
|
|
const _ = require("lodash");
|
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
const {mock_esm, with_field, zrequire} = require("../zjsunit/namespace");
|
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-03-25 22:35:45 +01:00
|
|
|
const {page_params} = require("../zjsunit/zpage_params");
|
2018-08-01 21:17:03 +02:00
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
const timerender = mock_esm("../../static/js/timerender");
|
2021-02-28 01:14:36 +01:00
|
|
|
|
2021-03-19 14:38:22 +01:00
|
|
|
const compose_fade_helper = zrequire("compose_fade_helper");
|
2021-04-23 17:30:00 +02:00
|
|
|
const muting = zrequire("muting");
|
2021-03-19 14:38:22 +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 presence = zrequire("presence");
|
2021-03-19 14:38:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub_store = zrequire("sub_store");
|
2021-02-10 04:53:22 +01:00
|
|
|
const user_status = zrequire("user_status");
|
|
|
|
const buddy_data = zrequire("buddy_data");
|
2018-04-20 18:22:28 +02:00
|
|
|
|
|
|
|
// The buddy_data module is mostly tested indirectly through
|
|
|
|
// activity.js, but we should feel free to add direct tests
|
|
|
|
// here.
|
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
const selma = {
|
|
|
|
user_id: 1000,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Human Selma",
|
|
|
|
email: "selma@example.com",
|
2018-12-18 19:25:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const me = {
|
|
|
|
user_id: 1001,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Human Myself",
|
|
|
|
email: "self@example.com",
|
2018-12-18 19:25:14 +01:00
|
|
|
};
|
|
|
|
|
2020-05-27 14:46:44 +02:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@zulip.com",
|
2020-05-27 14:46:44 +02:00
|
|
|
user_id: 1002,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice Smith",
|
2020-05-27 14:46:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const fred = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "fred@zulip.com",
|
2020-05-27 14:46:44 +02:00
|
|
|
user_id: 1003,
|
|
|
|
full_name: "Fred Flintstone",
|
|
|
|
};
|
|
|
|
|
|
|
|
const jill = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "jill@zulip.com",
|
2020-05-27 14:46:44 +02:00
|
|
|
user_id: 1004,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Jill Hill",
|
2020-05-27 14:46:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const mark = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "mark@zulip.com",
|
2020-05-27 14:46:44 +02:00
|
|
|
user_id: 1005,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Marky Mark",
|
2020-05-27 14:46:44 +02:00
|
|
|
};
|
|
|
|
|
2019-02-28 16:09:03 +01:00
|
|
|
const old_user = {
|
|
|
|
user_id: 9999,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Old User",
|
|
|
|
email: "old_user@example.com",
|
2019-02-28 16:09:03 +01:00
|
|
|
};
|
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
const bot = {
|
|
|
|
user_id: 55555,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Red Herring Bot",
|
|
|
|
email: "bot@example.com",
|
2018-12-18 19:25:14 +01:00
|
|
|
is_bot: true,
|
2019-08-04 14:57:32 +02:00
|
|
|
bot_owner_id: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
const bot_with_owner = {
|
|
|
|
user_id: 55556,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Blue Herring Bot",
|
|
|
|
email: "bot_with_owner@example.com",
|
2019-08-04 14:57:32 +02:00
|
|
|
is_bot: true,
|
|
|
|
bot_owner_id: 1001,
|
2020-07-15 01:29:15 +02:00
|
|
|
bot_owner_full_name: "Human Myself",
|
2018-12-18 19:25:14 +01:00
|
|
|
};
|
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
function add_canned_users() {
|
|
|
|
people.add_active_user(alice);
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(bot);
|
|
|
|
people.add_active_user(bot_with_owner);
|
2020-05-27 14:46:44 +02:00
|
|
|
people.add_active_user(fred);
|
|
|
|
people.add_active_user(jill);
|
|
|
|
people.add_active_user(mark);
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(old_user);
|
2021-03-14 10:18:07 +01:00
|
|
|
people.add_active_user(selma);
|
|
|
|
}
|
2018-12-18 18:50:58 +01:00
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
function test(label, f) {
|
|
|
|
run_test(label, (override) => {
|
2021-03-19 14:38:22 +01:00
|
|
|
compose_fade_helper.clear_focused_recipient();
|
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
peer_data.clear_for_testing();
|
2021-03-14 10:18:07 +01:00
|
|
|
user_status.initialize({user_status: {}});
|
|
|
|
presence.presence_info.clear();
|
|
|
|
people.init();
|
|
|
|
people.add_active_user(me);
|
|
|
|
people.initialize_current_user(me.user_id);
|
2021-04-23 17:30:00 +02:00
|
|
|
muting.set_muted_users([]);
|
2021-03-14 10:18:07 +01:00
|
|
|
f(override);
|
|
|
|
});
|
2018-09-08 14:41:41 +02:00
|
|
|
}
|
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("huddle_fraction_present", () => {
|
|
|
|
people.add_active_user(alice);
|
|
|
|
people.add_active_user(fred);
|
|
|
|
people.add_active_user(jill);
|
|
|
|
people.add_active_user(mark);
|
2020-05-27 14:46:44 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let huddle = "alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com";
|
2020-05-27 14:46:44 +02:00
|
|
|
huddle = people.emails_strings_to_user_ids_string(huddle);
|
|
|
|
|
|
|
|
let presence_info = new Map();
|
2020-07-16 22:40:18 +02:00
|
|
|
presence_info.set(alice.user_id, {status: "active"}); // counts as present
|
|
|
|
presence_info.set(fred.user_id, {status: "idle"}); // does not count as present
|
2020-05-27 14:46:44 +02:00
|
|
|
// jill not in list
|
2020-07-16 22:40:18 +02:00
|
|
|
presence_info.set(mark.user_id, {status: "offline"}); // does not count
|
2021-02-28 01:12:10 +01:00
|
|
|
presence.__Rewire__("presence_info", presence_info);
|
2020-05-27 14:46:44 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(buddy_data.huddle_fraction_present(huddle), 0.5);
|
2020-05-27 14:46:44 +02:00
|
|
|
|
|
|
|
presence_info = new Map();
|
|
|
|
for (const user of [alice, fred, jill, mark]) {
|
2020-07-16 22:40:18 +02:00
|
|
|
presence_info.set(user.user_id, {status: "active"}); // counts as present
|
2020-05-27 14:46:44 +02:00
|
|
|
}
|
2021-02-28 01:12:10 +01:00
|
|
|
presence.__Rewire__("presence_info", presence_info);
|
2020-05-27 14:46:44 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(buddy_data.huddle_fraction_present(huddle), 1);
|
2020-05-27 14:46:44 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
huddle = "alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com";
|
2020-05-27 14:46:44 +02:00
|
|
|
huddle = people.emails_strings_to_user_ids_string(huddle);
|
|
|
|
presence_info = new Map();
|
2020-07-16 22:40:18 +02:00
|
|
|
presence_info.set(alice.user_id, {status: "idle"});
|
|
|
|
presence_info.set(fred.user_id, {status: "idle"}); // does not count as present
|
2020-05-27 14:46:44 +02:00
|
|
|
// jill not in list
|
2020-07-16 22:40:18 +02:00
|
|
|
presence_info.set(mark.user_id, {status: "offline"}); // does not count
|
2021-02-28 01:12:10 +01:00
|
|
|
presence.__Rewire__("presence_info", presence_info);
|
2020-05-27 14:46:44 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(buddy_data.huddle_fraction_present(huddle), undefined);
|
2020-05-27 14:46:44 +02:00
|
|
|
});
|
|
|
|
|
2021-03-08 16:08:27 +01:00
|
|
|
function set_presence(user_id, status) {
|
|
|
|
presence.presence_info.set(user_id, {
|
|
|
|
status,
|
|
|
|
last_active: 9999,
|
|
|
|
});
|
|
|
|
}
|
2018-04-20 18:22:28 +02:00
|
|
|
|
2021-05-16 17:10:07 +02:00
|
|
|
test("user_circle, level, status_description", () => {
|
2021-03-14 10:18:07 +01:00
|
|
|
add_canned_users();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_presence(selma.user_id, "active");
|
|
|
|
assert.equal(buddy_data.get_user_circle_class(selma.user_id), "user_circle_green");
|
2019-02-17 02:10:42 +01:00
|
|
|
user_status.set_away(selma.user_id);
|
2021-05-16 17:10:07 +02:00
|
|
|
assert.equal(buddy_data.level(selma.user_id), 3);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.get_user_circle_class(selma.user_id), "user_circle_empty_line");
|
2019-02-17 02:10:42 +01:00
|
|
|
user_status.revoke_away(selma.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.get_user_circle_class(selma.user_id), "user_circle_green");
|
2021-05-16 17:10:07 +02:00
|
|
|
assert.equal(buddy_data.status_description(selma.user_id), "translated: Active");
|
2019-02-17 02:10:42 +01:00
|
|
|
|
2021-05-16 17:10:07 +02:00
|
|
|
set_presence(me.user_id, "active");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.get_user_circle_class(me.user_id), "user_circle_green");
|
2019-02-17 02:10:42 +01:00
|
|
|
user_status.set_away(me.user_id);
|
2021-05-16 17:10:07 +02:00
|
|
|
assert.equal(buddy_data.status_description(me.user_id), "translated: Unavailable");
|
|
|
|
assert.equal(buddy_data.level(me.user_id), 0);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.get_user_circle_class(me.user_id), "user_circle_empty_line");
|
2019-02-17 02:10:42 +01:00
|
|
|
user_status.revoke_away(me.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.get_user_circle_class(me.user_id), "user_circle_green");
|
2021-05-16 17:10:07 +02:00
|
|
|
|
|
|
|
set_presence(fred.user_id, "idle");
|
|
|
|
assert.equal(buddy_data.get_user_circle_class(fred.user_id), "user_circle_orange");
|
|
|
|
assert.equal(buddy_data.level(fred.user_id), 2);
|
|
|
|
assert.equal(buddy_data.status_description(fred.user_id), "translated: Idle");
|
|
|
|
|
|
|
|
set_presence(fred.user_id, undefined);
|
|
|
|
assert.equal(buddy_data.status_description(fred.user_id), "translated: Offline");
|
2019-02-17 02:10:42 +01:00
|
|
|
});
|
|
|
|
|
2021-03-19 14:38:22 +01:00
|
|
|
test("compose fade interactions (streams)", () => {
|
|
|
|
const sub = {
|
|
|
|
stream_id: 101,
|
|
|
|
name: "Devel",
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(sub);
|
|
|
|
stream_data.subscribe_myself(sub);
|
|
|
|
|
|
|
|
people.add_active_user(fred);
|
|
|
|
|
|
|
|
set_presence(fred.user_id, "active");
|
|
|
|
|
|
|
|
function faded() {
|
|
|
|
return buddy_data.get_item(fred.user_id).faded;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are not narrowed, then we don't fade fred in the buddy list.
|
|
|
|
assert.equal(faded(), false);
|
|
|
|
|
|
|
|
// If we narrow to a stream that fred has not subscribed
|
|
|
|
// to, we will fade him.
|
|
|
|
compose_fade_helper.set_focused_recipient({
|
|
|
|
type: "stream",
|
|
|
|
stream_id: sub.stream_id,
|
|
|
|
topic: "whatever",
|
|
|
|
});
|
|
|
|
assert.equal(faded(), true);
|
|
|
|
|
|
|
|
// If we subscribe, we don't fade.
|
|
|
|
peer_data.add_subscriber(sub.stream_id, fred.user_id);
|
|
|
|
assert.equal(faded(), false);
|
|
|
|
|
|
|
|
// Test our punting logic.
|
|
|
|
const bogus_stream_id = 99999;
|
2021-04-15 17:02:54 +02:00
|
|
|
assert.equal(sub_store.get(bogus_stream_id), undefined);
|
2021-03-19 14:38:22 +01:00
|
|
|
|
|
|
|
compose_fade_helper.set_focused_recipient({
|
|
|
|
type: "stream",
|
|
|
|
stream_id: bogus_stream_id,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(faded(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("compose fade interactions (missing topic)", () => {
|
|
|
|
const sub = {
|
|
|
|
stream_id: 102,
|
|
|
|
name: "Social",
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(sub);
|
|
|
|
stream_data.subscribe_myself(sub);
|
|
|
|
|
|
|
|
people.add_active_user(fred);
|
|
|
|
|
|
|
|
set_presence(fred.user_id, "active");
|
|
|
|
|
|
|
|
function faded() {
|
|
|
|
return buddy_data.get_item(fred.user_id).faded;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are not narrowed, then we don't fade fred in the buddy list.
|
|
|
|
assert.equal(faded(), false);
|
|
|
|
|
|
|
|
// If we narrow to a stream that fred has not subscribed
|
|
|
|
// to, we will fade him.
|
|
|
|
compose_fade_helper.set_focused_recipient({
|
|
|
|
type: "stream",
|
|
|
|
stream_id: sub.stream_id,
|
|
|
|
topic: "whatever",
|
|
|
|
});
|
|
|
|
assert.equal(faded(), true);
|
|
|
|
|
|
|
|
// If the user clears the topic, we won't fade fred.
|
|
|
|
compose_fade_helper.set_focused_recipient({
|
|
|
|
type: "stream",
|
|
|
|
stream_id: sub.stream_id,
|
|
|
|
topic: "",
|
|
|
|
});
|
|
|
|
assert.equal(faded(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("compose fade interactions (PMs)", () => {
|
|
|
|
people.add_active_user(fred);
|
|
|
|
|
|
|
|
set_presence(fred.user_id, "active");
|
|
|
|
|
|
|
|
function faded() {
|
|
|
|
return buddy_data.get_item(fred.user_id).faded;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dont fade if we're not in a narrow.
|
|
|
|
assert.equal(faded(), false);
|
|
|
|
|
|
|
|
// Fade fred if we are narrowed to a PM narrow that does
|
|
|
|
// not include him.
|
|
|
|
compose_fade_helper.set_focused_recipient({
|
|
|
|
type: "private",
|
|
|
|
to_user_ids: "9999999",
|
|
|
|
});
|
|
|
|
assert.equal(faded(), true);
|
|
|
|
|
|
|
|
// Now include fred in a narrow with jill, and we will
|
|
|
|
// stop fading him.
|
|
|
|
compose_fade_helper.set_focused_recipient({
|
|
|
|
type: "private",
|
|
|
|
to_user_ids: [fred.user_id, jill.user_id].join(","),
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(faded(), false);
|
|
|
|
});
|
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("buddy_status", () => {
|
2021-03-08 16:08:27 +01:00
|
|
|
set_presence(selma.user_id, "active");
|
|
|
|
set_presence(me.user_id, "active");
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.buddy_status(selma.user_id), "active");
|
2018-12-19 21:16:03 +01:00
|
|
|
user_status.set_away(selma.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.buddy_status(selma.user_id), "away_them");
|
2018-12-19 21:16:03 +01:00
|
|
|
user_status.revoke_away(selma.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.buddy_status(selma.user_id), "active");
|
2018-12-19 21:16:03 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.buddy_status(me.user_id), "active");
|
2018-12-19 21:16:03 +01:00
|
|
|
user_status.set_away(me.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.buddy_status(me.user_id), "away_me");
|
2018-12-19 21:16:03 +01:00
|
|
|
user_status.revoke_away(me.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(buddy_data.buddy_status(me.user_id), "active");
|
2018-12-19 21:16:03 +01:00
|
|
|
});
|
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("title_data", () => {
|
|
|
|
add_canned_users();
|
|
|
|
|
2019-08-04 14:57:32 +02:00
|
|
|
// Groups
|
2019-11-02 00:06:25 +01:00
|
|
|
let is_group = true;
|
|
|
|
const user_ids_string = "9999,1000";
|
|
|
|
let expected_group_data = {
|
2020-07-15 01:29:15 +02:00
|
|
|
first_line: "Human Selma, Old User",
|
|
|
|
second_line: "",
|
|
|
|
third_line: "",
|
2019-08-04 14:57:32 +02:00
|
|
|
};
|
|
|
|
assert.deepEqual(buddy_data.get_title_data(user_ids_string, is_group), expected_group_data);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
is_group = "";
|
2019-08-04 14:57:32 +02:00
|
|
|
|
|
|
|
// Bots with owners.
|
|
|
|
expected_group_data = {
|
2020-07-15 01:29:15 +02:00
|
|
|
first_line: "Blue Herring Bot",
|
|
|
|
second_line: "translated: Owner: Human Myself",
|
|
|
|
third_line: "",
|
2019-08-04 14:57:32 +02:00
|
|
|
};
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
buddy_data.get_title_data(bot_with_owner.user_id, is_group),
|
|
|
|
expected_group_data,
|
|
|
|
);
|
2019-08-04 14:57:32 +02:00
|
|
|
|
|
|
|
// Bots without owners.
|
|
|
|
expected_group_data = {
|
2020-07-15 01:29:15 +02:00
|
|
|
first_line: "Red Herring Bot",
|
|
|
|
second_line: "",
|
|
|
|
third_line: "",
|
2019-08-04 14:57:32 +02:00
|
|
|
};
|
|
|
|
assert.deepEqual(buddy_data.get_title_data(bot.user_id, is_group), expected_group_data);
|
|
|
|
|
2020-10-23 02:43:28 +02:00
|
|
|
// Individual users.
|
2019-01-25 16:40:18 +01:00
|
|
|
user_status.set_status_text({
|
|
|
|
user_id: me.user_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "out to lunch",
|
2019-01-25 16:40:18 +01:00
|
|
|
});
|
2019-08-04 14:57:32 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let expected_data = {
|
2020-07-15 01:29:15 +02:00
|
|
|
first_line: "Human Myself",
|
|
|
|
second_line: "out to lunch",
|
|
|
|
third_line: "translated: Active now",
|
2021-04-02 13:05:26 +02:00
|
|
|
show_you: true,
|
2019-08-04 14:57:32 +02:00
|
|
|
};
|
2021-04-02 13:05:26 +02:00
|
|
|
page_params.user_id = me.user_id;
|
2019-08-04 14:57:32 +02:00
|
|
|
assert.deepEqual(buddy_data.get_title_data(me.user_id, is_group), expected_data);
|
|
|
|
|
|
|
|
expected_data = {
|
2020-07-15 01:29:15 +02:00
|
|
|
first_line: "Old User",
|
|
|
|
second_line: "translated: Last active: translated: More than 2 weeks ago",
|
|
|
|
third_line: "",
|
2021-04-02 13:05:26 +02:00
|
|
|
show_you: false,
|
2019-08-04 14:57:32 +02:00
|
|
|
};
|
|
|
|
assert.deepEqual(buddy_data.get_title_data(old_user.user_id, is_group), expected_data);
|
2019-01-25 16:40:18 +01:00
|
|
|
});
|
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("simple search", () => {
|
|
|
|
add_canned_users();
|
2021-03-08 16:08:27 +01:00
|
|
|
|
|
|
|
set_presence(selma.user_id, "active");
|
|
|
|
set_presence(me.user_id, "active");
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const user_ids = buddy_data.get_filtered_and_sorted_user_ids("sel");
|
2018-12-18 19:25:14 +01:00
|
|
|
|
2018-12-18 19:29:08 +01:00
|
|
|
assert.deepEqual(user_ids, [selma.user_id]);
|
2018-06-02 01:42:05 +02:00
|
|
|
});
|
2018-04-20 18:22:28 +02:00
|
|
|
|
2021-04-23 17:30:00 +02:00
|
|
|
test("muted users excluded from search", () => {
|
2021-05-16 17:24:11 +02:00
|
|
|
people.add_active_user(selma);
|
2021-04-23 17:30:00 +02:00
|
|
|
muting.add_muted_user(selma.user_id);
|
|
|
|
|
|
|
|
let user_ids = buddy_data.get_filtered_and_sorted_user_ids();
|
|
|
|
assert.equal(user_ids.includes(selma.user_id), false);
|
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids("sel");
|
|
|
|
assert.deepEqual(user_ids, []);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!buddy_data.matches_filter("sel", selma.user_id));
|
2021-04-23 17:30:00 +02:00
|
|
|
|
|
|
|
muting.remove_muted_user(selma.user_id);
|
2021-05-16 17:24:11 +02:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids("sel");
|
|
|
|
assert.deepEqual(user_ids, [selma.user_id]);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(buddy_data.matches_filter("sel", selma.user_id));
|
2021-04-23 17:30:00 +02:00
|
|
|
});
|
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("bulk_data_hacks", () => {
|
|
|
|
// sanity check
|
|
|
|
assert.equal(mark.user_id, 1005);
|
|
|
|
|
|
|
|
for (const i of _.range(mark.user_id + 1, 2000)) {
|
|
|
|
const person = {
|
|
|
|
user_id: i,
|
|
|
|
full_name: `Human ${i}`,
|
|
|
|
email: `person${i}@example.com`,
|
|
|
|
};
|
|
|
|
people.add_active_user(person);
|
|
|
|
}
|
|
|
|
add_canned_users();
|
2021-03-08 16:08:27 +01:00
|
|
|
|
|
|
|
// Make 400 of the users active
|
|
|
|
set_presence(selma.user_id, "active");
|
|
|
|
set_presence(me.user_id, "active");
|
|
|
|
|
|
|
|
for (const user_id of _.range(1000, 1400)) {
|
|
|
|
set_presence(user_id, "active");
|
|
|
|
}
|
|
|
|
|
|
|
|
// And then 300 not active
|
|
|
|
for (const user_id of _.range(1400, 1700)) {
|
|
|
|
set_presence(user_id, "offline");
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let user_ids;
|
2018-04-20 18:22:28 +02:00
|
|
|
|
2018-04-23 23:13:52 +02:00
|
|
|
// Even though we have 1000 users, we only get the 400 active
|
2018-04-20 18:22:28 +02:00
|
|
|
// users. This is a consequence of buddy_data.maybe_shrink_list.
|
2018-04-23 23:13:52 +02:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids();
|
2018-04-20 18:22:28 +02:00
|
|
|
assert.equal(user_ids.length, 400);
|
2018-04-23 23:13:52 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids("");
|
2018-04-23 23:13:52 +02:00
|
|
|
assert.equal(user_ids.length, 400);
|
|
|
|
|
2018-12-18 19:25:14 +01:00
|
|
|
// We don't match on "so", because it's not at the start of a
|
2018-04-23 23:13:52 +02:00
|
|
|
// word in the name/email.
|
2020-07-15 01:29:15 +02:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids("so");
|
2018-04-23 23:13:52 +02:00
|
|
|
assert.equal(user_ids.length, 0);
|
|
|
|
|
|
|
|
// We match on "h" for the first name, and the result limit
|
2018-12-18 19:29:08 +01:00
|
|
|
// is relaxed for searches. (We exclude "me", though.)
|
2020-07-15 01:29:15 +02:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids("h");
|
2020-05-27 14:46:44 +02:00
|
|
|
assert.equal(user_ids.length, 996);
|
2018-04-23 23:13:52 +02:00
|
|
|
|
|
|
|
// We match on "p" for the email.
|
2020-07-15 01:29:15 +02:00
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids("p");
|
2020-05-27 14:46:44 +02:00
|
|
|
assert.equal(user_ids.length, 994);
|
2018-04-23 23:13:52 +02:00
|
|
|
|
|
|
|
// Make our shrink limit higher, and go back to an empty search.
|
|
|
|
// We won't get all 1000 users, just the present ones.
|
2021-03-08 16:08:27 +01:00
|
|
|
with_field(buddy_data, "max_size_before_shrinking", 50000, () => {
|
|
|
|
user_ids = buddy_data.get_filtered_and_sorted_user_ids("");
|
|
|
|
});
|
2018-04-23 23:13:52 +02:00
|
|
|
assert.equal(user_ids.length, 700);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-12-20 15:55:20 +01:00
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("user_status", () => {
|
2021-03-08 16:08:27 +01:00
|
|
|
user_status.initialize({user_status: []});
|
|
|
|
set_presence(me.user_id, "active");
|
2020-09-24 10:57:52 +02:00
|
|
|
assert.equal(buddy_data.get_my_user_status(me.user_id), "translated: (you)");
|
2018-12-21 20:10:27 +01:00
|
|
|
user_status.set_away(me.user_id);
|
2020-09-24 10:57:52 +02:00
|
|
|
assert.equal(buddy_data.get_my_user_status(me.user_id), "translated: (unavailable)");
|
2018-12-21 20:10:27 +01:00
|
|
|
user_status.revoke_away(me.user_id);
|
2020-09-24 10:57:52 +02:00
|
|
|
assert.equal(buddy_data.get_my_user_status(me.user_id), "translated: (you)");
|
2018-12-21 20:10:27 +01:00
|
|
|
});
|
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("level", () => {
|
|
|
|
add_canned_users();
|
2018-12-20 15:55:20 +01:00
|
|
|
assert.equal(buddy_data.level(me.user_id), 0);
|
|
|
|
assert.equal(buddy_data.level(selma.user_id), 3);
|
|
|
|
|
|
|
|
const server_time = 9999;
|
|
|
|
const info = {
|
|
|
|
website: {
|
|
|
|
status: "active",
|
|
|
|
timestamp: server_time,
|
|
|
|
},
|
|
|
|
};
|
2020-02-07 17:19:03 +01:00
|
|
|
presence.update_info_from_event(me.user_id, info, server_time);
|
|
|
|
presence.update_info_from_event(selma.user_id, info, server_time);
|
2018-12-20 15:55:20 +01:00
|
|
|
|
|
|
|
assert.equal(buddy_data.level(me.user_id), 0);
|
|
|
|
assert.equal(buddy_data.level(selma.user_id), 1);
|
|
|
|
|
|
|
|
user_status.set_away(me.user_id);
|
|
|
|
user_status.set_away(selma.user_id);
|
|
|
|
|
2018-12-19 21:16:03 +01:00
|
|
|
// Selma gets demoted to level 3, but "me"
|
|
|
|
// stays in level 0.
|
2018-12-20 15:55:20 +01:00
|
|
|
assert.equal(buddy_data.level(me.user_id), 0);
|
2018-12-19 21:16:03 +01:00
|
|
|
assert.equal(buddy_data.level(selma.user_id), 3);
|
2018-12-20 15:55:20 +01:00
|
|
|
});
|
2019-02-28 16:09:03 +01:00
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("user_last_seen_time_status", (override) => {
|
2021-03-08 16:08:27 +01:00
|
|
|
set_presence(selma.user_id, "active");
|
|
|
|
set_presence(me.user_id, "active");
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(buddy_data.user_last_seen_time_status(selma.user_id), "translated: Active now");
|
2019-02-28 16:09:03 +01:00
|
|
|
|
|
|
|
page_params.realm_is_zephyr_mirror_realm = true;
|
2021-06-03 20:43:19 +02:00
|
|
|
assert.equal(
|
|
|
|
buddy_data.user_last_seen_time_status(old_user.user_id),
|
|
|
|
"translated: Last active: translated: Unknown",
|
|
|
|
);
|
2019-02-28 16:09:03 +01:00
|
|
|
page_params.realm_is_zephyr_mirror_realm = false;
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
buddy_data.user_last_seen_time_status(old_user.user_id),
|
2021-06-03 20:43:19 +02:00
|
|
|
"translated: Last active: translated: More than 2 weeks ago",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2019-02-28 16:09:03 +01:00
|
|
|
|
2021-02-19 14:52:41 +01:00
|
|
|
override(presence, "last_active_date", (user_id) => {
|
2019-02-28 16:09:03 +01:00
|
|
|
assert.equal(user_id, old_user.user_id);
|
2021-02-05 21:20:14 +01:00
|
|
|
return new Date(1526137743000);
|
2021-02-19 14:52:41 +01:00
|
|
|
});
|
2019-02-28 16:09:03 +01:00
|
|
|
|
2021-02-19 14:52:41 +01:00
|
|
|
override(timerender, "last_seen_status_from_date", (date) => {
|
2021-02-05 21:20:14 +01:00
|
|
|
assert.deepEqual(date, new Date(1526137743000));
|
2020-07-15 01:29:15 +02:00
|
|
|
return "May 12";
|
2021-02-19 14:52:41 +01:00
|
|
|
});
|
2019-02-28 16:09:03 +01:00
|
|
|
|
2021-06-03 20:43:19 +02:00
|
|
|
assert.equal(
|
|
|
|
buddy_data.user_last_seen_time_status(old_user.user_id),
|
|
|
|
"translated: Last active: May 12",
|
|
|
|
);
|
2021-06-03 20:45:59 +02:00
|
|
|
|
|
|
|
set_presence(selma.user_id, "idle");
|
|
|
|
assert.equal(buddy_data.user_last_seen_time_status(selma.user_id), "translated: Idle");
|
2019-02-28 16:09:03 +01:00
|
|
|
});
|
2020-02-04 15:38:37 +01:00
|
|
|
|
2021-05-16 17:17:44 +02:00
|
|
|
test("get_items_for_users", () => {
|
|
|
|
people.add_active_user(alice);
|
|
|
|
people.add_active_user(fred);
|
|
|
|
user_status.set_away(alice.user_id);
|
|
|
|
|
|
|
|
const user_ids = [me.user_id, alice.user_id, fred.user_id];
|
|
|
|
assert.deepEqual(buddy_data.get_items_for_users(user_ids), [
|
|
|
|
{
|
|
|
|
faded: false,
|
|
|
|
href: "#narrow/pm-with/1001-self",
|
|
|
|
is_current_user: true,
|
|
|
|
my_user_status: "translated: (you)",
|
|
|
|
name: "Human Myself",
|
|
|
|
num_unread: 0,
|
|
|
|
user_circle_class: "user_circle_green",
|
|
|
|
user_circle_status: "translated: Active",
|
|
|
|
user_id: 1001,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
faded: false,
|
|
|
|
href: "#narrow/pm-with/1002-alice",
|
|
|
|
is_current_user: false,
|
|
|
|
my_user_status: undefined,
|
|
|
|
name: "Alice Smith",
|
|
|
|
num_unread: 0,
|
|
|
|
user_circle_class: "user_circle_empty_line",
|
|
|
|
user_circle_status: "translated: Unavailable",
|
|
|
|
user_id: 1002,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
faded: false,
|
|
|
|
href: "#narrow/pm-with/1003-fred",
|
|
|
|
is_current_user: false,
|
|
|
|
my_user_status: undefined,
|
|
|
|
name: "Fred Flintstone",
|
|
|
|
num_unread: 0,
|
|
|
|
user_circle_class: "user_circle_empty",
|
|
|
|
user_circle_status: "translated: Offline",
|
|
|
|
user_id: 1003,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-03-14 10:18:07 +01:00
|
|
|
test("error handling", (override) => {
|
2021-02-19 14:52:41 +01:00
|
|
|
override(presence, "get_user_ids", () => [42]);
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Unknown user_id in get_by_user_id: 42");
|
|
|
|
blueslip.expect("warn", "Got user_id in presence but not people: 42");
|
2020-02-04 15:38:37 +01:00
|
|
|
buddy_data.get_filtered_and_sorted_user_ids();
|
|
|
|
});
|