2018-04-25 15:18:37 +02:00
|
|
|
// This tests the stream searching functionality which currently
|
|
|
|
// lives in stream_list.js.
|
|
|
|
|
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
zrequire('stream_list');
|
|
|
|
|
|
|
|
const noop = () => {};
|
|
|
|
|
|
|
|
set_global('resize', {
|
|
|
|
resize_page_components: noop,
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
resize_stream_filters_container: noop,
|
2018-04-25 15:18:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
set_global('popovers', {});
|
|
|
|
set_global('stream_popover', {});
|
|
|
|
|
|
|
|
function expand_sidebar() {
|
|
|
|
$('.app-main .column-left').addClass('expanded');
|
|
|
|
}
|
|
|
|
|
|
|
|
function make_cursor_helper() {
|
|
|
|
const events = [];
|
|
|
|
|
|
|
|
stream_list.stream_cursor = {
|
|
|
|
reset: () => {
|
|
|
|
events.push('reset');
|
|
|
|
},
|
|
|
|
clear: () => {
|
|
|
|
events.push('clear');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
events: events,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function simulate_search_expanded() {
|
|
|
|
// The way we check if the search widget is expanded
|
|
|
|
// is kind of awkward.
|
|
|
|
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
$('.stream_search_section.notdisplayed').length = 0;
|
2018-04-25 15:18:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function simulate_search_collapsed() {
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
$('.stream_search_section.notdisplayed').length = 1;
|
2018-04-25 15:18:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_filter() {
|
|
|
|
stream_list.toggle_filter_displayed({preventDefault: noop});
|
|
|
|
}
|
|
|
|
|
2019-02-23 15:10:12 +01:00
|
|
|
function clear_search_input() {
|
|
|
|
stream_list.clear_search({stopPropagation: noop});
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('basics', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let cursor_helper;
|
2018-04-25 15:18:37 +02:00
|
|
|
const input = $('.stream-list-filter');
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
const section = $('.stream_search_section');
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
expand_sidebar();
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
section.addClass('notdisplayed');
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
cursor_helper = make_cursor_helper();
|
|
|
|
|
|
|
|
function verify_expanded() {
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
assert(!section.hasClass('notdisplayed'));
|
2018-04-25 15:18:37 +02:00
|
|
|
simulate_search_expanded();
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_focused() {
|
|
|
|
assert(stream_list.searching());
|
|
|
|
assert(input.is_focused());
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_blurred() {
|
|
|
|
assert(stream_list.searching());
|
|
|
|
assert(input.is_focused());
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_collapsed() {
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
assert(section.hasClass('notdisplayed'));
|
2018-04-25 15:18:37 +02:00
|
|
|
assert(!input.is_focused());
|
|
|
|
assert(!stream_list.searching());
|
|
|
|
simulate_search_collapsed();
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_list_updated(f) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let updated;
|
2018-04-25 15:18:37 +02:00
|
|
|
stream_list.update_streams_sidebar = () => {
|
|
|
|
updated = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
f();
|
|
|
|
assert(updated);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initiate search (so expand widget).
|
|
|
|
stream_list.initiate_search();
|
|
|
|
verify_expanded();
|
|
|
|
verify_focused();
|
|
|
|
|
|
|
|
assert.deepEqual(cursor_helper.events, ['reset']);
|
|
|
|
|
|
|
|
// Collapse the widget.
|
|
|
|
cursor_helper = make_cursor_helper();
|
|
|
|
|
|
|
|
toggle_filter();
|
|
|
|
verify_collapsed();
|
|
|
|
|
|
|
|
assert.deepEqual(cursor_helper.events, ['clear']);
|
|
|
|
|
|
|
|
// Expand the widget.
|
|
|
|
toggle_filter();
|
|
|
|
verify_expanded();
|
|
|
|
verify_focused();
|
|
|
|
|
|
|
|
(function add_some_text_and_collapse() {
|
|
|
|
cursor_helper = make_cursor_helper();
|
|
|
|
input.val('foo');
|
|
|
|
verify_list_updated(() => {
|
|
|
|
toggle_filter();
|
|
|
|
});
|
|
|
|
|
|
|
|
verify_collapsed();
|
|
|
|
assert.deepEqual(cursor_helper.events, ['reset', 'clear']);
|
|
|
|
}());
|
|
|
|
|
|
|
|
// Expand the widget.
|
|
|
|
toggle_filter();
|
|
|
|
verify_expanded();
|
|
|
|
verify_focused();
|
|
|
|
|
|
|
|
// Clear an empty search.
|
2019-02-23 15:10:12 +01:00
|
|
|
clear_search_input();
|
2018-04-25 15:18:37 +02:00
|
|
|
verify_collapsed();
|
|
|
|
|
|
|
|
// Expand the widget.
|
|
|
|
toggle_filter();
|
|
|
|
stream_list.initiate_search();
|
|
|
|
|
|
|
|
// Clear a non-empty search.
|
|
|
|
input.val('foo');
|
|
|
|
verify_list_updated(() => {
|
2019-02-23 15:10:12 +01:00
|
|
|
clear_search_input();
|
2018-04-25 15:18:37 +02:00
|
|
|
});
|
|
|
|
verify_expanded();
|
|
|
|
|
|
|
|
// Expand the widget.
|
|
|
|
toggle_filter();
|
|
|
|
stream_list.initiate_search();
|
|
|
|
|
|
|
|
// Escape a non-empty search.
|
|
|
|
input.val('foo');
|
|
|
|
stream_list.escape_search();
|
|
|
|
verify_blurred();
|
|
|
|
|
|
|
|
// Expand the widget.
|
|
|
|
toggle_filter();
|
|
|
|
stream_list.initiate_search();
|
|
|
|
|
|
|
|
// Escape an empty search.
|
|
|
|
input.val('');
|
|
|
|
stream_list.escape_search();
|
|
|
|
verify_collapsed();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 15:18:37 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('expanding_sidebar', () => {
|
2018-04-25 15:18:37 +02:00
|
|
|
$('.app-main .column-left').removeClass('expanded');
|
|
|
|
|
|
|
|
const events = [];
|
|
|
|
popovers.hide_all = () => {
|
|
|
|
events.push('popovers.hide_all');
|
|
|
|
};
|
|
|
|
stream_popover.show_streamlist_sidebar = () => {
|
|
|
|
events.push('stream_popover.show_streamlist_sidebar');
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.initiate_search();
|
|
|
|
|
|
|
|
assert.deepEqual(events, [
|
|
|
|
'popovers.hide_all',
|
|
|
|
'stream_popover.show_streamlist_sidebar',
|
|
|
|
]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|