Add unit tests for stream_list.

(imported from commit 1d04a2e6115f29b7949466260ec2ba3126b882e6)
This commit is contained in:
Steve Howell
2013-11-26 10:39:58 -05:00
parent 3459962e69
commit c53845a69c
5 changed files with 58 additions and 3 deletions

View File

@@ -157,3 +157,6 @@ exports.initialize = function () {
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = hashchange;
}

View File

@@ -226,7 +226,7 @@ function remove_expanded_subjects() {
$("ul.expanded_subjects").remove();
}
function build_subject_list(stream, active_topic, max_subjects) {
exports._build_subject_list = function (stream, active_topic, max_subjects) {
var subjects = recent_subjects.get(stream) || [];
if (active_topic) {
@@ -265,7 +265,7 @@ function build_subject_list(stream, active_topic, max_subjects) {
stream: stream});
return topic_dom;
}
};
function rebuild_recent_subjects(stream, active_topic) {
// TODO: Call rebuild_recent_subjects less, not on every new
@@ -274,7 +274,7 @@ function rebuild_recent_subjects(stream, active_topic) {
var max_subjects = 5;
var stream_li = get_filter_li('stream', stream);
var topic_dom = build_subject_list(stream, active_topic, max_subjects);
var topic_dom = exports._build_subject_list(stream, active_topic, max_subjects);
stream_li.append(topic_dom);
if (active_topic) {
@@ -501,3 +501,6 @@ $(function () {
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = stream_list;
}

View File

@@ -58,3 +58,6 @@ Handlebars.registerHelper('if_and', function () {
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = templates;
}

View File

@@ -1,5 +1,6 @@
var fs = require('fs');
var _ = require('third/underscore/underscore.js');
var Handlebars = require('handlebars');
// Run all the JS scripts in our test directory. Tests do NOT run
// in isolation.
@@ -26,6 +27,15 @@ global.add_dependencies = function (dct) {
});
};
global.use_template = function (name) {
if (Handlebars.templates === undefined) {
Handlebars.templates = {};
}
var template_dir = __dirname+'/../../../../static/templates/';
var data = fs.readFileSync(template_dir + name + '.handlebars').toString();
Handlebars.templates[name] = Handlebars.compile(data);
};
tests.forEach(function (filename) {
if (filename === 'index') {
return;

View File

@@ -0,0 +1,36 @@
var assert = require('assert');
add_dependencies({
_: 'third/underscore/underscore',
Dict: 'js/dict',
Handlebars: 'handlebars',
templates: 'js/templates',
muting: 'js/muting',
narrow: 'js/narrow',
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.use_template('sidebar_subject_list');
(function test_build_subject_list() {
var stream = "devel";
var active_topic = "testing";
var max_topics = 5;
var topics = [
{subject: "coding"}
];
global.recent_subjects.set("devel", topics);
global.unread.num_unread_for_subject = function () {
return 1;
};
var topic_html = stream_list._build_subject_list(stream, active_topic, max_topics);
}());