2018-07-14 12:46:02 +02:00
|
|
|
set_global('page_params', {
|
|
|
|
search_pills_enabled: true,
|
|
|
|
});
|
2017-11-08 18:43:27 +01:00
|
|
|
zrequire('util');
|
|
|
|
zrequire('typeahead_helper');
|
|
|
|
zrequire('Handlebars', 'handlebars');
|
|
|
|
zrequire('Filter', 'js/filter');
|
|
|
|
zrequire('narrow_state');
|
|
|
|
zrequire('stream_data');
|
|
|
|
zrequire('topic_data');
|
|
|
|
zrequire('people');
|
2018-05-13 12:17:00 +02:00
|
|
|
zrequire('unread');
|
2018-06-25 17:14:45 +02:00
|
|
|
zrequire('common');
|
2017-11-08 18:43:27 +01:00
|
|
|
var search = zrequire('search_suggestion');
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2017-01-20 19:22:25 +01:00
|
|
|
var bob = {
|
2016-12-03 23:17:57 +01:00
|
|
|
email: 'bob@zulip.com',
|
2017-01-20 19:22:25 +01:00
|
|
|
full_name: 'Bob Roberts',
|
|
|
|
user_id: 42,
|
|
|
|
};
|
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
const noop = () => {};
|
2017-01-20 19:22:25 +01:00
|
|
|
|
|
|
|
function init() {
|
|
|
|
people.init();
|
|
|
|
people.add(bob);
|
2017-01-20 23:16:28 +01:00
|
|
|
people.initialize_current_user(bob.user_id);
|
2017-01-20 19:22:25 +01:00
|
|
|
}
|
|
|
|
init();
|
2013-08-20 18:45:09 +02:00
|
|
|
|
2013-08-22 01:29:28 +02:00
|
|
|
set_global('narrow', {});
|
2019-04-23 18:02:06 +02:00
|
|
|
set_global('settings_org', {
|
|
|
|
show_email: () => true,
|
|
|
|
});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.reset();
|
2016-10-28 18:26:30 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('basic_get_suggestions', () => {
|
2013-07-28 23:05:01 +02:00
|
|
|
var query = 'fred';
|
|
|
|
|
2013-08-15 21:11:07 +02:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
2013-07-28 23:05:01 +02:00
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2013-07-28 23:05:01 +02:00
|
|
|
return 'office';
|
|
|
|
};
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2013-07-28 23:05:01 +02:00
|
|
|
|
|
|
|
var expected = [
|
2016-12-03 23:17:57 +01:00
|
|
|
'fred',
|
2013-07-28 23:05:01 +02:00
|
|
|
];
|
2013-07-30 19:41:23 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('subset_suggestions', () => {
|
2018-07-02 22:30:18 +02:00
|
|
|
var query = 'shakespeare';
|
|
|
|
var base_query = 'stream:Denmark topic:Hamlet';
|
2013-08-28 01:23:42 +02:00
|
|
|
|
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2018-03-13 13:04:16 +01:00
|
|
|
return;
|
2013-08-28 01:23:42 +02:00
|
|
|
};
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions(base_query, query);
|
2013-08-28 01:23:42 +02:00
|
|
|
|
|
|
|
var expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"shakespeare",
|
2013-08-28 01:23:42 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-08-28 01:23:42 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('private_suggestions', () => {
|
2013-08-28 01:45:39 +02:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2018-03-13 13:04:16 +01:00
|
|
|
return;
|
2013-08-28 01:45:39 +02:00
|
|
|
};
|
|
|
|
|
2016-11-01 19:37:19 +01:00
|
|
|
var ted =
|
|
|
|
{
|
|
|
|
email: 'ted@zulip.com',
|
|
|
|
user_id: 101,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Ted Smith',
|
2016-11-01 19:37:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
var alice =
|
|
|
|
{
|
|
|
|
email: 'alice@zulip.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 102,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice Ignore',
|
2016-11-01 19:37:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
people.add(ted);
|
|
|
|
people.add(alice);
|
2013-08-28 01:45:39 +02:00
|
|
|
|
|
|
|
var query = 'is:private';
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2013-08-28 01:45:39 +02:00
|
|
|
var expected = [
|
|
|
|
"is:private",
|
|
|
|
"pm-with:alice@zulip.com",
|
2017-01-20 19:22:25 +01:00
|
|
|
"pm-with:bob@zulip.com",
|
2016-12-03 23:17:57 +01:00
|
|
|
"pm-with:ted@zulip.com",
|
2013-08-28 01:45:39 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'al';
|
|
|
|
var base_query = 'is:private';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2014-01-21 20:53:52 +01:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"al",
|
|
|
|
"is:alerted",
|
|
|
|
"sender:alice@zulip.com",
|
|
|
|
"pm-with:alice@zulip.com",
|
|
|
|
"group-pm-with:alice@zulip.com",
|
2014-01-21 20:53:52 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2013-10-07 20:48:25 +02:00
|
|
|
query = 'pm-with:t';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2013-10-07 20:48:25 +02:00
|
|
|
expected = [
|
|
|
|
"pm-with:t",
|
|
|
|
"pm-with:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2014-03-04 23:22:15 +01:00
|
|
|
query = '-pm-with:t';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2014-03-04 23:22:15 +01:00
|
|
|
expected = [
|
|
|
|
"-pm-with:t",
|
|
|
|
"is:private -pm-with:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2013-08-28 01:45:39 +02:00
|
|
|
query = 'pm-with:ted@zulip.com';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2013-08-28 01:45:39 +02:00
|
|
|
expected = [
|
|
|
|
"pm-with:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2013-10-07 20:48:25 +02:00
|
|
|
query = 'sender:ted';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2013-10-07 20:48:25 +02:00
|
|
|
expected = [
|
|
|
|
"sender:ted",
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'sender:te';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2013-10-07 20:48:25 +02:00
|
|
|
expected = [
|
|
|
|
"sender:te",
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2014-03-04 23:22:15 +01:00
|
|
|
query = '-sender:te';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2014-03-04 23:22:15 +01:00
|
|
|
expected = [
|
|
|
|
"-sender:te",
|
2017-06-03 09:19:57 +02:00
|
|
|
"-sender:ted@zulip.com",
|
2014-03-04 23:22:15 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2013-10-07 20:48:25 +02:00
|
|
|
query = 'sender:ted@zulip.com';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2013-10-07 20:48:25 +02:00
|
|
|
expected = [
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'from:ted';
|
|
|
|
base_query = 'is:unread';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-01-11 19:13:13 +01:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"from:ted",
|
|
|
|
"from:ted@zulip.com",
|
2017-01-11 19:13:13 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
|
2013-08-28 01:45:39 +02:00
|
|
|
// Users can enter bizarre queries, and if they do, we want to
|
|
|
|
// be conservative with suggestions.
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'near:3';
|
|
|
|
base_query = 'is:private';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2013-08-28 01:45:39 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"near:3",
|
2013-08-28 01:45:39 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'near:3';
|
|
|
|
base_query = 'pm-with:ted@zulip.com';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2013-08-28 01:45:39 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"near:3",
|
2013-08-28 01:45:39 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-06-03 09:19:57 +02:00
|
|
|
|
|
|
|
// Make sure suggestions still work if preceding tokens
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'sender:ted@zulip.com';
|
|
|
|
base_query = 'is:alerted';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 09:19:57 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"sender:ted@zulip.com",
|
2017-06-03 09:19:57 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'al';
|
|
|
|
base_query = 'is:starred has:link is:private';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 09:19:57 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"al",
|
|
|
|
"is:alerted",
|
|
|
|
"sender:alice@zulip.com",
|
|
|
|
"pm-with:alice@zulip.com",
|
|
|
|
"group-pm-with:alice@zulip.com",
|
2017-06-03 09:19:57 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// Make sure it handles past context correctly
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'pm-with:';
|
|
|
|
base_query = 'stream:Denmark';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 09:19:57 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'pm-with:',
|
2017-06-03 09:19:57 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'sender:';
|
|
|
|
base_query = 'sender:ted@zulip.com';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 09:19:57 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'sender:',
|
2017-06-03 09:19:57 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-08-28 01:45:39 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('group_suggestions', () => {
|
2017-02-05 22:11:18 +01:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2018-03-13 13:04:16 +01:00
|
|
|
return;
|
2017-02-05 22:11:18 +01:00
|
|
|
};
|
|
|
|
|
2017-07-05 02:58:05 +02:00
|
|
|
set_global('activity', {
|
2018-05-07 03:30:13 +02:00
|
|
|
get_huddles: function () {
|
|
|
|
return [];
|
|
|
|
},
|
2017-07-05 02:58:05 +02:00
|
|
|
});
|
|
|
|
|
2017-02-05 22:11:18 +01:00
|
|
|
var ted =
|
|
|
|
{
|
|
|
|
email: 'ted@zulip.com',
|
|
|
|
user_id: 101,
|
|
|
|
full_name: 'Ted Smith',
|
|
|
|
};
|
|
|
|
|
|
|
|
var alice =
|
|
|
|
{
|
|
|
|
email: 'alice@zulip.com',
|
|
|
|
user_id: 102,
|
|
|
|
full_name: 'Alice Ignore',
|
|
|
|
};
|
|
|
|
|
2017-07-05 02:58:05 +02:00
|
|
|
var jeff =
|
|
|
|
{
|
|
|
|
email: 'jeff@zulip.com',
|
|
|
|
user_id: 103,
|
|
|
|
full_name: 'Jeff Zoolipson',
|
|
|
|
};
|
|
|
|
|
2017-02-05 22:11:18 +01:00
|
|
|
people.add(ted);
|
|
|
|
people.add(alice);
|
2017-07-05 02:58:05 +02:00
|
|
|
people.add(jeff);
|
2017-02-05 22:11:18 +01:00
|
|
|
|
|
|
|
// Entering a comma in a pm-with query should immediately generate
|
|
|
|
// suggestions for the next person.
|
|
|
|
var query = 'pm-with:bob@zulip.com,';
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2017-02-05 22:11:18 +01:00
|
|
|
var expected = [
|
|
|
|
"pm-with:bob@zulip.com,",
|
|
|
|
"pm-with:bob@zulip.com,alice@zulip.com",
|
2017-07-05 02:58:05 +02:00
|
|
|
"pm-with:bob@zulip.com,jeff@zulip.com",
|
2017-02-05 22:11:18 +01:00
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// Only the last part of a comma-separated pm-with query should be used to
|
|
|
|
// generate suggestions.
|
|
|
|
query = 'pm-with:bob@zulip.com,t';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-02-05 22:11:18 +01:00
|
|
|
expected = [
|
|
|
|
"pm-with:bob@zulip.com,t",
|
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// Smit should also generate ted@zulip.com (Ted Smith) as a suggestion.
|
|
|
|
query = 'pm-with:bob@zulip.com,Smit';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-02-05 22:11:18 +01:00
|
|
|
expected = [
|
|
|
|
"pm-with:bob@zulip.com,Smit",
|
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-07-04 22:14:42 +02:00
|
|
|
// Do not suggest "bob@zulip.com" (the name of the current user)
|
|
|
|
query = 'pm-with:ted@zulip.com,bo';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-07-04 22:14:42 +02:00
|
|
|
expected = [
|
|
|
|
"pm-with:ted@zulip.com,bo",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-02-05 22:11:18 +01:00
|
|
|
// No superfluous suggestions should be generated.
|
|
|
|
query = 'pm-with:bob@zulip.com,red';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-02-05 22:11:18 +01:00
|
|
|
expected = [
|
|
|
|
"pm-with:bob@zulip.com,red",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// is:private should be properly prepended to each suggestion if the pm-with
|
|
|
|
// operator is negated.
|
|
|
|
|
|
|
|
query = '-pm-with:bob@zulip.com,';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-02-05 22:11:18 +01:00
|
|
|
expected = [
|
|
|
|
"-pm-with:bob@zulip.com,",
|
|
|
|
"is:private -pm-with:bob@zulip.com,alice@zulip.com",
|
2017-07-05 02:58:05 +02:00
|
|
|
"is:private -pm-with:bob@zulip.com,jeff@zulip.com",
|
2017-02-05 22:11:18 +01:00
|
|
|
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = '-pm-with:bob@zulip.com,t';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-02-05 22:11:18 +01:00
|
|
|
expected = [
|
|
|
|
"-pm-with:bob@zulip.com,t",
|
|
|
|
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = '-pm-with:bob@zulip.com,Smit';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-02-05 22:11:18 +01:00
|
|
|
expected = [
|
|
|
|
"-pm-with:bob@zulip.com,Smit",
|
|
|
|
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = '-pm-with:bob@zulip.com,red';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-02-05 22:11:18 +01:00
|
|
|
expected = [
|
|
|
|
"-pm-with:bob@zulip.com,red",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-06-03 09:19:57 +02:00
|
|
|
|
|
|
|
// Test multiple operators
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'pm-with:bob@zulip.com,Smit';
|
|
|
|
var base_query = 'is:starred has:link';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 09:19:57 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"pm-with:bob@zulip.com,Smit",
|
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com",
|
2017-06-03 09:19:57 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'pm-with:bob@zulip.com,Smit';
|
|
|
|
base_query = 'stream:Denmark has:link';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 09:19:57 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"pm-with:bob@zulip.com,Smit",
|
2017-06-03 09:19:57 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-07-05 02:58:05 +02:00
|
|
|
|
|
|
|
set_global('activity', {
|
2018-05-07 03:30:13 +02:00
|
|
|
get_huddles: function () {
|
|
|
|
return ['101,42', '101,103,42'];
|
|
|
|
},
|
2017-07-05 02:58:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Simulate a past huddle which should now prioritize ted over alice
|
|
|
|
query = 'pm-with:bob@zulip.com,';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-07-05 02:58:05 +02:00
|
|
|
expected = [
|
|
|
|
"pm-with:bob@zulip.com,",
|
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
"pm-with:bob@zulip.com,alice@zulip.com",
|
|
|
|
"pm-with:bob@zulip.com,jeff@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// bob,ted,jeff is already an existing huddle, so prioritize this one
|
|
|
|
query = 'pm-with:bob@zulip.com,ted@zulip.com,';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-07-05 02:58:05 +02:00
|
|
|
expected = [
|
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com,",
|
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com,jeff@zulip.com",
|
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com,alice@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// bob,ted,jeff is already an existing huddle, but if we start with just bob,
|
|
|
|
// then don't prioritize ted over alice because it doesn't complete the full huddle.
|
|
|
|
query = 'pm-with:jeff@zulip.com,';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-07-05 02:58:05 +02:00
|
|
|
expected = [
|
|
|
|
"pm-with:jeff@zulip.com,",
|
|
|
|
"pm-with:jeff@zulip.com,alice@zulip.com",
|
|
|
|
"pm-with:jeff@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-02-05 22:11:18 +01:00
|
|
|
|
2017-01-20 19:22:25 +01:00
|
|
|
init();
|
2016-12-15 22:18:59 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('empty_query_suggestions', () => {
|
2013-07-28 23:05:01 +02:00
|
|
|
var query = '';
|
|
|
|
|
2013-08-15 21:11:07 +02:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
2013-07-28 23:05:01 +02:00
|
|
|
return ['devel', 'office'];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2018-03-13 13:04:16 +01:00
|
|
|
return;
|
2013-07-28 23:05:01 +02:00
|
|
|
};
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2013-07-28 23:05:01 +02:00
|
|
|
|
|
|
|
var expected = [
|
|
|
|
"",
|
|
|
|
"is:private",
|
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
2013-08-30 21:15:01 +02:00
|
|
|
"is:alerted",
|
2017-06-19 00:33:24 +02:00
|
|
|
"is:unread",
|
2013-07-28 23:05:01 +02:00
|
|
|
"sender:bob@zulip.com",
|
|
|
|
"stream:devel",
|
2016-12-03 23:17:57 +01:00
|
|
|
"stream:office",
|
2018-05-18 10:10:49 +02:00
|
|
|
'has:link',
|
|
|
|
'has:image',
|
|
|
|
'has:attachment',
|
2013-07-28 23:05:01 +02:00
|
|
|
];
|
|
|
|
|
2013-07-30 19:41:23 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2013-07-30 22:39:32 +02:00
|
|
|
|
|
|
|
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');
|
2013-08-30 21:15:01 +02:00
|
|
|
assert.equal(describe('is:alerted'), 'Alerted messages');
|
2017-06-19 00:33:24 +02:00
|
|
|
assert.equal(describe('is:unread'), 'Unread messages');
|
2013-07-30 22:39:32 +02:00
|
|
|
assert.equal(describe('sender:bob@zulip.com'), 'Sent by me');
|
2018-05-18 10:10:49 +02:00
|
|
|
assert.equal(describe('has:link'), 'Messages with one or more link');
|
|
|
|
assert.equal(describe('has:image'), 'Messages with one or more image');
|
|
|
|
assert.equal(describe('has:attachment'), 'Messages with one or more attachment');
|
|
|
|
});
|
|
|
|
|
2018-05-20 16:38:28 +02:00
|
|
|
run_test('has_suggestions', () => {
|
2018-05-18 10:10:49 +02:00
|
|
|
// Checks that category wise suggestions are displayed instead of a single
|
|
|
|
// default suggestion when suggesting `has` operator.
|
|
|
|
var query = 'h';
|
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return ['devel', 'office'];
|
|
|
|
};
|
|
|
|
global.narrow_state.stream = function () {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2018-05-18 10:10:49 +02:00
|
|
|
var expected = [
|
|
|
|
"h",
|
|
|
|
'has:link',
|
|
|
|
'has:image',
|
|
|
|
'has:attachment',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
function describe(q) {
|
|
|
|
return suggestions.lookup_table[q].description;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(describe('has:link'), 'Messages with one or more link');
|
|
|
|
assert.equal(describe('has:image'), 'Messages with one or more image');
|
|
|
|
assert.equal(describe('has:attachment'), 'Messages with one or more attachment');
|
2018-05-20 16:30:06 +02:00
|
|
|
|
|
|
|
query = '-h';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-20 16:30:06 +02:00
|
|
|
expected = [
|
|
|
|
"-h",
|
|
|
|
'-has:link',
|
|
|
|
'-has:image',
|
|
|
|
'-has:attachment',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
assert.equal(describe('-has:link'), 'Exclude messages with one or more link');
|
|
|
|
assert.equal(describe('-has:image'), 'Exclude messages with one or more image');
|
|
|
|
assert.equal(describe('-has:attachment'), 'Exclude messages with one or more attachment');
|
2018-05-20 16:38:28 +02:00
|
|
|
|
|
|
|
// operand suggestions follow.
|
|
|
|
|
|
|
|
query = 'has:';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-20 16:38:28 +02:00
|
|
|
expected = [
|
|
|
|
'has:link',
|
|
|
|
'has:image',
|
|
|
|
'has:attachment',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'has:im';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-20 16:38:28 +02:00
|
|
|
expected = [
|
|
|
|
'has:image',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = '-has:im';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-20 16:38:28 +02:00
|
|
|
expected = [
|
|
|
|
'-has:image',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'att';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-20 16:38:28 +02:00
|
|
|
expected = [
|
|
|
|
'att',
|
|
|
|
'has:attachment',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'has:lin';
|
|
|
|
var base_query = 'stream:Denmark is:alerted';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2018-05-20 16:38:28 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'has:link',
|
2018-05-20 16:38:28 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2018-05-22 14:37:51 +02:00
|
|
|
run_test('check_is_suggestions', () => {
|
|
|
|
var query = 'i';
|
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return ['devel', 'office'];
|
|
|
|
};
|
|
|
|
global.narrow_state.stream = function () {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2018-05-22 14:37:51 +02:00
|
|
|
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';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-22 14:37:51 +02:00
|
|
|
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');
|
|
|
|
|
2018-07-04 01:48:10 +02:00
|
|
|
query = '';
|
|
|
|
suggestions = search.get_suggestions('', query);
|
|
|
|
expected = [
|
|
|
|
'',
|
|
|
|
'is:private',
|
|
|
|
'is:starred',
|
|
|
|
'is:mentioned',
|
|
|
|
'is:alerted',
|
|
|
|
'is:unread',
|
|
|
|
'sender:bob@zulip.com',
|
|
|
|
'stream:devel',
|
|
|
|
'stream:office',
|
|
|
|
'has:link',
|
|
|
|
'has:image',
|
|
|
|
'has:attachment',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = '';
|
|
|
|
var base_query = 'is:private';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
|
|
|
expected = [
|
|
|
|
'is:starred',
|
|
|
|
'is:mentioned',
|
|
|
|
'is:alerted',
|
|
|
|
'is:unread',
|
|
|
|
'sender:bob@zulip.com',
|
|
|
|
'has:link',
|
|
|
|
'has:image',
|
|
|
|
'has:attachment',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-05-22 14:37:51 +02:00
|
|
|
// operand suggestions follow.
|
|
|
|
|
|
|
|
query = 'is:';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-22 14:37:51 +02:00
|
|
|
expected = [
|
|
|
|
'is:private',
|
|
|
|
'is:starred',
|
|
|
|
'is:mentioned',
|
|
|
|
'is:alerted',
|
|
|
|
'is:unread',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'is:st';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-22 14:37:51 +02:00
|
|
|
expected = [
|
|
|
|
'is:starred',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = '-is:st';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-22 14:37:51 +02:00
|
|
|
expected = [
|
|
|
|
'-is:starred',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'st';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-22 14:37:51 +02:00
|
|
|
expected = [
|
|
|
|
'st',
|
|
|
|
'is:starred',
|
|
|
|
'stream:',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'is:sta';
|
2018-07-04 01:48:10 +02:00
|
|
|
base_query = 'stream:Denmark has:link';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2018-05-22 14:37:51 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'is:starred',
|
2018-05-22 14:37:51 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('sent_by_me_suggestions', () => {
|
2017-01-11 19:20:31 +01:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2018-03-13 13:04:16 +01:00
|
|
|
return;
|
2017-01-11 19:20:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
var query = '';
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2017-01-11 19:20:31 +01:00
|
|
|
assert(suggestions.strings.indexOf('sender:bob@zulip.com') !== -1);
|
|
|
|
assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description,
|
|
|
|
'Sent by me');
|
|
|
|
|
|
|
|
query = 'sender';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-01-11 19:20:31 +01:00
|
|
|
var expected = [
|
|
|
|
"sender",
|
|
|
|
"sender:bob@zulip.com",
|
2017-06-15 09:07:12 +02:00
|
|
|
"sender:",
|
2017-01-11 19:20:31 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-05-21 07:35:27 +02:00
|
|
|
query = '-sender';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-21 07:35:27 +02:00
|
|
|
expected = [
|
|
|
|
"-sender",
|
|
|
|
"-sender:bob@zulip.com",
|
|
|
|
"-sender:",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-01-11 19:20:31 +01:00
|
|
|
query = 'from';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-01-11 19:20:31 +01:00
|
|
|
expected = [
|
|
|
|
"from",
|
|
|
|
"from:bob@zulip.com",
|
2017-06-15 09:07:12 +02:00
|
|
|
"from:",
|
2017-01-11 19:20:31 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-05-21 07:35:27 +02:00
|
|
|
query = '-from';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-21 07:35:27 +02:00
|
|
|
expected = [
|
|
|
|
"-from",
|
|
|
|
"-from:bob@zulip.com",
|
|
|
|
"-from:",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-01-11 19:20:31 +01:00
|
|
|
query = 'sender:bob@zulip.com';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-01-11 19:20:31 +01:00
|
|
|
expected = [
|
|
|
|
"sender:bob@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'from:bob@zulip.com';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-01-11 19:20:31 +01:00
|
|
|
expected = [
|
|
|
|
"from:bob@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'sent';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-01-11 19:20:31 +01:00
|
|
|
expected = [
|
|
|
|
"sent",
|
|
|
|
"sender:bob@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-06-03 05:33:02 +02:00
|
|
|
|
2018-05-21 07:35:27 +02:00
|
|
|
query = '-sent';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-21 07:35:27 +02:00
|
|
|
expected = [
|
|
|
|
"-sent",
|
|
|
|
"-sender:bob@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'sent';
|
|
|
|
var base_query = 'stream:Denmark topic:Denmark1';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 05:33:02 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"sent",
|
|
|
|
"sender:bob@zulip.com",
|
2017-06-03 05:33:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'sender:m';
|
|
|
|
base_query = 'is:starred';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 05:33:02 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"sender:m",
|
|
|
|
"sender:bob@zulip.com",
|
2017-06-03 05:33:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'sender:';
|
|
|
|
base_query = 'is:starred';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-03 05:33:02 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"sender:",
|
|
|
|
"sender:bob@zulip.com",
|
2017-06-03 05:33:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-01-11 19:20:31 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('topic_suggestions', () => {
|
2014-02-20 17:29:14 +01:00
|
|
|
var suggestions;
|
|
|
|
var expected;
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2013-08-15 21:11:07 +02:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
2013-07-28 23:05:01 +02:00
|
|
|
return ['office'];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2013-07-28 23:05:01 +02:00
|
|
|
return 'office';
|
|
|
|
};
|
|
|
|
|
2017-05-14 15:39:02 +02:00
|
|
|
var devel_id = 44;
|
|
|
|
var office_id = 77;
|
|
|
|
|
|
|
|
global.stream_data.get_stream_id = function (stream_name) {
|
|
|
|
switch (stream_name) {
|
2018-05-07 03:30:13 +02:00
|
|
|
case 'office': return office_id;
|
|
|
|
case 'devel': return devel_id;
|
2017-05-14 15:39:02 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.reset();
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', 'te');
|
2017-07-24 15:15:28 +02:00
|
|
|
expected = [
|
|
|
|
"te",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-05-14 15:39:02 +02:00
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.add_message({
|
|
|
|
stream_id: devel_id,
|
|
|
|
topic_name: 'REXX',
|
|
|
|
});
|
2017-05-14 15:39:02 +02:00
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
_.each(['team', 'ignore', 'test'], function (topic_name) {
|
|
|
|
topic_data.add_message({
|
|
|
|
stream_id: office_id,
|
|
|
|
topic_name: topic_name,
|
|
|
|
});
|
|
|
|
});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', 'te');
|
2014-02-20 17:29:14 +01:00
|
|
|
expected = [
|
2013-07-28 23:05:01 +02:00
|
|
|
"te",
|
|
|
|
"stream:office topic:team",
|
2016-12-03 23:17:57 +01:00
|
|
|
"stream:office topic:test",
|
2013-07-28 23:05:01 +02:00
|
|
|
];
|
2013-07-30 19:41:23 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2013-07-30 22:39:32 +02:00
|
|
|
|
|
|
|
function describe(q) {
|
|
|
|
return suggestions.lookup_table[q].description;
|
|
|
|
}
|
|
|
|
assert.equal(describe('te'), "Search for te");
|
2018-04-10 20:22:15 +02:00
|
|
|
assert.equal(describe('stream:office topic:team'), "Stream office > team");
|
2013-07-30 22:39:32 +02:00
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('topic:staplers', 'stream:office');
|
2014-02-20 17:29:14 +01:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'stream:office',
|
2014-02-20 17:29:14 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('stream:devel', 'topic:');
|
2014-02-20 17:29:14 +01:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'topic:',
|
|
|
|
'topic:REXX',
|
2014-02-20 17:29:14 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2014-03-04 22:52:13 +01:00
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('stream:devel', '-topic:');
|
2014-03-04 22:52:13 +01:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'-topic:',
|
|
|
|
'-topic:REXX',
|
2014-03-04 22:52:13 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', '-topic:te');
|
2014-03-04 22:52:13 +01:00
|
|
|
expected = [
|
|
|
|
'-topic:te',
|
|
|
|
'stream:office -topic:team',
|
2016-12-03 23:17:57 +01:00
|
|
|
'stream:office -topic:test',
|
2014-03-04 22:52:13 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-06-03 22:54:35 +02:00
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('is:alerted stream:devel is:starred', 'topic:');
|
2017-06-03 22:54:35 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'topic:',
|
|
|
|
'topic:REXX',
|
2017-06-03 22:54:35 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('is:private stream:devel', 'topic:');
|
2017-06-03 22:54:35 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'topic:',
|
2017-06-03 22:54:35 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('topic:REXX stream:devel', 'topic:');
|
2017-06-03 22:54:35 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'topic:',
|
2017-06-03 22:54:35 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('whitespace_glitch', () => {
|
2013-08-06 19:08:39 +02:00
|
|
|
var query = 'stream:office '; // note trailing space
|
|
|
|
|
2013-08-15 21:11:07 +02:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
2013-08-06 19:08:39 +02:00
|
|
|
return ['office'];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2013-08-06 19:08:39 +02:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.reset();
|
2013-08-06 19:08:39 +02:00
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2013-08-06 19:08:39 +02:00
|
|
|
|
|
|
|
var expected = [
|
2016-12-03 23:17:57 +01:00
|
|
|
"stream:office",
|
2013-08-06 19:08:39 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('stream_completion', () => {
|
2014-02-20 16:28:52 +01:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
2017-06-23 08:39:37 +02:00
|
|
|
return ['office', 'dev help'];
|
2014-02-20 16:28:52 +01:00
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2014-02-20 16:28:52 +01:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.reset();
|
2014-02-20 16:28:52 +01:00
|
|
|
|
2017-06-23 08:39:37 +02:00
|
|
|
var query = 'stream:of';
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('s', query);
|
2014-02-20 16:28:52 +01:00
|
|
|
var expected = [
|
|
|
|
"stream:of",
|
2016-12-03 23:17:57 +01:00
|
|
|
"stream:office",
|
2014-02-20 16:28:52 +01:00
|
|
|
];
|
2017-06-23 08:39:37 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-21 06:23:08 +02:00
|
|
|
|
|
|
|
query = '-stream:of';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2018-05-21 06:23:08 +02:00
|
|
|
expected = [
|
|
|
|
"-stream:of",
|
|
|
|
"-stream:office",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2014-02-20 16:28:52 +01:00
|
|
|
|
2017-06-23 08:39:37 +02:00
|
|
|
query = 'hel';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-06-23 08:39:37 +02:00
|
|
|
expected = [
|
|
|
|
"hel",
|
|
|
|
"stream:dev+help",
|
|
|
|
];
|
2014-02-20 16:28:52 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2014-02-20 16:28:52 +01:00
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
function people_suggestion_setup() {
|
|
|
|
global.stream_data.subscribed_streams = noop;
|
|
|
|
global.narrow_state.stream = noop;
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
const ted = {
|
2016-11-01 19:37:19 +01:00
|
|
|
email: 'ted@zulip.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 201,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Ted Smith',
|
2016-11-01 19:37:19 +01:00
|
|
|
};
|
2019-04-23 18:02:06 +02:00
|
|
|
people.add(ted);
|
2016-11-01 19:37:19 +01:00
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
const bob = {
|
2016-11-01 19:37:19 +01:00
|
|
|
email: 'bob@zulip.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 202,
|
2017-06-23 08:39:37 +02:00
|
|
|
full_name: 'Bob Térry',
|
2016-11-01 19:37:19 +01:00
|
|
|
};
|
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
people.add(bob);
|
|
|
|
const alice = {
|
2016-11-01 19:37:19 +01:00
|
|
|
email: 'alice@zulip.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 203,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice Ignore',
|
2016-11-01 19:37:19 +01:00
|
|
|
};
|
|
|
|
people.add(alice);
|
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.reset();
|
2019-04-23 18:02:06 +02:00
|
|
|
}
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
run_test('people_suggestions', () => {
|
|
|
|
people_suggestion_setup();
|
|
|
|
let query = 'te';
|
|
|
|
let suggestions = search.get_suggestions('', query);
|
|
|
|
let expected = [
|
2013-07-28 23:05:01 +02:00
|
|
|
"te",
|
2014-02-20 16:47:29 +01:00
|
|
|
"sender:bob@zulip.com",
|
2016-12-03 23:17:57 +01:00
|
|
|
"sender:ted@zulip.com",
|
2018-05-21 07:46:25 +02:00
|
|
|
"pm-with:bob@zulip.com", // bob térry
|
|
|
|
"pm-with:ted@zulip.com",
|
2017-06-04 01:51:53 +02:00
|
|
|
"group-pm-with:bob@zulip.com",
|
|
|
|
"group-pm-with:ted@zulip.com",
|
2013-07-28 23:05:01 +02:00
|
|
|
];
|
|
|
|
|
2013-07-30 19:41:23 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2019-04-23 18:02:06 +02:00
|
|
|
|
|
|
|
const describe = (q) => suggestions.lookup_table[q].description;
|
|
|
|
|
2013-07-30 22:39:32 +02:00
|
|
|
assert.equal(describe('pm-with:ted@zulip.com'),
|
2018-05-07 03:30:13 +02:00
|
|
|
"Private messages with <strong>Te</strong>d Smith <<strong>te</strong>d@zulip.com>");
|
2013-07-30 22:39:32 +02:00
|
|
|
assert.equal(describe('sender:ted@zulip.com'),
|
2018-05-07 03:30:13 +02:00
|
|
|
"Sent by <strong>Te</strong>d Smith <<strong>te</strong>d@zulip.com>");
|
2013-07-30 22:39:32 +02:00
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', 'Ted '); // note space
|
2013-08-07 15:40:47 +02:00
|
|
|
expected = [
|
|
|
|
"Ted",
|
2016-12-03 23:17:57 +01:00
|
|
|
"sender:ted@zulip.com",
|
2018-05-21 07:46:25 +02:00
|
|
|
"pm-with:ted@zulip.com",
|
2017-06-04 01:51:53 +02:00
|
|
|
"group-pm-with:ted@zulip.com",
|
2013-08-07 15:40:47 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2016-11-01 19:37:19 +01:00
|
|
|
|
2018-05-25 17:03:13 +02:00
|
|
|
query = 'sender:ted sm';
|
2019-04-23 18:02:06 +02:00
|
|
|
let base_query = '';
|
2018-05-25 17:03:13 +02:00
|
|
|
expected = [
|
|
|
|
'sender:ted+sm',
|
|
|
|
'sender:ted@zulip.com',
|
|
|
|
];
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2018-05-25 17:03:13 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = 'new';
|
|
|
|
base_query = 'sender:ted@zulip.com';
|
2018-05-25 17:03:13 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'new',
|
2018-05-25 17:03:13 +02:00
|
|
|
];
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2018-05-25 17:03:13 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'sender:ted@tulip.com new';
|
2018-07-02 22:30:18 +02:00
|
|
|
base_query = '';
|
2018-05-25 17:03:13 +02:00
|
|
|
expected = [
|
|
|
|
'sender:ted@tulip.com+new',
|
|
|
|
];
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'new';
|
|
|
|
base_query = 'sender:ted@tulip.com';
|
|
|
|
expected = [
|
|
|
|
'new',
|
|
|
|
];
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2018-05-25 17:03:13 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-05 09:54:56 +02:00
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
run_test('people_suggestion (Admin only email visibility)', () => {
|
|
|
|
/* Suggestions when realm_email_address_visibility is set to admin
|
|
|
|
only */
|
|
|
|
people_suggestion_setup();
|
|
|
|
const query = 'te';
|
|
|
|
settings_org.show_email = () => false;
|
|
|
|
const suggestions = search.get_suggestions('', query);
|
|
|
|
const expected = [
|
|
|
|
"te",
|
|
|
|
"sender:bob@zulip.com",
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
"pm-with:bob@zulip.com", // bob térry
|
|
|
|
"pm-with:ted@zulip.com",
|
|
|
|
"group-pm-with:bob@zulip.com",
|
|
|
|
"group-pm-with:ted@zulip.com",
|
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
const describe = (q) => suggestions.lookup_table[q].description;
|
|
|
|
|
|
|
|
assert.equal(describe('pm-with:ted@zulip.com'),
|
|
|
|
'Private messages with <strong>Te</strong>d Smith');
|
|
|
|
assert.equal(describe('sender:ted@zulip.com'),
|
|
|
|
'Sent by <strong>Te</strong>d Smith');
|
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('operator_suggestions', () => {
|
2017-06-15 09:07:12 +02:00
|
|
|
// Completed operator should return nothing
|
|
|
|
var query = 'stream:';
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2017-06-15 09:07:12 +02:00
|
|
|
var expected = [
|
|
|
|
'stream:',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'st';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-06-15 09:07:12 +02:00
|
|
|
expected = [
|
|
|
|
'st',
|
|
|
|
'is:starred',
|
|
|
|
'stream:',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-09-24 18:02:56 +02:00
|
|
|
query = 'group-';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-09-24 18:02:56 +02:00
|
|
|
expected = [
|
|
|
|
'group-',
|
|
|
|
'group-pm-with:',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-06-15 09:07:12 +02:00
|
|
|
query = '-s';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-06-15 09:07:12 +02:00
|
|
|
expected = [
|
|
|
|
'-s',
|
2018-05-21 07:35:27 +02:00
|
|
|
'-sender:bob@zulip.com',
|
2017-06-15 09:07:12 +02:00
|
|
|
'-stream:',
|
|
|
|
'-sender:',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-07-02 22:30:18 +02:00
|
|
|
query = '-f';
|
|
|
|
var base_query = 'stream:Denmark is:alerted';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
2017-06-15 09:07:12 +02:00
|
|
|
expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
'-f',
|
|
|
|
'-from:bob@zulip.com',
|
|
|
|
'-from:',
|
2017-06-15 09:07:12 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-12 08:44:41 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('queries_with_spaces', () => {
|
2017-07-12 08:44:41 +02:00
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return ['office', 'dev help'];
|
|
|
|
};
|
|
|
|
|
|
|
|
global.narrow_state.stream = function () {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2017-07-24 22:16:13 +02:00
|
|
|
topic_data.reset();
|
2017-07-12 08:44:41 +02:00
|
|
|
|
|
|
|
// test allowing spaces with quotes surrounding operand
|
|
|
|
var query = 'stream:"dev he"';
|
2018-07-02 22:30:18 +02:00
|
|
|
var suggestions = search.get_suggestions('', query);
|
2017-07-12 08:44:41 +02:00
|
|
|
var expected = [
|
|
|
|
"stream:dev+he",
|
|
|
|
"stream:dev+help",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// test mismatched quote
|
|
|
|
query = 'stream:"dev h';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-07-12 08:44:41 +02:00
|
|
|
expected = [
|
|
|
|
"stream:dev+h",
|
|
|
|
"stream:dev+help",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// test extra space after operator still works
|
|
|
|
query = 'stream: offi';
|
2018-07-02 22:30:18 +02:00
|
|
|
suggestions = search.get_suggestions('', query);
|
2017-07-12 08:44:41 +02:00
|
|
|
expected = [
|
|
|
|
"stream:offi",
|
|
|
|
"stream:office",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-07-02 22:30:18 +02:00
|
|
|
|
|
|
|
// When input search query contains multiple operators
|
|
|
|
// and a pill hasn't been formed from those operators.
|
|
|
|
run_test('multiple_operators_without_pills', () => {
|
|
|
|
var query = 'is:private al';
|
|
|
|
var base_query = '';
|
|
|
|
var suggestions = search.get_suggestions(base_query, query);
|
|
|
|
var expected = [
|
|
|
|
"is:private al",
|
|
|
|
"is:private is:alerted",
|
|
|
|
"is:private sender:alice@zulip.com",
|
|
|
|
"is:private pm-with:alice@zulip.com",
|
|
|
|
"is:private group-pm-with:alice@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'abc is:alerted sender:ted@zulip.com';
|
|
|
|
base_query = '';
|
|
|
|
suggestions = search.get_suggestions(base_query, query);
|
|
|
|
expected = [
|
|
|
|
"is:alerted sender:ted@zulip.com abc",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|