mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 16:43:57 +00:00
Add unit tests for stream_list.
(imported from commit 1d04a2e6115f29b7949466260ec2ba3126b882e6)
This commit is contained in:
@@ -157,3 +157,6 @@ exports.initialize = function () {
|
|||||||
return exports;
|
return exports;
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
if (typeof module !== 'undefined') {
|
||||||
|
module.exports = hashchange;
|
||||||
|
}
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ function remove_expanded_subjects() {
|
|||||||
$("ul.expanded_subjects").remove();
|
$("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) || [];
|
var subjects = recent_subjects.get(stream) || [];
|
||||||
|
|
||||||
if (active_topic) {
|
if (active_topic) {
|
||||||
@@ -265,7 +265,7 @@ function build_subject_list(stream, active_topic, max_subjects) {
|
|||||||
stream: stream});
|
stream: stream});
|
||||||
|
|
||||||
return topic_dom;
|
return topic_dom;
|
||||||
}
|
};
|
||||||
|
|
||||||
function rebuild_recent_subjects(stream, active_topic) {
|
function rebuild_recent_subjects(stream, active_topic) {
|
||||||
// TODO: Call rebuild_recent_subjects less, not on every new
|
// 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 max_subjects = 5;
|
||||||
var stream_li = get_filter_li('stream', stream);
|
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);
|
stream_li.append(topic_dom);
|
||||||
|
|
||||||
if (active_topic) {
|
if (active_topic) {
|
||||||
@@ -501,3 +501,6 @@ $(function () {
|
|||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
}());
|
}());
|
||||||
|
if (typeof module !== 'undefined') {
|
||||||
|
module.exports = stream_list;
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,3 +58,6 @@ Handlebars.registerHelper('if_and', function () {
|
|||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
}());
|
}());
|
||||||
|
if (typeof module !== 'undefined') {
|
||||||
|
module.exports = templates;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var _ = require('third/underscore/underscore.js');
|
var _ = require('third/underscore/underscore.js');
|
||||||
|
var Handlebars = require('handlebars');
|
||||||
|
|
||||||
// Run all the JS scripts in our test directory. Tests do NOT run
|
// Run all the JS scripts in our test directory. Tests do NOT run
|
||||||
// in isolation.
|
// 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) {
|
tests.forEach(function (filename) {
|
||||||
if (filename === 'index') {
|
if (filename === 'index') {
|
||||||
return;
|
return;
|
||||||
|
|||||||
36
zerver/tests/frontend/node/stream_list.js
Normal file
36
zerver/tests/frontend/node/stream_list.js
Normal 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);
|
||||||
|
|
||||||
|
}());
|
||||||
Reference in New Issue
Block a user