mirror of https://github.com/zulip/zulip.git
search: Do not show default suggestion for `is` operator.
Fixes #9492. Default suggestion e.g `abc messages` as a suggestion for `is:abc` is not shown in a new suggestion. But if the is operator is already present before any other operator, the default message text will be used. e.g `is:abc sender:abc@zulipchat.com` will have all the suggestions with the prefix `abc messages, sent by abc@zulipchat.com`.
This commit is contained in:
parent
30815b402c
commit
e5b3fb332b
|
@ -551,6 +551,101 @@ run_test('has_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
run_test('check_is_suggestions', () => {
|
||||||
|
var query = 'i';
|
||||||
|
global.stream_data.subscribed_streams = function () {
|
||||||
|
return ['devel', 'office'];
|
||||||
|
};
|
||||||
|
global.narrow_state.stream = function () {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
var suggestions = search.get_suggestions(query);
|
||||||
|
var expected = [
|
||||||
|
'i',
|
||||||
|
'is:private',
|
||||||
|
'is:starred',
|
||||||
|
'is:mentioned',
|
||||||
|
'is:alerted',
|
||||||
|
'is:unread',
|
||||||
|
'has:image',
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
function describe(q) {
|
||||||
|
return suggestions.lookup_table[q].description;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(describe('is:private'), 'Private messages');
|
||||||
|
assert.equal(describe('is:starred'), 'Starred messages');
|
||||||
|
assert.equal(describe('is:mentioned'), '@-mentions');
|
||||||
|
assert.equal(describe('is:alerted'), 'Alerted messages');
|
||||||
|
assert.equal(describe('is:unread'), 'Unread messages');
|
||||||
|
|
||||||
|
query = '-i';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
'-i',
|
||||||
|
'-is:private',
|
||||||
|
'-is:starred',
|
||||||
|
'-is:mentioned',
|
||||||
|
'-is:alerted',
|
||||||
|
'-is:unread',
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
assert.equal(describe('-is:private'), 'Exclude private messages');
|
||||||
|
assert.equal(describe('-is:starred'), 'Exclude starred messages');
|
||||||
|
assert.equal(describe('-is:mentioned'), 'Exclude @-mentions');
|
||||||
|
assert.equal(describe('-is:alerted'), 'Exclude alerted messages');
|
||||||
|
assert.equal(describe('-is:unread'), 'Exclude unread messages');
|
||||||
|
|
||||||
|
// operand suggestions follow.
|
||||||
|
|
||||||
|
query = 'is:';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
'is:private',
|
||||||
|
'is:starred',
|
||||||
|
'is:mentioned',
|
||||||
|
'is:alerted',
|
||||||
|
'is:unread',
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'is:st';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
'is:starred',
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = '-is:st';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
'-is:starred',
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'st';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
'st',
|
||||||
|
'is:starred',
|
||||||
|
'stream:',
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'stream:Denmark has:link is:sta';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
'stream:Denmark has:link is:starred',
|
||||||
|
'stream:Denmark has:link',
|
||||||
|
'stream:Denmark',
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
});
|
||||||
|
|
||||||
run_test('sent_by_me_suggestions', () => {
|
run_test('sent_by_me_suggestions', () => {
|
||||||
global.stream_data.subscribed_streams = function () {
|
global.stream_data.subscribed_streams = function () {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -581,10 +581,10 @@ exports.get_suggestions = function (query) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display the default first
|
// Display the default first
|
||||||
// `has` operator works only on predefined categories. Default suggestion
|
// `has` and `is` operators work only on predefined categories. Default suggestion
|
||||||
// is not displayed in that case. e.g. `messages with one or more abc` as
|
// is not displayed in that case. e.g. `messages with one or more abc` as
|
||||||
// a suggestion for `has:abc`does not make sense.
|
// a suggestion for `has:abc`does not make sense.
|
||||||
if (last.operator !== '' && last.operator !== 'has') {
|
if (last.operator !== '' && last.operator !== 'has' && last.operator !== 'is') {
|
||||||
suggestion = get_default_suggestion(operators);
|
suggestion = get_default_suggestion(operators);
|
||||||
result = [suggestion];
|
result = [suggestion];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue