2016-07-30 20:01:15 +02:00
|
|
|
global.stub_out_jquery();
|
2014-01-30 22:42:19 +01:00
|
|
|
|
2016-10-30 20:46:57 +01:00
|
|
|
set_global('page_params', {
|
2016-12-03 23:17:57 +01:00
|
|
|
people_list: [],
|
2016-10-30 20:46:57 +01:00
|
|
|
});
|
|
|
|
|
2017-01-09 18:20:31 +01:00
|
|
|
set_global('feature_flags', {});
|
|
|
|
|
|
|
|
set_global('document', {
|
|
|
|
hasFocus: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2014-01-30 22:42:19 +01:00
|
|
|
add_dependencies({
|
2017-01-09 18:20:31 +01:00
|
|
|
Handlebars: 'handlebars',
|
|
|
|
templates: 'js/templates',
|
2014-01-30 22:42:19 +01:00
|
|
|
util: 'js/util.js',
|
2017-01-09 18:20:31 +01:00
|
|
|
compose_fade: 'js/compose_fade.js',
|
2016-12-03 23:17:57 +01:00
|
|
|
people: 'js/people.js',
|
2017-01-09 18:20:31 +01:00
|
|
|
unread: 'js/unread.js',
|
|
|
|
activity: 'js/activity.js',
|
2014-01-30 22:42:19 +01:00
|
|
|
});
|
2013-09-10 17:38:53 +02:00
|
|
|
|
2016-11-11 19:30:04 +01:00
|
|
|
set_global('resize', {
|
2016-12-03 23:17:57 +01:00
|
|
|
resize_page_components: function () {},
|
2016-11-11 19:30:04 +01:00
|
|
|
});
|
|
|
|
|
2016-11-17 21:43:12 +01:00
|
|
|
var 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
|
|
|
};
|
|
|
|
var 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
|
|
|
};
|
|
|
|
var 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
|
|
|
};
|
|
|
|
var 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
|
|
|
};
|
|
|
|
var 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
|
|
|
};
|
|
|
|
|
|
|
|
global.people.add(alice);
|
|
|
|
global.people.add(fred);
|
|
|
|
global.people.add(jill);
|
|
|
|
global.people.add(mark);
|
|
|
|
global.people.add(norbert);
|
|
|
|
|
2016-11-17 23:16:29 +01:00
|
|
|
var people = global.people;
|
|
|
|
|
2013-08-21 20:27:14 +02:00
|
|
|
var activity = require('js/activity.js');
|
2017-01-09 18:20:31 +01:00
|
|
|
var compose_fade = require('js/compose_fade.js');
|
|
|
|
var jsdom = require('jsdom');
|
|
|
|
var window = jsdom.jsdom().defaultView;
|
|
|
|
|
|
|
|
global.$ = require('jquery')(window);
|
|
|
|
$.fn.expectOne = function () {
|
|
|
|
assert(this.length === 1);
|
|
|
|
return this;
|
|
|
|
};
|
2013-08-09 14:42:49 +02:00
|
|
|
|
2017-01-09 18:20:31 +01:00
|
|
|
compose_fade.update_faded_users = function () {};
|
2016-11-11 18:00:09 +01:00
|
|
|
activity.update_huddles = function () {};
|
|
|
|
|
2017-01-09 18:20:31 +01:00
|
|
|
global.compile_template('user_presence_row');
|
|
|
|
global.compile_template('user_presence_rows');
|
|
|
|
|
2013-08-09 14:42:49 +02:00
|
|
|
(function test_sort_users() {
|
2016-11-17 21:43:12 +01:00
|
|
|
var user_ids = [alice.user_id, fred.user_id, jill.user_id];
|
2013-08-09 14:42:49 +02:00
|
|
|
|
2016-11-17 21:43:12 +01:00
|
|
|
var user_info = {};
|
2017-01-09 18:20:31 +01:00
|
|
|
user_info[alice.user_id] = { status: 'inactive' };
|
|
|
|
user_info[fred.user_id] = { status: 'active' };
|
|
|
|
user_info[jill.user_id] = { status: 'active' };
|
2013-08-09 14:42:49 +02:00
|
|
|
|
2016-11-17 21:43:12 +01:00
|
|
|
activity._sort_users(user_ids, user_info);
|
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
|
|
|
]);
|
|
|
|
}());
|
2013-10-23 20:44:31 +02:00
|
|
|
|
|
|
|
(function test_process_loaded_messages() {
|
|
|
|
|
2016-11-17 23:16:29 +01:00
|
|
|
var huddle1 = 'jill@zulip.com,norbert@zulip.com';
|
2013-10-23 20:44:31 +02:00
|
|
|
var timestamp1 = 1382479029; // older
|
|
|
|
|
2016-11-17 23:16:29 +01:00
|
|
|
var huddle2 = 'alice@zulip.com,fred@zulip.com';
|
2013-10-23 20:44:31 +02:00
|
|
|
var timestamp2 = 1382479033; // newer
|
|
|
|
|
|
|
|
var old_timestamp = 1382479000;
|
|
|
|
|
2017-01-09 18:20:31 +01:00
|
|
|
var messages = [{
|
2013-10-23 20:44:31 +02:00
|
|
|
type: 'private',
|
|
|
|
reply_to: huddle1,
|
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',
|
2016-12-03 23:17:57 +01:00
|
|
|
reply_to: 'ignore@zulip.com',
|
2013-10-23 20:44:31 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'private',
|
|
|
|
reply_to: huddle2,
|
2016-12-03 23:17:57 +01:00
|
|
|
timestamp: timestamp2,
|
2013-10-23 20:44:31 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'private',
|
|
|
|
reply_to: huddle2,
|
2016-12-03 23:17:57 +01:00
|
|
|
timestamp: old_timestamp,
|
|
|
|
},
|
2013-10-23 20:44:31 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
activity.process_loaded_messages(messages);
|
|
|
|
|
2016-11-17 23:16:29 +01:00
|
|
|
var user_ids_string1 = people.emails_strings_to_user_ids_string(huddle1);
|
|
|
|
var user_ids_string2 = people.emails_strings_to_user_ids_string(huddle2);
|
|
|
|
assert.deepEqual(activity.get_huddles(), [user_ids_string2, user_ids_string1]);
|
2013-10-23 20:44:31 +02:00
|
|
|
}());
|
|
|
|
|
2013-10-23 22:22:34 +02:00
|
|
|
(function test_full_huddle_name() {
|
2016-11-17 23:16:29 +01:00
|
|
|
function full_name(emails_string) {
|
|
|
|
var user_ids_string = people.emails_strings_to_user_ids_string(emails_string);
|
|
|
|
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');
|
2013-10-23 22:22:34 +02:00
|
|
|
}());
|
2013-11-04 21:56:56 +01:00
|
|
|
|
2013-11-04 22:59:03 +01:00
|
|
|
(function test_short_huddle_name() {
|
2016-11-17 23:16:29 +01:00
|
|
|
function short_name(emails_string) {
|
|
|
|
var user_ids_string = people.emails_strings_to_user_ids_string(emails_string);
|
|
|
|
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
|
|
|
|
2013-11-04 22:59:03 +01:00
|
|
|
}());
|
|
|
|
|
2013-11-04 21:56:56 +01:00
|
|
|
(function test_huddle_fraction_present() {
|
|
|
|
var 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
|
|
|
|
2016-11-17 21:43:12 +01:00
|
|
|
var presence_list = {};
|
2017-01-09 18:20:31 +01:00
|
|
|
presence_list[alice.user_id] = { status: 'active' };
|
|
|
|
presence_list[fred.user_id] = { status: 'idle' }; // counts as present
|
2016-11-17 21:43:12 +01:00
|
|
|
// jill not in list
|
2017-01-09 18:20:31 +01:00
|
|
|
presence_list[mark.user_id] = { status: 'offline' }; // does not count
|
2013-11-04 21:56:56 +01:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.huddle_fraction_present(huddle, presence_list),
|
2016-12-03 23:17:57 +01:00
|
|
|
'0.50');
|
2013-11-04 21:56:56 +01:00
|
|
|
}());
|
|
|
|
|
2014-02-27 01:46:17 +01:00
|
|
|
|
|
|
|
(function test_on_mobile_property() {
|
|
|
|
var base_time = 500;
|
|
|
|
var presence = {
|
|
|
|
website: {
|
|
|
|
status: "active",
|
2016-12-03 23:17:57 +01:00
|
|
|
timestamp: base_time,
|
|
|
|
},
|
2014-02-27 01:46:17 +01:00
|
|
|
};
|
|
|
|
var status = activity._status_from_timestamp(
|
2016-12-03 23:17:57 +01:00
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS - 1, presence);
|
2014-02-27 01:46:17 +01:00
|
|
|
assert.equal(status.mobile, false);
|
|
|
|
|
|
|
|
presence.Android = {
|
|
|
|
status: "active",
|
|
|
|
timestamp: base_time + activity._OFFLINE_THRESHOLD_SECS / 2,
|
2016-12-03 23:17:57 +01:00
|
|
|
pushable: false,
|
2014-02-27 01:46:17 +01:00
|
|
|
};
|
|
|
|
status = activity._status_from_timestamp(
|
2016-12-03 23:17:57 +01:00
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS, presence);
|
2014-02-27 01:46:17 +01:00
|
|
|
assert.equal(status.mobile, true);
|
|
|
|
assert.equal(status.status, "active");
|
|
|
|
|
|
|
|
status = activity._status_from_timestamp(
|
2016-12-03 23:17:57 +01:00
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS - 1, presence);
|
2014-02-27 01:46:17 +01:00
|
|
|
assert.equal(status.mobile, false);
|
|
|
|
assert.equal(status.status, "active");
|
|
|
|
|
|
|
|
status = activity._status_from_timestamp(
|
2016-12-03 23:17:57 +01:00
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS * 2, presence);
|
2014-02-27 01:46:17 +01:00
|
|
|
assert.equal(status.mobile, false);
|
|
|
|
assert.equal(status.status, "offline");
|
|
|
|
|
|
|
|
presence.Android = {
|
|
|
|
status: "idle",
|
|
|
|
timestamp: base_time + activity._OFFLINE_THRESHOLD_SECS / 2,
|
2016-12-03 23:17:57 +01:00
|
|
|
pushable: true,
|
2014-02-27 01:46:17 +01:00
|
|
|
};
|
|
|
|
status = activity._status_from_timestamp(
|
2016-12-03 23:17:57 +01:00
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS, presence);
|
2014-02-27 01:46:17 +01:00
|
|
|
assert.equal(status.mobile, true);
|
|
|
|
assert.equal(status.status, "idle");
|
|
|
|
|
|
|
|
status = activity._status_from_timestamp(
|
2016-12-03 23:17:57 +01:00
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS - 1, presence);
|
2014-02-27 01:46:17 +01:00
|
|
|
assert.equal(status.mobile, false);
|
|
|
|
assert.equal(status.status, "active");
|
|
|
|
|
|
|
|
status = activity._status_from_timestamp(
|
2016-12-03 23:17:57 +01:00
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS * 2, presence);
|
2014-02-27 01:46:17 +01:00
|
|
|
assert.equal(status.mobile, true);
|
|
|
|
assert.equal(status.status, "offline");
|
|
|
|
|
|
|
|
}());
|
2017-01-09 18:20:31 +01:00
|
|
|
|
|
|
|
activity.presence_info = {};
|
|
|
|
activity.presence_info[alice.user_id] = { status: activity.IDLE };
|
|
|
|
activity.presence_info[fred.user_id] = { status: activity.ACTIVE };
|
|
|
|
activity.presence_info[jill.user_id] = { status: activity.ACTIVE };
|
|
|
|
activity.presence_info[mark.user_id] = { status: activity.IDLE };
|
|
|
|
activity.presence_info[norbert.user_id] = { status: activity.ACTIVE };
|
|
|
|
|
|
|
|
(function test_presence_list_full_update() {
|
|
|
|
var users = activity.update_users();
|
|
|
|
assert.deepEqual(users, [{
|
|
|
|
name: 'Fred Flintstone',
|
|
|
|
user_id: fred.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
|
|
|
mobile: undefined
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Jill Hill',
|
|
|
|
user_id: jill.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
|
|
|
mobile: undefined
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Norbert Oswald',
|
|
|
|
user_id: norbert.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
|
|
|
mobile: undefined
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Alice Smith',
|
|
|
|
user_id: alice.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'idle',
|
|
|
|
type_desc: 'is not active',
|
|
|
|
mobile: undefined
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Marky Mark',
|
|
|
|
user_id: mark.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'idle',
|
|
|
|
type_desc: 'is not active',
|
|
|
|
mobile: undefined
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_presence_list_partial_update() {
|
|
|
|
activity.presence_info[alice.user_id] = { status: 'active' };
|
|
|
|
activity.presence_info[mark.user_id] = { status: 'active' };
|
|
|
|
|
|
|
|
var users = {};
|
|
|
|
|
|
|
|
users[alice.user_id] = { status: 'active' };
|
|
|
|
users = activity.update_users(users);
|
|
|
|
assert.deepEqual(users, [{
|
|
|
|
name: 'Alice Smith',
|
|
|
|
user_id: alice.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
|
|
|
mobile: undefined
|
|
|
|
}, ]);
|
|
|
|
|
|
|
|
// Test if user index in presence_info is the expected one
|
|
|
|
var all_users = activity._filter_and_sort(activity.presence_info);
|
|
|
|
assert.equal(all_users.indexOf(alice.user_id.toString()), 0);
|
|
|
|
|
|
|
|
// Test another user
|
|
|
|
users = {};
|
|
|
|
users[mark.user_id] = { status: 'active' };
|
|
|
|
users = activity.update_users(users);
|
|
|
|
assert.deepEqual(users, [{
|
|
|
|
name: 'Marky Mark',
|
|
|
|
user_id: mark.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
|
|
|
mobile: undefined
|
|
|
|
}, ]);
|
|
|
|
|
|
|
|
all_users = activity._filter_and_sort(activity.presence_info);
|
|
|
|
assert.equal(all_users.indexOf(mark.user_id.toString()), 3);
|
|
|
|
|
|
|
|
}());
|