Add tests for the Filter class.

(imported from commit ef0917bd7911c5cc6f6d20d356c156d483ba723f)
This commit is contained in:
Steve Howell
2013-08-09 09:30:18 -04:00
parent cc73619a9d
commit cef72fd8b8
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
var assert = require('assert');
(function set_up_dependencies () {
global._ = require('third/underscore/underscore.js');
// An upcoming change is to put Filter in its own module, but
// for now it still lives in narrow.js. (I'm waiting for a big
// commit from Zev to hit master first. Once that happens,
// I will make js/filter.js, update the references here, and
// hopefully remember to delete this comment.)
global.narrow = require('js/narrow.js');
global.$ = function () {}; // for subs.js to load
global.subs = require('js/subs.js');
global.page_params = {
domain: 'zulip.com'
};
}());
var Filter = global.narrow.Filter;
(function test_basics() {
var operators = [['stream', 'foo'], ['topic', 'bar']];
var filter = new Filter(operators);
assert.deepEqual(filter.operators(), operators);
var predicate = filter.predicate();
assert(predicate({type: 'stream', stream: 'foo', subject: 'bar'}));
assert(!predicate({type: 'stream', stream: 'foo', subject: 'whatever'}));
assert.deepEqual(filter.operands('stream'), ['foo']);
assert(filter.has_operator('stream'));
assert(!filter.has_operator('search'));
assert(filter.has_operand('stream', 'foo'));
assert(!filter.has_operand('stream', 'nada'));
assert(!filter.is_search());
assert(filter.can_apply_locally());
operators = [['stream', 'foo'], ['topic', 'bar'], ['search', 'pizza']];
filter = new Filter(operators);
assert(filter.is_search());
assert(! filter.can_apply_locally());
}());