narrow: Add condition whether to show unread message first in narrow.

All narrows that have is: query or can mark unread message as read
will show unread message first.
This commit is contained in:
Mohit Gupta
2019-07-18 03:55:00 +05:30
committed by Tim Abbott
parent 6ec40cf9a0
commit 648a60baf6
3 changed files with 34 additions and 2 deletions

View File

@@ -69,6 +69,7 @@ run_test('basics', () => {
assert(!filter.is_search());
assert(filter.can_mark_messages_read());
assert(filter.allow_use_first_unread_when_narrowing());
assert(filter.can_apply_locally());
operators = [
@@ -80,6 +81,7 @@ run_test('basics', () => {
assert(filter.is_search());
assert(!filter.can_mark_messages_read());
assert(!filter.allow_use_first_unread_when_narrowing());
assert(!filter.can_apply_locally());
assert(!filter.is_exactly('stream'));
@@ -110,7 +112,32 @@ run_test('basics', () => {
assert(filter.has_operator('has'));
assert(!filter.can_apply_locally());
});
run_test('show_first_unread', () => {
var operators = [
{operator: 'is', operand: 'any'},
];
var filter = new Filter(operators);
assert(filter.allow_use_first_unread_when_narrowing());
operators = [
{operator: 'search', operand: 'query to search'},
];
filter = new Filter(operators);
assert(!filter.allow_use_first_unread_when_narrowing());
filter = new Filter();
filter.can_mark_messages_read = () => true;
assert(filter.allow_use_first_unread_when_narrowing());
// Side case
operators = [
{operator: 'is', operand: 'any'},
];
filter = new Filter(operators);
filter.can_mark_messages_read = () => false;
assert(filter.allow_use_first_unread_when_narrowing());
});
run_test('topic_stuff', () => {
var operators = [
{operator: 'stream', operand: 'foo'},