mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
search: Extract 'Sent by me' suggestion logic into separate method.
This also adds a nice test suite for it.
This commit is contained in:
committed by
Tim Abbott
parent
c613e510ed
commit
e666a62c6a
@@ -245,6 +245,62 @@ people.init();
|
|||||||
assert.equal(describe('stream:devel'), 'Narrow to stream <strong>devel</strong>');
|
assert.equal(describe('stream:devel'), 'Narrow to stream <strong>devel</strong>');
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
(function test_sent_by_me_suggestions() {
|
||||||
|
global.stream_data.subscribed_streams = function () {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
global.narrow.stream = function () {
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
var query = '';
|
||||||
|
var suggestions = search.get_suggestions(query);
|
||||||
|
assert(suggestions.strings.indexOf('sender:bob@zulip.com') !== -1);
|
||||||
|
assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description,
|
||||||
|
'Sent by me');
|
||||||
|
|
||||||
|
query = 'sender';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
var expected = [
|
||||||
|
"sender",
|
||||||
|
"sender:bob@zulip.com",
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'from';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"from",
|
||||||
|
"from:bob@zulip.com",
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'sender:bob@zulip.com';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"sender:bob@zulip.com",
|
||||||
|
"is:private",
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'from:bob@zulip.com';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"from:bob@zulip.com",
|
||||||
|
"is:private",
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = 'sent';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"sent",
|
||||||
|
"sender:bob@zulip.com",
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
}());
|
||||||
|
|
||||||
(function test_topic_suggestions() {
|
(function test_topic_suggestions() {
|
||||||
var suggestions;
|
var suggestions;
|
||||||
var expected;
|
var expected;
|
||||||
|
|||||||
@@ -346,10 +346,6 @@ function get_special_filter_suggestions(query, operators) {
|
|||||||
search_string: 'is:alerted',
|
search_string: 'is:alerted',
|
||||||
description: 'Alerted messages',
|
description: 'Alerted messages',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
search_string: 'sender:' + page_params.email,
|
|
||||||
description: 'Sent by me',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
query = query.toLowerCase();
|
query = query.toLowerCase();
|
||||||
@@ -368,6 +364,39 @@ function get_special_filter_suggestions(query, operators) {
|
|||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_sent_by_me_suggestions(query, operators) {
|
||||||
|
if (operators.length >= 2) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var sender_query = 'sender:' + page_params.email;
|
||||||
|
var from_query = 'from:' + page_params.email;
|
||||||
|
var description = 'Sent by me';
|
||||||
|
|
||||||
|
query = query.toLowerCase();
|
||||||
|
|
||||||
|
if (query === sender_query || query === from_query) {
|
||||||
|
return [];
|
||||||
|
} else if (query === '' ||
|
||||||
|
sender_query.indexOf(query) === 0 ||
|
||||||
|
description.toLowerCase().indexOf(query) === 0) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
search_string: sender_query,
|
||||||
|
description: description,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
} else if (from_query.indexOf(query) === 0) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
search_string: from_query,
|
||||||
|
description: description,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
exports.get_suggestions = function (query) {
|
exports.get_suggestions = function (query) {
|
||||||
// This method works in tandem with the typeahead library to generate
|
// This method works in tandem with the typeahead library to generate
|
||||||
// search suggestions. If you want to change its behavior, be sure to update
|
// search suggestions. If you want to change its behavior, be sure to update
|
||||||
@@ -386,6 +415,9 @@ exports.get_suggestions = function (query) {
|
|||||||
suggestions = get_special_filter_suggestions(query, operators);
|
suggestions = get_special_filter_suggestions(query, operators);
|
||||||
result = result.concat(suggestions);
|
result = result.concat(suggestions);
|
||||||
|
|
||||||
|
suggestions = get_sent_by_me_suggestions(query, operators);
|
||||||
|
result = result.concat(suggestions);
|
||||||
|
|
||||||
suggestions = get_stream_suggestions(operators);
|
suggestions = get_stream_suggestions(operators);
|
||||||
result = result.concat(suggestions);
|
result = result.concat(suggestions);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user