2013-08-09 02:05:23 +02:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
(function set_up_dependencies () {
|
|
|
|
global._ = require('third/underscore/underscore.js');
|
|
|
|
global.util = require('js/util.js');
|
2013-08-07 23:56:51 +02:00
|
|
|
global.Dict = require('js/dict.js');
|
2013-08-09 02:05:23 +02:00
|
|
|
global.narrow = require('js/narrow.js');
|
2013-08-15 21:11:07 +02:00
|
|
|
global.stream_data = require('js/stream_data.js');
|
2013-08-10 01:31:31 +02:00
|
|
|
global.Filter = require('js/filter.js');
|
2013-08-09 02:05:23 +02:00
|
|
|
}());
|
|
|
|
|
|
|
|
var narrow = global.narrow;
|
2013-08-10 01:31:31 +02:00
|
|
|
var Filter = global.Filter;
|
2013-08-19 21:04:28 +02:00
|
|
|
var stream_data = global.stream_data;
|
2013-08-09 02:05:23 +02:00
|
|
|
|
|
|
|
(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);
|
|
|
|
|
2013-08-20 18:55:30 +02:00
|
|
|
string = 'stream:Foo topic:Bar yo';
|
2013-08-09 02:05:23 +02:00
|
|
|
assert.deepEqual(narrow.unparse(operators), string);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_stream() {
|
|
|
|
var operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']];
|
2013-08-10 01:31:31 +02:00
|
|
|
narrow._set_current_filter(new Filter(operators));
|
2013-08-09 02:05:23 +02:00
|
|
|
|
2013-08-20 15:56:27 +02:00
|
|
|
assert.equal(narrow.stream(), 'Foo');
|
2013-08-09 02:05:23 +02:00
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_operators() {
|
2013-08-20 15:56:27 +02:00
|
|
|
var operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'Yo']];
|
|
|
|
var canonical_operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']];
|
2013-08-10 01:31:31 +02:00
|
|
|
narrow._set_current_filter(new Filter(operators));
|
2013-08-09 02:05:23 +02:00
|
|
|
|
|
|
|
assert.deepEqual(narrow.operators(), canonical_operators);
|
|
|
|
}());
|
2013-08-19 20:06:51 +02:00
|
|
|
|
|
|
|
(function test_set_compose_defaults() {
|
|
|
|
var operators = [['stream', 'Foo'], ['topic', 'Bar']];
|
|
|
|
narrow._set_current_filter(new Filter(operators));
|
|
|
|
|
|
|
|
var opts = {};
|
|
|
|
narrow.set_compose_defaults(opts);
|
2013-08-20 15:56:27 +02:00
|
|
|
assert.equal(opts.stream, 'Foo');
|
|
|
|
assert.equal(opts.subject, 'Bar');
|
2013-08-19 21:04:28 +02:00
|
|
|
|
|
|
|
stream_data.add_sub('ROME', {name: 'ROME'});
|
|
|
|
operators = [['stream', 'rome']];
|
|
|
|
narrow._set_current_filter(new Filter(operators));
|
|
|
|
|
|
|
|
opts = {};
|
|
|
|
narrow.set_compose_defaults(opts);
|
|
|
|
assert.equal(opts.stream, 'ROME');
|
2013-08-19 20:06:51 +02:00
|
|
|
}());
|