2016-07-30 20:01:15 +02:00
|
|
|
global.stub_out_jquery();
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2013-11-26 16:39:58 +01:00
|
|
|
add_dependencies({
|
|
|
|
Handlebars: 'handlebars',
|
|
|
|
templates: 'js/templates',
|
|
|
|
muting: 'js/muting',
|
|
|
|
narrow: 'js/narrow',
|
2016-11-18 15:48:53 +01:00
|
|
|
people: 'js/people',
|
2014-01-16 21:38:40 +01:00
|
|
|
stream_color: 'js/stream_color',
|
|
|
|
stream_data: 'js/stream_data',
|
|
|
|
subs: 'js/subs',
|
2016-11-11 02:39:22 +01:00
|
|
|
util: 'js/util',
|
2016-12-03 23:17:57 +01:00
|
|
|
hashchange: 'js/hashchange',
|
2013-11-26 16:39:58 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
set_global('unread', {});
|
2015-11-25 18:41:32 +01:00
|
|
|
set_global('message_store', {
|
2016-12-03 23:17:57 +01:00
|
|
|
recent_private_messages: new global.Array(),
|
2015-11-25 18:41:32 +01:00
|
|
|
});
|
2013-11-26 16:39:58 +01:00
|
|
|
|
2016-11-11 12:33:51 +01:00
|
|
|
// TODO: move pm_list-related tests to their own module
|
|
|
|
var pm_list = require('js/pm_list.js');
|
2013-11-26 16:39:58 +01:00
|
|
|
var stream_list = require('js/stream_list.js');
|
|
|
|
|
2016-08-24 21:49:53 +02:00
|
|
|
var jsdom = require("jsdom");
|
|
|
|
var window = jsdom.jsdom().defaultView;
|
|
|
|
global.$ = require('jquery')(window);
|
2014-01-16 21:38:40 +01:00
|
|
|
$.fn.expectOne = function () {
|
|
|
|
assert(this.length === 1);
|
|
|
|
return this;
|
|
|
|
};
|
2013-11-27 20:48:34 +01:00
|
|
|
|
2016-11-04 16:34:27 +01:00
|
|
|
global.compile_template('sidebar_private_message_list');
|
|
|
|
global.compile_template('stream_sidebar_row');
|
|
|
|
global.compile_template('stream_privacy');
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2016-11-18 15:48:53 +01:00
|
|
|
var alice = {
|
|
|
|
email: 'alice@zulip.com',
|
|
|
|
user_id: 101,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice',
|
2016-11-18 15:48:53 +01:00
|
|
|
};
|
|
|
|
var bob = {
|
|
|
|
email: 'bob@zulip.com',
|
|
|
|
user_id: 102,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Bob',
|
2016-11-18 15:48:53 +01:00
|
|
|
};
|
|
|
|
global.people.add_in_realm(alice);
|
|
|
|
global.people.add_in_realm(bob);
|
|
|
|
|
2015-11-25 18:41:32 +01:00
|
|
|
(function test_build_private_messages_list() {
|
2016-11-18 15:48:53 +01:00
|
|
|
var active_conversation = "alice@zulip.com,bob@zulip.com";
|
2015-11-25 18:41:32 +01:00
|
|
|
var max_conversations = 5;
|
|
|
|
|
|
|
|
|
2016-11-18 15:48:53 +01:00
|
|
|
var conversations = {user_ids_string: '101,102',
|
|
|
|
display_reply_to: active_conversation,
|
|
|
|
timestamp: 0 };
|
2015-11-25 18:41:32 +01:00
|
|
|
global.message_store.recent_private_messages.push(conversations);
|
|
|
|
|
|
|
|
global.unread.num_unread_for_person = function () {
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
2016-11-11 12:33:51 +01:00
|
|
|
var convos_html = pm_list._build_private_messages_list(active_conversation, max_conversations);
|
2015-11-25 18:41:32 +01:00
|
|
|
global.write_test_output("test_build_private_messages_list", convos_html);
|
|
|
|
|
|
|
|
var conversation = $(convos_html).find('a').text().trim();
|
|
|
|
assert.equal(conversation, active_conversation);
|
|
|
|
}());
|
|
|
|
|
2016-11-11 02:39:22 +01:00
|
|
|
function clear_filters() {
|
|
|
|
var stream_search_box = $('<input class="stream-list-filter" type="text" placeholder="Search streams">');
|
|
|
|
var stream_filters = $('<ul id="stream_filters">');
|
|
|
|
$("body").empty();
|
|
|
|
$("body").append(stream_search_box);
|
|
|
|
$("body").append(stream_filters);
|
|
|
|
|
|
|
|
}
|
2015-11-25 18:41:32 +01:00
|
|
|
|
2016-10-17 20:02:32 +02:00
|
|
|
(function test_create_sidebar_row() {
|
|
|
|
// Make a couple calls to create_sidebar_row() and make sure they
|
2014-01-16 21:38:40 +01:00
|
|
|
// generate the right markup as well as play nice with get_stream_li().
|
|
|
|
|
2016-11-11 02:39:22 +01:00
|
|
|
clear_filters();
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2016-10-17 20:02:32 +02:00
|
|
|
var devel = {
|
2014-01-16 21:38:40 +01:00
|
|
|
name: 'devel',
|
2016-11-11 14:20:19 +01:00
|
|
|
stream_id: 100,
|
2014-01-16 21:38:40 +01:00
|
|
|
color: 'blue',
|
2016-11-11 02:39:22 +01:00
|
|
|
subscribed: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
id: 5,
|
2014-01-16 21:38:40 +01:00
|
|
|
};
|
2016-10-17 20:02:32 +02:00
|
|
|
global.stream_data.add_sub('devel', devel);
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2016-10-17 20:02:32 +02:00
|
|
|
var social = {
|
2014-01-16 21:38:40 +01:00
|
|
|
name: 'social',
|
2016-11-11 14:20:19 +01:00
|
|
|
stream_id: 200,
|
2014-01-16 21:38:40 +01:00
|
|
|
color: 'green',
|
2016-11-11 02:39:22 +01:00
|
|
|
subscribed: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
id: 6,
|
2014-01-16 21:38:40 +01:00
|
|
|
};
|
2016-10-17 20:02:32 +02:00
|
|
|
global.stream_data.add_sub('social', social);
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2016-10-17 20:02:32 +02:00
|
|
|
stream_list.create_sidebar_row(devel);
|
|
|
|
stream_list.create_sidebar_row(social);
|
2016-11-11 02:39:22 +01:00
|
|
|
stream_list.build_stream_list();
|
2014-01-16 21:38:40 +01:00
|
|
|
|
|
|
|
var html = $("body").html();
|
2016-10-17 20:02:32 +02:00
|
|
|
global.write_test_output("test_create_sidebar_row", html);
|
2014-01-16 21:38:40 +01:00
|
|
|
|
|
|
|
var li = stream_list.get_stream_li('social');
|
|
|
|
assert.equal(li.attr('data-name'), 'social');
|
2016-08-24 21:49:53 +02:00
|
|
|
assert.equal(li.find('.streamlist_swatch').attr('style'), 'background-color: green');
|
2016-10-28 23:27:02 +02:00
|
|
|
assert.equal(li.find('a.stream-name').text().trim(), 'social');
|
2014-01-16 21:38:40 +01:00
|
|
|
assert(li.find('.arrow').find("i").hasClass("icon-vector-chevron-down"));
|
|
|
|
|
2014-01-17 18:23:39 +01:00
|
|
|
global.append_test_output("Then make 'social' private.");
|
|
|
|
global.stream_data.get_sub('social').invite_only = true;
|
2016-11-11 02:39:22 +01:00
|
|
|
|
2014-01-17 18:23:39 +01:00
|
|
|
stream_list.redraw_stream_privacy('social');
|
|
|
|
|
|
|
|
html = $("body").html();
|
|
|
|
global.append_test_output(html);
|
|
|
|
|
|
|
|
assert(li.find('.stream-privacy').find("i").hasClass("icon-vector-lock"));
|
2014-01-16 21:38:40 +01:00
|
|
|
}());
|
2016-07-01 07:26:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
(function test_sort_pin_to_top_streams() {
|
2016-11-11 02:39:22 +01:00
|
|
|
clear_filters();
|
2016-07-01 07:26:09 +02:00
|
|
|
|
|
|
|
var develSub = {
|
|
|
|
name: 'devel',
|
|
|
|
stream_id: 1000,
|
|
|
|
color: 'blue',
|
|
|
|
id: 5,
|
|
|
|
pin_to_top: false,
|
2016-12-03 23:17:57 +01:00
|
|
|
subscribed: true,
|
2016-07-01 07:26:09 +02:00
|
|
|
};
|
2016-10-17 20:02:32 +02:00
|
|
|
stream_list.create_sidebar_row(develSub);
|
2016-07-01 07:26:09 +02:00
|
|
|
global.stream_data.add_sub('devel', develSub);
|
|
|
|
|
|
|
|
var socialSub = {
|
|
|
|
name: 'social',
|
|
|
|
stream_id: 2000,
|
|
|
|
color: 'green',
|
|
|
|
id: 6,
|
|
|
|
pin_to_top: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
subscribed: true,
|
2016-07-01 07:26:09 +02:00
|
|
|
};
|
2016-10-17 20:02:32 +02:00
|
|
|
stream_list.create_sidebar_row(socialSub);
|
2016-07-01 07:26:09 +02:00
|
|
|
global.stream_data.add_sub('social', socialSub);
|
|
|
|
stream_list.build_stream_list();
|
2016-11-11 14:20:19 +01:00
|
|
|
var li = stream_list.stream_sidebar.get_row(socialSub.stream_id).get_li();
|
2016-11-11 02:39:22 +01:00
|
|
|
assert.equal(li.nextAll().find('[ data-name="devel"]').length, 1);
|
2016-07-01 07:26:09 +02:00
|
|
|
}());
|