2013-07-30 23:02:10 +02:00
|
|
|
// Unit test the search_suggestion.js module.
|
2013-07-28 23:05:01 +02:00
|
|
|
//
|
|
|
|
// These tests are framework-free and run sequentially; they are invoked
|
|
|
|
// immediately after being defined. The contract here is that tests should
|
|
|
|
// clean up after themselves, and they should explicitly stub all
|
|
|
|
// dependencies.
|
|
|
|
|
2013-08-21 20:27:14 +02:00
|
|
|
add_dependencies({
|
|
|
|
util: 'js/util.js',
|
|
|
|
Handlebars: 'handlebars',
|
|
|
|
Filter: 'js/filter.js',
|
|
|
|
typeahead_helper: 'js/typeahead_helper.js',
|
2016-11-01 19:37:19 +01:00
|
|
|
people: 'js/people.js',
|
2013-08-21 20:27:14 +02:00
|
|
|
stream_data: 'js/stream_data.js',
|
2017-04-25 15:25:31 +02:00
|
|
|
narrow_state: 'js/narrow_state.js',
|
2013-08-21 20:27:14 +02:00
|
|
|
});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2016-11-01 19:37:19 +01:00
|
|
|
var people = global.people;
|
|
|
|
|
2013-08-22 00:01:14 +02:00
|
|
|
var search = require('js/search_suggestion.js');
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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', {});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2016-10-28 18:26:30 +02:00
|
|
|
global.stream_data.populate_stream_topics_for_tests({});
|
|
|
|
|
2013-07-28 23:05:01 +02:00
|
|
|
(function test_basic_get_suggestions() {
|
|
|
|
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';
|
|
|
|
};
|
|
|
|
|
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
|
|
|
|
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);
|
2013-07-28 23:05:01 +02:00
|
|
|
}());
|
|
|
|
|
2013-08-28 01:23:42 +02:00
|
|
|
(function test_subset_suggestions() {
|
|
|
|
var query = 'stream:Denmark topic:Hamlet shakespeare';
|
|
|
|
|
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2013-08-28 01:23:42 +02:00
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
|
|
|
|
var expected = [
|
|
|
|
"stream:Denmark topic:Hamlet shakespeare",
|
|
|
|
"stream:Denmark topic:Hamlet",
|
2016-12-03 23:17:57 +01:00
|
|
|
"stream:Denmark",
|
2013-08-28 01:23:42 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
}());
|
|
|
|
|
2013-08-28 01:45:39 +02:00
|
|
|
(function test_private_suggestions() {
|
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2013-08-28 01:45:39 +02:00
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
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';
|
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
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);
|
|
|
|
|
2014-01-21 20:53:52 +01:00
|
|
|
query = 'is:private al';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"is:private al",
|
2017-06-03 04:32:25 +02:00
|
|
|
"is:private is:alerted",
|
2017-06-03 09:19:57 +02:00
|
|
|
"is:private pm-with:alice@zulip.com",
|
|
|
|
"is:private sender:alice@zulip.com",
|
2016-12-03 23:17:57 +01:00
|
|
|
"is:private",
|
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';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
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';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
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';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"pm-with:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2013-10-07 20:48:25 +02:00
|
|
|
query = 'sender:ted';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"sender:ted",
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'sender:te';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"sender:te",
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2014-03-04 23:22:15 +01:00
|
|
|
query = '-sender:te';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
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';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-06-19 00:33:24 +02:00
|
|
|
query = 'is:unread from:ted';
|
2017-01-11 19:13:13 +01:00
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
2017-06-19 00:33:24 +02:00
|
|
|
"is:unread from:ted",
|
|
|
|
"is:unread from:ted@zulip.com",
|
|
|
|
"is:unread",
|
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.
|
|
|
|
query = 'is:private near:3';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"is:private near:3",
|
2016-12-03 23:17:57 +01:00
|
|
|
"is:private",
|
2013-08-28 01:45:39 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'pm-with:ted@zulip.com near:3';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"pm-with:ted@zulip.com near:3",
|
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);
|
2017-06-03 09:19:57 +02:00
|
|
|
|
|
|
|
// Make sure suggestions still work if preceding tokens
|
|
|
|
query = 'is:alerted sender:ted@zulip.com';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"is:alerted sender:ted@zulip.com",
|
|
|
|
"is:alerted",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'is:starred has:link is:private al';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"is:starred has:link is:private al",
|
|
|
|
"is:starred has:link is:private is:alerted",
|
|
|
|
"is:starred has:link is:private pm-with:alice@zulip.com",
|
|
|
|
"is:starred has:link is:private sender:alice@zulip.com",
|
|
|
|
"is:starred has:link is:private",
|
|
|
|
"is:starred has:link",
|
|
|
|
"is:starred",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// Make sure it handles past context correctly
|
|
|
|
query = 'stream:Denmark pm-with:';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
'stream:Denmark pm-with:',
|
|
|
|
'stream:Denmark',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'sender:ted@zulip.com sender:';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
'sender:ted@zulip.com sender:',
|
|
|
|
'sender:ted@zulip.com',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2013-08-28 01:45:39 +02:00
|
|
|
}());
|
|
|
|
|
2017-02-05 22:11:18 +01:00
|
|
|
(function test_group_suggestions() {
|
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2017-02-05 22:11:18 +01:00
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
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',
|
|
|
|
};
|
|
|
|
|
|
|
|
people.add(ted);
|
|
|
|
people.add(alice);
|
|
|
|
|
|
|
|
// Entering a comma in a pm-with query should immediately generate
|
|
|
|
// suggestions for the next person.
|
|
|
|
var query = 'pm-with:bob@zulip.com,';
|
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
var expected = [
|
|
|
|
"pm-with:bob@zulip.com,",
|
|
|
|
"pm-with:bob@zulip.com,alice@zulip.com",
|
|
|
|
"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';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
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';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"pm-with:bob@zulip.com,Smit",
|
|
|
|
"pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// No superfluous suggestions should be generated.
|
|
|
|
query = 'pm-with:bob@zulip.com,red';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
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,';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"-pm-with:bob@zulip.com,",
|
|
|
|
"is:private -pm-with:bob@zulip.com,alice@zulip.com",
|
|
|
|
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = '-pm-with:bob@zulip.com,t';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
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';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
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';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"-pm-with:bob@zulip.com,red",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-06-03 09:19:57 +02:00
|
|
|
|
|
|
|
// Test multiple operators
|
|
|
|
query = 'is:starred has:link pm-with:bob@zulip.com,Smit';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"is:starred has:link pm-with:bob@zulip.com,Smit",
|
|
|
|
"is:starred has:link pm-with:bob@zulip.com,ted@zulip.com",
|
|
|
|
"is:starred has:link",
|
|
|
|
"is:starred",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'stream:Denmark has:link pm-with:bob@zulip.com,Smit';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"stream:Denmark has:link pm-with:bob@zulip.com,Smit",
|
|
|
|
"stream:Denmark has:link",
|
|
|
|
"stream:Denmark",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
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
|
|
|
|
2013-07-28 23:05:01 +02:00
|
|
|
(function test_empty_query_suggestions() {
|
|
|
|
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 () {
|
2013-07-28 23:05:01 +02:00
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
|
|
|
|
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",
|
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');
|
2017-06-06 02:28:12 +02:00
|
|
|
assert.equal(describe('stream:devel'), 'Stream <strong>devel</strong>');
|
2013-07-28 23:05:01 +02:00
|
|
|
}());
|
|
|
|
|
2017-01-11 19:20:31 +01:00
|
|
|
(function test_sent_by_me_suggestions() {
|
|
|
|
global.stream_data.subscribed_streams = function () {
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
global.narrow_state.stream = function () {
|
2017-01-11 19:20:31 +01:00
|
|
|
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",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'from:bob@zulip.com';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"from:bob@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'sent';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"sent",
|
|
|
|
"sender:bob@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-06-03 05:33:02 +02:00
|
|
|
|
|
|
|
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);
|
2017-01-11 19:20:31 +01:00
|
|
|
}());
|
|
|
|
|
2013-07-28 23:05:01 +02:00
|
|
|
(function 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) {
|
|
|
|
case 'office': return office_id;
|
|
|
|
case 'devel': return devel_id;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var recent_data = {};
|
|
|
|
|
|
|
|
recent_data[devel_id] = [
|
|
|
|
{subject: 'REXX'},
|
|
|
|
];
|
|
|
|
|
|
|
|
recent_data[office_id] = [
|
|
|
|
{subject: 'team'},
|
|
|
|
{subject: 'ignore'},
|
|
|
|
{subject: 'test'},
|
|
|
|
];
|
|
|
|
|
|
|
|
global.stream_data.populate_stream_topics_for_tests(recent_data);
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2014-02-20 17:29:14 +01:00
|
|
|
suggestions = search.get_suggestions('te');
|
|
|
|
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");
|
2017-06-06 02:28:12 +02:00
|
|
|
assert.equal(describe('stream:office topic:team'), "Stream office > team");
|
2013-07-30 22:39:32 +02:00
|
|
|
|
2014-02-20 17:29:14 +01:00
|
|
|
suggestions = search.get_suggestions('topic:staplers stream:office');
|
|
|
|
expected = [
|
|
|
|
'topic:staplers stream:office',
|
2016-12-03 23:17:57 +01:00
|
|
|
'topic:staplers',
|
2014-02-20 17:29:14 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
suggestions = search.get_suggestions('stream:devel topic:');
|
|
|
|
expected = [
|
|
|
|
'stream:devel topic:',
|
|
|
|
'stream:devel topic:REXX',
|
2016-12-03 23:17:57 +01:00
|
|
|
'stream:devel',
|
2014-02-20 17:29:14 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2014-03-04 22:52:13 +01:00
|
|
|
|
|
|
|
suggestions = search.get_suggestions('stream:devel -topic:');
|
|
|
|
expected = [
|
|
|
|
'stream:devel -topic:',
|
|
|
|
'stream:devel -topic:REXX',
|
2016-12-03 23:17:57 +01:00
|
|
|
'stream:devel',
|
2014-03-04 22:52:13 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
suggestions = search.get_suggestions('-topic:te');
|
|
|
|
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
|
|
|
|
|
|
|
suggestions = search.get_suggestions('is:alerted stream:devel is:starred topic:');
|
|
|
|
expected = [
|
|
|
|
'is:alerted stream:devel is:starred topic:',
|
|
|
|
'is:alerted stream:devel is:starred topic:REXX',
|
|
|
|
'is:alerted stream:devel is:starred',
|
|
|
|
'is:alerted stream:devel',
|
|
|
|
'is:alerted',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
suggestions = search.get_suggestions('is:private stream:devel topic:');
|
|
|
|
expected = [
|
|
|
|
'is:private stream:devel topic:',
|
|
|
|
'is:private stream:devel',
|
|
|
|
'is:private',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
suggestions = search.get_suggestions('topic:REXX stream:devel topic:');
|
|
|
|
expected = [
|
|
|
|
'topic:REXX stream:devel topic:',
|
|
|
|
'topic:REXX stream:devel',
|
|
|
|
'topic:REXX',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2013-07-28 23:05:01 +02:00
|
|
|
}());
|
|
|
|
|
2013-08-06 19:08:39 +02:00
|
|
|
(function test_whitespace_glitch() {
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2016-10-28 18:26:30 +02:00
|
|
|
global.stream_data.populate_stream_topics_for_tests({});
|
2013-08-06 19:08:39 +02:00
|
|
|
|
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}());
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2014-02-20 16:28:52 +01:00
|
|
|
(function test_stream_completion() {
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2016-10-28 18:26:30 +02:00
|
|
|
global.stream_data.populate_stream_topics_for_tests({});
|
2014-02-20 16:28:52 +01:00
|
|
|
|
2017-06-23 08:39:37 +02:00
|
|
|
var query = 'stream:of';
|
2014-02-20 16:28:52 +01:00
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
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);
|
2014-02-20 16:28:52 +01:00
|
|
|
|
2017-06-23 08:39:37 +02:00
|
|
|
query = 'hel';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
"hel",
|
|
|
|
"stream:dev+help",
|
|
|
|
];
|
2014-02-20 16:28:52 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
}());
|
|
|
|
|
2013-07-28 23:05:01 +02:00
|
|
|
(function test_people_suggestions() {
|
|
|
|
var query = 'te';
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2016-11-01 19:37:19 +01:00
|
|
|
var ted = {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
var bob = {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
var alice = {
|
|
|
|
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(ted);
|
|
|
|
people.add(bob);
|
|
|
|
people.add(alice);
|
|
|
|
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2016-10-28 18:26:30 +02:00
|
|
|
global.stream_data.populate_stream_topics_for_tests({
|
2013-07-28 23:05:01 +02:00
|
|
|
office: [
|
|
|
|
{subject: 'team'},
|
|
|
|
{subject: 'ignore'},
|
2016-12-03 23:17:57 +01:00
|
|
|
{subject: 'test'},
|
|
|
|
],
|
2016-10-28 18:26:30 +02:00
|
|
|
});
|
2013-07-28 23:05:01 +02:00
|
|
|
|
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
|
|
|
|
var expected = [
|
|
|
|
"te",
|
2017-06-23 08:39:37 +02:00
|
|
|
"pm-with:bob@zulip.com", // bob térry
|
2013-07-28 23:05:01 +02:00
|
|
|
"pm-with:ted@zulip.com",
|
2014-02-20 16:47:29 +01:00
|
|
|
"sender:bob@zulip.com",
|
2016-12-03 23:17:57 +01:00
|
|
|
"sender:ted@zulip.com",
|
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('pm-with:ted@zulip.com'),
|
2017-06-06 02:28:12 +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'),
|
2017-06-06 02:28:12 +02:00
|
|
|
"Messages sent by <strong>Te</strong>d Smith <<strong>te</strong>d@zulip.com>");
|
2013-07-30 22:39:32 +02:00
|
|
|
|
2013-08-07 15:40:47 +02:00
|
|
|
suggestions = search.get_suggestions('Ted '); // note space
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
"Ted",
|
|
|
|
"pm-with:ted@zulip.com",
|
2016-12-03 23:17:57 +01:00
|
|
|
"sender:ted@zulip.com",
|
2013-08-07 15:40:47 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2016-11-01 19:37:19 +01:00
|
|
|
|
2013-07-28 23:05:01 +02:00
|
|
|
}());
|
2017-06-05 09:54:56 +02:00
|
|
|
|
|
|
|
(function test_contains_suggestions() {
|
|
|
|
var query = 'has:';
|
|
|
|
var suggestions = search.get_suggestions(query);
|
|
|
|
var expected = [
|
|
|
|
'has:',
|
|
|
|
'has:link',
|
|
|
|
'has:image',
|
|
|
|
'has:attachment',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'has:im';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
'has:im',
|
|
|
|
'has:image',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-06-15 09:10:52 +02:00
|
|
|
query = '-has:im';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
'-has:im',
|
|
|
|
'-has:image',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-06-05 09:54:56 +02:00
|
|
|
query = 'att';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
'att',
|
|
|
|
'has:attachment',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = 'stream:Denmark is:alerted has:lin';
|
|
|
|
suggestions = search.get_suggestions(query);
|
|
|
|
expected = [
|
|
|
|
'stream:Denmark is:alerted has:lin',
|
|
|
|
'stream:Denmark is:alerted has:link',
|
|
|
|
'stream:Denmark is:alerted',
|
|
|
|
'stream:Denmark',
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
}());
|