2016-12-26 10:13:31 +01:00
|
|
|
global.stub_out_jquery();
|
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
set_global('ui', {});
|
|
|
|
set_global('stream_data', {});
|
2018-05-31 23:55:28 +02:00
|
|
|
global.patch_builtin('window', {
|
2018-05-15 19:36:25 +02:00
|
|
|
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-05-15 12:40:07 +02:00
|
|
|
run_test('filter_table', () => {
|
2018-05-15 19:36:25 +02:00
|
|
|
var stream_list = $(".streams-list");
|
|
|
|
|
|
|
|
var scrolltop_called = false;
|
|
|
|
stream_list.scrollTop = function (set) {
|
|
|
|
scrolltop_called = true;
|
|
|
|
if (!set) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
assert.equal(set, 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
// set-up sub rows stubs
|
|
|
|
var sub_row_data = {};
|
|
|
|
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-05-15 19:36:25 +02:00
|
|
|
var sub_stubs = [];
|
|
|
|
_.each(sub_row_data, function (data) {
|
|
|
|
var sub_row = ".stream-row-" + data.elem;
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
var tooltip_called = false;
|
|
|
|
$(".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
|
|
|
stream_data.get_sub_by_id = function (id) {
|
|
|
|
return sub_row_data[id];
|
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
$.stub_selector("#subscriptions_table .stream-row", sub_stubs);
|
|
|
|
|
|
|
|
var sub_table = $('#subscriptions_table .streams-list');
|
|
|
|
var sub_table_append = [];
|
|
|
|
sub_table.append = function (rows) {
|
|
|
|
if (typeof rows === "string") {
|
|
|
|
sub_table_append.push(rows);
|
|
|
|
} else {
|
|
|
|
_.each(rows, function (row) {
|
|
|
|
sub_table_append.push(row);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
var ui_called = false;
|
|
|
|
ui.update_scrollbar = function (elem) {
|
|
|
|
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-denmark',
|
|
|
|
'.stream-row-cpp',
|
|
|
|
]);
|
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-denmark',
|
|
|
|
'.stream-row-cpp',
|
|
|
|
]);
|
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
|
|
|
// data-temp-view condition
|
|
|
|
$(".stream-row-denmark").attr("data-temp-view", "true");
|
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"));
|
2017-03-04 17:55:16 +01:00
|
|
|
|
2018-05-15 19:36:25 +02:00
|
|
|
$(".stream-row-denmark").attr("data-temp-view", "false");
|
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
|
|
|
});
|