2016-12-26 10:13:31 +01:00
|
|
|
global.stub_out_jquery();
|
|
|
|
|
2017-08-02 16:51:37 +02:00
|
|
|
set_global('ui', {
|
|
|
|
update_scrollbar: function () {},
|
|
|
|
});
|
|
|
|
|
2017-11-08 19:06:27 +01:00
|
|
|
set_global('i18n', global.stub_i18n);
|
2017-03-04 17:55:16 +01:00
|
|
|
set_global('channel', {});
|
|
|
|
|
2017-11-08 19:06:27 +01:00
|
|
|
zrequire('stream_data');
|
|
|
|
zrequire('Handlebars', 'handlebars');
|
|
|
|
zrequire('templates');
|
|
|
|
zrequire('subs');
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
var jsdom = require("jsdom");
|
|
|
|
var window = jsdom.jsdom().defaultView;
|
|
|
|
global.$ = require('jquery')(window);
|
2018-03-15 05:24:00 +01:00
|
|
|
set_global('window', window);
|
|
|
|
zrequire('bootstrap', 'third/bootstrap/js/bootstrap');
|
2016-12-26 10:13:31 +01:00
|
|
|
|
2017-01-03 13:26:48 +01:00
|
|
|
subs.stream_name_match_stream_ids = [];
|
|
|
|
subs.stream_description_match_stream_ids = [];
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
(function test_filter_table() {
|
|
|
|
var denmark = {
|
|
|
|
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
|
|
|
};
|
|
|
|
var poland = {
|
|
|
|
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
|
|
|
};
|
|
|
|
var pomona = {
|
|
|
|
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
|
|
|
};
|
2017-02-04 13:02:31 +01:00
|
|
|
var cpp = {
|
|
|
|
subscribed: true,
|
|
|
|
name: 'C++',
|
|
|
|
stream_id: 4,
|
|
|
|
};
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
var elem_1 = $(global.render_template("subscription", denmark));
|
|
|
|
var elem_2 = $(global.render_template("subscription", poland));
|
|
|
|
var elem_3 = $(global.render_template("subscription", pomona));
|
2017-02-04 13:02:31 +01:00
|
|
|
var elem_4 = $(global.render_template("subscription", cpp));
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
$("body").empty();
|
|
|
|
$("body").append('<div id="subscriptions_table"></div>');
|
|
|
|
var streams_list = $('<div class="streams-list"></div>');
|
|
|
|
$("#subscriptions_table").append(streams_list);
|
|
|
|
|
|
|
|
stream_data.add_sub("Denmark", denmark);
|
|
|
|
stream_data.add_sub("Poland", poland);
|
|
|
|
stream_data.add_sub("Pomona", pomona);
|
2017-02-04 13:02:31 +01:00
|
|
|
stream_data.add_sub("C++", cpp);
|
2016-12-26 10:13:31 +01:00
|
|
|
|
|
|
|
streams_list.append(elem_1);
|
|
|
|
streams_list.append(elem_2);
|
|
|
|
streams_list.append(elem_3);
|
|
|
|
|
|
|
|
// Search with single keyword
|
|
|
|
subs.filter_table({input: "Po", subscribed_only: false});
|
|
|
|
assert(elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_3.hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
// Search with multiple keywords
|
|
|
|
subs.filter_table({input: "Denmark, Pol", subscribed_only: false});
|
|
|
|
assert(!elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(elem_3.hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
subs.filter_table({input: "Den, Pol", subscribed_only: false});
|
2016-12-28 03:13:21 +01:00
|
|
|
assert(!elem_1.hasClass("notdisplayed"));
|
2016-12-26 10:13:31 +01:00
|
|
|
assert(!elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(elem_3.hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
// Search is case-insensitive
|
|
|
|
subs.filter_table({input: "po", subscribed_only: false});
|
|
|
|
assert(elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_3.hasClass("notdisplayed"));
|
|
|
|
|
2017-02-04 13:02:31 +01:00
|
|
|
// Search handles unusual characters like C++
|
|
|
|
subs.filter_table({input: "c++", subscribed_only: false});
|
|
|
|
assert(elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(elem_3.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_4.hasClass("notdisplayed"));
|
|
|
|
|
2016-12-26 10:13:31 +01:00
|
|
|
// Search subscribed streams only
|
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
|
|
|
assert(elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(elem_3.hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
// data-temp-view condition
|
|
|
|
elem_1.attr("data-temp-view", "true");
|
|
|
|
|
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
|
|
|
assert(!elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(elem_3.hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
elem_1.attr("data-temp-view", "false");
|
|
|
|
|
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
|
|
|
assert(elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(elem_3.hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
elem_1.removeAttr("data-temp-view");
|
|
|
|
|
|
|
|
// active stream-row is not included in results
|
|
|
|
elem_1.addClass("active");
|
|
|
|
$("#subscriptions_table").append($('<div class="right"></div>'));
|
|
|
|
$(".right").append($('<div class="settings"></div>'));
|
|
|
|
$(".right").append($('<div class="nothing-selected"></div>').hide());
|
|
|
|
|
|
|
|
subs.filter_table({input: "d", subscribed_only: true});
|
|
|
|
assert(!elem_1.hasClass("active"));
|
|
|
|
assert.equal($(".right .settings").css("display"), "none");
|
|
|
|
assert.notEqual($(".right .nothing-selected").css("display"), "none");
|
2017-01-03 13:26:48 +01:00
|
|
|
|
|
|
|
// Search terms match stream description
|
|
|
|
subs.filter_table({input: "Co", subscribed_only: false});
|
|
|
|
assert(!elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_3.hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
subs.filter_table({input: "Mon", subscribed_only: false});
|
|
|
|
assert(elem_1.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_2.hasClass("notdisplayed"));
|
|
|
|
assert(!elem_3.hasClass("notdisplayed"));
|
|
|
|
|
|
|
|
subs.filter_table({input: "p", subscribed_only: false});
|
|
|
|
assert.equal(subs.stream_name_match_stream_ids.length, 2);
|
|
|
|
assert.equal(subs.stream_description_match_stream_ids, 1);
|
|
|
|
assert.equal(subs.stream_name_match_stream_ids[0], 2);
|
|
|
|
assert.equal(subs.stream_name_match_stream_ids[1], 3);
|
|
|
|
assert.equal(subs.stream_description_match_stream_ids[0], 1);
|
|
|
|
|
|
|
|
subs.filter_table({input: "d", subscribed_only: false});
|
|
|
|
assert.equal(subs.stream_name_match_stream_ids.length, 2);
|
|
|
|
assert.equal(subs.stream_description_match_stream_ids, 0);
|
|
|
|
assert.equal(subs.stream_name_match_stream_ids[0], 1);
|
|
|
|
assert.equal(subs.stream_name_match_stream_ids[1], 2);
|
2016-12-26 10:13:31 +01:00
|
|
|
}());
|
|
|
|
|
2017-03-04 17:55:16 +01:00
|
|
|
(function test_sub_or_unsub() {
|
|
|
|
var denmark = {
|
|
|
|
subscribed: false,
|
|
|
|
name: 'Denmark',
|
|
|
|
stream_id: 1,
|
|
|
|
description: 'Copenhagen',
|
|
|
|
};
|
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
stream_data.add_sub("Denmark", denmark);
|
|
|
|
|
|
|
|
var post_params;
|
|
|
|
|
|
|
|
global.channel.post = function (params) {
|
|
|
|
post_params = params;
|
|
|
|
};
|
|
|
|
|
2017-03-04 18:10:23 +01:00
|
|
|
subs.sub_or_unsub(denmark);
|
2017-03-04 17:55:16 +01:00
|
|
|
assert.equal(post_params.url, '/json/users/me/subscriptions');
|
|
|
|
assert.deepEqual(post_params.data,
|
2018-05-07 03:30:13 +02:00
|
|
|
{subscriptions: '[{"name":"Denmark"}]'});
|
2017-03-04 17:55:16 +01:00
|
|
|
|
|
|
|
global.channel.post = undefined;
|
|
|
|
|
|
|
|
global.channel.del = function (params) {
|
|
|
|
post_params = params;
|
|
|
|
};
|
|
|
|
|
|
|
|
stream_data.get_sub_by_id(denmark.stream_id).subscribed = true;
|
2017-03-04 18:10:23 +01:00
|
|
|
subs.sub_or_unsub(denmark);
|
2017-03-04 17:55:16 +01:00
|
|
|
assert.equal(post_params.url, '/json/users/me/subscriptions');
|
|
|
|
assert.deepEqual(post_params.data,
|
2018-05-07 03:30:13 +02:00
|
|
|
{subscriptions: '["Denmark"]'});
|
2017-03-04 17:55:16 +01:00
|
|
|
|
|
|
|
}());
|
|
|
|
|