2013-08-09 14:42:49 +02:00
|
|
|
var assert = require('assert');
|
|
|
|
|
2013-08-21 20:27:14 +02:00
|
|
|
add_dependencies({
|
|
|
|
_: 'third/underscore/underscore.js',
|
|
|
|
util: 'js/util.js',
|
|
|
|
Dict: 'js/dict.js'
|
|
|
|
});
|
2013-08-09 14:42:49 +02:00
|
|
|
|
2013-09-10 17:38:53 +02:00
|
|
|
set_global('$', function () {
|
|
|
|
return {
|
|
|
|
on: function () {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2013-09-16 18:22:52 +02:00
|
|
|
set_global('document', {
|
|
|
|
hasFocus: function () {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-23 22:05:57 +02:00
|
|
|
set_global('people_dict', new global.Dict.from({
|
|
|
|
'alice@zulip.com': {
|
|
|
|
full_name: 'Alice Smith'
|
|
|
|
},
|
|
|
|
'fred@zulip.com': {
|
|
|
|
full_name: "Fred Flintstone"
|
|
|
|
},
|
|
|
|
'jill@zulip.com': {
|
|
|
|
full_name: 'Jill Hill'
|
2013-11-04 22:59:03 +01:00
|
|
|
},
|
|
|
|
'mark@zulip.com': {
|
|
|
|
full_name: 'Marky Mark'
|
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
|
|
|
|
|
|
|
(function test_sort_users() {
|
|
|
|
var users = ['alice@zulip.com', 'fred@zulip.com', 'jill@zulip.com'];
|
|
|
|
|
|
|
|
var user_info = {
|
|
|
|
'alice@zulip.com': 'inactive',
|
|
|
|
'fred@zulip.com': 'active',
|
|
|
|
'jill@zulip.com': 'active'
|
|
|
|
};
|
|
|
|
|
|
|
|
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'),
|
|
|
|
'Alice Smith, Fred Flintstone, + 1 other'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.short_huddle_name('alice@zulip.com,fred@zulip.com,jill@zulip.com,mark@zulip.com'),
|
|
|
|
'Alice Smith, Fred Flintstone, + 2 others'
|
|
|
|
);
|
|
|
|
}());
|
|
|
|
|
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 = {
|
|
|
|
'alice@zulip.com': 'active',
|
|
|
|
'fred@zulip.com': 'idle', // counts as present
|
|
|
|
// jill not in list
|
|
|
|
'mark@zulip.com': 'offline' // does not count
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
activity.huddle_fraction_present(huddle, presence_list),
|
|
|
|
'0.50'
|
|
|
|
);
|
|
|
|
}());
|
|
|
|
|