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', {
|
|
|
|
people_list: []
|
|
|
|
});
|
|
|
|
|
2014-01-30 22:42:19 +01:00
|
|
|
add_dependencies({
|
|
|
|
util: 'js/util.js',
|
|
|
|
people: 'js/people.js'
|
|
|
|
});
|
2013-09-10 17:38:53 +02:00
|
|
|
|
2016-11-11 19:30:04 +01:00
|
|
|
set_global('resize', {
|
|
|
|
resize_page_components: function () {}
|
|
|
|
});
|
|
|
|
|
2013-09-16 18:22:52 +02:00
|
|
|
set_global('document', {
|
|
|
|
hasFocus: function () {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-30 20:46:57 +01:00
|
|
|
global.people.add({
|
|
|
|
email: 'alice@zulip.com',
|
|
|
|
user_id: 1,
|
|
|
|
full_name: 'Alice Smith'
|
|
|
|
});
|
|
|
|
global.people.add({
|
|
|
|
email: 'fred@zulip.com',
|
|
|
|
user_id: 2,
|
|
|
|
full_name: "Fred Flintstone"
|
|
|
|
});
|
|
|
|
global.people.add({
|
|
|
|
email: 'jill@zulip.com',
|
|
|
|
user_id: 3,
|
|
|
|
full_name: 'Jill Hill'
|
|
|
|
});
|
|
|
|
global.people.add({
|
|
|
|
email: 'mark@zulip.com',
|
|
|
|
user_id: 4,
|
|
|
|
full_name: 'Marky Mark'
|
|
|
|
});
|
|
|
|
global.people.add({
|
|
|
|
email: 'norbert@zulip.com',
|
|
|
|
user_id: 5,
|
|
|
|
full_name: 'Norbert Oswald'
|
2014-01-30 22:42:19 +01:00
|
|
|
});
|
2013-10-23 22:05:57 +02:00
|
|
|
|
2013-08-21 20:27:14 +02:00
|
|
|
var activity = require('js/activity.js');
|
2013-08-09 14:42:49 +02:00
|
|
|
|
2016-11-11 18:00:09 +01:00
|
|
|
activity.update_huddles = function () {};
|
|
|
|
|
2013-08-09 14:42:49 +02:00
|
|
|
(function test_sort_users() {
|
|
|
|
var users = ['alice@zulip.com', 'fred@zulip.com', 'jill@zulip.com'];
|
|
|
|
|
|
|
|
var user_info = {
|
2014-02-14 21:05:51 +01:00
|
|
|
'alice@zulip.com': {status: 'inactive'},
|
|
|
|
'fred@zulip.com': {status: 'active'},
|
|
|
|
'jill@zulip.com': {status: 'active'}
|
2013-08-09 14:42:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
activity._sort_users(users, user_info);
|
|
|
|
|
|
|
|
assert.deepEqual(users, [
|
|
|
|
'fred@zulip.com',
|
|
|
|
'jill@zulip.com',
|
|
|
|
'alice@zulip.com'
|
|
|
|
]);
|
|
|
|
}());
|
2013-10-23 20:44:31 +02:00
|
|
|
|
|
|
|
(function test_process_loaded_messages() {
|
|
|
|
|
|
|
|
var huddle1 = 'bar@zulip.com,foo@zulip.com';
|
|
|
|
var timestamp1 = 1382479029; // older
|
|
|
|
|
|
|
|
var huddle2 = 'alice@zulip.com,bob@zulip.com';
|
|
|
|
var timestamp2 = 1382479033; // newer
|
|
|
|
|
|
|
|
var old_timestamp = 1382479000;
|
|
|
|
|
|
|
|
var messages = [
|
|
|
|
{
|
|
|
|
type: 'private',
|
|
|
|
reply_to: huddle1,
|
|
|
|
timestamp: timestamp1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'stream'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'private',
|
|
|
|
reply_to: 'ignore@zulip.com'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'private',
|
|
|
|
reply_to: huddle2,
|
|
|
|
timestamp: timestamp2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'private',
|
|
|
|
reply_to: huddle2,
|
|
|
|
timestamp: old_timestamp
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
activity.process_loaded_messages(messages);
|
|
|
|
|
|
|
|
assert.deepEqual(activity.get_huddles(), [huddle2, huddle1]);
|
|
|
|
}());
|
|
|
|
|
2013-10-23 22:22:34 +02:00
|
|
|
(function test_full_huddle_name() {
|
|
|
|
assert.equal(
|
|
|
|
activity.full_huddle_name('alice@zulip.com,jill@zulip.com'),
|
|
|
|
'Alice Smith, Jill Hill'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.full_huddle_name('alice@zulip.com,fred@zulip.com,jill@zulip.com'),
|
|
|
|
'Alice Smith, Fred Flintstone, Jill Hill'
|
|
|
|
);
|
|
|
|
}());
|
2013-11-04 21:56:56 +01:00
|
|
|
|
2013-11-04 22:59:03 +01:00
|
|
|
(function test_short_huddle_name() {
|
|
|
|
assert.equal(
|
|
|
|
activity.short_huddle_name('alice@zulip.com'),
|
|
|
|
'Alice Smith'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.short_huddle_name('alice@zulip.com,jill@zulip.com'),
|
|
|
|
'Alice Smith, Jill Hill'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.short_huddle_name('alice@zulip.com,fred@zulip.com,jill@zulip.com'),
|
2013-12-05 22:20:20 +01:00
|
|
|
'Alice Smith, Fred Flintstone, Jill Hill'
|
2013-11-04 22:59:03 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.short_huddle_name('alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com'),
|
2013-12-05 22:20:20 +01:00
|
|
|
'Alice Smith, Fred Flintstone, Jill Hill, + 1 other'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.short_huddle_name('alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com,norbert@zulip.com'),
|
|
|
|
'Alice Smith, Fred Flintstone, Jill Hill, + 2 others'
|
2013-11-04 22:59:03 +01:00
|
|
|
);
|
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';
|
|
|
|
|
|
|
|
var presence_list = {
|
2014-02-14 21:05:51 +01:00
|
|
|
'alice@zulip.com': {status: 'active'},
|
|
|
|
'fred@zulip.com': {status: 'idle'}, // counts as present
|
2013-11-04 21:56:56 +01:00
|
|
|
// jill not in list
|
2014-02-14 21:05:51 +01:00
|
|
|
'mark@zulip.com': {status: 'offline'} // does not count
|
2013-11-04 21:56:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.huddle_fraction_present(huddle, presence_list),
|
|
|
|
'0.50'
|
|
|
|
);
|
|
|
|
}());
|
|
|
|
|
2014-02-27 01:46:17 +01:00
|
|
|
|
|
|
|
(function test_on_mobile_property() {
|
|
|
|
var base_time = 500;
|
|
|
|
var presence = {
|
|
|
|
website: {
|
|
|
|
status: "active",
|
|
|
|
timestamp: base_time
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var status = activity._status_from_timestamp(
|
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS - 1, presence
|
|
|
|
);
|
|
|
|
assert.equal(status.mobile, false);
|
|
|
|
|
|
|
|
presence.Android = {
|
|
|
|
status: "active",
|
|
|
|
timestamp: base_time + activity._OFFLINE_THRESHOLD_SECS / 2,
|
|
|
|
pushable: false
|
|
|
|
};
|
|
|
|
status = activity._status_from_timestamp(
|
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS, presence
|
|
|
|
);
|
|
|
|
assert.equal(status.mobile, true);
|
|
|
|
assert.equal(status.status, "active");
|
|
|
|
|
|
|
|
status = activity._status_from_timestamp(
|
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS - 1, presence
|
|
|
|
);
|
|
|
|
assert.equal(status.mobile, false);
|
|
|
|
assert.equal(status.status, "active");
|
|
|
|
|
|
|
|
status = activity._status_from_timestamp(
|
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS * 2, presence
|
|
|
|
);
|
|
|
|
assert.equal(status.mobile, false);
|
|
|
|
assert.equal(status.status, "offline");
|
|
|
|
|
|
|
|
presence.Android = {
|
|
|
|
status: "idle",
|
|
|
|
timestamp: base_time + activity._OFFLINE_THRESHOLD_SECS / 2,
|
|
|
|
pushable: true
|
|
|
|
};
|
|
|
|
status = activity._status_from_timestamp(
|
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS, presence
|
|
|
|
);
|
|
|
|
assert.equal(status.mobile, true);
|
|
|
|
assert.equal(status.status, "idle");
|
|
|
|
|
|
|
|
status = activity._status_from_timestamp(
|
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS - 1, presence
|
|
|
|
);
|
|
|
|
assert.equal(status.mobile, false);
|
|
|
|
assert.equal(status.status, "active");
|
|
|
|
|
|
|
|
status = activity._status_from_timestamp(
|
|
|
|
base_time + activity._OFFLINE_THRESHOLD_SECS * 2, presence
|
|
|
|
);
|
|
|
|
assert.equal(status.mobile, true);
|
|
|
|
assert.equal(status.status, "offline");
|
|
|
|
|
|
|
|
}());
|