2017-05-25 01:49:29 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2014-01-30 22:42:19 +01:00
|
|
|
|
2016-10-30 20:46:57 +01:00
|
|
|
set_global('page_params', {
|
2017-04-24 21:59:07 +02:00
|
|
|
realm_users: [],
|
2017-10-05 06:06:42 +02:00
|
|
|
user_id: 999,
|
2016-10-30 20:46:57 +01:00
|
|
|
});
|
|
|
|
|
2017-08-02 16:51:37 +02:00
|
|
|
set_global('ui', {
|
|
|
|
set_up_scrollbar: function () {},
|
|
|
|
});
|
|
|
|
|
2017-01-09 18:20:31 +01:00
|
|
|
set_global('feature_flags', {});
|
|
|
|
|
|
|
|
set_global('document', {
|
|
|
|
hasFocus: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-05-01 00:40:14 +02:00
|
|
|
set_global('blueslip', global.make_zblueslip());
|
2017-06-24 15:15:37 +02:00
|
|
|
set_global('channel', {});
|
|
|
|
set_global('compose_actions', {});
|
2017-05-12 20:16:39 +02:00
|
|
|
|
2017-09-27 20:41:19 +02:00
|
|
|
set_global('ui', {
|
|
|
|
set_up_scrollbar: function () {},
|
|
|
|
update_scrollbar: function () {},
|
|
|
|
});
|
|
|
|
|
2017-08-09 18:34:41 +02:00
|
|
|
zrequire('compose_fade');
|
|
|
|
zrequire('Handlebars', 'handlebars');
|
|
|
|
zrequire('templates');
|
|
|
|
zrequire('unread');
|
|
|
|
zrequire('hash_util');
|
|
|
|
zrequire('hashchange');
|
|
|
|
zrequire('narrow');
|
|
|
|
zrequire('util');
|
|
|
|
zrequire('presence');
|
|
|
|
zrequire('people');
|
2018-04-19 15:46:56 +02:00
|
|
|
zrequire('buddy_data');
|
2018-04-19 14:17:22 +02:00
|
|
|
zrequire('buddy_list');
|
2018-04-19 17:47:41 +02:00
|
|
|
zrequire('user_search');
|
2018-04-21 14:59:03 +02:00
|
|
|
zrequire('list_cursor');
|
2017-08-09 18:34:41 +02:00
|
|
|
zrequire('activity');
|
2017-03-30 20:04:01 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
var filter_key_handlers;
|
|
|
|
set_global('keydown_util', {
|
|
|
|
handle: (opts) => {
|
|
|
|
filter_key_handlers = opts.handlers;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-04-22 17:46:20 +02:00
|
|
|
set_global('compose_state', {});
|
|
|
|
|
2018-04-24 14:09:16 +02:00
|
|
|
set_global('scroll_util', {
|
2018-04-21 14:59:03 +02:00
|
|
|
scroll_element_into_container: () => {},
|
|
|
|
});
|
|
|
|
|
2017-10-12 05:07:12 +02:00
|
|
|
set_global('popovers', {
|
|
|
|
hide_all: function () {},
|
|
|
|
show_userlist_sidebar: function () {
|
|
|
|
$('.column-right').addClass('expanded');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('stream_popover', {
|
|
|
|
show_streamlist_sidebar: function () {
|
|
|
|
$('.column-left').addClass('expanded');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-10-12 05:31:32 +02:00
|
|
|
set_global('reload', {
|
2018-04-12 23:54:13 +02:00
|
|
|
is_in_progress: () => false,
|
2017-10-12 05:31:32 +02:00
|
|
|
});
|
2016-11-11 19:30:04 +01:00
|
|
|
set_global('resize', {
|
2018-04-12 23:54:13 +02:00
|
|
|
resize_page_components: () => {},
|
2016-11-11 19:30:04 +01:00
|
|
|
});
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const me = {
|
2017-02-05 00:22:16 +01:00
|
|
|
email: 'me@zulip.com',
|
|
|
|
user_id: 999,
|
|
|
|
full_name: 'Me Myself',
|
|
|
|
};
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const alice = {
|
2016-10-30 20:46:57 +01:00
|
|
|
email: 'alice@zulip.com',
|
|
|
|
user_id: 1,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice Smith',
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
2018-04-12 23:40:03 +02:00
|
|
|
const fred = {
|
2016-10-30 20:46:57 +01:00
|
|
|
email: 'fred@zulip.com',
|
|
|
|
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 = {
|
2016-10-30 20:46:57 +01:00
|
|
|
email: 'jill@zulip.com',
|
|
|
|
user_id: 3,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Jill Hill',
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
2018-04-12 23:40:03 +02:00
|
|
|
const mark = {
|
2016-10-30 20:46:57 +01:00
|
|
|
email: 'mark@zulip.com',
|
|
|
|
user_id: 4,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Marky Mark',
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
2018-04-12 23:40:03 +02:00
|
|
|
const norbert = {
|
2016-10-30 20:46:57 +01:00
|
|
|
email: 'norbert@zulip.com',
|
|
|
|
user_id: 5,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Norbert Oswald',
|
2016-11-17 21:43:12 +01:00
|
|
|
};
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const zoe = {
|
2017-03-31 00:18:04 +02:00
|
|
|
email: 'zoe@example.com',
|
|
|
|
user_id: 6,
|
|
|
|
full_name: 'Zoe Yang',
|
|
|
|
};
|
2016-11-17 21:43:12 +01:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const people = global.people;
|
2016-11-17 23:16:29 +01:00
|
|
|
|
2017-03-31 00:18:04 +02:00
|
|
|
people.add_in_realm(alice);
|
|
|
|
people.add_in_realm(fred);
|
|
|
|
people.add_in_realm(jill);
|
|
|
|
people.add_in_realm(mark);
|
|
|
|
people.add_in_realm(norbert);
|
|
|
|
people.add_in_realm(zoe);
|
|
|
|
people.add_in_realm(me);
|
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const real_update_huddles = activity.update_huddles;
|
2018-04-12 23:54:13 +02:00
|
|
|
activity.update_huddles = () => {};
|
2016-11-11 18:00:09 +01:00
|
|
|
|
2017-01-09 18:20:31 +01:00
|
|
|
global.compile_template('user_presence_row');
|
|
|
|
global.compile_template('user_presence_rows');
|
2017-06-24 15:15:37 +02:00
|
|
|
global.compile_template('group_pms');
|
2017-01-09 18:20:31 +01:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const presence_info = {};
|
2017-04-13 04:28:15 +02:00
|
|
|
presence_info[alice.user_id] = { status: 'inactive' };
|
|
|
|
presence_info[fred.user_id] = { status: 'active' };
|
|
|
|
presence_info[jill.user_id] = { status: 'active' };
|
|
|
|
|
|
|
|
presence.presence_info = presence_info;
|
|
|
|
|
2018-05-15 12:40:07 +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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('reload_defaults', () => {
|
2018-05-01 00:40:14 +02:00
|
|
|
blueslip.set_test_data('warn', 'get_filter_text() is called before initialization');
|
2017-10-07 19:55:44 +02:00
|
|
|
assert.equal(activity.get_filter_text(), '');
|
2018-05-01 00:40:14 +02:00
|
|
|
assert(blueslip.get_test_logs('warn').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-10-07 19:55:44 +02:00
|
|
|
|
2018-05-15 12:40:07 +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
|
|
|
|
2016-11-17 21:43:12 +01:00
|
|
|
assert.deepEqual(user_ids, [
|
|
|
|
fred.user_id,
|
|
|
|
jill.user_id,
|
2016-12-03 23:17:57 +01:00
|
|
|
alice.user_id,
|
2013-08-09 14:42:49 +02:00
|
|
|
]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('process_loaded_messages', () => {
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const huddle1 = 'jill@zulip.com,norbert@zulip.com';
|
|
|
|
const timestamp1 = 1382479029; // older
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const huddle2 = 'alice@zulip.com,fred@zulip.com';
|
|
|
|
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
|
|
|
{
|
2013-10-23 20:44:31 +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
|
|
|
},
|
|
|
|
{
|
2016-12-03 23:17:57 +01:00
|
|
|
type: 'stream',
|
2013-10-23 20:44:31 +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
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
|
|
];
|
|
|
|
|
|
|
|
activity.process_loaded_messages(messages);
|
|
|
|
|
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);
|
2016-11-17 23:16:29 +01:00
|
|
|
assert.deepEqual(activity.get_huddles(), [user_ids_string2, user_ids_string1]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-10-23 20:44:31 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('full_huddle_name', () => {
|
2016-11-17 23:16:29 +01:00
|
|
|
function full_name(emails_string) {
|
2018-04-18 22:51:40 +02:00
|
|
|
const user_ids_string = people.emails_strings_to_user_ids_string(emails_string);
|
2016-11-17 23:16:29 +01:00
|
|
|
return activity.full_huddle_name(user_ids_string);
|
|
|
|
}
|
|
|
|
|
2013-10-23 22:22:34 +02:00
|
|
|
assert.equal(
|
2016-11-17 23:16:29 +01:00
|
|
|
full_name('alice@zulip.com,jill@zulip.com'),
|
2016-12-03 23:17:57 +01:00
|
|
|
'Alice Smith, Jill Hill');
|
2013-10-23 22:22:34 +02:00
|
|
|
|
|
|
|
assert.equal(
|
2016-11-17 23:16:29 +01:00
|
|
|
full_name('alice@zulip.com,fred@zulip.com,jill@zulip.com'),
|
2016-12-03 23:17:57 +01:00
|
|
|
'Alice Smith, Fred Flintstone, Jill Hill');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-11-04 21:56:56 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('short_huddle_name', () => {
|
2016-11-17 23:16:29 +01:00
|
|
|
function short_name(emails_string) {
|
2018-04-18 22:51:40 +02:00
|
|
|
const user_ids_string = people.emails_strings_to_user_ids_string(emails_string);
|
2016-11-17 23:16:29 +01:00
|
|
|
return activity.short_huddle_name(user_ids_string);
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:59:03 +01:00
|
|
|
assert.equal(
|
2016-11-17 23:16:29 +01:00
|
|
|
short_name('alice@zulip.com'),
|
2016-12-03 23:17:57 +01:00
|
|
|
'Alice Smith');
|
2013-11-04 22:59:03 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2016-11-17 23:16:29 +01:00
|
|
|
short_name('alice@zulip.com,jill@zulip.com'),
|
2016-12-03 23:17:57 +01:00
|
|
|
'Alice Smith, Jill Hill');
|
2013-11-04 22:59:03 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2016-11-17 23:16:29 +01:00
|
|
|
short_name('alice@zulip.com,fred@zulip.com,jill@zulip.com'),
|
2016-12-03 23:17:57 +01:00
|
|
|
'Alice Smith, Fred Flintstone, Jill Hill');
|
2013-11-04 22:59:03 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2016-11-17 23:16:29 +01:00
|
|
|
short_name('alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com'),
|
2016-12-03 23:17:57 +01:00
|
|
|
'Alice Smith, Fred Flintstone, Jill Hill, + 1 other');
|
2013-12-05 22:20:20 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2016-11-17 23:16:29 +01:00
|
|
|
short_name('alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com,norbert@zulip.com'),
|
2016-12-03 23:17:57 +01:00
|
|
|
'Alice Smith, Fred Flintstone, Jill Hill, + 2 others');
|
2013-12-05 22:20:20 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-11-04 22:59:03 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('huddle_fraction_present', () => {
|
2018-04-18 22:51:40 +02:00
|
|
|
let huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
|
2016-11-17 23:16:29 +01:00
|
|
|
huddle = people.emails_strings_to_user_ids_string(huddle);
|
2013-11-04 21:56:56 +01:00
|
|
|
|
2018-04-24 18:12:09 +02:00
|
|
|
var presence_info = {};
|
|
|
|
presence_info[alice.user_id] = { status: 'active' }; // counts as present
|
|
|
|
presence_info[fred.user_id] = { status: 'idle' }; // doest not count as present
|
2016-11-17 21:43:12 +01:00
|
|
|
// jill not in list
|
2017-03-06 16:14:52 +01:00
|
|
|
presence_info[mark.user_id] = { status: 'offline' }; // does not count
|
2017-03-30 20:04:01 +02:00
|
|
|
presence.presence_info = presence_info;
|
2013-11-04 21:56:56 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2017-03-06 16:14:52 +01:00
|
|
|
activity.huddle_fraction_present(huddle),
|
2016-12-03 23:17:57 +01:00
|
|
|
'0.50');
|
2018-04-24 18:12:09 +02:00
|
|
|
|
2018-05-07 03:30:13 +02:00
|
|
|
huddle = 'alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com';
|
|
|
|
huddle = people.emails_strings_to_user_ids_string(huddle);
|
|
|
|
presence_info = {};
|
|
|
|
presence_info[alice.user_id] = { status: 'idle' };
|
|
|
|
presence_info[fred.user_id] = { status: 'idle' }; // does not count as present
|
|
|
|
// jill not in list
|
|
|
|
presence_info[mark.user_id] = { status: 'offline' }; // does not count
|
|
|
|
presence.presence_info = presence_info;
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.huddle_fraction_present(huddle),
|
|
|
|
false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-11-04 21:56:56 +01:00
|
|
|
|
2017-03-30 20:04:01 +02:00
|
|
|
presence.presence_info = {};
|
|
|
|
presence.presence_info[alice.user_id] = { status: activity.IDLE };
|
|
|
|
presence.presence_info[fred.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[jill.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[mark.user_id] = { status: activity.IDLE };
|
|
|
|
presence.presence_info[norbert.user_id] = { status: activity.ACTIVE };
|
2017-10-05 06:06:42 +02:00
|
|
|
presence.presence_info[zoe.user_id] = { status: activity.ACTIVE };
|
2017-10-07 20:45:13 +02:00
|
|
|
presence.presence_info[me.user_id] = { status: activity.ACTIVE };
|
2017-01-09 18:20:31 +01:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
function reset_setup() {
|
2018-04-19 17:47:41 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2018-04-21 14:59:03 +02:00
|
|
|
activity.set_cursor_and_filter();
|
2018-04-20 16:13:39 +02:00
|
|
|
|
|
|
|
buddy_list.container = $('#user_presences');
|
2018-04-21 14:59:03 +02:00
|
|
|
const stub = $.create('first elem stub');
|
|
|
|
stub.first = () => [];
|
|
|
|
buddy_list.container.set_find_results('li.user_sidebar_entry', stub);
|
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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('presence_list_full_update', () => {
|
2018-02-12 23:31:17 +01:00
|
|
|
$('.user-list-filter').focus();
|
2018-04-22 17:46:20 +02:00
|
|
|
compose_state.recipient = () => fred.email;
|
|
|
|
compose_fade.set_focused_recipient("private");
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const users = activity.build_user_sidebar();
|
2018-05-07 03:30:13 +02:00
|
|
|
assert.deepEqual(users, [
|
|
|
|
{
|
2017-01-09 18:20:31 +01:00
|
|
|
name: 'Fred Flintstone',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/2-fred',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: fred.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
2018-04-22 17:46:20 +02:00
|
|
|
faded: false,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Jill Hill',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/3-jill',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: jill.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
2018-04-22 17:46:20 +02:00
|
|
|
faded: true,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Norbert Oswald',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/5-norbert',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: norbert.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
2018-04-22 17:46:20 +02:00
|
|
|
faded: true,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
2017-10-05 06:06:42 +02:00
|
|
|
{
|
|
|
|
name: 'Zoe Yang',
|
|
|
|
href: '#narrow/pm-with/6-zoe',
|
|
|
|
user_id: zoe.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
2018-04-22 17:46:20 +02:00
|
|
|
faded: true,
|
2017-10-05 06:06:42 +02:00
|
|
|
},
|
2017-01-09 18:20:31 +01:00
|
|
|
{
|
|
|
|
name: 'Alice Smith',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/1-alice',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: alice.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'idle',
|
|
|
|
type_desc: 'is not active',
|
2018-04-22 17:46:20 +02:00
|
|
|
faded: true,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Marky Mark',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/4-mark',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: mark.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'idle',
|
|
|
|
type_desc: 'is not active',
|
2018-04-22 17:46:20 +02:00
|
|
|
faded: true,
|
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() {
|
|
|
|
$('.user-list-filter').closest = function (selector) {
|
|
|
|
assert.equal(selector, ".app-main [class^='column-']");
|
|
|
|
return $.create('right-sidebar').addClass('column-right');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function simulate_left_column_buddy_list() {
|
|
|
|
$('.user-list-filter').closest = function (selector) {
|
|
|
|
assert.equal(selector, ".app-main [class^='column-']");
|
|
|
|
return $.create('left-sidebar').addClass('column-left');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
function simulate_list_items(items) {
|
|
|
|
const list = {
|
|
|
|
length: items.length,
|
|
|
|
eq: (i) => items[i],
|
2018-04-21 14:59:03 +02:00
|
|
|
first: () => items[0] || {length: 0},
|
2018-04-20 16:13:39 +02:00
|
|
|
};
|
|
|
|
$('#user_presences').set_find_results('li.user_sidebar_entry', list);
|
2018-04-21 14:59:03 +02:00
|
|
|
|
|
|
|
_.each(items, (item, i) => {
|
2018-06-04 21:13:07 +02:00
|
|
|
item.next = () => items[i + 1] || {length: 0};
|
|
|
|
item.prev = () => items[i - 1] || {length: 0};
|
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) {
|
|
|
|
stub.attr('data-user-id', user_id);
|
|
|
|
}
|
2018-04-20 16:13:39 +02:00
|
|
|
const sel = `li.user_sidebar_entry[data-user-id='${user_id}']`;
|
|
|
|
$('#user_presences').set_find_results(sel, stub);
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('PM_update_dom_counts', () => {
|
2018-04-12 23:40:03 +02:00
|
|
|
const value = $.create('alice-value');
|
|
|
|
const count = $.create('alice-count');
|
|
|
|
const pm_key = alice.user_id.toString();
|
2018-04-20 16:13:39 +02:00
|
|
|
const li = $.create('alice stub');
|
|
|
|
buddy_list_add(pm_key, li);
|
2017-07-08 14:31:18 +02:00
|
|
|
count.set_find_results('.value', value);
|
|
|
|
li.set_find_results('.count', count);
|
2017-07-08 14:05:49 +02:00
|
|
|
count.set_parent(li);
|
2017-05-24 19:46:15 +02:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const counts = new Dict();
|
2017-05-24 19:46:15 +02:00
|
|
|
counts.set(pm_key, 5);
|
|
|
|
li.addClass('user_sidebar_entry');
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
|
|
|
assert(li.hasClass('user-with-count'));
|
|
|
|
assert.equal(value.text(), 5);
|
|
|
|
|
|
|
|
counts.set(pm_key, 0);
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
|
|
|
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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('group_update_dom_counts', () => {
|
2018-04-12 23:40:03 +02:00
|
|
|
const value = $.create('alice-fred-value');
|
|
|
|
const count = $.create('alice-fred-count');
|
|
|
|
const pm_key = alice.user_id.toString() + "," + fred.user_id.toString();
|
|
|
|
const li_selector = "li.group-pms-sidebar-entry[data-user-ids='" + pm_key + "']";
|
|
|
|
const li = $(li_selector);
|
2017-07-08 14:31:18 +02:00
|
|
|
count.set_find_results('.value', value);
|
|
|
|
li.set_find_results('.count', count);
|
2017-07-08 14:05:49 +02:00
|
|
|
count.set_parent(li);
|
2017-05-24 19:46:15 +02:00
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const counts = new Dict();
|
2017-05-24 19:46:15 +02:00
|
|
|
counts.set(pm_key, 5);
|
|
|
|
li.addClass('group-pms-sidebar-entry');
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
|
|
|
assert(li.hasClass('group-with-count'));
|
|
|
|
assert.equal(value.text(), 5);
|
|
|
|
|
|
|
|
counts.set(pm_key, 0);
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
|
|
|
assert(!li.hasClass('group-with-count'));
|
|
|
|
assert.equal(value.text(), '');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-24 23:28:18 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
2018-04-19 17:47:41 +02:00
|
|
|
|
2018-05-15 12:40:07 +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-02-12 23:31:17 +01:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
const alice_li = $.create('alice stub');
|
|
|
|
const fred_li = $.create('fred stub');
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
(function test_click_filter() {
|
|
|
|
const e = {
|
|
|
|
stopPropagation: () => {},
|
2018-02-12 23:31:17 +01:00
|
|
|
};
|
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
simulate_list_items([alice_li, fred_li]);
|
|
|
|
const handler = $('.user-list-filter').get_on_handler('focus');
|
|
|
|
handler(e);
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
simulate_list_items([]);
|
|
|
|
handler(e);
|
|
|
|
}());
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
(function test_click_header_filter() {
|
|
|
|
const e = {};
|
|
|
|
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);
|
|
|
|
}());
|
2018-04-19 21:50:14 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
(function test_filter_keys() {
|
|
|
|
simulate_list_items([alice_li, fred_li]);
|
|
|
|
buddy_list_add(alice.user_id, alice_li);
|
|
|
|
buddy_list_add(fred.user_id, fred_li);
|
2018-04-19 21:50:14 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
activity.user_cursor.go_to(alice.user_id);
|
|
|
|
filter_key_handlers.down_arrow();
|
|
|
|
filter_key_handlers.up_arrow();
|
|
|
|
filter_key_handlers.up_arrow();
|
|
|
|
filter_key_handlers.down_arrow();
|
|
|
|
filter_key_handlers.down_arrow();
|
2018-04-19 21:50:14 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
simulate_list_items([]);
|
|
|
|
filter_key_handlers.down_arrow();
|
|
|
|
filter_key_handlers.up_arrow();
|
|
|
|
}());
|
2018-04-19 21:50:14 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
(function test_enter_key() {
|
|
|
|
var narrowed;
|
2018-04-19 21:50:14 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
narrow.by = (method, email) => {
|
|
|
|
assert.equal(email, 'alice@zulip.com');
|
|
|
|
narrowed = true;
|
|
|
|
};
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
$('.user-list-filter').val('al');
|
|
|
|
buddy_list_add(alice.user_id, alice_li);
|
|
|
|
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();
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_click_handler() {
|
|
|
|
// We wire up the click handler in click_handlers.js,
|
|
|
|
// so this just tests the called function.
|
|
|
|
var narrowed;
|
|
|
|
|
|
|
|
narrow.by = (method, email) => {
|
|
|
|
assert.equal(email, 'alice@zulip.com');
|
|
|
|
narrowed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
buddy_list_add(alice.user_id, alice_li);
|
|
|
|
activity.narrow_for_user({li: alice_li});
|
|
|
|
assert(narrowed);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_blur_filter() {
|
|
|
|
const e = {};
|
|
|
|
const handler = $('.user-list-filter').get_on_handler('blur');
|
|
|
|
handler(e);
|
|
|
|
}());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-12 23:31:17 +01:00
|
|
|
|
2017-05-25 01:49:39 +02:00
|
|
|
presence.presence_info = {};
|
|
|
|
presence.presence_info[alice.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[fred.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[jill.user_id] = { status: activity.ACTIVE };
|
2017-10-05 06:06:42 +02:00
|
|
|
presence.presence_info[mark.user_id] = { status: activity.IDLE };
|
|
|
|
presence.presence_info[norbert.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[zoe.user_id] = { status: activity.ACTIVE };
|
2017-05-24 23:28:18 +02:00
|
|
|
|
2018-04-21 14:59:03 +02:00
|
|
|
reset_setup();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('filter_user_ids', () => {
|
2018-04-12 23:40:03 +02:00
|
|
|
const user_filter = $('.user-list-filter');
|
2017-05-24 23:28:18 +02:00
|
|
|
user_filter.val(''); // no search filter
|
|
|
|
|
2018-04-19 15:46:56 +02:00
|
|
|
function get_user_ids() {
|
|
|
|
var filter_text = activity.get_filter_text();
|
|
|
|
var user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
|
|
|
|
return user_ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
var 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
|
|
|
|
|
|
|
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, []);
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
presence.presence_info[alice.user_id] = { status: activity.IDLE };
|
|
|
|
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]);
|
|
|
|
|
|
|
|
$.stub_selector('.user-list-filter', []);
|
|
|
|
presence.presence_info[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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('insert_one_user_into_empty_list', () => {
|
2018-04-12 23:40:03 +02:00
|
|
|
const alice_li = $.create('alice list item');
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-04-18 22:51:40 +02:00
|
|
|
let appended_html;
|
2017-05-25 01:49:39 +02:00
|
|
|
$('#user_presences').append = function (html) {
|
|
|
|
appended_html = html;
|
2018-04-20 16:13:39 +02:00
|
|
|
buddy_list_add(alice.user_id, alice_li);
|
2017-05-25 01:49:39 +02:00
|
|
|
};
|
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
var removed;
|
|
|
|
const remove_stub = {
|
|
|
|
remove: () => {
|
|
|
|
removed = true;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
buddy_list_add(alice.user_id, remove_stub);
|
|
|
|
|
|
|
|
simulate_list_items([]);
|
2017-05-25 01:49:39 +02:00
|
|
|
activity.insert_user_into_list(alice.user_id);
|
|
|
|
assert(appended_html.indexOf('data-user-id="1"') > 0);
|
|
|
|
assert(appended_html.indexOf('user_active') > 0);
|
2018-04-20 16:13:39 +02:00
|
|
|
assert(removed);
|
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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('insert_fred_after_alice', () => {
|
2018-04-20 16:13:39 +02:00
|
|
|
const alice_li = $.create('alice list item');
|
2018-04-12 23:40:03 +02:00
|
|
|
const fred_li = $.create('fred list item');
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
alice_li.attr('data-user-id', alice.user_id);
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-04-18 22:51:40 +02:00
|
|
|
let appended_html;
|
2017-05-25 01:49:39 +02:00
|
|
|
$('#user_presences').append = function (html) {
|
|
|
|
appended_html = html;
|
2018-04-20 16:13:39 +02:00
|
|
|
buddy_list_add(fred.user_id, fred_li);
|
2017-05-25 01:49:39 +02:00
|
|
|
};
|
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
var removed;
|
|
|
|
const remove_stub = {
|
|
|
|
remove: () => {
|
|
|
|
removed = true;
|
|
|
|
},
|
2017-05-25 01:49:39 +02:00
|
|
|
};
|
2018-04-20 16:13:39 +02:00
|
|
|
buddy_list_add(fred.user_id, remove_stub);
|
|
|
|
|
|
|
|
simulate_list_items([alice_li]);
|
2017-05-25 01:49:39 +02:00
|
|
|
|
|
|
|
activity.insert_user_into_list(fred.user_id);
|
|
|
|
|
|
|
|
assert(appended_html.indexOf('data-user-id="2"') > 0);
|
|
|
|
assert(appended_html.indexOf('user_active') > 0);
|
2018-04-20 16:13:39 +02:00
|
|
|
assert(removed);
|
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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('insert_fred_before_jill', () => {
|
2018-04-12 23:40:03 +02:00
|
|
|
const fred_li = $.create('fred-li');
|
2018-04-20 16:13:39 +02:00
|
|
|
const jill_li = $.create('jill-li');
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
jill_li.attr('data-user-id', jill.user_id);
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
var before_html;
|
|
|
|
jill_li.before = function (html) {
|
|
|
|
before_html = html;
|
|
|
|
buddy_list_add(fred.user_id, fred_li);
|
2017-05-25 01:49:39 +02:00
|
|
|
};
|
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
var removed;
|
|
|
|
const remove_stub = {
|
|
|
|
remove: () => {
|
|
|
|
removed = true;
|
2017-05-25 01:49:39 +02:00
|
|
|
},
|
|
|
|
};
|
2018-04-20 16:13:39 +02:00
|
|
|
buddy_list_add(fred.user_id, remove_stub);
|
|
|
|
|
|
|
|
simulate_list_items([jill_li]);
|
|
|
|
|
2017-05-25 01:49:39 +02:00
|
|
|
activity.insert_user_into_list(fred.user_id);
|
|
|
|
|
|
|
|
assert(before_html.indexOf('data-user-id="2"') > 0);
|
|
|
|
assert(before_html.indexOf('user_active') > 0);
|
2018-04-20 16:13:39 +02:00
|
|
|
assert(removed);
|
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
|
|
|
|
2018-05-15 12:40:07 +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.
|
2018-04-12 23:40:03 +02:00
|
|
|
const user_filter = $('.user-list-filter');
|
2017-05-25 01:49:39 +02:00
|
|
|
user_filter.val('do-not-match-filter');
|
|
|
|
activity.insert_user_into_list(fred.user_id);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('realm_presence_disabled', () => {
|
2017-05-25 01:49:39 +02:00
|
|
|
page_params.realm_presence_disabled = true;
|
2017-06-24 15:15:37 +02:00
|
|
|
unread.suppress_unread_counts = false;
|
2017-05-25 01:49:39 +02:00
|
|
|
|
|
|
|
activity.insert_user_into_list();
|
|
|
|
activity.build_user_sidebar();
|
|
|
|
|
|
|
|
real_update_huddles();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 01:49:39 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('clear_search', () => {
|
2017-06-24 15:15:37 +02:00
|
|
|
$('.user-list-filter').val('somevalue');
|
2018-04-19 17:47:41 +02:00
|
|
|
activity.user_filter.clear_search();
|
2017-06-24 15:15:37 +02:00
|
|
|
assert.equal($('.user-list-filter').val(), '');
|
2018-04-19 17:47:41 +02:00
|
|
|
activity.user_filter.clear_search();
|
2018-01-04 18:15:42 +01:00
|
|
|
assert($('#user-list .input-append').hasClass('notdisplayed'));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('escape_search', () => {
|
2017-06-24 15:15:37 +02:00
|
|
|
$('.user-list-filter').val('somevalue');
|
2018-01-04 18:15:42 +01:00
|
|
|
activity.escape_search();
|
|
|
|
assert.equal($('.user-list-filter').val(), '');
|
|
|
|
activity.escape_search();
|
|
|
|
assert($('#user-list .input-append').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();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('initiate_search', () => {
|
2017-06-24 15:15:37 +02:00
|
|
|
$('.user-list-filter').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();
|
|
|
|
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();
|
2017-10-12 05:07:12 +02:00
|
|
|
assert.equal($('.column-left').hasClass('expanded'), true);
|
2017-06-24 15:15:37 +02:00
|
|
|
assert.equal($('.user-list-filter').is_focused(), true);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('toggle_filter_display', () => {
|
2018-04-19 17:47:41 +02:00
|
|
|
activity.user_filter.toggle_filter_displayed();
|
2018-01-04 18:15:42 +01:00
|
|
|
assert($('#user-list .input-append').hasClass('notdisplayed'));
|
|
|
|
$('.user-list-filter').closest = function (selector) {
|
|
|
|
assert.equal(selector, ".app-main [class^='column-']");
|
|
|
|
return $.create('sidebar').addClass('column-right');
|
|
|
|
};
|
2018-04-19 17:47:41 +02:00
|
|
|
activity.user_filter.toggle_filter_displayed();
|
2018-01-04 18:15:42 +01:00
|
|
|
assert.equal($('#user-list .input-append').hasClass('notdisplayed'), false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('searching', () => {
|
2017-06-24 15:15:37 +02:00
|
|
|
$('.user-list-filter').focus();
|
|
|
|
assert.equal(activity.searching(), true);
|
|
|
|
$('.user-list-filter').blur();
|
|
|
|
assert.equal(activity.searching(), false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('update_huddles_and_redraw', () => {
|
2018-04-12 23:40:03 +02:00
|
|
|
const value = $.create('alice-fred-value');
|
|
|
|
const count = $.create('alice-fred-count');
|
|
|
|
const pm_key = alice.user_id.toString() + "," + fred.user_id.toString();
|
|
|
|
const li_selector = "li.group-pms-sidebar-entry[data-user-ids='" + pm_key + "']";
|
|
|
|
const li = $(li_selector);
|
2017-07-08 14:31:18 +02:00
|
|
|
count.set_find_results('.value', value);
|
|
|
|
li.set_find_results('.count', count);
|
2017-07-08 14:05:49 +02:00
|
|
|
count.set_parent(li);
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const real_get_huddles = activity.get_huddles;
|
2018-04-12 23:54:13 +02:00
|
|
|
activity.get_huddles = () => ['1,2'];
|
2017-06-24 15:15:37 +02:00
|
|
|
activity.update_huddles = real_update_huddles;
|
|
|
|
activity.redraw();
|
|
|
|
assert.equal($('#group-pm-list').hasClass('show'), false);
|
|
|
|
page_params.realm_presence_disabled = false;
|
|
|
|
activity.redraw();
|
|
|
|
assert.equal($('#group-pm-list').hasClass('show'), true);
|
2018-04-12 23:54:13 +02:00
|
|
|
activity.get_huddles = () => [];
|
2017-06-24 15:15:37 +02:00
|
|
|
activity.redraw();
|
|
|
|
assert.equal($('#group-pm-list').hasClass('show'), false);
|
|
|
|
activity.get_huddles = real_get_huddles;
|
|
|
|
activity.update_huddles = function () {};
|
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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('set_user_status', () => {
|
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
|
|
|
|
2018-04-20 16:13:39 +02:00
|
|
|
const alice_li = $.create('alice stub');
|
|
|
|
buddy_list_add(alice.user_id, alice_li);
|
|
|
|
|
|
|
|
var inserted;
|
|
|
|
buddy_list.insert_or_move = () => {
|
|
|
|
inserted = true;
|
|
|
|
};
|
2017-06-24 15:15:37 +02:00
|
|
|
|
|
|
|
presence.presence_info[alice.user_id] = undefined;
|
|
|
|
activity.set_user_status(me.email, info, server_time);
|
2018-04-20 16:13:39 +02:00
|
|
|
assert(!inserted);
|
|
|
|
|
2017-06-24 15:15:37 +02:00
|
|
|
assert.equal(presence.presence_info[alice.user_id], undefined);
|
|
|
|
activity.set_user_status(alice.email, info, server_time);
|
2018-04-20 16:13:39 +02:00
|
|
|
assert(inserted);
|
|
|
|
|
2018-04-12 23:40:03 +02:00
|
|
|
const expected = { status: 'active', mobile: false, last_active: 500 };
|
2017-06-24 15:15:37 +02:00
|
|
|
assert.deepEqual(presence.presence_info[alice.user_id], expected);
|
2018-05-01 00:40:14 +02:00
|
|
|
|
2017-06-24 15:15:37 +02:00
|
|
|
activity.set_user_status(alice.email, info, server_time);
|
2018-05-01 00:40:14 +02:00
|
|
|
blueslip.set_test_data('warn', 'unknown email: foo@bar.com');
|
|
|
|
blueslip.set_test_data('error', 'Unknown email for get_user_id: foo@bar.com');
|
2017-06-24 15:15:37 +02:00
|
|
|
activity.set_user_status('foo@bar.com', info, server_time);
|
2018-05-01 00:40:14 +02:00
|
|
|
assert(blueslip.get_test_logs('warn').length, 1);
|
|
|
|
assert(blueslip.get_test_logs('error').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-24 15:15:37 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('initialize', () => {
|
2018-05-07 03:30:13 +02:00
|
|
|
$.stub_selector('html', {
|
|
|
|
on: function (name, func) {
|
|
|
|
func();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
$(window).focus = func => func();
|
|
|
|
$(window).idle = () => {};
|
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 = {
|
|
|
|
check_for_unsuspend: function () {},
|
|
|
|
};
|
|
|
|
activity.has_focus = false;
|
|
|
|
activity.initialize();
|
|
|
|
assert(!activity.new_user_input);
|
|
|
|
assert(!$('#zephyr-mirror-error').hasClass('show'));
|
|
|
|
assert.equal(page_params.presences, undefined);
|
|
|
|
assert(activity.has_focus);
|
|
|
|
$(window).idle = function (params) {
|
|
|
|
params.onIdle();
|
|
|
|
};
|
|
|
|
channel.post = function (payload) {
|
|
|
|
payload.success({
|
|
|
|
zephyr_mirror_active: false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
global.setInterval = (func) => func();
|
|
|
|
|
|
|
|
activity.initialize();
|
|
|
|
assert($('#zephyr-mirror-error').hasClass('show'));
|
|
|
|
assert(!activity.new_user_input);
|
|
|
|
assert(!activity.has_focus);
|
|
|
|
|
|
|
|
// Now execute the reload-in-progress code path
|
|
|
|
reload.is_in_progress = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
activity.initialize();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|