2017-06-02 00:33:39 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
|
|
|
set_global('templates', {});
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2013-11-26 16:39:58 +01:00
|
|
|
add_dependencies({
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
colorspace: 'js/colorspace',
|
2017-06-14 20:17:09 +02:00
|
|
|
Filter: 'js/filter',
|
2017-03-19 00:43:14 +01:00
|
|
|
hash_util: 'js/hash_util',
|
2013-11-26 16:39:58 +01:00
|
|
|
narrow: 'js/narrow',
|
2014-01-16 21:38:40 +01:00
|
|
|
stream_color: 'js/stream_color',
|
|
|
|
stream_data: 'js/stream_data',
|
2017-04-18 17:08:59 +02:00
|
|
|
stream_sort: 'js/stream_sort',
|
2017-01-25 17:11:29 +01:00
|
|
|
unread: 'js/unread',
|
2017-06-14 18:21:50 +02:00
|
|
|
unread_ui: 'js/unread_ui',
|
2016-11-11 02:39:22 +01:00
|
|
|
util: 'js/util',
|
2013-11-26 16:39:58 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
var stream_list = require('js/stream_list.js');
|
|
|
|
|
2017-06-14 14:33:04 +02:00
|
|
|
var noop = function () {};
|
|
|
|
var return_false = function () { return false; };
|
2017-06-14 16:06:21 +02:00
|
|
|
var return_true = function () { return true; };
|
2017-06-14 14:33:04 +02:00
|
|
|
|
2017-06-14 20:17:09 +02:00
|
|
|
set_global('topic_list', {});
|
|
|
|
|
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-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,
|
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,
|
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
|
|
|
|
2017-01-15 17:09:16 +01:00
|
|
|
global.unread.num_unread_for_stream = function () {
|
|
|
|
return 42;
|
|
|
|
};
|
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
(function create_devel_sidebar_row() {
|
|
|
|
var devel_value = $('devel-value');
|
|
|
|
var devel_count = $('devel-count');
|
|
|
|
$('devel-stub-html').add_child('.count', devel_count);
|
|
|
|
$('devel-count').add_child('.value', devel_value);
|
|
|
|
|
|
|
|
global.templates.render = function (template_name, data) {
|
|
|
|
assert.equal(template_name, 'stream_sidebar_row');
|
|
|
|
assert.equal(data.uri, '#narrow/stream/devel');
|
|
|
|
return 'devel-stub-html';
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.create_sidebar_row(devel);
|
|
|
|
assert.equal(devel_value.text(), '42');
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function create_social_sidebar_row() {
|
|
|
|
var social_value = $('social-value');
|
|
|
|
var social_count = $('social-count');
|
|
|
|
$('social-stub-html').add_child('.count', social_count);
|
|
|
|
$('social-count').add_child('.value', social_value);
|
|
|
|
|
|
|
|
global.templates.render = function (template_name, data) {
|
|
|
|
assert.equal(template_name, 'stream_sidebar_row');
|
|
|
|
assert.equal(data.uri, '#narrow/stream/social');
|
|
|
|
return 'social-stub-html';
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.create_sidebar_row(social);
|
|
|
|
assert.equal(social_value.text(), '42');
|
|
|
|
}());
|
|
|
|
|
|
|
|
function set_getter(elem, stub_value) {
|
|
|
|
elem.get = function (idx) {
|
|
|
|
assert.equal(idx, 0);
|
|
|
|
return stub_value;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
set_getter($('<hr class="stream-split">'), 'split');
|
|
|
|
set_getter($('devel-stub-html'), 'devel-sidebar');
|
|
|
|
set_getter($('social-stub-html'), 'social-sidebar');
|
|
|
|
|
|
|
|
var appended_elems;
|
|
|
|
$('#stream_filters').append = function (elems) {
|
|
|
|
appended_elems = elems;
|
|
|
|
};
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
stream_list.build_stream_list();
|
2016-11-11 02:39:22 +01:00
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
var expected_elems = [
|
|
|
|
'split',
|
|
|
|
'devel-sidebar',
|
|
|
|
'social-sidebar',
|
|
|
|
];
|
2014-01-17 18:23:39 +01:00
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
assert.deepEqual(appended_elems, expected_elems);
|
2014-01-17 18:23:39 +01:00
|
|
|
|
2017-06-14 16:06:21 +02:00
|
|
|
var social_li = $('social-stub-html');
|
|
|
|
var stream_id = social.stream_id;
|
|
|
|
|
2017-06-14 16:33:30 +02:00
|
|
|
var privacy_elem = $('privacy-stub');
|
|
|
|
social_li.add_child('.stream-privacy', privacy_elem);
|
|
|
|
|
|
|
|
social.invite_only = true;
|
|
|
|
social.color = '#222222';
|
|
|
|
global.templates.render = function (template_name, data) {
|
|
|
|
assert.equal(template_name, 'stream_privacy');
|
|
|
|
assert.equal(data.invite_only, true);
|
|
|
|
assert.equal(data.dark_background, 'dark_background');
|
|
|
|
return '<div>privacy-html';
|
|
|
|
};
|
|
|
|
stream_list.redraw_stream_privacy(social);
|
|
|
|
assert.equal(privacy_elem.html(), '<div>privacy-html');
|
|
|
|
|
2017-06-14 16:06:21 +02:00
|
|
|
stream_list.set_in_home_view(stream_id, false);
|
|
|
|
assert(social_li.hasClass('out_of_home_view'));
|
|
|
|
|
|
|
|
stream_list.set_in_home_view(stream_id, true);
|
|
|
|
assert(!social_li.hasClass('out_of_home_view'));
|
|
|
|
|
|
|
|
var row = stream_list.stream_sidebar.get_row(stream_id);
|
|
|
|
stream_data.is_active = return_true;
|
|
|
|
row.update_whether_active();
|
|
|
|
assert(!social_li.hasClass('inactive_stream'));
|
|
|
|
|
|
|
|
stream_data.is_active = return_false;
|
|
|
|
row.update_whether_active();
|
|
|
|
assert(social_li.hasClass('inactive_stream'));
|
|
|
|
|
|
|
|
var removed;
|
|
|
|
social_li.remove = function () {
|
|
|
|
removed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
row.remove();
|
|
|
|
assert(removed);
|
2014-01-16 21:38:40 +01:00
|
|
|
}());
|
2016-07-01 07:26:09 +02:00
|
|
|
|
2017-06-14 14:33:04 +02:00
|
|
|
function initialize_stream_data() {
|
2017-04-28 15:37:52 +02:00
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
function add_row(sub) {
|
|
|
|
global.stream_data.add_sub(sub.name, sub);
|
|
|
|
var row = {
|
|
|
|
update_whether_active: function () {},
|
|
|
|
get_li: function () {
|
2017-06-14 20:17:09 +02:00
|
|
|
var selector = 'stub-' + sub.name;
|
|
|
|
return $(selector);
|
2017-06-02 00:33:39 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
stream_list.stream_sidebar.set_row(sub.stream_id, row);
|
|
|
|
}
|
|
|
|
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
// pinned streams
|
2016-07-01 07:26:09 +02:00
|
|
|
var develSub = {
|
|
|
|
name: 'devel',
|
|
|
|
stream_id: 1000,
|
|
|
|
color: 'blue',
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
pin_to_top: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
subscribed: true,
|
2016-07-01 07:26:09 +02:00
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(develSub);
|
2016-07-01 07:26:09 +02:00
|
|
|
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
var RomeSub = {
|
|
|
|
name: 'Rome',
|
2016-07-01 07:26:09 +02:00
|
|
|
stream_id: 2000,
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
color: 'blue',
|
2016-07-01 07:26:09 +02:00
|
|
|
pin_to_top: true,
|
2016-12-03 23:17:57 +01:00
|
|
|
subscribed: true,
|
2016-07-01 07:26:09 +02:00
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(RomeSub);
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
|
|
|
var testSub = {
|
|
|
|
name: 'test',
|
|
|
|
stream_id: 3000,
|
|
|
|
color: 'blue',
|
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(testSub);
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
|
|
|
// unpinned streams
|
|
|
|
var announceSub = {
|
|
|
|
name: 'announce',
|
|
|
|
stream_id: 4000,
|
|
|
|
color: 'green',
|
|
|
|
pin_to_top: false,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(announceSub);
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
|
|
|
var DenmarkSub = {
|
|
|
|
name: 'Denmark',
|
|
|
|
stream_id: 5000,
|
|
|
|
color: 'green',
|
|
|
|
pin_to_top: false,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(DenmarkSub);
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2017-04-28 15:37:52 +02:00
|
|
|
var carSub = {
|
|
|
|
name: 'cars',
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
stream_id: 6000,
|
|
|
|
color: 'green',
|
|
|
|
pin_to_top: false,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2017-06-02 00:33:39 +02:00
|
|
|
add_row(carSub);
|
2017-06-14 14:33:04 +02:00
|
|
|
}
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2017-06-14 20:17:09 +02:00
|
|
|
(function test_narrowing() {
|
|
|
|
initialize_stream_data();
|
|
|
|
|
|
|
|
var document = 'document-stub';
|
|
|
|
|
|
|
|
set_global('document', document);
|
|
|
|
set_global('narrow_state', {
|
|
|
|
stream: function () { return 'devel'; },
|
|
|
|
topic: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
var pm_expanded;
|
|
|
|
|
|
|
|
set_global('pm_list', {
|
|
|
|
close: noop,
|
|
|
|
expand: function () { pm_expanded = true; },
|
|
|
|
});
|
|
|
|
|
|
|
|
topic_list.set_click_handlers = noop;
|
|
|
|
topic_list.is_zoomed = return_false;
|
|
|
|
topic_list.remove_expanded_topics = noop;
|
|
|
|
topic_list.rebuild = noop;
|
|
|
|
stream_list.scroll_element_into_container = noop;
|
|
|
|
|
2017-07-01 22:30:50 +02:00
|
|
|
var scrollbar_updated = false;
|
|
|
|
$.stub_selector("#stream-filters-container", {
|
|
|
|
perfectScrollbar: function () { scrollbar_updated = true; },
|
|
|
|
});
|
|
|
|
|
2017-06-14 20:17:09 +02:00
|
|
|
assert(!$('stub-devel').hasClass('active-filter'));
|
|
|
|
|
|
|
|
stream_list.initialize();
|
|
|
|
|
|
|
|
function activate_filter(filter) {
|
2017-07-06 15:23:06 +02:00
|
|
|
var handler = $(document).get_on_handler('narrow_activated.zulip');
|
|
|
|
handler({filter: filter});
|
2017-06-14 20:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var filter;
|
|
|
|
|
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'stream', operand: 'devel'},
|
|
|
|
]);
|
|
|
|
activate_filter(filter);
|
|
|
|
assert($('stub-devel').hasClass('active-filter'));
|
2017-07-01 22:30:50 +02:00
|
|
|
assert(scrollbar_updated); // Make sure we are updating perfectScrollbar.
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2017-07-01 22:30:50 +02:00
|
|
|
scrollbar_updated = false;
|
2017-06-14 20:17:09 +02:00
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'stream', operand: 'cars'},
|
|
|
|
{operator: 'topic', operand: 'sedans'},
|
|
|
|
]);
|
|
|
|
activate_filter(filter);
|
|
|
|
assert(!$("ul.filters li").hasClass('active-filter'));
|
|
|
|
assert(!$('stub-cars').hasClass('active-filter')); // false because of topic
|
2017-07-01 22:30:50 +02:00
|
|
|
assert(scrollbar_updated); // Make sure we are updating perfectScrollbar.
|
2017-06-14 20:17:09 +02:00
|
|
|
|
|
|
|
assert(!pm_expanded);
|
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'is', operand: 'private'},
|
|
|
|
]);
|
|
|
|
activate_filter(filter);
|
|
|
|
assert(pm_expanded);
|
|
|
|
|
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'is', operand: 'mentioned'},
|
|
|
|
]);
|
|
|
|
activate_filter(filter);
|
|
|
|
assert(stream_list.get_global_filter_li('mentioned').hasClass('active-filter'));
|
|
|
|
|
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'in', operand: 'home'},
|
|
|
|
]);
|
|
|
|
activate_filter(filter);
|
|
|
|
assert(stream_list.get_global_filter_li('home').hasClass('active-filter'));
|
|
|
|
|
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'stream', operand: 'cars'},
|
|
|
|
]);
|
|
|
|
activate_filter(filter);
|
|
|
|
assert(!$("ul.filters li").hasClass('active-filter'));
|
|
|
|
assert($('stub-cars').hasClass('active-filter'));
|
|
|
|
}());
|
|
|
|
|
2017-06-14 14:33:04 +02:00
|
|
|
(function test_sort_streams() {
|
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
|
|
|
|
// Get coverage on early-exit.
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
|
|
|
initialize_stream_data();
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2017-04-28 15:38:02 +02:00
|
|
|
global.stream_data.is_active = function (sub) {
|
|
|
|
return sub.name !== 'cars';
|
2017-04-18 19:59:35 +02:00
|
|
|
};
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
|
|
|
|
var appended_elems;
|
|
|
|
$('#stream_filters').append = function (elems) {
|
|
|
|
appended_elems = elems;
|
|
|
|
};
|
|
|
|
|
2017-04-28 15:37:52 +02:00
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
var expected_elems = [
|
|
|
|
'stub-devel',
|
|
|
|
'stub-Rome',
|
|
|
|
'stub-test',
|
|
|
|
'split',
|
|
|
|
'stub-announce',
|
|
|
|
'stub-Denmark',
|
|
|
|
'split',
|
|
|
|
'stub-cars',
|
|
|
|
];
|
|
|
|
assert.deepEqual(appended_elems, expected_elems);
|
|
|
|
|
|
|
|
var streams = global.stream_sort.get_streams();
|
2017-04-18 17:08:59 +02:00
|
|
|
|
|
|
|
assert.deepEqual(streams, [
|
2017-04-18 19:59:35 +02:00
|
|
|
// three groups: pinned, normal, dormant
|
2017-04-18 17:08:59 +02:00
|
|
|
'devel',
|
|
|
|
'Rome',
|
|
|
|
'test',
|
2017-04-18 19:59:35 +02:00
|
|
|
//
|
|
|
|
'announce',
|
2017-04-18 17:08:59 +02:00
|
|
|
'Denmark',
|
2017-04-18 19:59:35 +02:00
|
|
|
//
|
2017-04-28 15:37:52 +02:00
|
|
|
'cars',
|
2017-04-18 17:08:59 +02:00
|
|
|
]);
|
|
|
|
|
2017-06-14 14:33:04 +02:00
|
|
|
var denmark_sub = stream_data.get_sub('Denmark');
|
|
|
|
var stream_id = denmark_sub.stream_id;
|
|
|
|
assert(stream_list.stream_sidebar.has_row_for(stream_id));
|
|
|
|
stream_list.remove_sidebar_row(stream_id);
|
|
|
|
assert(!stream_list.stream_sidebar.has_row_for(stream_id));
|
2016-07-01 07:26:09 +02:00
|
|
|
}());
|
2017-06-14 00:27:06 +02:00
|
|
|
|
|
|
|
(function test_update_count_in_dom() {
|
2017-06-14 18:21:50 +02:00
|
|
|
function make_elem(elem_selector, count_selector, value_selector) {
|
|
|
|
var elem = $(elem_selector);
|
|
|
|
var count = $(count_selector);
|
|
|
|
var value = $(value_selector);
|
|
|
|
elem.add_child('.count', count);
|
|
|
|
count.add_child('.value', value);
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
var stream_li = make_elem(
|
|
|
|
'stream-li',
|
|
|
|
'stream-count',
|
|
|
|
'stream-value'
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
stream_li.addClass('subscription_block');
|
|
|
|
stream_li.addClass('stream-with-count');
|
|
|
|
assert(stream_li.hasClass('stream-with-count'));
|
|
|
|
|
|
|
|
make_elem(
|
|
|
|
"#global_filters li[data-name='mentioned']",
|
|
|
|
'mentioned-count',
|
|
|
|
'mentioned-value'
|
|
|
|
);
|
|
|
|
|
|
|
|
make_elem(
|
|
|
|
"#global_filters li[data-name='home']",
|
|
|
|
'home-count',
|
|
|
|
'home-value'
|
|
|
|
);
|
|
|
|
|
|
|
|
unread_ui.set_count_toggle_button = noop;
|
|
|
|
|
|
|
|
var stream_count = new Dict();
|
|
|
|
var stream_id = 11;
|
|
|
|
|
|
|
|
var stream_row = {
|
|
|
|
get_li: function () { return stream_li; },
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.stream_sidebar.set_row(stream_id, stream_row);
|
|
|
|
|
|
|
|
stream_count.set(stream_id, 0);
|
|
|
|
var counts = {
|
|
|
|
stream_count: stream_count,
|
|
|
|
subject_count: new Dict(),
|
|
|
|
mentioned_message_count: 222,
|
|
|
|
home_unread_messages: 333,
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.update_dom_with_unread_counts(counts);
|
|
|
|
assert.equal($('stream-value').text(), '');
|
|
|
|
assert(!stream_li.hasClass('stream-with-count'));
|
|
|
|
|
|
|
|
assert.equal($('mentioned-value').text(), '222');
|
|
|
|
assert.equal($('home-value').text(), '333');
|
|
|
|
|
|
|
|
stream_count.set(stream_id, 99);
|
|
|
|
|
|
|
|
stream_list.update_dom_with_unread_counts(counts);
|
|
|
|
assert.equal($('stream-value').text(), '99');
|
|
|
|
assert(stream_li.hasClass('stream-with-count'));
|
|
|
|
|
|
|
|
var topic_results;
|
|
|
|
|
|
|
|
topic_list.set_count = function (stream_id, topic, count) {
|
|
|
|
topic_results = {
|
|
|
|
stream_id: stream_id,
|
|
|
|
topic: topic,
|
|
|
|
count: count,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var topic_count = new Dict({fold_case: true});
|
|
|
|
topic_count.set('lunch', '555');
|
|
|
|
counts.subject_count.set(stream_id, topic_count);
|
|
|
|
|
|
|
|
stream_list.update_dom_with_unread_counts(counts);
|
|
|
|
|
|
|
|
assert.deepEqual(topic_results, {
|
|
|
|
stream_id: stream_id,
|
|
|
|
topic: 'lunch',
|
|
|
|
count: 555,
|
|
|
|
});
|
2017-06-14 00:27:06 +02:00
|
|
|
}());
|
2017-06-14 14:33:04 +02:00
|
|
|
|
|
|
|
(function test_create_initial_sidebar_rows() {
|
|
|
|
initialize_stream_data();
|
|
|
|
|
|
|
|
var html_dict = new Dict();
|
|
|
|
|
|
|
|
stream_list.stream_sidebar = {
|
|
|
|
has_row_for: return_false,
|
|
|
|
set_row: function (stream_id, widget) {
|
|
|
|
html_dict.set(stream_id, widget.get_li().html());
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.update_count_in_dom = noop;
|
|
|
|
|
|
|
|
global.templates.render = function (template_name, data) {
|
|
|
|
assert.equal(template_name, 'stream_sidebar_row');
|
|
|
|
return '<div>stub-html-' + data.name;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test this code with stubs above...
|
|
|
|
stream_list.create_initial_sidebar_rows();
|
|
|
|
|
|
|
|
assert.equal(html_dict.get(1000), '<div>stub-html-devel');
|
|
|
|
assert.equal(html_dict.get(5000), '<div>stub-html-Denmark');
|
|
|
|
}());
|