Add narrowed_to_topic() helper function.

(imported from commit 9190caa9b183893fb7ae883686b9bdbd661d5895)
This commit is contained in:
Steve Howell 2013-09-18 13:27:12 -04:00
parent a4e2ed9fd2
commit e79e74ade4
2 changed files with 13 additions and 0 deletions

View File

@ -435,6 +435,14 @@ exports.narrowed_by_reply = function () {
current_filter.operands("topic").length === 1));
};
exports.narrowed_to_topic = function () {
if (current_filter === undefined) {
return false;
}
return (current_filter.has_operator("stream") &&
current_filter.has_operator("topic"));
};
exports.narrowed_to_search = function () {
return (current_filter !== undefined) && current_filter.is_search();
};

View File

@ -27,26 +27,31 @@ function set_filter(operators) {
assert(!narrow.narrowed_to_pms());
assert(!narrow.narrowed_by_reply());
assert(!narrow.narrowed_to_search());
assert(!narrow.narrowed_to_topic());
set_filter([['stream', 'Foo']]);
assert(!narrow.narrowed_to_pms());
assert(!narrow.narrowed_by_reply());
assert(!narrow.narrowed_to_search());
assert(!narrow.narrowed_to_topic());
set_filter([['pm-with', 'steve@zulip.com']]);
assert(narrow.narrowed_to_pms());
assert(narrow.narrowed_by_reply());
assert(!narrow.narrowed_to_search());
assert(!narrow.narrowed_to_topic());
set_filter([['stream', 'Foo'], ['topic', 'bar']]);
assert(!narrow.narrowed_to_pms());
assert(narrow.narrowed_by_reply());
assert(!narrow.narrowed_to_search());
assert(narrow.narrowed_to_topic());
set_filter([['search', 'grail']]);
assert(!narrow.narrowed_to_pms());
assert(!narrow.narrowed_by_reply());
assert(narrow.narrowed_to_search());
assert(!narrow.narrowed_to_topic());
}());
(function test_operators() {