mirror of https://github.com/zulip/zulip.git
Add unit tests to narrow.js.
This includes slightly invasive, but harmless, changes to production code. (imported from commit 847557c11088b75c836cc399d0af75353a8faa3a)
This commit is contained in:
parent
509c3b4dc3
commit
cc73619a9d
|
@ -209,6 +209,11 @@ exports.Filter = Filter;
|
|||
|
||||
var current_filter;
|
||||
|
||||
// A small concession to unit testing follows:
|
||||
exports._set_current_filter = function (filter) {
|
||||
current_filter = filter;
|
||||
};
|
||||
|
||||
exports.active = function () {
|
||||
return current_filter !== undefined;
|
||||
};
|
||||
|
|
|
@ -863,3 +863,6 @@ exports.show_and_focus_on_narrow = function () {
|
|||
return exports;
|
||||
|
||||
}());
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = subs;
|
||||
}
|
||||
|
|
|
@ -11,5 +11,6 @@ NODEJS=$(which nodejs || which node)
|
|||
$NODEJS util.js
|
||||
$NODEJS message_list.js
|
||||
$NODEJS message_tour.js
|
||||
$NODEJS narrow.js
|
||||
$NODEJS unread.js
|
||||
$NODEJS search_suggestion.js
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
var assert = require('assert');
|
||||
|
||||
(function set_up_dependencies () {
|
||||
global._ = require('third/underscore/underscore.js');
|
||||
global.util = require('js/util.js');
|
||||
global.narrow = require('js/narrow.js');
|
||||
global.$ = function () {}; // for subs.js
|
||||
global.subs = require('js/subs.js');
|
||||
}());
|
||||
|
||||
var narrow = global.narrow;
|
||||
|
||||
(function test_parse_and_unparse() {
|
||||
var string ='stream:Foo topic:Bar yo';
|
||||
var operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']];
|
||||
|
||||
assert.deepEqual(narrow.parse(string), operators);
|
||||
|
||||
string = 'stream:foo topic:bar yo';
|
||||
assert.deepEqual(narrow.unparse(operators), string);
|
||||
}());
|
||||
|
||||
(function test_stream() {
|
||||
var operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']];
|
||||
narrow._set_current_filter(new narrow.Filter(operators));
|
||||
|
||||
assert.equal(narrow.stream(), 'foo');
|
||||
}());
|
||||
|
||||
(function test_operators() {
|
||||
var operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']];
|
||||
var canonical_operators = [['stream', 'foo'], ['topic', 'bar'], ['search', 'yo']];
|
||||
narrow._set_current_filter(new narrow.Filter(operators));
|
||||
|
||||
assert.deepEqual(narrow.operators(), canonical_operators);
|
||||
}());
|
Loading…
Reference in New Issue