2013-08-09 02:05:23 +02:00
|
|
|
var assert = require('assert');
|
|
|
|
|
2013-08-21 20:27:14 +02:00
|
|
|
add_dependencies({
|
|
|
|
_: 'third/underscore/underscore.js',
|
|
|
|
Dict: 'js/dict.js',
|
|
|
|
stream_data: 'js/stream_data.js',
|
|
|
|
Filter: 'js/filter.js'
|
|
|
|
});
|
2013-08-09 02:05:23 +02:00
|
|
|
|
2013-08-21 20:27:14 +02:00
|
|
|
var narrow = require('js/narrow.js');
|
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
|
|
|
|
2013-09-18 19:01:21 +02:00
|
|
|
function set_filter(operators) {
|
2013-08-10 01:31:31 +02:00
|
|
|
narrow._set_current_filter(new Filter(operators));
|
2013-09-18 19:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(function test_stream() {
|
|
|
|
set_filter([['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']]);
|
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
|
|
|
}());
|
|
|
|
|
2013-09-18 19:14:08 +02:00
|
|
|
|
|
|
|
(function test_narrowed() {
|
|
|
|
narrow._set_current_filter(undefined); // not narrowed, basically
|
|
|
|
assert(!narrow.narrowed_to_pms());
|
|
|
|
assert(!narrow.narrowed_by_reply());
|
|
|
|
assert(!narrow.narrowed_to_search());
|
2013-09-18 19:27:12 +02:00
|
|
|
assert(!narrow.narrowed_to_topic());
|
2013-09-18 19:14:08 +02:00
|
|
|
|
|
|
|
set_filter([['stream', 'Foo']]);
|
|
|
|
assert(!narrow.narrowed_to_pms());
|
|
|
|
assert(!narrow.narrowed_by_reply());
|
|
|
|
assert(!narrow.narrowed_to_search());
|
2013-09-18 19:27:12 +02:00
|
|
|
assert(!narrow.narrowed_to_topic());
|
2013-09-18 19:14:08 +02:00
|
|
|
|
|
|
|
set_filter([['pm-with', 'steve@zulip.com']]);
|
|
|
|
assert(narrow.narrowed_to_pms());
|
|
|
|
assert(narrow.narrowed_by_reply());
|
|
|
|
assert(!narrow.narrowed_to_search());
|
2013-09-18 19:27:12 +02:00
|
|
|
assert(!narrow.narrowed_to_topic());
|
2013-09-18 19:14:08 +02:00
|
|
|
|
|
|
|
set_filter([['stream', 'Foo'], ['topic', 'bar']]);
|
|
|
|
assert(!narrow.narrowed_to_pms());
|
|
|
|
assert(narrow.narrowed_by_reply());
|
|
|
|
assert(!narrow.narrowed_to_search());
|
2013-09-18 19:27:12 +02:00
|
|
|
assert(narrow.narrowed_to_topic());
|
2013-09-18 19:14:08 +02:00
|
|
|
|
|
|
|
set_filter([['search', 'grail']]);
|
|
|
|
assert(!narrow.narrowed_to_pms());
|
|
|
|
assert(!narrow.narrowed_by_reply());
|
|
|
|
assert(narrow.narrowed_to_search());
|
2013-09-18 19:27:12 +02:00
|
|
|
assert(!narrow.narrowed_to_topic());
|
2013-09-18 19:14:08 +02:00
|
|
|
}());
|
|
|
|
|
2013-08-09 02:05:23 +02:00
|
|
|
(function test_operators() {
|
2013-09-18 19:01:21 +02:00
|
|
|
set_filter([['stream', 'Foo'], ['topic', 'Bar'], ['search', 'Yo']]);
|
2013-08-20 15:56:27 +02:00
|
|
|
var canonical_operators = [['stream', 'Foo'], ['topic', 'Bar'], ['search', 'yo']];
|
2013-08-09 02:05:23 +02:00
|
|
|
|
|
|
|
assert.deepEqual(narrow.operators(), canonical_operators);
|
|
|
|
}());
|
2013-08-19 20:06:51 +02:00
|
|
|
|
2013-09-19 14:42:05 +02:00
|
|
|
(function test_muting_enabled() {
|
|
|
|
set_filter([['stream', 'devel']]);
|
|
|
|
assert(narrow.muting_enabled());
|
|
|
|
|
|
|
|
narrow._set_current_filter(undefined); // not narrowed, basically
|
|
|
|
assert(narrow.muting_enabled());
|
|
|
|
|
|
|
|
set_filter([['stream', 'devel'], ['topic', 'mac']]);
|
|
|
|
assert(!narrow.muting_enabled());
|
|
|
|
|
|
|
|
set_filter([['search', 'whatever']]);
|
|
|
|
assert(!narrow.muting_enabled());
|
|
|
|
|
|
|
|
set_filter([['is', 'private']]);
|
|
|
|
assert(!narrow.muting_enabled());
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
2013-08-19 20:06:51 +02:00
|
|
|
(function test_set_compose_defaults() {
|
2013-09-18 19:01:21 +02:00
|
|
|
set_filter([['stream', 'Foo'], ['topic', 'Bar']]);
|
2013-08-19 20:06:51 +02:00
|
|
|
|
|
|
|
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'});
|
2013-09-18 19:01:21 +02:00
|
|
|
set_filter([['stream', 'rome']]);
|
2013-08-19 21:04:28 +02:00
|
|
|
|
|
|
|
opts = {};
|
|
|
|
narrow.set_compose_defaults(opts);
|
|
|
|
assert.equal(opts.stream, 'ROME');
|
2013-08-19 20:06:51 +02:00
|
|
|
}());
|