2013-08-21 20:27:14 +02:00
|
|
|
add_dependencies({
|
|
|
|
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;
|
2014-02-10 18:59:48 +01:00
|
|
|
var _ = global._;
|
2013-08-09 02:05:23 +02:00
|
|
|
|
2013-09-18 19:01:21 +02:00
|
|
|
function set_filter(operators) {
|
2014-02-10 18:59:48 +01:00
|
|
|
operators = _.map(operators, function (op) {
|
|
|
|
return {operator: op[0], operand: op[1]};
|
|
|
|
});
|
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');
|
2016-11-10 18:43:34 +01:00
|
|
|
assert.equal(narrow.topic(), 'Bar');
|
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']]);
|
2014-01-30 00:05:36 +01:00
|
|
|
var result = narrow.operators();
|
|
|
|
assert.equal(result.length, 3);
|
|
|
|
assert.equal(result[0].operator, 'stream');
|
|
|
|
assert.equal(result[0].operand, 'Foo');
|
2013-08-09 02:05:23 +02:00
|
|
|
|
2014-01-30 00:05:36 +01:00
|
|
|
assert.equal(result[1].operator, 'topic');
|
|
|
|
assert.equal(result[1].operand, 'Bar');
|
|
|
|
|
|
|
|
assert.equal(result[2].operator, 'search');
|
|
|
|
assert.equal(result[2].operand, 'yo');
|
2013-08-09 02:05:23 +02:00
|
|
|
}());
|
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');
|
2013-11-27 16:43:00 +01:00
|
|
|
assert.equal(opts.subject, 'Bar');
|
2013-08-19 21:04:28 +02:00
|
|
|
|
2014-02-05 20:35:16 +01:00
|
|
|
stream_data.add_sub('ROME', {name: 'ROME', stream_id: 99});
|
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
|
|
|
}());
|