2017-05-31 01:32:55 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
2019-12-29 13:49:29 +01:00
|
|
|
const Dict = zrequire('dict').Dict;
|
|
|
|
|
2017-05-31 16:59:37 +02:00
|
|
|
set_global('narrow_state', {});
|
|
|
|
set_global('resize', {
|
|
|
|
resize_stream_filters_container: function () {},
|
|
|
|
});
|
2019-02-13 14:05:58 +01:00
|
|
|
set_global('ui', {
|
2019-05-03 03:16:09 +02:00
|
|
|
get_content_element: element => element,
|
2019-02-13 14:05:58 +01:00
|
|
|
});
|
2017-05-31 16:59:37 +02:00
|
|
|
set_global('stream_popover', {
|
|
|
|
hide_topic_popover: function () {},
|
|
|
|
});
|
2017-01-25 17:11:29 +01:00
|
|
|
set_global('unread', {});
|
2017-05-31 15:56:22 +02:00
|
|
|
set_global('unread_ui', {});
|
2018-05-01 06:01:10 +02:00
|
|
|
set_global('blueslip', global.make_zblueslip());
|
2017-06-22 16:55:56 +02:00
|
|
|
set_global('popovers', {
|
|
|
|
hide_all: function () {},
|
|
|
|
});
|
2017-01-25 17:11:29 +01:00
|
|
|
|
2019-02-18 16:32:27 +01:00
|
|
|
zrequire('user_status');
|
|
|
|
zrequire('presence');
|
|
|
|
zrequire('buddy_data');
|
2017-08-09 18:42:26 +02:00
|
|
|
zrequire('hash_util');
|
2019-07-12 02:03:55 +02:00
|
|
|
set_global('Handlebars', global.make_handlebars());
|
2017-08-09 18:42:26 +02:00
|
|
|
zrequire('people');
|
2018-02-09 18:10:39 +01:00
|
|
|
zrequire('pm_conversations');
|
2017-08-09 18:42:26 +02:00
|
|
|
zrequire('pm_list');
|
2017-01-25 17:11:29 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2017-01-25 17:11:29 +01:00
|
|
|
email: 'alice@zulip.com',
|
|
|
|
user_id: 101,
|
|
|
|
full_name: 'Alice',
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob = {
|
2017-01-25 17:11:29 +01:00
|
|
|
email: 'bob@zulip.com',
|
|
|
|
user_id: 102,
|
|
|
|
full_name: 'Bob',
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2017-01-25 17:11:29 +01:00
|
|
|
email: 'me@zulip.com',
|
|
|
|
user_id: 103,
|
|
|
|
full_name: 'Me Myself',
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const bot_test = {
|
2019-09-16 23:57:18 +02:00
|
|
|
email: 'outgoingwebhook@zulip.com',
|
|
|
|
user_id: 314,
|
|
|
|
full_name: "Outgoing webhook",
|
|
|
|
is_admin: false,
|
|
|
|
is_bot: true,
|
|
|
|
};
|
2017-01-25 17:11:29 +01:00
|
|
|
global.people.add_in_realm(alice);
|
|
|
|
global.people.add_in_realm(bob);
|
|
|
|
global.people.add_in_realm(me);
|
2019-09-16 23:57:18 +02:00
|
|
|
global.people.add_in_realm(bot_test);
|
2017-01-25 17:11:29 +01:00
|
|
|
global.people.initialize_current_user(me.user_id);
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('close', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let collapsed;
|
2019-05-03 03:16:09 +02:00
|
|
|
$('#private-container').empty = function () {
|
2017-06-22 16:55:56 +02:00
|
|
|
collapsed = true;
|
|
|
|
};
|
|
|
|
pm_list.close();
|
|
|
|
assert(collapsed);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-22 16:55:56 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('build_private_messages_list', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const timestamp = 0;
|
2020-01-01 15:42:46 +01:00
|
|
|
pm_conversations.recent.insert([101, 102], timestamp);
|
2017-01-25 17:11:29 +01:00
|
|
|
|
|
|
|
global.unread.num_unread_for_person = function () {
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let template_data;
|
2017-05-31 01:32:55 +02:00
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(function (template_name, data) {
|
2017-05-31 01:32:55 +02:00
|
|
|
assert.equal(template_name, 'sidebar_private_message_list');
|
|
|
|
template_data = data;
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2017-05-31 01:32:55 +02:00
|
|
|
|
2020-01-06 15:00:11 +01:00
|
|
|
narrow_state.filter = () => {};
|
2020-01-06 13:07:00 +01:00
|
|
|
pm_list._build_private_messages_list();
|
2017-05-31 01:32:55 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected_data = {
|
2017-05-31 01:32:55 +02:00
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
recipients: 'Alice, Bob',
|
|
|
|
user_ids_string: '101,102',
|
|
|
|
unread: 1,
|
|
|
|
is_zero: false,
|
2020-01-06 15:00:11 +01:00
|
|
|
is_active: false,
|
2017-05-31 01:32:55 +02:00
|
|
|
url: '#narrow/pm-with/101,102-group',
|
2019-02-18 16:32:27 +01:00
|
|
|
user_circle_class: 'user_circle_fraction',
|
2019-11-20 23:38:42 +01:00
|
|
|
fraction_present: undefined,
|
2019-02-18 16:32:27 +01:00
|
|
|
is_group: true,
|
2017-05-31 01:32:55 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(template_data, expected_data);
|
2017-01-25 17:11:29 +01:00
|
|
|
|
2017-06-22 16:55:56 +02:00
|
|
|
global.unread.num_unread_for_person = function () {
|
|
|
|
return 0;
|
|
|
|
};
|
2020-01-06 13:07:00 +01:00
|
|
|
pm_list._build_private_messages_list();
|
2017-06-22 16:55:56 +02:00
|
|
|
expected_data.messages[0].unread = 0;
|
|
|
|
expected_data.messages[0].is_zero = true;
|
|
|
|
assert.deepEqual(template_data, expected_data);
|
|
|
|
|
|
|
|
pm_list.initialize();
|
2020-01-06 13:07:00 +01:00
|
|
|
pm_list._build_private_messages_list();
|
2017-06-22 16:55:56 +02:00
|
|
|
assert.deepEqual(template_data, expected_data);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-31 15:56:22 +02:00
|
|
|
|
2019-09-16 23:57:18 +02:00
|
|
|
run_test('build_private_messages_list_bot', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const timestamp = 0;
|
2020-01-01 15:42:46 +01:00
|
|
|
pm_conversations.recent.insert([314], timestamp);
|
2019-09-16 23:57:18 +02:00
|
|
|
|
|
|
|
global.unread.num_unread_for_person = function () {
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let template_data;
|
2019-09-16 23:57:18 +02:00
|
|
|
global.stub_templates(function (template_name, data) {
|
|
|
|
assert.equal(template_name, 'sidebar_private_message_list');
|
|
|
|
template_data = data;
|
|
|
|
});
|
|
|
|
|
2020-01-06 13:07:00 +01:00
|
|
|
pm_list._build_private_messages_list();
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected_data = {
|
2019-09-16 23:57:18 +02:00
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
recipients: 'Outgoing webhook',
|
|
|
|
user_ids_string: '314',
|
|
|
|
unread: 1,
|
|
|
|
is_zero: false,
|
2020-01-06 15:00:11 +01:00
|
|
|
is_active: false,
|
2019-09-16 23:57:18 +02:00
|
|
|
url: '#narrow/pm-with/314-outgoingwebhook',
|
|
|
|
user_circle_class: 'user_circle_green',
|
2019-11-20 23:38:42 +01:00
|
|
|
fraction_present: undefined,
|
2019-09-16 23:57:18 +02:00
|
|
|
is_group: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
recipients: 'Alice, Bob',
|
|
|
|
user_ids_string: '101,102',
|
|
|
|
unread: 1,
|
|
|
|
is_zero: false,
|
2020-01-06 15:00:11 +01:00
|
|
|
is_active: false,
|
2019-09-16 23:57:18 +02:00
|
|
|
url: '#narrow/pm-with/101,102-group',
|
|
|
|
user_circle_class: 'user_circle_fraction',
|
2019-11-20 23:38:42 +01:00
|
|
|
fraction_present: undefined,
|
2019-09-16 23:57:18 +02:00
|
|
|
is_group: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(template_data, expected_data);
|
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('update_dom_with_unread_counts', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const total_value = $.create('total-value-stub');
|
|
|
|
const total_count = $.create('total-count-stub');
|
|
|
|
const private_li = $(".top_left_private_messages");
|
2017-07-08 14:31:18 +02:00
|
|
|
private_li.set_find_results('.count', total_count);
|
|
|
|
total_count.set_find_results('.value', total_value);
|
2017-05-31 15:56:22 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const child_value = $.create('child-value-stub');
|
|
|
|
const child_count = $.create('child-count-stub');
|
|
|
|
const child_li = $.create('child-li-stub');
|
2017-07-08 14:31:18 +02:00
|
|
|
private_li.set_find_results("li[data-user-ids-string='101,102']", child_li);
|
|
|
|
child_li.set_find_results('.private_message_count', child_count);
|
|
|
|
child_count.set_find_results('.value', child_value);
|
2017-05-31 15:56:22 +02:00
|
|
|
|
2019-04-18 21:11:30 +02:00
|
|
|
child_value.length = 1;
|
|
|
|
child_count.length = 1;
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const pm_count = new Dict();
|
|
|
|
const user_ids_string = '101,102';
|
2017-05-31 15:56:22 +02:00
|
|
|
pm_count.set(user_ids_string, 7);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let counts = {
|
2017-05-31 15:56:22 +02:00
|
|
|
private_message_count: 10,
|
|
|
|
pm_count: pm_count,
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let toggle_button_set;
|
2017-05-31 15:56:22 +02:00
|
|
|
unread_ui.set_count_toggle_button = function (elt, count) {
|
|
|
|
toggle_button_set = true;
|
|
|
|
assert.equal(count, 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
pm_list.update_dom_with_unread_counts(counts);
|
|
|
|
|
|
|
|
assert(toggle_button_set);
|
|
|
|
assert.equal(child_value.text(), '7');
|
|
|
|
assert.equal(total_value.text(), '10');
|
2017-06-22 16:55:56 +02:00
|
|
|
|
|
|
|
pm_count.set(user_ids_string, 0);
|
|
|
|
counts = {
|
|
|
|
private_message_count: 0,
|
|
|
|
pm_count: pm_count,
|
|
|
|
};
|
|
|
|
toggle_button_set = false;
|
|
|
|
unread_ui.set_count_toggle_button = function (elt, count) {
|
|
|
|
toggle_button_set = true;
|
|
|
|
assert.equal(count, 0);
|
|
|
|
};
|
|
|
|
pm_list.update_dom_with_unread_counts(counts);
|
|
|
|
|
|
|
|
assert(toggle_button_set);
|
|
|
|
assert.equal(child_value.text(), '');
|
|
|
|
assert.equal(total_value.text(), '');
|
|
|
|
|
2020-01-06 15:00:11 +01:00
|
|
|
const pm_li = pm_list.get_li_for_user_ids_string("101,102");
|
2017-06-22 16:55:56 +02:00
|
|
|
pm_li.find = function (sel) {
|
|
|
|
assert.equal(sel, '.private_message_count');
|
|
|
|
return {find: function (sel) {
|
|
|
|
assert.equal(sel, '.value');
|
|
|
|
return [];
|
|
|
|
}};
|
|
|
|
};
|
|
|
|
pm_list.update_dom_with_unread_counts(counts);
|
|
|
|
assert(toggle_button_set);
|
|
|
|
assert.equal(child_value.text(), '');
|
|
|
|
assert.equal(total_value.text(), '');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2020-01-06 15:00:11 +01:00
|
|
|
|
|
|
|
run_test('get_active_user_ids_string', () => {
|
|
|
|
narrow_state.filter = () => {};
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
pm_list.get_active_user_ids_string(),
|
|
|
|
undefined);
|
|
|
|
|
|
|
|
function set_filter_result(emails) {
|
|
|
|
narrow_state.filter = () => {
|
|
|
|
return {
|
|
|
|
operands: (operand) => {
|
|
|
|
assert.equal(operand, 'pm-with');
|
|
|
|
return emails;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
set_filter_result([]);
|
|
|
|
assert.equal(
|
|
|
|
pm_list.get_active_user_ids_string(),
|
|
|
|
undefined);
|
|
|
|
|
|
|
|
set_filter_result(['bob@zulip.com,alice@zulip.com']);
|
|
|
|
assert.equal(
|
|
|
|
pm_list.get_active_user_ids_string(),
|
|
|
|
'101,102');
|
|
|
|
});
|
2020-01-06 16:18:20 +01:00
|
|
|
|
|
|
|
run_test('is_all_privates', () => {
|
|
|
|
narrow_state.filter = () => {};
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
pm_list.is_all_privates(),
|
|
|
|
false);
|
|
|
|
|
|
|
|
narrow_state.filter = () => {
|
|
|
|
return {
|
|
|
|
operands: (operand) => {
|
|
|
|
assert.equal(operand, 'is');
|
|
|
|
return ['private', 'starred'];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
pm_list.is_all_privates(),
|
|
|
|
true);
|
|
|
|
});
|
2020-01-06 16:49:53 +01:00
|
|
|
|
|
|
|
function with_fake_list(f) {
|
|
|
|
const orig = pm_list._build_private_messages_list;
|
|
|
|
pm_list._build_private_messages_list = () => {
|
|
|
|
return 'PM_LIST_CONTENTS';
|
|
|
|
};
|
|
|
|
f();
|
|
|
|
pm_list._build_private_messages_list = orig;
|
|
|
|
}
|
|
|
|
|
|
|
|
run_test('expand', () => {
|
|
|
|
with_fake_list(() => {
|
|
|
|
let html_inserted;
|
|
|
|
|
|
|
|
$('#private-container').html = function (html) {
|
|
|
|
assert.equal(html, 'PM_LIST_CONTENTS');
|
|
|
|
html_inserted = true;
|
|
|
|
};
|
|
|
|
pm_list.expand();
|
|
|
|
|
|
|
|
assert(html_inserted);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test('update_private_messages', () => {
|
|
|
|
narrow_state.active = () => true;
|
|
|
|
|
|
|
|
with_fake_list(() => {
|
|
|
|
let html_inserted;
|
|
|
|
|
|
|
|
$('#private-container').html = function (html) {
|
|
|
|
assert.equal(html, 'PM_LIST_CONTENTS');
|
|
|
|
html_inserted = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const orig_is_all_privates = pm_list.is_all_privates;
|
|
|
|
pm_list.is_all_privates = () => true;
|
|
|
|
|
|
|
|
pm_list.update_private_messages();
|
|
|
|
|
|
|
|
assert(html_inserted);
|
|
|
|
assert($(".top_left_private_messages").hasClass('active-filter'));
|
|
|
|
|
|
|
|
pm_list.is_all_privates = orig_is_all_privates;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test('ensure coverage', () => {
|
|
|
|
// These aren't rigorous; they just cover cases
|
|
|
|
// where functions early exit.
|
|
|
|
narrow_state.active = () => false;
|
|
|
|
pm_list.rebuild_recent = () => {
|
|
|
|
throw Error('we should not call rebuild_recent');
|
|
|
|
};
|
|
|
|
pm_list.update_private_messages();
|
|
|
|
});
|