2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("$", global.make_zjquery());
|
2020-07-21 06:16:05 +02:00
|
|
|
const window_stub = $.create("window-stub");
|
|
|
|
set_global("to_$", () => window_stub);
|
|
|
|
$(window).idle = () => {};
|
2018-08-01 21:17:03 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let filter_key_handlers;
|
2014-01-30 22:42:19 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const huddle_data = zrequire("huddle_data");
|
2020-05-26 14:25:21 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _page_params = {
|
2017-04-24 21:59:07 +02:00
|
|
|
realm_users: [],
|
2017-10-05 06:06:42 +02:00
|
|
|
user_id: 999,
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
2017-08-02 16:51:37 +02:00
|
|
|
|
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
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _channel = {};
|
2017-05-12 20:16:39 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _ui = {
|
2020-07-02 01:39:34 +02:00
|
|
|
get_content_element: (element) => element,
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
2017-03-30 20:04:01 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _keydown_util = {
|
2018-04-21 14:59:03 +02:00
|
|
|
handle: (opts) => {
|
|
|
|
filter_key_handlers = opts.handlers;
|
|
|
|
},
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
2018-04-21 14:59:03 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _compose_state = {};
|
2018-04-22 17:46:20 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _scroll_util = {
|
2018-04-21 14:59:03 +02:00
|
|
|
scroll_element_into_container: () => {},
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
2018-04-21 14:59:03 +02:00
|
|
|
|
2019-02-18 16:32:27 +01:00
|
|
|
const _pm_list = {
|
|
|
|
update_private_messages: () => {},
|
|
|
|
};
|
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _popovers = {
|
2020-07-20 22:18:43 +02:00
|
|
|
hide_all_except_sidebars() {},
|
|
|
|
hide_all() {},
|
|
|
|
show_userlist_sidebar() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".column-right").addClass("expanded");
|
2017-10-12 05:07:12 +02:00
|
|
|
},
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
2017-10-12 05:07:12 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _stream_popover = {
|
2020-07-20 22:18:43 +02:00
|
|
|
show_streamlist_sidebar() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".column-left").addClass("expanded");
|
2017-10-12 05:07:12 +02:00
|
|
|
},
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
2017-10-12 05:07:12 +02:00
|
|
|
|
2018-08-01 21:17:03 +02:00
|
|
|
const _resize = {
|
2020-05-27 21:43:47 +02:00
|
|
|
resize_sidebars: () => {},
|
2018-04-12 23:54:13 +02:00
|
|
|
resize_page_components: () => {},
|
2018-08-01 21:17:03 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("padded_widget", {
|
2018-07-26 19:50:15 +02:00
|
|
|
update_padding: () => {},
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("channel", _channel);
|
|
|
|
set_global("compose_state", _compose_state);
|
|
|
|
set_global("document", _document);
|
|
|
|
set_global("keydown_util", _keydown_util);
|
|
|
|
set_global("page_params", _page_params);
|
|
|
|
set_global("pm_list", _pm_list);
|
|
|
|
set_global("popovers", _popovers);
|
|
|
|
set_global("resize", _resize);
|
|
|
|
set_global("scroll_util", _scroll_util);
|
|
|
|
set_global("stream_popover", _stream_popover);
|
|
|
|
set_global("ui", _ui);
|
|
|
|
|
|
|
|
zrequire("compose_fade");
|
|
|
|
zrequire("unread");
|
|
|
|
zrequire("hash_util");
|
|
|
|
zrequire("narrow");
|
|
|
|
zrequire("presence");
|
|
|
|
zrequire("people");
|
|
|
|
zrequire("buddy_data");
|
|
|
|
zrequire("buddy_list");
|
|
|
|
zrequire("user_search");
|
|
|
|
zrequire("user_status");
|
|
|
|
zrequire("list_cursor");
|
|
|
|
zrequire("activity");
|
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);
|
|
|
|
|
2020-02-06 04:21:07 +01:00
|
|
|
const presence_info = new Map();
|
2020-07-16 22:40:18 +02:00
|
|
|
presence_info.set(alice.user_id, {status: "inactive"});
|
|
|
|
presence_info.set(fred.user_id, {status: "active"});
|
|
|
|
presence_info.set(jill.user_id, {status: "active"});
|
2017-04-13 04:28:15 +02:00
|
|
|
|
|
|
|
presence.presence_info = presence_info;
|
|
|
|
|
2018-07-16 15:16:33 +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.
|
|
|
|
buddy_list.fill_screen_with_content = () => {
|
|
|
|
buddy_list.render_more({
|
|
|
|
chunk_size: 100,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("get_status", () => {
|
2017-04-13 04:28:15 +02:00
|
|
|
assert.equal(presence.get_status(page_params.user_id), "active");
|
|
|
|
assert.equal(presence.get_status(alice.user_id), "inactive");
|
|
|
|
assert.equal(presence.get_status(fred.user_id), "active");
|
2017-10-12 18:08:42 +02:00
|
|
|
assert.equal(presence.get_status(zoe.user_id), "offline");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-13 04:28:15 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("reload_defaults", () => {
|
|
|
|
blueslip.expect("warn", "get_filter_text() is called before initialization");
|
|
|
|
assert.equal(activity.get_filter_text(), "");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-10-07 19:55:44 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_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
|
|
|
|
2018-04-19 15:46:56 +02:00
|
|
|
buddy_data.sort_users(user_ids);
|
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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("huddle_data.process_loaded_messages", () => {
|
2020-05-26 13:58:18 +02:00
|
|
|
// TODO: move this to a module for just testing `huddle_data`
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const huddle1 = "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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const huddle2 = "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
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2017-02-05 00:22:16 +01:00
|
|
|
display_recipient: [{id: me.user_id}], // PM to myself
|
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
|
|
|
];
|
|
|
|
|
2020-05-26 13:58:18 +02:00
|
|
|
huddle_data.process_loaded_messages(messages);
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const user_ids_string1 = people.emails_strings_to_user_ids_string(huddle1);
|
|
|
|
const user_ids_string2 = people.emails_strings_to_user_ids_string(huddle2);
|
2020-05-26 14:25:21 +02:00
|
|
|
assert.deepEqual(huddle_data.get_huddles(), [user_ids_string2, user_ids_string1]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2020-02-06 04:21:07 +01:00
|
|
|
presence.presence_info = new Map();
|
2020-07-16 22:40:18 +02:00
|
|
|
presence.presence_info.set(alice.user_id, {status: activity.IDLE});
|
|
|
|
presence.presence_info.set(fred.user_id, {status: activity.ACTIVE});
|
|
|
|
presence.presence_info.set(jill.user_id, {status: activity.ACTIVE});
|
|
|
|
presence.presence_info.set(mark.user_id, {status: activity.IDLE});
|
|
|
|
presence.presence_info.set(norbert.user_id, {status: activity.ACTIVE});
|
|
|
|
presence.presence_info.set(zoe.user_id, {status: activity.ACTIVE});
|
|
|
|
presence.presence_info.set(me.user_id, {status: activity.ACTIVE});
|
2017-01-09 18:20:31 +01:00
|
|
|
|
2018-07-14 14:06:30 +02:00
|
|
|
function clear_buddy_list() {
|
|
|
|
buddy_list.populate({
|
|
|
|
keys: [],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
function reset_setup() {
|
2019-04-18 19:28:25 +02:00
|
|
|
$.clear_all_elements();
|
2018-04-21 14:59:03 +02:00
|
|
|
activity.set_cursor_and_filter();
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
buddy_list.container = $("#user_presences");
|
2018-07-16 15:16:33 +02:00
|
|
|
|
|
|
|
buddy_list.container.append = () => {};
|
2018-07-14 18:08:13 +02:00
|
|
|
clear_buddy_list();
|
2018-04-19 17:47:41 +02:00
|
|
|
}
|
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("presence_list_full_update", () => {
|
2020-07-20 21:24:26 +02:00
|
|
|
$(".user-list-filter").trigger("focus");
|
2019-12-02 17:53:55 +01:00
|
|
|
compose_state.private_message_recipient = () => fred.email;
|
2018-04-22 17:46:20 +02:00
|
|
|
compose_fade.set_focused_recipient("private");
|
|
|
|
|
2019-12-29 15:07:05 +01:00
|
|
|
const user_ids = activity.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,
|
2018-07-14 14:06:30 +02:00
|
|
|
fred.user_id,
|
|
|
|
jill.user_id,
|
|
|
|
norbert.user_id,
|
|
|
|
zoe.user_id,
|
|
|
|
alice.user_id,
|
|
|
|
mark.user_id,
|
2017-01-09 18:20:31 +01:00
|
|
|
]);
|
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() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".user-list-filter").closest = function (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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function simulate_left_column_buddy_list() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".user-list-filter").closest = function (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("left-sidebar").addClass("column-left");
|
2018-04-21 14:59:03 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
function buddy_list_add(user_id, stub) {
|
2018-04-21 14:59:03 +02:00
|
|
|
if (stub.attr) {
|
2020-07-15 01:29:15 +02:00
|
|
|
stub.attr("data-user-id", user_id);
|
2018-04-21 14:59:03 +02:00
|
|
|
}
|
2018-07-16 15:16:33 +02:00
|
|
|
stub.length = 1;
|
2018-04-20 16:13:39 +02:00
|
|
|
const sel = `li.user_sidebar_entry[data-user-id='${user_id}']`;
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user_presences").set_find_results(sel, stub);
|
2018-04-20 16:13:39 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("PM_update_dom_counts", () => {
|
|
|
|
const value = $.create("alice-value");
|
|
|
|
const count = $.create("alice-count");
|
2018-04-12 23:40:03 +02:00
|
|
|
const pm_key = alice.user_id.toString();
|
2020-07-15 01:29:15 +02:00
|
|
|
const li = $.create("alice stub");
|
2018-04-20 16:13:39 +02:00
|
|
|
buddy_list_add(pm_key, li);
|
2020-07-15 01:29:15 +02:00
|
|
|
count.set_find_results(".value", value);
|
|
|
|
li.set_find_results(".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);
|
2020-07-15 01:29:15 +02:00
|
|
|
li.addClass("user_sidebar_entry");
|
2017-05-24 19:46:15 +02:00
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(li.hasClass("user-with-count"));
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal(value.text(), "5");
|
2017-05-24 19:46:15 +02:00
|
|
|
|
|
|
|
counts.set(pm_key, 0);
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(!li.hasClass("user-with-count"));
|
|
|
|
assert.equal(value.text(), "");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-24 19:46:15 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("handlers", () => {
|
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.
|
2018-12-18 18:50:58 +01:00
|
|
|
let me_li;
|
2018-07-16 15:16:33 +02:00
|
|
|
let alice_li;
|
|
|
|
let fred_li;
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2018-07-16 15:16:33 +02:00
|
|
|
function init() {
|
|
|
|
reset_setup();
|
|
|
|
buddy_list.populate({
|
2018-12-18 18:50:58 +01:00
|
|
|
keys: [me.user_id, alice.user_id, fred.user_id],
|
2018-07-16 15:16:33 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
me_li = $.create("me stub");
|
|
|
|
alice_li = $.create("alice stub");
|
|
|
|
fred_li = $.create("fred stub");
|
2018-07-16 15:16:33 +02:00
|
|
|
|
2018-12-18 18:50:58 +01:00
|
|
|
buddy_list_add(me.user_id, me_li);
|
2018-07-16 15:16:33 +02:00
|
|
|
buddy_list_add(alice.user_id, alice_li);
|
|
|
|
buddy_list_add(fred.user_id, fred_li);
|
|
|
|
}
|
2018-07-14 18:08:13 +02:00
|
|
|
|
|
|
|
(function test_filter_keys() {
|
2018-07-16 15:16:33 +02:00
|
|
|
init();
|
2018-07-14 18:08:13 +02:00
|
|
|
activity.user_cursor.go_to(alice.user_id);
|
|
|
|
filter_key_handlers.down_arrow();
|
|
|
|
filter_key_handlers.up_arrow();
|
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 = {
|
|
|
|
stopPropagation: () => {},
|
2018-02-12 23:31:17 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const handler = $(".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();
|
2019-11-02 00:06:25 +01:00
|
|
|
let narrowed;
|
2018-04-19 21:50:14 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
narrow.by = (method, email) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(email, "alice@zulip.com");
|
2018-04-21 14:59:03 +02:00
|
|
|
narrowed = true;
|
|
|
|
};
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".user-list-filter").val("al");
|
2018-04-21 14:59:03 +02:00
|
|
|
activity.user_cursor.go_to(alice.user_id);
|
|
|
|
|
|
|
|
filter_key_handlers.enter_key();
|
|
|
|
assert(narrowed);
|
|
|
|
|
|
|
|
// get line coverage for cleared case
|
|
|
|
activity.user_cursor.clear();
|
|
|
|
filter_key_handlers.enter_key();
|
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.
|
2019-11-02 00:06:25 +01:00
|
|
|
let narrowed;
|
2018-04-21 14:59:03 +02:00
|
|
|
|
|
|
|
narrow.by = (method, email) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(email, "alice@zulip.com");
|
2018-04-21 14:59:03 +02:00
|
|
|
narrowed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
activity.narrow_for_user({li: alice_li});
|
|
|
|
assert(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 = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
const handler = $(".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
|
|
|
|
2020-02-06 04:21:07 +01:00
|
|
|
presence.presence_info = new Map();
|
2020-07-16 22:40:18 +02:00
|
|
|
presence.presence_info.set(alice.user_id, {status: activity.ACTIVE});
|
|
|
|
presence.presence_info.set(fred.user_id, {status: activity.ACTIVE});
|
|
|
|
presence.presence_info.set(jill.user_id, {status: activity.ACTIVE});
|
|
|
|
presence.presence_info.set(mark.user_id, {status: activity.IDLE});
|
|
|
|
presence.presence_info.set(norbert.user_id, {status: activity.ACTIVE});
|
|
|
|
presence.presence_info.set(zoe.user_id, {status: activity.ACTIVE});
|
2017-05-24 23:28:18 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("first/prev/next", () => {
|
2018-07-14 18:08:13 +02:00
|
|
|
clear_buddy_list();
|
|
|
|
|
|
|
|
assert.equal(buddy_list.first_key(), undefined);
|
|
|
|
assert.equal(buddy_list.prev_key(alice.user_id), undefined);
|
|
|
|
assert.equal(buddy_list.next_key(alice.user_id), undefined);
|
|
|
|
|
|
|
|
buddy_list.container.append = () => {};
|
|
|
|
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user(alice.user_id);
|
|
|
|
activity.redraw_user(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);
|
|
|
|
|
|
|
|
assert.equal(buddy_list.next_key(alice.user_id), fred.user_id);
|
|
|
|
assert.equal(buddy_list.next_key(fred.user_id), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
reset_setup();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("filter_user_ids", () => {
|
|
|
|
const user_filter = $(".user-list-filter");
|
|
|
|
user_filter.val(""); // no search filter
|
2017-05-24 23:28:18 +02:00
|
|
|
|
2018-04-19 15:46:56 +02:00
|
|
|
function get_user_ids() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const filter_text = activity.get_filter_text();
|
|
|
|
const user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
|
2018-04-19 15:46:56 +02:00
|
|
|
return user_ids;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let user_ids = buddy_data.get_filtered_and_sorted_user_ids();
|
2017-10-07 20:45:13 +02:00
|
|
|
assert.deepEqual(user_ids, [
|
|
|
|
alice.user_id,
|
|
|
|
fred.user_id,
|
|
|
|
jill.user_id,
|
|
|
|
norbert.user_id,
|
|
|
|
zoe.user_id,
|
|
|
|
mark.user_id,
|
|
|
|
]);
|
2017-05-24 23:28:18 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_filter.val("abc"); // no match
|
2018-04-19 15:46:56 +02:00
|
|
|
user_ids = get_user_ids();
|
2017-05-24 23:28:18 +02:00
|
|
|
assert.deepEqual(user_ids, []);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_filter.val("fred"); // match fred
|
2018-04-19 15:46:56 +02:00
|
|
|
user_ids = get_user_ids();
|
2017-05-24 23:28:18 +02:00
|
|
|
assert.deepEqual(user_ids, [fred.user_id]);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_filter.val("fred,alice"); // match fred and alice
|
2018-04-19 15:46:56 +02:00
|
|
|
user_ids = get_user_ids();
|
2017-05-24 23:28:18 +02:00
|
|
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_filter.val("fr,al"); // match fred and alice partials
|
2018-04-19 15:46:56 +02:00
|
|
|
user_ids = get_user_ids();
|
2017-05-24 23:28:18 +02:00
|
|
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_filter.val("fr|al"); // test | as OR-operator
|
2019-03-06 09:20:50 +01:00
|
|
|
user_ids = get_user_ids();
|
|
|
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
presence.presence_info.set(alice.user_id, {status: activity.IDLE});
|
2020-07-15 01:29:15 +02:00
|
|
|
user_filter.val("fr,al"); // match fred and alice partials and idle user
|
2018-04-19 15:46:56 +02:00
|
|
|
user_ids = get_user_ids();
|
2017-05-24 23:28:18 +02:00
|
|
|
assert.deepEqual(user_ids, [fred.user_id, alice.user_id]);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$.stub_selector(".user-list-filter", []);
|
2020-07-16 22:40:18 +02:00
|
|
|
presence.presence_info.set(alice.user_id, {status: activity.ACTIVE});
|
2018-04-19 15:46:56 +02:00
|
|
|
user_ids = get_user_ids();
|
2017-05-24 23:28:18 +02:00
|
|
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("insert_one_user_into_empty_list", () => {
|
2018-04-18 22:51:40 +02:00
|
|
|
let appended_html;
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user_presences").append = function (html) {
|
2017-05-25 01:49:39 +02:00
|
|
|
appended_html = html;
|
|
|
|
};
|
|
|
|
|
2018-07-14 14:06:30 +02:00
|
|
|
clear_buddy_list();
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user(alice.user_id);
|
2017-05-25 01:49:39 +02:00
|
|
|
assert(appended_html.indexOf('data-user-id="1"') > 0);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(appended_html.indexOf("user_circle_green") > 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("insert_alice_then_fred", () => {
|
2018-07-14 14:06:30 +02:00
|
|
|
clear_buddy_list();
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-04-18 22:51:40 +02:00
|
|
|
let appended_html;
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user_presences").append = function (html) {
|
2017-05-25 01:49:39 +02:00
|
|
|
appended_html = html;
|
|
|
|
};
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user(alice.user_id);
|
2018-07-14 14:06:30 +02:00
|
|
|
assert(appended_html.indexOf('data-user-id="1"') > 0);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(appended_html.indexOf("user_circle_green") > 0);
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user(fred.user_id);
|
2017-05-25 01:49:39 +02:00
|
|
|
assert(appended_html.indexOf('data-user-id="2"') > 0);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(appended_html.indexOf("user_circle_green") > 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("insert_fred_then_alice_then_rename", () => {
|
2018-07-14 14:06:30 +02:00
|
|
|
clear_buddy_list();
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-07-14 14:06:30 +02:00
|
|
|
let appended_html;
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#user_presences").append = function (html) {
|
2018-07-14 14:06:30 +02:00
|
|
|
appended_html = html;
|
|
|
|
};
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user(fred.user_id);
|
2018-07-14 14:06:30 +02:00
|
|
|
assert(appended_html.indexOf('data-user-id="2"') > 0);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(appended_html.indexOf("user_circle_green") > 0);
|
2018-07-14 14:06:30 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const fred_stub = $.create("fred-first");
|
2018-07-14 14:06:30 +02:00
|
|
|
buddy_list_add(fred.user_id, fred_stub);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let inserted_html;
|
2018-07-14 14:06:30 +02:00
|
|
|
fred_stub.before = (html) => {
|
|
|
|
inserted_html = html;
|
2017-05-25 01:49:39 +02:00
|
|
|
};
|
|
|
|
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user(alice.user_id);
|
2018-07-14 14:06:30 +02:00
|
|
|
assert(inserted_html.indexOf('data-user-id="1"') > 0);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(inserted_html.indexOf("user_circle_green") > 0);
|
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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const alice_stub = $.create("alice-first");
|
2018-07-14 14:06:30 +02:00
|
|
|
buddy_list_add(alice.user_id, alice_stub);
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2018-07-14 14:06:30 +02:00
|
|
|
alice_stub.before = (html) => {
|
|
|
|
inserted_html = html;
|
|
|
|
};
|
|
|
|
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user(fred_with_new_name.user_id);
|
2018-07-14 14:06:30 +02:00
|
|
|
assert(appended_html.indexOf('data-user-id="2"') > 0);
|
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
|
|
|
|
|
|
|
// Reset jquery here.
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_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.
|
2020-07-15 01:29:15 +02:00
|
|
|
const user_filter = $(".user-list-filter");
|
|
|
|
user_filter.val("do-not-match-filter");
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user(fred.user_id);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("realm_presence_disabled", () => {
|
2017-05-25 01:49:39 +02:00
|
|
|
page_params.realm_presence_disabled = true;
|
|
|
|
|
2019-01-25 19:20:51 +01:00
|
|
|
activity.redraw_user();
|
2017-05-25 01:49:39 +02:00
|
|
|
activity.build_user_sidebar();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("clear_search", () => {
|
|
|
|
$(".user-list-filter").val("somevalue");
|
2020-07-23 04:10:24 +02:00
|
|
|
$("#clear_search_people_button").trigger("click");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($(".user-list-filter").val(), "");
|
2020-07-23 04:10:24 +02:00
|
|
|
$("#clear_search_people_button").trigger("click");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert($("#user_search_section").hasClass("notdisplayed"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("escape_search", () => {
|
2018-07-14 18:08:13 +02:00
|
|
|
clear_buddy_list();
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".user-list-filter").val("somevalue");
|
2018-01-04 18:15:42 +01:00
|
|
|
activity.escape_search();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($(".user-list-filter").val(), "");
|
2018-01-04 18:15:42 +01:00
|
|
|
activity.escape_search();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert($("#user_search_section").hasClass("notdisplayed"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("initiate_search", () => {
|
2020-07-20 21:24:26 +02:00
|
|
|
$(".user-list-filter").trigger("blur");
|
2018-04-21 14:59:03 +02:00
|
|
|
simulate_right_column_buddy_list();
|
2017-10-12 05:07:12 +02:00
|
|
|
activity.initiate_search();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($(".column-right").hasClass("expanded"), true);
|
|
|
|
assert.equal($(".user-list-filter").is_focused(), true);
|
2018-04-21 14:59:03 +02:00
|
|
|
|
|
|
|
simulate_left_column_buddy_list();
|
2017-06-24 15:15:37 +02:00
|
|
|
activity.initiate_search();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($(".column-left").hasClass("expanded"), true);
|
|
|
|
assert.equal($(".user-list-filter").is_focused(), true);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("toggle_filter_display", () => {
|
2018-04-19 17:47:41 +02:00
|
|
|
activity.user_filter.toggle_filter_displayed();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert($("#user_search_section").hasClass("notdisplayed"));
|
|
|
|
$(".user-list-filter").closest = function (selector) {
|
2018-01-04 18:15:42 +01:00
|
|
|
assert.equal(selector, ".app-main [class^='column-']");
|
2020-07-15 01:29:15 +02:00
|
|
|
return $.create("sidebar").addClass("column-right");
|
2018-01-04 18:15:42 +01:00
|
|
|
};
|
2018-04-19 17:47:41 +02:00
|
|
|
activity.user_filter.toggle_filter_displayed();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#user_search_section").hasClass("notdisplayed"), false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("searching", () => {
|
2020-07-20 21:24:26 +02:00
|
|
|
$(".user-list-filter").trigger("focus");
|
2017-06-24 15:15:37 +02:00
|
|
|
assert.equal(activity.searching(), true);
|
2020-07-20 21:24:26 +02:00
|
|
|
$(".user-list-filter").trigger("blur");
|
2017-06-24 15:15:37 +02:00
|
|
|
assert.equal(activity.searching(), false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
2018-04-20 16:13:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("update_presence_info", () => {
|
2020-05-26 13:58:18 +02:00
|
|
|
page_params.realm_presence_disabled = false;
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
buddy_data.matches_filter = () => true;
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const alice_li = $.create("alice stub");
|
2018-04-20 16:13:39 +02:00
|
|
|
buddy_list_add(alice.user_id, alice_li);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let inserted;
|
2018-04-20 16:13:39 +02:00
|
|
|
buddy_list.insert_or_move = () => {
|
|
|
|
inserted = true;
|
|
|
|
};
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2020-02-06 04:21:07 +01:00
|
|
|
presence.presence_info.delete(me.user_id);
|
2020-02-03 16:25:13 +01:00
|
|
|
activity.update_presence_info(me.user_id, info, server_time);
|
2018-09-08 14:41:41 +02:00
|
|
|
assert(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);
|
2020-02-03 16:25:13 +01:00
|
|
|
activity.update_presence_info(alice.user_id, info, server_time);
|
2018-04-20 16:13:39 +02:00
|
|
|
assert(inserted);
|
|
|
|
|
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);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("initialize", () => {
|
2019-04-18 19:28:25 +02:00
|
|
|
function clear() {
|
|
|
|
$.clear_all_elements();
|
2020-07-15 01:29:15 +02:00
|
|
|
buddy_list.container = $("#user_presences");
|
2019-04-18 19:28:25 +02:00
|
|
|
buddy_list.container.append = () => {};
|
|
|
|
clear_buddy_list();
|
2020-02-06 03:58:06 +01:00
|
|
|
page_params.presences = {};
|
2019-04-18 19:28:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$.stub_selector("html", {
|
2020-07-20 22:18:43 +02:00
|
|
|
on(name, func) {
|
2018-05-07 03:30:13 +02:00
|
|
|
func();
|
|
|
|
},
|
|
|
|
});
|
2017-10-12 05:31:32 +02:00
|
|
|
|
2018-05-07 03:30:13 +02:00
|
|
|
channel.post = function (payload) {
|
|
|
|
payload.success({});
|
|
|
|
};
|
|
|
|
global.server_events = {
|
2020-07-20 22:18:43 +02:00
|
|
|
check_for_unsuspend() {},
|
2018-05-07 03:30:13 +02:00
|
|
|
};
|
2018-07-16 15:16:33 +02:00
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2019-06-29 02:52:15 +02:00
|
|
|
activity.client_is_active = false;
|
2019-04-18 19:28:25 +02:00
|
|
|
|
2020-07-21 09:44:41 +02:00
|
|
|
$(window).off("focus");
|
2018-05-07 03:30:13 +02:00
|
|
|
activity.initialize();
|
2020-07-21 06:16:05 +02:00
|
|
|
$(window).trigger("focus");
|
2019-04-18 19:28:25 +02:00
|
|
|
clear();
|
|
|
|
|
2018-07-16 15:16:33 +02:00
|
|
|
assert(scroll_handler_started);
|
2018-05-07 03:30:13 +02:00
|
|
|
assert(!activity.new_user_input);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(!$("#zephyr-mirror-error").hasClass("show"));
|
2019-06-29 02:52:15 +02:00
|
|
|
assert(activity.client_is_active);
|
2018-05-07 03:30:13 +02:00
|
|
|
$(window).idle = function (params) {
|
|
|
|
params.onIdle();
|
|
|
|
};
|
|
|
|
channel.post = function (payload) {
|
|
|
|
payload.success({
|
|
|
|
zephyr_mirror_active: false,
|
2020-02-06 03:58:06 +01:00
|
|
|
presences: {},
|
2018-05-07 03:30:13 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
global.setInterval = (func) => func();
|
|
|
|
|
2020-07-21 09:44:41 +02:00
|
|
|
$(window).off("focus");
|
2018-05-07 03:30:13 +02:00
|
|
|
activity.initialize();
|
2019-04-18 19:28:25 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert($("#zephyr-mirror-error").hasClass("show"));
|
2018-05-07 03:30:13 +02:00
|
|
|
assert(!activity.new_user_input);
|
2019-06-29 02:52:15 +02:00
|
|
|
assert(!activity.client_is_active);
|
2018-05-07 03:30:13 +02:00
|
|
|
|
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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("away_status", () => {
|
2018-12-19 18:41:47 +01:00
|
|
|
assert(!user_status.is_away(alice.user_id));
|
|
|
|
activity.on_set_away(alice.user_id);
|
|
|
|
assert(user_status.is_away(alice.user_id));
|
|
|
|
activity.on_revoke_away(alice.user_id);
|
|
|
|
assert(!user_status.is_away(alice.user_id));
|
|
|
|
});
|
2019-03-29 00:13:07 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("electron_bridge", () => {
|
2019-03-29 00:13:07 +01:00
|
|
|
activity.client_is_active = false;
|
|
|
|
window.electron_bridge = undefined;
|
|
|
|
assert.equal(activity.compute_active_status(), activity.IDLE);
|
|
|
|
|
|
|
|
activity.client_is_active = true;
|
|
|
|
assert.equal(activity.compute_active_status(), activity.ACTIVE);
|
|
|
|
|
|
|
|
window.electron_bridge = {
|
2020-04-26 23:13:25 +02:00
|
|
|
get_idle_on_system: () => true,
|
2019-03-29 00:13:07 +01:00
|
|
|
};
|
|
|
|
assert.equal(activity.compute_active_status(), activity.IDLE);
|
|
|
|
activity.client_is_active = false;
|
|
|
|
assert.equal(activity.compute_active_status(), activity.IDLE);
|
|
|
|
|
|
|
|
window.electron_bridge = {
|
2020-04-26 23:13:25 +02:00
|
|
|
get_idle_on_system: () => false,
|
2019-03-29 00:13:07 +01:00
|
|
|
};
|
|
|
|
assert.equal(activity.compute_active_status(), activity.ACTIVE);
|
|
|
|
activity.client_is_active = true;
|
|
|
|
assert.equal(activity.compute_active_status(), activity.ACTIVE);
|
|
|
|
});
|