mirror of https://github.com/zulip/zulip.git
Improve sent_by_me in search_suggestions.js.
Added appropriate tests.
This commit is contained in:
parent
79d56c94dc
commit
c8d4eff8aa
|
@ -417,6 +417,33 @@ init();
|
||||||
"sender:bob@zulip.com",
|
"sender:bob@zulip.com",
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'stream:Denmark topic:Denmark1 sent';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"stream:Denmark topic:Denmark1 sent",
|
||||||
|
"stream:Denmark topic:Denmark1 sender:bob@zulip.com",
|
||||||
|
"stream:Denmark topic:Denmark1",
|
||||||
|
"stream:Denmark",
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'is:starred sender:m';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"is:starred sender:m",
|
||||||
|
"is:starred sender:bob@zulip.com",
|
||||||
|
"is:starred",
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'sender:alice@zulip.com sender:';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"sender:alice@zulip.com sender:",
|
||||||
|
"sender:alice@zulip.com",
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
(function test_topic_suggestions() {
|
(function test_topic_suggestions() {
|
||||||
|
|
|
@ -463,29 +463,29 @@ function get_special_filter_suggestions(last, operators) {
|
||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_sent_by_me_suggestions(query, operators) {
|
function get_sent_by_me_suggestions(last, operators) {
|
||||||
if (operators.length >= 2) {
|
var last_string = Filter.unparse([last]).toLowerCase();
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
var sender_query = 'sender:' + people.my_current_email();
|
var sender_query = 'sender:' + people.my_current_email();
|
||||||
var from_query = 'from:' + people.my_current_email();
|
var from_query = 'from:' + people.my_current_email();
|
||||||
var description = 'Sent by me';
|
var description = 'Sent by me';
|
||||||
|
var invalid = [
|
||||||
|
{operator: 'sender'},
|
||||||
|
{operator: 'from'},
|
||||||
|
];
|
||||||
|
|
||||||
query = query.toLowerCase();
|
if (match_criteria(operators, invalid)) {
|
||||||
|
|
||||||
if (query === sender_query || query === from_query) {
|
|
||||||
return [];
|
return [];
|
||||||
} else if (query === '' ||
|
}
|
||||||
sender_query.indexOf(query) === 0 ||
|
|
||||||
description.toLowerCase().indexOf(query) === 0) {
|
if (last.operator === '' || sender_query.indexOf(last_string) === 0 ||
|
||||||
|
'sender:me'.indexOf(last_string) === 0 || last_string === 'sent') {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
search_string: sender_query,
|
search_string: sender_query,
|
||||||
description: description,
|
description: description,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
} else if (from_query.indexOf(query) === 0) {
|
} else if (from_query.indexOf(last_string) === 0 || 'sender:me'.indexOf(last_string) === 0) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
search_string: from_query,
|
search_string: from_query,
|
||||||
|
@ -541,8 +541,8 @@ exports.get_suggestions = function (query) {
|
||||||
suggestions = get_special_filter_suggestions(last, base_operators);
|
suggestions = get_special_filter_suggestions(last, base_operators);
|
||||||
attach_suggestions(result, base, suggestions);
|
attach_suggestions(result, base, suggestions);
|
||||||
|
|
||||||
suggestions = get_sent_by_me_suggestions(query, operators);
|
suggestions = get_sent_by_me_suggestions(last, base_operators);
|
||||||
result = result.concat(suggestions);
|
attach_suggestions(result, base, suggestions);
|
||||||
|
|
||||||
suggestions = get_stream_suggestions(operators);
|
suggestions = get_stream_suggestions(operators);
|
||||||
result = result.concat(suggestions);
|
result = result.concat(suggestions);
|
||||||
|
|
Loading…
Reference in New Issue