2018-04-25 15:18:37 +02:00
|
|
|
// This tests the stream searching functionality which currently
|
|
|
|
// lives in stream_list.js.
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("$", global.make_zjquery());
|
|
|
|
zrequire("stream_list");
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
const noop = () => {};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("resize", {
|
2018-04-25 15:18:37 +02:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("popovers", {});
|
|
|
|
set_global("stream_popover", {});
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
function expand_sidebar() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".app-main .column-left").addClass("expanded");
|
2018-04-25 15:18:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function make_cursor_helper() {
|
|
|
|
const events = [];
|
|
|
|
|
|
|
|
stream_list.stream_cursor = {
|
|
|
|
reset: () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
events.push("reset");
|
2018-04-25 15:18:37 +02:00
|
|
|
},
|
|
|
|
clear: () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
events.push("clear");
|
2018-04-25 15:18:37 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
2020-07-20 22:18:43 +02:00
|
|
|
events,
|
2018-04-25 15:18:37 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function simulate_search_expanded() {
|
|
|
|
// The way we check if the search widget is expanded
|
|
|
|
// is kind of awkward.
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".stream_search_section.notdisplayed").length = 0;
|
2018-04-25 15:18:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function simulate_search_collapsed() {
|
2020-07-15 01:29:15 +02: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});
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("basics", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let cursor_helper;
|
2020-07-15 01:29:15 +02:00
|
|
|
const input = $(".stream-list-filter");
|
|
|
|
const section = $(".stream_search_section");
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
expand_sidebar();
|
2020-07-15 01:29:15 +02:00
|
|
|
section.addClass("notdisplayed");
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
cursor_helper = make_cursor_helper();
|
|
|
|
|
|
|
|
function verify_expanded() {
|
2020-07-15 01:29:15 +02: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() {
|
2020-07-15 01:29:15 +02: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();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.deepEqual(cursor_helper.events, ["reset"]);
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
// Collapse the widget.
|
|
|
|
cursor_helper = make_cursor_helper();
|
|
|
|
|
|
|
|
toggle_filter();
|
|
|
|
verify_collapsed();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.deepEqual(cursor_helper.events, ["clear"]);
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
// Expand the widget.
|
|
|
|
toggle_filter();
|
|
|
|
verify_expanded();
|
|
|
|
verify_focused();
|
|
|
|
|
|
|
|
(function add_some_text_and_collapse() {
|
|
|
|
cursor_helper = make_cursor_helper();
|
2020-07-15 01:29:15 +02:00
|
|
|
input.val("foo");
|
2018-04-25 15:18:37 +02:00
|
|
|
verify_list_updated(() => {
|
|
|
|
toggle_filter();
|
|
|
|
});
|
|
|
|
|
|
|
|
verify_collapsed();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.deepEqual(cursor_helper.events, ["reset", "clear"]);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
// 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.
|
2020-07-15 01:29:15 +02:00
|
|
|
input.val("foo");
|
2018-04-25 15:18:37 +02:00
|
|
|
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.
|
2020-07-15 01:29:15 +02:00
|
|
|
input.val("foo");
|
2018-04-25 15:18:37 +02:00
|
|
|
stream_list.escape_search();
|
|
|
|
verify_blurred();
|
|
|
|
|
|
|
|
// Expand the widget.
|
|
|
|
toggle_filter();
|
|
|
|
stream_list.initiate_search();
|
|
|
|
|
|
|
|
// Escape an empty search.
|
2020-07-15 01:29:15 +02:00
|
|
|
input.val("");
|
2018-04-25 15:18:37 +02:00
|
|
|
stream_list.escape_search();
|
|
|
|
verify_collapsed();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 15:18:37 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("expanding_sidebar", () => {
|
|
|
|
$(".app-main .column-left").removeClass("expanded");
|
2018-04-25 15:18:37 +02:00
|
|
|
|
|
|
|
const events = [];
|
|
|
|
popovers.hide_all = () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
events.push("popovers.hide_all");
|
2018-04-25 15:18:37 +02:00
|
|
|
};
|
2020-07-16 23:29:01 +02:00
|
|
|
stream_popover.show_streamlist_sidebar = () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
events.push("stream_popover.show_streamlist_sidebar");
|
2018-04-25 15:18:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.initiate_search();
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(events, ["popovers.hide_all", "stream_popover.show_streamlist_sidebar"]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|