2017-05-25 01:49:29 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2014-01-30 22:42:19 +01:00
|
|
|
|
2016-10-30 20:46:57 +01:00
|
|
|
set_global('page_params', {
|
2017-04-24 21:59:07 +02:00
|
|
|
realm_users: [],
|
2017-04-13 04:28:15 +02:00
|
|
|
user_id: 5,
|
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',
|
2017-03-19 00:43:14 +01:00
|
|
|
hash_util: 'js/hash_util.js',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
hashchange: 'js/hashchange.js',
|
|
|
|
narrow: 'js/narrow.js',
|
2017-03-30 20:04:01 +02:00
|
|
|
presence: 'js/presence.js',
|
2017-01-09 18:20:31 +01:00
|
|
|
activity: 'js/activity.js',
|
2014-01-30 22:42:19 +01:00
|
|
|
});
|
2013-09-10 17:38:53 +02:00
|
|
|
|
2017-03-30 20:04:01 +02:00
|
|
|
var presence = global.presence;
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2017-02-05 00:22:16 +01:00
|
|
|
var me = {
|
|
|
|
email: 'me@zulip.com',
|
|
|
|
user_id: 999,
|
|
|
|
full_name: 'Me Myself',
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2017-03-31 00:18:04 +02:00
|
|
|
var zoe = {
|
|
|
|
email: 'zoe@example.com',
|
|
|
|
user_id: 6,
|
|
|
|
full_name: 'Zoe Yang',
|
|
|
|
};
|
2016-11-17 21:43:12 +01:00
|
|
|
|
2016-11-17 23:16:29 +01:00
|
|
|
var people = global.people;
|
|
|
|
|
2017-03-31 00:18:04 +02:00
|
|
|
people.add_in_realm(alice);
|
|
|
|
people.add_in_realm(fred);
|
|
|
|
people.add_in_realm(jill);
|
|
|
|
people.add_in_realm(mark);
|
|
|
|
people.add_in_realm(norbert);
|
|
|
|
people.add_in_realm(zoe);
|
|
|
|
people.add_in_realm(me);
|
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
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');
|
2013-08-09 14:42:49 +02:00
|
|
|
|
2017-01-09 18:20:31 +01:00
|
|
|
compose_fade.update_faded_users = function () {};
|
2017-05-25 01:49:39 +02:00
|
|
|
|
|
|
|
var real_update_huddles = activity.update_huddles;
|
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');
|
|
|
|
|
2017-04-13 04:28:15 +02:00
|
|
|
var presence_info = {};
|
|
|
|
presence_info[alice.user_id] = { status: 'inactive' };
|
|
|
|
presence_info[fred.user_id] = { status: 'active' };
|
|
|
|
presence_info[jill.user_id] = { status: 'active' };
|
|
|
|
|
|
|
|
presence.presence_info = presence_info;
|
|
|
|
|
|
|
|
(function test_get_status() {
|
|
|
|
assert.equal(presence.get_status(page_params.user_id), "active");
|
|
|
|
assert.equal(presence.get_status(alice.user_id), "inactive");
|
|
|
|
assert.equal(presence.get_status(fred.user_id), "active");
|
|
|
|
}());
|
|
|
|
|
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
|
|
|
|
2017-03-06 16:14:52 +01:00
|
|
|
activity._sort_users(user_ids);
|
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-02-05 00:22:16 +01:00
|
|
|
var messages = [
|
|
|
|
{
|
2013-10-23 20:44:31 +02:00
|
|
|
type: 'private',
|
2017-02-05 00:22:16 +01:00
|
|
|
display_recipient: [{id: jill.user_id}, {id: norbert.user_id}],
|
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',
|
2017-02-05 00:22:16 +01:00
|
|
|
display_recipient: [{id: me.user_id}], // PM to myself
|
2013-10-23 20:44:31 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'private',
|
2017-02-05 00:22:16 +01:00
|
|
|
display_recipient: [{id: alice.user_id}, {id: fred.user_id}],
|
2016-12-03 23:17:57 +01:00
|
|
|
timestamp: timestamp2,
|
2013-10-23 20:44:31 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'private',
|
2017-02-05 00:22:16 +01:00
|
|
|
display_recipient: [{id: fred.user_id}, {id: alice.user_id}],
|
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
|
|
|
|
2017-03-06 16:14:52 +01:00
|
|
|
var presence_info = {};
|
|
|
|
presence_info[alice.user_id] = { status: 'active' };
|
|
|
|
presence_info[fred.user_id] = { status: 'idle' }; // counts as present
|
2016-11-17 21:43:12 +01:00
|
|
|
// jill not in list
|
2017-03-06 16:14:52 +01:00
|
|
|
presence_info[mark.user_id] = { status: 'offline' }; // does not count
|
2017-03-30 20:04:01 +02:00
|
|
|
presence.presence_info = presence_info;
|
2013-11-04 21:56:56 +01:00
|
|
|
|
|
|
|
assert.equal(
|
2017-03-06 16:14:52 +01:00
|
|
|
activity.huddle_fraction_present(huddle),
|
2016-12-03 23:17:57 +01:00
|
|
|
'0.50');
|
2013-11-04 21:56:56 +01:00
|
|
|
}());
|
|
|
|
|
2017-03-30 20:04:01 +02:00
|
|
|
presence.presence_info = {};
|
|
|
|
presence.presence_info[alice.user_id] = { status: activity.IDLE };
|
|
|
|
presence.presence_info[fred.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[jill.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[mark.user_id] = { status: activity.IDLE };
|
|
|
|
presence.presence_info[norbert.user_id] = { status: activity.ACTIVE };
|
2017-01-09 18:20:31 +01:00
|
|
|
|
|
|
|
(function test_presence_list_full_update() {
|
2017-02-21 00:53:08 +01:00
|
|
|
var users = activity.build_user_sidebar();
|
2017-01-09 18:20:31 +01:00
|
|
|
assert.deepEqual(users, [{
|
|
|
|
name: 'Fred Flintstone',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/2-fred',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: fred.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
2017-01-12 00:17:43 +01:00
|
|
|
mobile: undefined,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Jill Hill',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/3-jill',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: jill.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
2017-01-12 00:17:43 +01:00
|
|
|
mobile: undefined,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Norbert Oswald',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/5-norbert',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: norbert.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'active',
|
|
|
|
type_desc: 'is active',
|
2017-01-12 00:17:43 +01:00
|
|
|
mobile: undefined,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Alice Smith',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/1-alice',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: alice.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'idle',
|
|
|
|
type_desc: 'is not active',
|
2017-01-12 00:17:43 +01:00
|
|
|
mobile: undefined,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Marky Mark',
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
href: '#narrow/pm-with/4-mark',
|
2017-01-09 18:20:31 +01:00
|
|
|
user_id: mark.user_id,
|
|
|
|
num_unread: 0,
|
|
|
|
type: 'idle',
|
|
|
|
type_desc: 'is not active',
|
2017-01-12 00:17:43 +01:00
|
|
|
mobile: undefined,
|
2017-01-09 18:20:31 +01:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
}());
|
2017-05-24 19:46:15 +02:00
|
|
|
|
|
|
|
(function test_PM_update_dom_counts() {
|
|
|
|
var value = $('alice-value');
|
|
|
|
var count = $('alice-count');
|
|
|
|
var pm_key = alice.user_id.toString();
|
|
|
|
var li = $("li.user_sidebar_entry[data-user-id='" + pm_key + "']");
|
|
|
|
count.add_child('.value', value);
|
|
|
|
li.add_child('.count', count);
|
|
|
|
|
|
|
|
var counts = new Dict();
|
|
|
|
counts.set(pm_key, 5);
|
|
|
|
li.addClass('user_sidebar_entry');
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
|
|
|
assert(li.hasClass('user-with-count'));
|
|
|
|
assert.equal(value.text(), 5);
|
|
|
|
|
|
|
|
counts.set(pm_key, 0);
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
|
|
|
assert(!li.hasClass('user-with-count'));
|
|
|
|
assert.equal(value.text(), '');
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_group_update_dom_counts() {
|
|
|
|
var value = $('alice-fred-value');
|
|
|
|
var count = $('alice-fred-count');
|
|
|
|
var pm_key = alice.user_id.toString() + "," + fred.user_id.toString();
|
|
|
|
var li_selector = "li.group-pms-sidebar-entry[data-user-ids='" + pm_key + "']";
|
|
|
|
var li = $(li_selector);
|
|
|
|
count.add_child('.value', value);
|
|
|
|
li.add_child('.count', count);
|
|
|
|
|
|
|
|
var counts = new Dict();
|
|
|
|
counts.set(pm_key, 5);
|
|
|
|
li.addClass('group-pms-sidebar-entry');
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
|
|
|
assert(li.hasClass('group-with-count'));
|
|
|
|
assert.equal(value.text(), 5);
|
|
|
|
|
|
|
|
counts.set(pm_key, 0);
|
|
|
|
|
|
|
|
activity.update_dom_with_unread_counts({pm_count: counts});
|
|
|
|
assert(!li.hasClass('group-with-count'));
|
|
|
|
assert.equal(value.text(), '');
|
|
|
|
}());
|
2017-05-24 23:28:18 +02:00
|
|
|
|
2017-05-25 01:49:39 +02:00
|
|
|
presence.presence_info = {};
|
|
|
|
presence.presence_info[alice.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[fred.user_id] = { status: activity.ACTIVE };
|
|
|
|
presence.presence_info[jill.user_id] = { status: activity.ACTIVE };
|
2017-05-24 23:28:18 +02:00
|
|
|
|
2017-05-25 01:49:39 +02:00
|
|
|
(function test_filter_user_ids() {
|
2017-05-24 23:28:18 +02:00
|
|
|
var user_filter = $('.user-list-filter');
|
|
|
|
user_filter.val(''); // no search filter
|
|
|
|
|
|
|
|
var user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
|
|
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
|
|
|
|
|
|
|
user_filter.val('abc'); // no match
|
|
|
|
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
|
|
|
assert.deepEqual(user_ids, []);
|
|
|
|
|
|
|
|
user_filter.val('fred'); // match fred
|
|
|
|
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
|
|
|
assert.deepEqual(user_ids, [fred.user_id]);
|
|
|
|
|
|
|
|
user_filter.val('fred,alice'); // match fred and alice
|
|
|
|
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
|
|
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
|
|
|
|
|
|
|
user_filter.val('fr,al'); // match fred and alice partials
|
|
|
|
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
|
|
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
|
|
|
|
|
|
|
presence.presence_info[alice.user_id] = { status: activity.IDLE };
|
|
|
|
user_filter.val('fr,al'); // match fred and alice partials and idle user
|
|
|
|
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
|
|
|
assert.deepEqual(user_ids, [fred.user_id, alice.user_id]);
|
|
|
|
|
|
|
|
$.stub_selector('.user-list-filter', []);
|
|
|
|
presence.presence_info[alice.user_id] = { status: activity.ACTIVE };
|
|
|
|
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
|
|
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
|
|
|
}());
|
2017-05-25 01:49:39 +02:00
|
|
|
|
|
|
|
(function test_insert_one_user_into_empty_list() {
|
|
|
|
var alice_li = $('alice-li');
|
|
|
|
|
|
|
|
// These selectors are here to avoid some short-circuit logic.
|
|
|
|
$('#user_presences').add_child('[data-user-id="1"]', alice_li);
|
|
|
|
|
|
|
|
var appended_html;
|
|
|
|
$('#user_presences').append = function (html) {
|
|
|
|
appended_html = html;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.stub_selector('#user_presences li', {
|
|
|
|
toArray: function () {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
});
|
|
|
|
activity.insert_user_into_list(alice.user_id);
|
|
|
|
assert(appended_html.indexOf('data-user-id="1"') > 0);
|
|
|
|
assert(appended_html.indexOf('user_active') > 0);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_insert_fred_after_alice() {
|
|
|
|
var fred_li = $('fred-li');
|
|
|
|
|
|
|
|
// These selectors are here to avoid some short-circuit logic.
|
|
|
|
$('#user_presences').add_child('[data-user-id="2"]', fred_li);
|
|
|
|
|
|
|
|
var appended_html;
|
|
|
|
$('#user_presences').append = function (html) {
|
|
|
|
appended_html = html;
|
|
|
|
};
|
|
|
|
|
|
|
|
$('fake-dom-for-alice').attr = function (attr_name) {
|
|
|
|
assert.equal(attr_name, 'data-user-id');
|
|
|
|
return alice.user_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.stub_selector('#user_presences li', {
|
|
|
|
toArray: function () {
|
|
|
|
return [
|
|
|
|
'fake-dom-for-alice',
|
|
|
|
];
|
|
|
|
},
|
|
|
|
});
|
|
|
|
activity.insert_user_into_list(fred.user_id);
|
|
|
|
|
|
|
|
assert(appended_html.indexOf('data-user-id="2"') > 0);
|
|
|
|
assert(appended_html.indexOf('user_active') > 0);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_insert_fred_before_jill() {
|
|
|
|
var fred_li = $('fred-li');
|
|
|
|
|
|
|
|
// These selectors are here to avoid some short-circuit logic.
|
|
|
|
$('#user_presences').add_child('[data-user-id="2"]', fred_li);
|
|
|
|
|
|
|
|
$('fake-dom-for-jill').attr = function (attr_name) {
|
|
|
|
assert.equal(attr_name, 'data-user-id');
|
|
|
|
return jill.user_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.stub_selector('#user_presences li', {
|
|
|
|
toArray: function () {
|
|
|
|
return [
|
|
|
|
'fake-dom-for-jill',
|
|
|
|
];
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
var before_html;
|
|
|
|
$('fake-dom-for-jill').before = function (html) {
|
|
|
|
before_html = html;
|
|
|
|
};
|
|
|
|
activity.insert_user_into_list(fred.user_id);
|
|
|
|
|
|
|
|
assert(before_html.indexOf('data-user-id="2"') > 0);
|
|
|
|
assert(before_html.indexOf('user_active') > 0);
|
|
|
|
}());
|
|
|
|
|
|
|
|
// Reset jquery here.
|
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
|
|
|
(function test_insert_unfiltered_user_with_filter() {
|
|
|
|
// This test only tests that we do not explode when
|
|
|
|
// try to insert Fred into a list where he does not
|
|
|
|
// match the search filter.
|
|
|
|
var user_filter = $('.user-list-filter');
|
|
|
|
user_filter.val('do-not-match-filter');
|
|
|
|
activity.insert_user_into_list(fred.user_id);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_realm_presence_disabled() {
|
|
|
|
page_params.realm_presence_disabled = true;
|
|
|
|
|
|
|
|
activity.insert_user_into_list();
|
|
|
|
activity.build_user_sidebar();
|
|
|
|
|
|
|
|
real_update_huddles();
|
|
|
|
}());
|
|
|
|
|