mirror of
https://github.com/zulip/zulip.git
synced 2026-06-21 21:32:29 +08:00
* In most cases, eslint --fix with the right comma-dangle settings was able to update the code correctly. * The exceptions were cases where the parser incorrectly treated the arguments to functions like `assert_equal` as arguments; we fixed these manually. Since this is test code, we can be reasonably confident that just fixing the failures suffices to correct any bugs introduced by making changes automatically.
232 lines
6.2 KiB
JavaScript
232 lines
6.2 KiB
JavaScript
global.stub_out_jquery();
|
|
|
|
set_global('page_params', {
|
|
people_list: [],
|
|
});
|
|
|
|
add_dependencies({
|
|
util: 'js/util.js',
|
|
people: 'js/people.js',
|
|
});
|
|
|
|
set_global('resize', {
|
|
resize_page_components: function () {},
|
|
});
|
|
|
|
set_global('document', {
|
|
hasFocus: function () {
|
|
return true;
|
|
},
|
|
});
|
|
|
|
var alice = {
|
|
email: '[email protected]',
|
|
user_id: 1,
|
|
full_name: 'Alice Smith',
|
|
};
|
|
var fred = {
|
|
email: '[email protected]',
|
|
user_id: 2,
|
|
full_name: "Fred Flintstone",
|
|
};
|
|
var jill = {
|
|
email: '[email protected]',
|
|
user_id: 3,
|
|
full_name: 'Jill Hill',
|
|
};
|
|
var mark = {
|
|
email: '[email protected]',
|
|
user_id: 4,
|
|
full_name: 'Marky Mark',
|
|
};
|
|
var norbert = {
|
|
email: '[email protected]',
|
|
user_id: 5,
|
|
full_name: 'Norbert Oswald',
|
|
};
|
|
|
|
global.people.add(alice);
|
|
global.people.add(fred);
|
|
global.people.add(jill);
|
|
global.people.add(mark);
|
|
global.people.add(norbert);
|
|
|
|
|
|
var people = global.people;
|
|
|
|
var activity = require('js/activity.js');
|
|
|
|
activity.update_huddles = function () {};
|
|
|
|
(function test_sort_users() {
|
|
var user_ids = [alice.user_id, fred.user_id, jill.user_id];
|
|
|
|
var user_info = {};
|
|
user_info[alice.user_id] = {status: 'inactive'};
|
|
user_info[fred.user_id] = {status: 'active'};
|
|
user_info[jill.user_id] = {status: 'active'};
|
|
|
|
activity._sort_users(user_ids, user_info);
|
|
|
|
assert.deepEqual(user_ids, [
|
|
fred.user_id,
|
|
jill.user_id,
|
|
alice.user_id,
|
|
]);
|
|
}());
|
|
|
|
(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);
|
|
|
|
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]);
|
|
}());
|
|
|
|
(function test_full_huddle_name() {
|
|
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);
|
|
}
|
|
|
|
assert.equal(
|
|
full_name('[email protected],[email protected]'),
|
|
'Alice Smith, Jill Hill');
|
|
|
|
assert.equal(
|
|
full_name('[email protected],[email protected],[email protected]'),
|
|
'Alice Smith, Fred Flintstone, Jill Hill');
|
|
}());
|
|
|
|
(function test_short_huddle_name() {
|
|
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);
|
|
}
|
|
|
|
assert.equal(
|
|
short_name('[email protected]'),
|
|
'Alice Smith');
|
|
|
|
assert.equal(
|
|
short_name('[email protected],[email protected]'),
|
|
'Alice Smith, Jill Hill');
|
|
|
|
assert.equal(
|
|
short_name('[email protected],[email protected],[email protected]'),
|
|
'Alice Smith, Fred Flintstone, Jill Hill');
|
|
|
|
assert.equal(
|
|
short_name('[email protected],[email protected],[email protected],[email protected]'),
|
|
'Alice Smith, Fred Flintstone, Jill Hill, + 1 other');
|
|
|
|
assert.equal(
|
|
short_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]';
|
|
huddle = people.emails_strings_to_user_ids_string(huddle);
|
|
|
|
var presence_list = {};
|
|
presence_list[alice.user_id] = {status: 'active'};
|
|
presence_list[fred.user_id] = {status: 'idle'}; // counts as present
|
|
// jill not in list
|
|
presence_list[mark.user_id] = {status: 'offline'}; // does not count
|
|
|
|
assert.equal(
|
|
activity.huddle_fraction_present(huddle, presence_list),
|
|
'0.50');
|
|
}());
|
|
|
|
|
|
(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");
|
|
|
|
}());
|