mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
1) The class Filter now lives in its own module. 2) The function canonicalized_operators() is now a class method on Filter. 3) The function message_in_home moved to filter.js and became private. 4) Various calling code had to change, of course. 5) Splitting out Filter helped simplify a few tests. (imported from commit e41d792b46d3d6a30d3bd03db0419f129d0a2a7b)
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
var assert = require('assert');
|
|
|
|
(function set_up_dependencies () {
|
|
global._ = require('third/underscore/underscore.js');
|
|
global.util = require('js/util.js');
|
|
global.Dict = require('js/dict.js');
|
|
global.narrow = require('js/narrow.js');
|
|
global.$ = function () {}; // for subs.js
|
|
global.subs = require('js/subs.js');
|
|
global.Filter = require('js/filter.js');
|
|
}());
|
|
|
|
var narrow = global.narrow;
|
|
var Filter = global.Filter;
|
|
|
|
(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 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 Filter(operators));
|
|
|
|
assert.deepEqual(narrow.operators(), canonical_operators);
|
|
}());
|