Add test_add_stream_to_sidebar().

This is a node test that verifies that
stream_list.add_stream_to_sidebar() creates the right
DOM when it renders the stream_sidebar_row template.
The test also makes sure that the DOM gets put in the
correct place to be retrieved by stream_list.get_stream_li()
calls.

(imported from commit ed4c0148da2261870e3db5a9b553913788b4eccd)
This commit is contained in:
Steve Howell 2014-01-16 15:38:40 -05:00
parent c9158dd3d9
commit 56dc4e0b8e
2 changed files with 57 additions and 1 deletions

View File

@ -149,6 +149,16 @@ function add_narrow_filter(name, type) {
return build_narrow_filter(name, type);
}
// This is a testing shim for now, but the goal is to replace
// add_narrow_filter() with this API.
exports.add_stream_to_sidebar = function (stream_name) {
return add_narrow_filter(stream_name, 'stream');
};
exports.get_stream_li = function (stream_name) {
return get_filter_li('stream', stream_name);
};
exports.get_count = function (type, name) {
return get_filter_li(type, name).find('.count .value').text();
};

View File

@ -1,5 +1,7 @@
var assert = require('assert');
set_global('$', function () {});
add_dependencies({
_: 'third/underscore/underscore',
Dict: 'js/dict',
@ -7,18 +9,25 @@ add_dependencies({
templates: 'js/templates',
muting: 'js/muting',
narrow: 'js/narrow',
stream_color: 'js/stream_color',
stream_data: 'js/stream_data',
subs: 'js/subs',
hashchange: 'js/hashchange'
});
set_global('recent_subjects', new global.Dict());
set_global('unread', {});
set_global('$', function () {});
var stream_list = require('js/stream_list.js');
global.$ = require('jquery');
$.fn.expectOne = function () {
assert(this.length === 1);
return this;
};
global.use_template('sidebar_subject_list');
global.use_template('stream_sidebar_row');
(function test_build_subject_list() {
var stream = "devel";
@ -39,3 +48,40 @@ global.use_template('sidebar_subject_list');
var topic = $(topic_html).find('a').text().trim();
assert.equal(topic, 'coding');
}());
(function test_add_stream_to_sidebar() {
// Make a couple calls to add_stream_to_sidebar() and make sure they
// generate the right markup as well as play nice with get_stream_li().
var stream_filters = $('<ul id="stream_filters">');
$("body").append(stream_filters);
var stream = "devel";
var sub = {
name: 'devel',
color: 'blue',
id: 5
};
global.stream_data.add_sub('devel', sub);
sub = {
name: 'social',
color: 'green',
id: 6
};
global.stream_data.add_sub('social', sub);
stream_list.add_stream_to_sidebar('devel');
stream_list.add_stream_to_sidebar('social');
var html = $("body").html();
global.write_test_output("test_add_stream_to_sidebar", html);
var li = stream_list.get_stream_li('social');
assert.equal(li.attr('data-name'), 'social');
assert.equal(li.find('.streamlist_swatch').css('background-color'), 'green');
assert.equal(li.find('a.subscription_name').text().trim(), 'social');
assert(li.find('.arrow').find("i").hasClass("icon-vector-chevron-down"));
}());