zulip/frontend_tests/node_tests/subs.js

209 lines
7.1 KiB
JavaScript
Raw Normal View History

2016-12-26 10:13:31 +01:00
global.stub_out_jquery();
set_global('ui', {});
zrequire('stream_data');
global.patch_builtin('window', {
location: {
hash: "#streams/1/announce",
},
});
2017-11-08 19:06:27 +01:00
zrequire('subs');
2016-12-26 10:13:31 +01:00
set_global('$', global.make_zjquery());
2016-12-26 10:13:31 +01:00
run_test('filter_table', () => {
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,
description: 'Copenhagen',
2016-12-26 10:13:31 +01:00
};
sub_row_data[2] = {
elem: 'poland',
2016-12-26 10:13:31 +01:00
subscribed: true,
name: 'Poland',
stream_id: 2,
description: 'monday',
2016-12-26 10:13:31 +01:00
};
sub_row_data[3] = {
elem: 'pomona',
2016-12-26 10:13:31 +01:00
subscribed: true,
name: 'Pomona',
stream_id: 3,
description: 'college',
2016-12-26 10:13:31 +01:00
};
sub_row_data[4] = {
elem: 'cpp',
subscribed: true,
name: 'C++',
stream_id: 4,
description: 'programming lang',
};
2016-12-26 10:13:31 +01:00
_.each(sub_row_data, function (sub) {
stream_data.add_sub(sub.name, sub);
});
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
$.stub_selector("#subscriptions_table .stream-row", sub_stubs);
var sub_table = $('#subscriptions_table .streams-list');
var sub_table_append = [];
sub_table.append = function (rows) {
sub_table_append.push(rows);
};
2016-12-26 10:13:31 +01: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});
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});
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});
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});
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 handles unusual characters like C++
subs.filter_table({input: "c++", subscribed_only: false});
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 subscribed streams only
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"));
// Search terms match stream description
subs.filter_table({input: "Co", subscribed_only: false});
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 = [];
subs.filter_table({input: "Mon", subscribed_only: false});
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
// 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
};
$(".stream-row.active").removeClass = function (cls) {
assert.equal(cls, "active");
$(".stream-row-denmark").removeClass("active");
2017-03-04 17:55:16 +01: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
// data-temp-view condition
$(".stream-row-denmark").attr("data-temp-view", "true");
2017-03-04 17:55:16 +01: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
$(".stream-row-denmark").attr("data-temp-view", "false");
2017-03-04 17:55:16 +01: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"));
});