mirror of
https://github.com/zulip/zulip.git
synced 2026-07-18 21:04:19 +08:00
Having to explicitly call out the underscore/Dict dependencies in nearly every test has proven to be more cumbersome than helpful. We never monkeypatch those modules in the tests. (imported from commit 49ef70c835edd4e22a5869eda9235ef3ffc3c59b)
158 lines
3.6 KiB
JavaScript
158 lines
3.6 KiB
JavaScript
var assert = require('assert');
|
|
|
|
set_global('$', function () {
|
|
return {
|
|
on: function () {
|
|
return;
|
|
}
|
|
};
|
|
});
|
|
$.fn = {};
|
|
|
|
add_dependencies({
|
|
util: 'js/util.js',
|
|
people: 'js/people.js'
|
|
});
|
|
|
|
set_global('document', {
|
|
hasFocus: function () {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
var people = require("js/people.js");
|
|
people.test_set_people_dict({
|
|
'[email protected]': {
|
|
full_name: 'Alice Smith'
|
|
},
|
|
'[email protected]': {
|
|
full_name: "Fred Flintstone"
|
|
},
|
|
'[email protected]': {
|
|
full_name: 'Jill Hill'
|
|
},
|
|
'[email protected]': {
|
|
full_name: 'Marky Mark'
|
|
},
|
|
'[email protected]': {
|
|
full_name: 'Norbert Oswald'
|
|
}
|
|
});
|
|
|
|
var activity = require('js/activity.js');
|
|
|
|
(function test_sort_users() {
|
|
var users = ['[email protected]', '[email protected]', '[email protected]'];
|
|
|
|
var user_info = {
|
|
'[email protected]': 'inactive',
|
|
'[email protected]': 'active',
|
|
'[email protected]': 'active'
|
|
};
|
|
|
|
activity._sort_users(users, user_info);
|
|
|
|
assert.deepEqual(users, [
|
|
'[email protected]',
|
|
'[email protected]',
|
|
'[email protected]'
|
|
]);
|
|
}());
|
|
|
|
(function test_process_loaded_messages() {
|
|
|
|
var huddle1 = '[email protected],[email protected]';
|
|
var timestamp1 = 1382479029; // older
|
|
|
|
var huddle2 = '[email protected],[email protected]';
|
|
var timestamp2 = 1382479033; // newer
|
|
|
|
var old_timestamp = 1382479000;
|
|
|
|
var messages = [
|
|
{
|
|
type: 'private',
|
|
reply_to: huddle1,
|
|
timestamp: timestamp1
|
|
},
|
|
{
|
|
type: 'stream'
|
|
},
|
|
{
|
|
type: 'private',
|
|
reply_to: '[email protected]'
|
|
},
|
|
{
|
|
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]);
|
|
}());
|
|
|
|
(function test_full_huddle_name() {
|
|
assert.equal(
|
|
activity.full_huddle_name('[email protected],[email protected]'),
|
|
'Alice Smith, Jill Hill'
|
|
);
|
|
|
|
assert.equal(
|
|
activity.full_huddle_name('[email protected],[email protected],[email protected]'),
|
|
'Alice Smith, Fred Flintstone, Jill Hill'
|
|
);
|
|
}());
|
|
|
|
(function test_short_huddle_name() {
|
|
assert.equal(
|
|
activity.short_huddle_name('[email protected]'),
|
|
'Alice Smith'
|
|
);
|
|
|
|
assert.equal(
|
|
activity.short_huddle_name('[email protected],[email protected]'),
|
|
'Alice Smith, Jill Hill'
|
|
);
|
|
|
|
assert.equal(
|
|
activity.short_huddle_name('[email protected],[email protected],[email protected]'),
|
|
'Alice Smith, Fred Flintstone, Jill Hill'
|
|
);
|
|
|
|
assert.equal(
|
|
activity.short_huddle_name('[email protected],[email protected],[email protected],[email protected]'),
|
|
'Alice Smith, Fred Flintstone, Jill Hill, + 1 other'
|
|
);
|
|
|
|
assert.equal(
|
|
activity.short_huddle_name('[email protected],[email protected],[email protected],[email protected],[email protected]'),
|
|
'Alice Smith, Fred Flintstone, Jill Hill, + 2 others'
|
|
);
|
|
|
|
}());
|
|
|
|
(function test_huddle_fraction_present() {
|
|
var huddle = '[email protected],[email protected],[email protected],[email protected]';
|
|
|
|
var presence_list = {
|
|
'[email protected]': 'active',
|
|
'[email protected]': 'idle', // counts as present
|
|
// jill not in list
|
|
'[email protected]': 'offline' // does not count
|
|
};
|
|
|
|
assert.equal(
|
|
activity.huddle_fraction_present(huddle, presence_list),
|
|
'0.50'
|
|
);
|
|
}());
|
|
|