2020-02-04 21:50:55 +01:00
|
|
|
set_global('i18n', global.stub_i18n);
|
2016-12-26 10:13:31 +01:00
|
|
|
global.stub_out_jquery();
|
|
|
|
|
2019-03-01 01:40:05 +01:00
|
|
|
set_global('ui', {
|
|
|
|
get_content_element: element => element,
|
|
|
|
get_scroll_element: element => element,
|
|
|
|
});
|
2018-07-30 20:05:56 +02:00
|
|
|
zrequire('util');
|
2018-07-29 15:26:45 +02:00
|
|
|
zrequire('stream_data');
|
2018-07-29 16:11:48 +02:00
|
|
|
zrequire('search_util');
|
2019-05-08 08:57:23 +02:00
|
|
|
set_global('page_params', {});
|
2020-01-15 15:05:44 +01:00
|
|
|
set_global('blueslip', global.make_zblueslip());
|
2018-07-29 16:11:48 +02:00
|
|
|
|
2019-07-25 09:13:22 +02:00
|
|
|
set_global('location', {
|
|
|
|
hash: "#streams/1/announce",
|
2017-08-02 16:51:37 +02:00
|
|
|
});
|
|
|
|
|
2017-11-08 19:06:27 +01:00
|
|
|
zrequire('subs');
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-07-30 20:05:56 +02:00
|
|
|
stream_data.update_calculated_fields = () => {};
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('filter_table', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_list = $(".streams-list");
|
2018-05-15 19:36:25 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let scrolltop_called = false;
|
2018-05-15 19:36:25 +02:00
|
|
|
stream_list.scrollTop = function (set) {
|
|
|
|
scrolltop_called = true;
|
|
|
|
if (!set) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
assert.equal(set, 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
// set-up sub rows stubs
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub_row_data = {};
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_row_data[1] = {
|
|
|
|
elem: 'denmark',
|
2016-12-26 10:13:31 +01:00
|
|
|
subscribed: false,
|
|
|
|
name: 'Denmark',
|
|
|
|
stream_id: 1,
|
2017-01-03 13:26:48 +01:00
|
|
|
description: 'Copenhagen',
|
2016-12-26 10:13:31 +01:00
|
|
|
};
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_row_data[2] = {
|
|
|
|
elem: 'poland',
|
2016-12-26 10:13:31 +01:00
|
|
|
subscribed: true,
|
|
|
|
name: 'Poland',
|
2017-01-12 00:17:43 +01:00
|
|
|
stream_id: 2,
|
2017-01-03 13:26:48 +01:00
|
|
|
description: 'monday',
|
2016-12-26 10:13:31 +01:00
|
|
|
};
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_row_data[3] = {
|
|
|
|
elem: 'pomona',
|
2016-12-26 10:13:31 +01:00
|
|
|
subscribed: true,
|
|
|
|
name: 'Pomona',
|
2017-01-12 00:17:43 +01:00
|
|
|
stream_id: 3,
|
2017-01-03 13:26:48 +01:00
|
|
|
description: 'college',
|
2016-12-26 10:13:31 +01:00
|
|
|
};
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_row_data[4] = {
|
|
|
|
elem: 'cpp',
|
2017-02-04 13:02:31 +01:00
|
|
|
subscribed: true,
|
|
|
|
name: 'C++',
|
|
|
|
stream_id: 4,
|
2018-05-15 19:36:25 +02:00
|
|
|
description: 'programming lang',
|
2017-02-04 13:02:31 +01:00
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-07-29 15:26:45 +02:00
|
|
|
_.each(sub_row_data, function (sub) {
|
|
|
|
stream_data.add_sub(sub.name, sub);
|
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let populated_subs;
|
2018-07-30 20:05:56 +02:00
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates((fn, data) => {
|
2018-07-30 20:05:56 +02:00
|
|
|
assert.equal(fn, 'subscriptions');
|
|
|
|
populated_subs = data.subscriptions;
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2018-07-30 20:05:56 +02:00
|
|
|
|
|
|
|
subs.populate_stream_settings_left_panel();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub_stubs = [];
|
2018-07-30 20:05:56 +02:00
|
|
|
_.each(populated_subs, function (data) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub_row = ".stream-row-" + data.elem;
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_stubs.push(sub_row);
|
|
|
|
|
|
|
|
$(sub_row).attr("data-stream-id", data.stream_id);
|
|
|
|
$(sub_row).set_find_results('.sub-info-box [class$="-bar"] [class$="-count"]', $(".tooltip"));
|
|
|
|
$(sub_row).detach = function () {
|
|
|
|
return sub_row;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let tooltip_called = false;
|
2018-05-15 19:36:25 +02:00
|
|
|
$(".tooltip").tooltip = function (obj) {
|
|
|
|
tooltip_called = true;
|
|
|
|
assert.deepEqual(obj, {
|
|
|
|
placement: 'left',
|
|
|
|
animation: false,
|
|
|
|
});
|
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
$.stub_selector("#subscriptions_table .stream-row", sub_stubs);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub_table = $('#subscriptions_table .streams-list');
|
|
|
|
let sub_table_append = [];
|
2018-05-15 19:36:25 +02:00
|
|
|
sub_table.append = function (rows) {
|
2018-07-29 14:55:29 +02:00
|
|
|
sub_table_append.push(rows);
|
2018-05-15 19:36:25 +02:00
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let ui_called = false;
|
2019-01-09 14:30:35 +01:00
|
|
|
ui.reset_scrollbar = function (elem) {
|
2018-05-15 19:36:25 +02:00
|
|
|
ui_called = true;
|
|
|
|
assert.equal(elem, $("#subscription_overlay .streams-list"));
|
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
// Search with single keyword
|
|
|
|
subs.filter_table({input: "Po", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
// assert these once and call it done
|
|
|
|
assert(ui_called);
|
|
|
|
assert(scrolltop_called);
|
|
|
|
assert(tooltip_called);
|
|
|
|
assert.deepEqual(sub_table_append, [
|
|
|
|
'.stream-row-poland',
|
|
|
|
'.stream-row-pomona',
|
|
|
|
'.stream-row-cpp',
|
2019-12-27 15:56:46 +01:00
|
|
|
'.stream-row-denmark',
|
2018-05-15 19:36:25 +02:00
|
|
|
]);
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
// Search with multiple keywords
|
|
|
|
subs.filter_table({input: "Denmark, Pol", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert(!$(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
subs.filter_table({input: "Den, Pol", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert(!$(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
// Search is case-insensitive
|
|
|
|
subs.filter_table({input: "po", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2017-02-04 13:02:31 +01:00
|
|
|
// Search handles unusual characters like C++
|
|
|
|
subs.filter_table({input: "c++", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-cpp").hasClass("notdisplayed"));
|
2017-02-04 13:02:31 +01:00
|
|
|
|
2016-12-26 10:13:31 +01:00
|
|
|
// Search subscribed streams only
|
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2017-01-03 13:26:48 +01:00
|
|
|
|
|
|
|
// Search terms match stream description
|
|
|
|
subs.filter_table({input: "Co", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert(!$(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
// Search names AND descriptions
|
|
|
|
sub_table_append = [];
|
2017-01-03 13:26:48 +01:00
|
|
|
|
|
|
|
subs.filter_table({input: "Mon", subscribed_only: false});
|
2018-05-15 19:36:25 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
|
|
|
assert.deepEqual(sub_table_append, [
|
|
|
|
'.stream-row-pomona',
|
|
|
|
'.stream-row-poland',
|
|
|
|
'.stream-row-cpp',
|
2019-12-27 15:56:46 +01:00
|
|
|
'.stream-row-denmark',
|
2018-05-15 19:36:25 +02:00
|
|
|
]);
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
// active stream-row is not included in results
|
|
|
|
$(".stream-row-denmark").addClass("active");
|
|
|
|
$(".stream-row.active").hasClass = function (cls) {
|
|
|
|
assert.equal(cls, "notdisplayed");
|
|
|
|
return $(".stream-row-denmark").hasClass("active");
|
2017-03-04 17:55:16 +01:00
|
|
|
};
|
2018-05-15 19:36:25 +02:00
|
|
|
$(".stream-row.active").removeClass = function (cls) {
|
|
|
|
assert.equal(cls, "active");
|
|
|
|
$(".stream-row-denmark").removeClass("active");
|
2017-03-04 17:55:16 +01:00
|
|
|
};
|
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
|
|
|
assert(!$(".stream-row-denmark").hasClass("active"));
|
|
|
|
assert(!$(".right .settings").visible());
|
|
|
|
assert($(".nothing-selected").visible());
|
2017-03-04 17:55:16 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
2018-07-30 20:51:08 +02:00
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
2018-05-15 19:36:25 +02:00
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
2017-03-04 17:55:16 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
|
|
|
assert($(".stream-row-denmark").hasClass("notdisplayed"));
|
|
|
|
assert(!$(".stream-row-poland").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-pomona").hasClass("notdisplayed"));
|
|
|
|
assert($(".stream-row-cpp").hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
// test selected row set to active
|
|
|
|
$(".stream-row[data-stream-id='1']").removeClass("active");
|
|
|
|
subs.filter_table({input: "", subscribed_only: false});
|
|
|
|
assert($(".stream-row[data-stream-id='1']").hasClass("active"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|