2018-04-25 13:03:39 +02:00
|
|
|
set_global('document', 'document-stub');
|
2017-06-02 00:33:39 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
2017-08-09 18:55:37 +02:00
|
|
|
zrequire('unread_ui');
|
|
|
|
zrequire('Filter', 'js/filter');
|
|
|
|
zrequire('util');
|
|
|
|
zrequire('topic_data');
|
|
|
|
zrequire('stream_sort');
|
|
|
|
zrequire('colorspace');
|
|
|
|
zrequire('stream_color');
|
|
|
|
zrequire('hash_util');
|
|
|
|
zrequire('unread');
|
|
|
|
zrequire('stream_data');
|
2018-04-24 14:09:16 +02:00
|
|
|
zrequire('scroll_util');
|
2018-04-24 16:59:01 +02:00
|
|
|
zrequire('list_cursor');
|
2017-08-09 18:55:37 +02:00
|
|
|
zrequire('stream_list');
|
2018-09-10 23:15:55 +02:00
|
|
|
zrequire('topic_zoom');
|
2019-03-01 01:40:05 +01:00
|
|
|
zrequire('ui');
|
2019-03-17 14:48:51 +01:00
|
|
|
set_global('i18n', global.stub_i18n);
|
2019-06-13 13:55:53 +02:00
|
|
|
set_global('page_params', {
|
|
|
|
is_admin: false,
|
|
|
|
realm_users: [],
|
|
|
|
});
|
2019-03-17 14:48:51 +01:00
|
|
|
zrequire('settings_display');
|
2013-11-26 16:39:58 +01:00
|
|
|
|
2018-05-15 22:03:14 +02:00
|
|
|
stream_color.initialize();
|
|
|
|
|
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', {});
|
2018-02-12 22:56:37 +01:00
|
|
|
set_global('overlays', {});
|
2018-04-25 13:03:39 +02:00
|
|
|
set_global('popovers', {});
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2018-04-24 16:59:01 +02:00
|
|
|
set_global('keydown_util', {
|
|
|
|
handle: noop,
|
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('create_sidebar_row', () => {
|
2016-10-17 20:02:32 +02:00
|
|
|
// 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().
|
2019-03-17 14:48:51 +01:00
|
|
|
page_params.demote_inactive_streams = 1;
|
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,
|
2017-11-13 17:17:34 +01:00
|
|
|
pin_to_top: 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() {
|
2017-07-08 15:16:19 +02:00
|
|
|
var devel_value = $.create('devel-value');
|
|
|
|
var devel_count = $.create('devel-count');
|
|
|
|
|
|
|
|
var sidebar_row = $('<devel sidebar row>');
|
|
|
|
|
|
|
|
sidebar_row.set_find_results('.count', devel_count);
|
|
|
|
devel_count.set_find_results('.value', devel_value);
|
|
|
|
devel_count.set_parent(sidebar_row);
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(function (template_name, data) {
|
2017-06-02 00:33:39 +02:00
|
|
|
assert.equal(template_name, 'stream_sidebar_row');
|
2018-02-15 21:02:47 +01:00
|
|
|
assert.equal(data.uri, '#narrow/stream/100-devel');
|
2017-07-08 15:16:19 +02:00
|
|
|
return '<devel sidebar row>';
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2017-06-02 00:33:39 +02:00
|
|
|
|
|
|
|
stream_list.create_sidebar_row(devel);
|
|
|
|
assert.equal(devel_value.text(), '42');
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function create_social_sidebar_row() {
|
2017-07-08 15:16:19 +02:00
|
|
|
var social_value = $.create('social-value');
|
|
|
|
var social_count = $.create('social-count');
|
|
|
|
var sidebar_row = $('<social sidebar row>');
|
|
|
|
|
|
|
|
sidebar_row.set_find_results('.count', social_count);
|
|
|
|
social_count.set_find_results('.value', social_value);
|
|
|
|
social_count.set_parent(sidebar_row);
|
2017-06-02 00:33:39 +02:00
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(function (template_name, data) {
|
2017-06-02 00:33:39 +02:00
|
|
|
assert.equal(template_name, 'stream_sidebar_row');
|
2018-02-15 21:02:47 +01:00
|
|
|
assert.equal(data.uri, '#narrow/stream/200-social');
|
2017-07-08 15:16:19 +02:00
|
|
|
return '<social sidebar row>';
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2017-06-02 00:33:39 +02:00
|
|
|
|
|
|
|
stream_list.create_sidebar_row(social);
|
|
|
|
assert.equal(social_value.text(), '42');
|
|
|
|
}());
|
|
|
|
|
2017-07-18 13:30:14 +02:00
|
|
|
var split = '<hr class="stream-split">';
|
|
|
|
var devel_sidebar = $('<devel sidebar row>');
|
|
|
|
var social_sidebar = $('<social sidebar row>');
|
2017-06-02 00:33:39 +02:00
|
|
|
|
|
|
|
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 = [
|
2017-11-13 17:17:34 +01:00
|
|
|
devel_sidebar, //pinned
|
|
|
|
split, //separator
|
|
|
|
social_sidebar, //not pinned
|
2017-06-02 00:33:39 +02:00
|
|
|
];
|
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-07-08 15:16:19 +02:00
|
|
|
var social_li = $('<social sidebar row>');
|
2017-06-14 16:06:21 +02:00
|
|
|
var stream_id = social.stream_id;
|
|
|
|
|
2019-04-18 21:11:30 +02:00
|
|
|
social_li.length = 0;
|
|
|
|
|
2017-07-08 15:16:19 +02:00
|
|
|
var privacy_elem = $.create('privacy-stub');
|
2017-07-08 14:31:18 +02:00
|
|
|
social_li.set_find_results('.stream-privacy', privacy_elem);
|
2017-06-14 16:33:30 +02:00
|
|
|
|
|
|
|
social.invite_only = true;
|
|
|
|
social.color = '#222222';
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(function (template_name, data) {
|
2017-06-14 16:33:30 +02:00
|
|
|
assert.equal(template_name, 'stream_privacy');
|
|
|
|
assert.equal(data.invite_only, true);
|
|
|
|
assert.equal(data.dark_background, 'dark_background');
|
|
|
|
return '<div>privacy-html';
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2017-06-14 16:33:30 +02:00
|
|
|
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);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2019-04-11 08:25:50 +02:00
|
|
|
run_test('pinned_streams_never_inactive', () => {
|
|
|
|
// Ensure that pinned streams are never treated as dormant ie never given "inactive" class
|
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
|
|
|
|
var devel = {
|
|
|
|
name: 'devel',
|
|
|
|
stream_id: 100,
|
|
|
|
color: 'blue',
|
|
|
|
subscribed: true,
|
|
|
|
pin_to_top: true,
|
|
|
|
};
|
|
|
|
global.stream_data.add_sub('devel', devel);
|
|
|
|
|
|
|
|
var social = {
|
|
|
|
name: 'social',
|
|
|
|
stream_id: 200,
|
|
|
|
color: 'green',
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
global.stream_data.add_sub('social', social);
|
|
|
|
|
|
|
|
// we use social and devel created in create_social_sidebar_row() and create_devel_sidebar_row()
|
|
|
|
|
|
|
|
// non-pinned streams can be made inactive
|
|
|
|
var social_sidebar = $('<social sidebar row>');
|
|
|
|
var stream_id = social.stream_id;
|
|
|
|
var row = stream_list.stream_sidebar.get_row(stream_id);
|
|
|
|
stream_data.is_active = return_false;
|
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
assert(social_sidebar.hasClass('inactive_stream'));
|
|
|
|
|
|
|
|
stream_data.is_active = return_true;
|
|
|
|
row.update_whether_active();
|
|
|
|
assert(!social_sidebar.hasClass('inactive_stream'));
|
|
|
|
|
|
|
|
stream_data.is_active = return_false;
|
|
|
|
row.update_whether_active();
|
|
|
|
assert(social_sidebar.hasClass('inactive_stream'));
|
|
|
|
|
|
|
|
// pinned streams can never be made inactive
|
|
|
|
var devel_sidebar = $('<devel sidebar row>');
|
|
|
|
stream_id = devel.stream_id;
|
|
|
|
row = stream_list.stream_sidebar.get_row(stream_id);
|
|
|
|
stream_data.is_active = return_false;
|
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
assert(!devel_sidebar.hasClass('inactive_stream'));
|
|
|
|
|
|
|
|
row.update_whether_active();
|
|
|
|
assert(!devel_sidebar.hasClass('inactive_stream'));
|
|
|
|
});
|
|
|
|
|
2018-04-25 13:03:39 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
2017-11-13 17:17:34 +01:00
|
|
|
function add_row(sub) {
|
|
|
|
global.stream_data.add_sub(sub.name, sub);
|
|
|
|
var row = {
|
|
|
|
update_whether_active: function () {},
|
|
|
|
get_li: function () {
|
|
|
|
var html = '<' + sub.name + ' sidebar row html>';
|
|
|
|
var obj = $(html);
|
|
|
|
|
|
|
|
obj.length = 1; // bypass blueslip error
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
stream_list.stream_sidebar.set_row(sub.stream_id, row);
|
|
|
|
}
|
2018-04-25 13:03:39 +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();
|
|
|
|
|
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
|
|
|
|
2018-04-25 13:03:39 +02:00
|
|
|
function elem($obj) {
|
|
|
|
return {to_$: () => $obj};
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('zoom_in_and_zoom_out', () => {
|
2018-04-25 13:03:39 +02:00
|
|
|
var label1 = $.create('label1 stub');
|
|
|
|
var label2 = $.create('label2 stub');
|
|
|
|
|
|
|
|
label1.show();
|
|
|
|
label2.show();
|
|
|
|
|
|
|
|
assert(label1.visible());
|
|
|
|
assert(label2.visible());
|
|
|
|
|
|
|
|
$('.stream-filters-label').each = (f) => {
|
|
|
|
f.call(elem(label1));
|
|
|
|
f.call(elem(label2));
|
|
|
|
};
|
|
|
|
|
|
|
|
const splitter = $.create('hr stub');
|
|
|
|
|
|
|
|
splitter.show();
|
|
|
|
assert(splitter.visible());
|
|
|
|
|
|
|
|
$('.stream-split').each = (f) => {
|
|
|
|
f.call(elem(splitter));
|
|
|
|
};
|
|
|
|
|
|
|
|
const stream_li1 = $.create('stream1 stub');
|
|
|
|
const stream_li2 = $.create('stream2 stub');
|
|
|
|
|
|
|
|
function make_attr(arg) {
|
|
|
|
return (sel) => {
|
|
|
|
assert.equal(sel, 'data-stream-id');
|
|
|
|
return arg;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_li1.attr = make_attr('42');
|
|
|
|
stream_li1.hide();
|
|
|
|
stream_li2.attr = make_attr('99');
|
|
|
|
|
|
|
|
$('#stream_filters li.narrow-filter').each = (f) => {
|
|
|
|
f.call(elem(stream_li1));
|
|
|
|
f.call(elem(stream_li2));
|
|
|
|
};
|
2019-07-26 00:22:43 +02:00
|
|
|
$('#stream-filters-container')[0] = {
|
|
|
|
dataset: {},
|
|
|
|
};
|
2019-03-22 17:26:51 +01:00
|
|
|
stream_list.set_event_handlers();
|
2018-04-25 13:03:39 +02:00
|
|
|
|
2018-09-10 14:52:58 +02:00
|
|
|
stream_list.zoom_in_topics({stream_id: 42});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
|
|
|
assert(!label1.visible());
|
|
|
|
assert(!label2.visible());
|
|
|
|
assert(!splitter.visible());
|
|
|
|
assert(stream_li1.visible());
|
|
|
|
assert(!stream_li2.visible());
|
|
|
|
assert($('#streams_list').hasClass('zoom-in'));
|
|
|
|
|
|
|
|
$('#stream_filters li.narrow-filter').show = () => {
|
|
|
|
stream_li1.show();
|
|
|
|
stream_li2.show();
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_li1.length = 1;
|
2018-09-10 14:52:58 +02:00
|
|
|
stream_list.zoom_out_topics({stream_li: stream_li1});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
|
|
|
assert(label1.visible());
|
|
|
|
assert(label2.visible());
|
|
|
|
assert(splitter.visible());
|
|
|
|
assert(stream_li1.visible());
|
|
|
|
assert(stream_li2.visible());
|
|
|
|
assert($('#streams_list').hasClass('zoom-out'));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 13:03:39 +02:00
|
|
|
|
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('narrowing', () => {
|
2017-06-14 20:17:09 +02:00
|
|
|
initialize_stream_data();
|
|
|
|
|
|
|
|
set_global('narrow_state', {
|
|
|
|
stream: function () { return 'devel'; },
|
|
|
|
topic: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
topic_list.set_click_handlers = noop;
|
2017-08-11 00:30:23 +02:00
|
|
|
topic_list.close = noop;
|
2017-06-14 20:17:09 +02:00
|
|
|
topic_list.remove_expanded_topics = noop;
|
|
|
|
topic_list.rebuild = noop;
|
2017-08-11 00:30:23 +02:00
|
|
|
topic_list.active_stream_id = noop;
|
2018-09-10 23:45:31 +02:00
|
|
|
topic_list.get_stream_li = noop;
|
2018-09-10 14:52:58 +02:00
|
|
|
stream_list.zoom_out_topics = noop;
|
2018-04-24 14:09:16 +02:00
|
|
|
scroll_util.scroll_element_into_container = noop;
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2018-03-15 17:02:29 +01:00
|
|
|
set_global('ui', {
|
2019-03-01 01:40:05 +01:00
|
|
|
get_scroll_element: element => element,
|
2017-07-01 22:30:50 +02:00
|
|
|
});
|
|
|
|
|
2017-07-08 15:16:19 +02:00
|
|
|
assert(!$('<devel sidebar row html>').hasClass('active-filter'));
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2019-03-22 17:26:51 +01:00
|
|
|
stream_list.set_event_handlers();
|
2017-06-14 20:17:09 +02:00
|
|
|
|
|
|
|
var filter;
|
|
|
|
|
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'stream', operand: 'devel'},
|
|
|
|
]);
|
2017-08-12 16:49:10 +02:00
|
|
|
stream_list.handle_narrow_activated(filter);
|
2017-07-08 15:16:19 +02:00
|
|
|
assert($('<devel sidebar row html>').hasClass('active-filter'));
|
2017-06-14 20:17:09 +02:00
|
|
|
|
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'stream', operand: 'cars'},
|
|
|
|
{operator: 'topic', operand: 'sedans'},
|
|
|
|
]);
|
2017-08-12 16:49:10 +02:00
|
|
|
stream_list.handle_narrow_activated(filter);
|
2017-06-14 20:17:09 +02:00
|
|
|
assert(!$("ul.filters li").hasClass('active-filter'));
|
2017-07-08 15:16:19 +02:00
|
|
|
assert(!$('<cars sidebar row html>').hasClass('active-filter')); // false because of topic
|
2017-06-14 20:17:09 +02:00
|
|
|
|
|
|
|
filter = new Filter([
|
|
|
|
{operator: 'stream', operand: 'cars'},
|
|
|
|
]);
|
2017-08-12 16:49:10 +02:00
|
|
|
stream_list.handle_narrow_activated(filter);
|
2017-06-14 20:17:09 +02:00
|
|
|
assert(!$("ul.filters li").hasClass('active-filter'));
|
2017-07-08 15:16:19 +02:00
|
|
|
assert($('<cars sidebar row html>').hasClass('active-filter'));
|
2018-04-25 18:30:07 +02:00
|
|
|
|
|
|
|
var removed_classes;
|
|
|
|
$("ul#stream_filters li").removeClass = (classes) => {
|
|
|
|
removed_classes = classes;
|
|
|
|
};
|
|
|
|
|
|
|
|
var topics_closed;
|
|
|
|
topic_list.close = () => {
|
|
|
|
topics_closed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.handle_narrow_deactivated();
|
|
|
|
assert.equal(removed_classes, 'active-filter active-sub-filter');
|
|
|
|
assert(topics_closed);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-14 20:17:09 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('focusout_user_filter', () => {
|
2018-02-12 22:56:37 +01:00
|
|
|
var e = { };
|
|
|
|
var click_handler = $('.stream-list-filter').get_on_handler('focusout');
|
|
|
|
click_handler(e);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-12 22:56:37 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('focus_user_filter', () => {
|
2018-02-12 22:56:37 +01:00
|
|
|
var e = {
|
|
|
|
stopPropagation: function () {},
|
|
|
|
};
|
|
|
|
var click_handler = $('.stream-list-filter').get_on_handler('click');
|
|
|
|
click_handler(e);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-12 22:56:37 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('sort_streams', () => {
|
2017-06-14 14:33:04 +02:00
|
|
|
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-07-18 13:30:14 +02:00
|
|
|
var split = '<hr class="stream-split">';
|
2017-06-02 00:33:39 +02:00
|
|
|
var expected_elems = [
|
2017-07-18 13:30:14 +02:00
|
|
|
$('<devel sidebar row html>'),
|
|
|
|
$('<Rome sidebar row html>'),
|
|
|
|
$('<test sidebar row html>'),
|
|
|
|
split,
|
|
|
|
$('<announce sidebar row html>'),
|
|
|
|
$('<Denmark sidebar row html>'),
|
|
|
|
split,
|
|
|
|
$('<cars sidebar row html>'),
|
2017-06-02 00:33:39 +02:00
|
|
|
];
|
2017-07-18 13:30:14 +02:00
|
|
|
|
2017-06-02 00:33:39 +02:00
|
|
|
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));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-14 00:27:06 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('separators_only_pinned_and_dormant', () => {
|
2017-11-13 17:17:34 +01:00
|
|
|
|
|
|
|
// Test only pinned and dormant streams
|
|
|
|
|
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
|
|
|
|
// Get coverage on early-exit.
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
|
|
|
// pinned streams
|
|
|
|
var develSub = {
|
|
|
|
name: 'devel',
|
|
|
|
stream_id: 1000,
|
|
|
|
color: 'blue',
|
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(develSub);
|
|
|
|
|
|
|
|
var RomeSub = {
|
|
|
|
name: 'Rome',
|
|
|
|
stream_id: 2000,
|
|
|
|
color: 'blue',
|
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(RomeSub);
|
|
|
|
// dorment stream
|
|
|
|
var DenmarkSub = {
|
|
|
|
name: 'Denmark',
|
|
|
|
stream_id: 3000,
|
|
|
|
color: 'blue',
|
|
|
|
pin_to_top: false,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(DenmarkSub);
|
|
|
|
|
|
|
|
global.stream_data.is_active = function (sub) {
|
|
|
|
return sub.name !== 'Denmark';
|
|
|
|
};
|
|
|
|
|
|
|
|
var appended_elems;
|
|
|
|
$('#stream_filters').append = function (elems) {
|
|
|
|
appended_elems = elems;
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
|
|
|
var split = '<hr class="stream-split">';
|
|
|
|
var expected_elems = [
|
|
|
|
// pinned
|
|
|
|
$('<devel sidebar row html>'),
|
|
|
|
$('<Rome sidebar row html>'),
|
|
|
|
split,
|
|
|
|
// dormant
|
|
|
|
$('<Denmark sidebar row html>'),
|
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(appended_elems, expected_elems);
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-11-13 17:17:34 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('separators_only_pinned', () => {
|
2017-11-13 17:17:34 +01:00
|
|
|
|
|
|
|
// Test only pinned streams
|
|
|
|
|
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
|
|
|
|
// Get coverage on early-exit.
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
|
|
|
// pinned streams
|
|
|
|
var develSub = {
|
|
|
|
name: 'devel',
|
|
|
|
stream_id: 1000,
|
|
|
|
color: 'blue',
|
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(develSub);
|
|
|
|
|
|
|
|
var RomeSub = {
|
|
|
|
name: 'Rome',
|
|
|
|
stream_id: 2000,
|
|
|
|
color: 'blue',
|
|
|
|
pin_to_top: true,
|
|
|
|
subscribed: true,
|
|
|
|
};
|
|
|
|
add_row(RomeSub);
|
|
|
|
|
|
|
|
|
|
|
|
var appended_elems;
|
|
|
|
$('#stream_filters').append = function (elems) {
|
|
|
|
appended_elems = elems;
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.build_stream_list();
|
|
|
|
|
|
|
|
var expected_elems = [
|
|
|
|
// pinned
|
|
|
|
$('<devel sidebar row html>'),
|
|
|
|
$('<Rome sidebar row html>'),
|
|
|
|
// no separator at the end as no stream follows
|
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(appended_elems, expected_elems);
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2019-04-11 08:25:50 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('update_count_in_dom', () => {
|
2017-07-08 15:16:19 +02:00
|
|
|
function make_elem(elem, count_selector, value_selector) {
|
2017-06-14 18:21:50 +02:00
|
|
|
var count = $(count_selector);
|
|
|
|
var value = $(value_selector);
|
2017-07-08 14:31:18 +02:00
|
|
|
elem.set_find_results('.count', count);
|
|
|
|
count.set_find_results('.value', value);
|
2017-07-08 14:05:49 +02:00
|
|
|
count.set_parent(elem);
|
2017-06-14 18:21:50 +02:00
|
|
|
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
var stream_li = make_elem(
|
2017-07-08 15:16:19 +02:00
|
|
|
$('<stream li>'),
|
|
|
|
'<stream-count>',
|
|
|
|
'<stream-value>'
|
2017-06-14 18:21:50 +02:00
|
|
|
);
|
|
|
|
|
2019-04-18 21:11:30 +02:00
|
|
|
$('<stream li>').length = 0;
|
2017-06-14 18:21:50 +02:00
|
|
|
stream_li.addClass('subscription_block');
|
|
|
|
stream_li.addClass('stream-with-count');
|
|
|
|
assert(stream_li.hasClass('stream-with-count'));
|
|
|
|
|
|
|
|
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,
|
2017-07-31 14:04:20 +02:00
|
|
|
topic_count: new Dict(),
|
2017-06-14 18:21:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.update_dom_with_unread_counts(counts);
|
2017-07-08 15:16:19 +02:00
|
|
|
assert.equal($('<stream li>').text(), 'never-been-set');
|
2017-06-14 18:21:50 +02:00
|
|
|
assert(!stream_li.hasClass('stream-with-count'));
|
|
|
|
|
|
|
|
stream_count.set(stream_id, 99);
|
|
|
|
|
|
|
|
stream_list.update_dom_with_unread_counts(counts);
|
2017-07-08 15:16:19 +02:00
|
|
|
assert.equal($('<stream-value>').text(), '99');
|
2017-06-14 18:21:50 +02:00
|
|
|
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');
|
2017-07-31 14:04:20 +02:00
|
|
|
counts.topic_count.set(stream_id, topic_count);
|
2017-06-14 18:21:50 +02:00
|
|
|
|
|
|
|
stream_list.update_dom_with_unread_counts(counts);
|
|
|
|
|
|
|
|
assert.deepEqual(topic_results, {
|
|
|
|
stream_id: stream_id,
|
|
|
|
topic: 'lunch',
|
|
|
|
count: 555,
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-14 14:33:04 +02:00
|
|
|
|
2018-04-25 17:40:49 +02:00
|
|
|
narrow_state.active = () => false;
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('rename_stream', () => {
|
2018-12-14 19:18:24 +01:00
|
|
|
const sub = stream_data.get_sub_by_name('devel');
|
|
|
|
const new_name = 'Development';
|
|
|
|
|
|
|
|
stream_data.rename_sub(sub, new_name);
|
2018-04-25 17:40:49 +02:00
|
|
|
|
|
|
|
const li_stub = $.create('li stub');
|
2019-04-18 21:11:30 +02:00
|
|
|
li_stub.length = 0;
|
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates((name, payload) => {
|
2018-04-25 17:40:49 +02:00
|
|
|
assert.equal(name, 'stream_sidebar_row');
|
|
|
|
assert.deepEqual(payload, {
|
|
|
|
name: 'Development',
|
|
|
|
id: 1000,
|
2018-12-14 19:18:24 +01:00
|
|
|
uri: '#narrow/stream/1000-Development',
|
2019-05-15 08:54:25 +02:00
|
|
|
is_muted: false,
|
2018-04-25 17:40:49 +02:00
|
|
|
invite_only: undefined,
|
2019-04-07 20:29:25 +02:00
|
|
|
is_web_public: undefined,
|
2018-04-25 17:40:49 +02:00
|
|
|
color: payload.color,
|
|
|
|
pin_to_top: true,
|
|
|
|
dark_background: payload.dark_background,
|
|
|
|
});
|
|
|
|
return {to_$: () => li_stub};
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2018-04-25 17:40:49 +02:00
|
|
|
|
|
|
|
var count_updated;
|
|
|
|
stream_list.update_count_in_dom = (li) => {
|
|
|
|
assert.equal(li, li_stub);
|
|
|
|
count_updated = true;
|
|
|
|
};
|
|
|
|
|
2018-12-14 19:18:24 +01:00
|
|
|
stream_list.rename_stream(sub);
|
2018-04-25 17:40:49 +02:00
|
|
|
assert(count_updated);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 17:40:49 +02:00
|
|
|
|
2018-04-25 18:12:16 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('refresh_pin', () => {
|
2018-04-25 18:12:16 +02:00
|
|
|
initialize_stream_data();
|
|
|
|
|
|
|
|
const sub = {
|
|
|
|
name: 'maybe_pin',
|
|
|
|
stream_id: 100,
|
|
|
|
color: 'blue',
|
|
|
|
pin_to_top: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_data.add_sub(sub.name, sub);
|
|
|
|
|
|
|
|
const pinned_sub = _.extend(sub, {
|
|
|
|
pin_to_top: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const li_stub = $.create('li stub');
|
2019-04-18 21:11:30 +02:00
|
|
|
li_stub.length = 0;
|
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(() => {
|
2018-04-25 18:12:16 +02:00
|
|
|
return {to_$: () => li_stub};
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2018-04-25 18:12:16 +02:00
|
|
|
|
|
|
|
stream_list.update_count_in_dom = noop;
|
|
|
|
$('#stream_filters').append = noop;
|
|
|
|
|
|
|
|
var scrolled;
|
|
|
|
stream_list.scroll_stream_into_view = (li) => {
|
|
|
|
assert.equal(li, li_stub);
|
|
|
|
scrolled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.refresh_pinned_or_unpinned_stream(pinned_sub);
|
|
|
|
assert(scrolled);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 18:12:16 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('create_initial_sidebar_rows', () => {
|
2017-06-14 14:33:04 +02:00
|
|
|
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;
|
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(function (template_name, data) {
|
2017-06-14 14:33:04 +02:00
|
|
|
assert.equal(template_name, 'stream_sidebar_row');
|
|
|
|
return '<div>stub-html-' + data.name;
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2017-06-14 14:33:04 +02:00
|
|
|
|
|
|
|
// 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');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|