2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-04-20 00:11:23 +02:00
|
|
|
const {mock_esm, with_field, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-03-25 22:35:45 +01:00
|
|
|
const {page_params} = require("../zjsunit/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-04-20 00:11:23 +02:00
|
|
|
const stream_topic_history_util = mock_esm("../../static/js/stream_topic_history_util");
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const settings_config = zrequire("settings_config");
|
2020-02-25 12:46:14 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const huddle_data = zrequire("huddle_data");
|
2020-05-26 14:25:21 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const narrow_state = zrequire("narrow_state");
|
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
const stream_topic_history = zrequire("stream_topic_history");
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2020-07-15 01:29:15 +02:00
|
|
|
const search = zrequire("search_suggestion");
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2021-02-28 01:04:35 +01:00
|
|
|
search.__Rewire__("max_num_of_search_results", 15);
|
2020-01-07 14:21:35 +01:00
|
|
|
|
2020-05-26 15:40:46 +02:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "myself@zulip.com",
|
|
|
|
full_name: "Me Myself",
|
2020-05-26 15:40:46 +02:00
|
|
|
user_id: 41,
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "bob@zulip.com",
|
|
|
|
full_name: "Bob Roberts",
|
2017-01-20 19:22:25 +01:00
|
|
|
user_id: 42,
|
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const ted = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "ted@zulip.com",
|
2020-05-26 16:06:57 +02:00
|
|
|
user_id: 101,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Ted Smith",
|
2020-05-26 16:06:57 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@zulip.com",
|
2020-05-26 16:06:57 +02:00
|
|
|
user_id: 102,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice Ignore",
|
2020-05-26 16:06:57 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const jeff = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "jeff@zulip.com",
|
2020-05-26 16:06:57 +02:00
|
|
|
user_id: 103,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Jeff Zoolipson",
|
2020-05-26 16:06:57 +02:00
|
|
|
};
|
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
const noop = () => {};
|
2017-01-20 19:22:25 +01:00
|
|
|
|
|
|
|
function init() {
|
2021-04-03 19:07:13 +02:00
|
|
|
page_params.is_admin = true;
|
|
|
|
page_params.search_pills_enabled = true;
|
|
|
|
page_params.realm_email_address_visibility =
|
|
|
|
settings_config.email_address_visibility_values.admins_only.code;
|
|
|
|
|
2017-01-20 19:22:25 +01:00
|
|
|
people.init();
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(bob);
|
|
|
|
people.add_active_user(me);
|
|
|
|
people.add_active_user(ted);
|
|
|
|
people.add_active_user(alice);
|
|
|
|
people.add_active_user(jeff);
|
2020-05-26 16:06:57 +02:00
|
|
|
|
2020-05-26 15:40:46 +02:00
|
|
|
people.initialize_current_user(me.user_id);
|
2021-03-12 19:42:25 +01:00
|
|
|
|
|
|
|
stream_topic_history.reset();
|
|
|
|
huddle_data.clear_for_testing();
|
2017-01-20 19:22:25 +01:00
|
|
|
}
|
2013-08-20 18:45:09 +02:00
|
|
|
|
2019-12-24 00:17:39 +01:00
|
|
|
function get_suggestions(base_query, query) {
|
|
|
|
return search.get_suggestions(base_query, query);
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:42:25 +01:00
|
|
|
function test(label, f) {
|
2022-01-08 10:27:06 +01:00
|
|
|
run_test(label, ({override, override_rewire}) => {
|
2021-03-12 19:42:25 +01:00
|
|
|
init();
|
2022-01-08 10:27:06 +01:00
|
|
|
f({override, override_rewire});
|
2021-03-12 19:42:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("basic_get_suggestions", ({override_rewire}) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
const query = "fred";
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_data, "subscribed_streams", () => []);
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(narrow_state, "stream", () => "office");
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const suggestions = get_suggestions("", query);
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const expected = ["fred"];
|
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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("basic_get_suggestions_for_spectator", ({override_rewire}) => {
|
|
|
|
override_rewire(stream_data, "subscribed_streams", () => []);
|
2020-08-31 09:40:36 +02:00
|
|
|
page_params.is_spectator = true;
|
|
|
|
|
|
|
|
const query = "";
|
|
|
|
const suggestions = get_suggestions("", query);
|
|
|
|
assert.deepEqual(suggestions.strings, [
|
|
|
|
"",
|
|
|
|
"streams:public",
|
|
|
|
"is:private",
|
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
|
|
|
"is:alerted",
|
|
|
|
"is:unread",
|
2021-07-13 10:03:26 +02:00
|
|
|
"is:resolved",
|
2020-08-31 09:40:36 +02:00
|
|
|
"has:link",
|
|
|
|
"has:image",
|
|
|
|
"has:attachment",
|
|
|
|
// "sender:myself@zulip.com",
|
|
|
|
]);
|
|
|
|
page_params.is_spectator = false;
|
|
|
|
});
|
|
|
|
|
2021-03-12 19:42:25 +01:00
|
|
|
test("subset_suggestions", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
const query = "shakespeare";
|
|
|
|
const base_query = "stream:Denmark topic:Hamlet";
|
2013-08-28 01:23:42 +02:00
|
|
|
|
2019-12-24 00:17:39 +01:00
|
|
|
const suggestions = get_suggestions(base_query, query);
|
2013-08-28 01:23:42 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const expected = ["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
|
|
|
|
2021-03-12 19:42:25 +01:00
|
|
|
test("private_suggestions", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "is:private";
|
|
|
|
let suggestions = get_suggestions("", query);
|
2019-11-02 00:06:25 +01:00
|
|
|
let expected = [
|
2013-08-28 01:45:39 +02:00
|
|
|
"is:private",
|
|
|
|
"pm-with:alice@zulip.com",
|
2017-01-20 19:22:25 +01:00
|
|
|
"pm-with:bob@zulip.com",
|
2020-05-26 16:06:57 +02:00
|
|
|
"pm-with:jeff@zulip.com",
|
2020-05-26 15:40:46 +02:00
|
|
|
"pm-with:myself@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);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "al";
|
|
|
|
let base_query = "is:private";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = 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);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:t";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["pm-with:t", "pm-with:ted@zulip.com"];
|
2013-10-07 20:48:25 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-pm-with:t";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-pm-with:t", "is:private -pm-with:ted@zulip.com"];
|
2014-03-04 23:22:15 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:ted@zulip.com";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["pm-with:ted@zulip.com"];
|
2013-08-28 01:45:39 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:ted", "sender:ted@zulip.com"];
|
2013-10-07 20:48:25 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:te";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:te", "sender:ted@zulip.com"];
|
2013-10-07 20:48:25 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-sender:te";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-sender:te", "-sender:ted@zulip.com"];
|
2014-03-04 23:22:15 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted@zulip.com";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:ted@zulip.com"];
|
2013-10-07 20:48:25 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "from:ted";
|
|
|
|
base_query = "is:unread";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["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.
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "near:3";
|
|
|
|
base_query = "is:private";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["near:3"];
|
2013-08-28 01:45:39 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "near:3";
|
|
|
|
base_query = "pm-with:ted@zulip.com";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["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
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted@zulip.com";
|
|
|
|
base_query = "is:alerted";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:ted@zulip.com"];
|
2017-06-03 09:19:57 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "al";
|
|
|
|
base_query = "is:starred has:link is:private";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = 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
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:";
|
|
|
|
base_query = "stream:Denmark";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["pm-with:"];
|
2017-06-03 09:19:57 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:";
|
|
|
|
base_query = "sender:ted@zulip.com";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["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
|
|
|
|
2021-03-12 19:42:25 +01:00
|
|
|
test("group_suggestions", () => {
|
2017-02-05 22:11:18 +01:00
|
|
|
// Entering a comma in a pm-with query should immediately generate
|
|
|
|
// suggestions for the next person.
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "pm-with:bob@zulip.com,";
|
|
|
|
let suggestions = get_suggestions("", query);
|
2019-11-02 00:06:25 +01:00
|
|
|
let expected = [
|
2017-02-05 22:11:18 +01:00
|
|
|
"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.
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:bob@zulip.com,t";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["pm-with:bob@zulip.com,t", "pm-with:bob@zulip.com,ted@zulip.com"];
|
2017-02-05 22:11:18 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// Smit should also generate ted@zulip.com (Ted Smith) as a suggestion.
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:bob@zulip.com,Smit";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["pm-with:bob@zulip.com,Smit", "pm-with:bob@zulip.com,ted@zulip.com"];
|
2017-02-05 22:11:18 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-05-26 15:40:46 +02:00
|
|
|
// Do not suggest "myself@zulip.com" (the name of the current user)
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:ted@zulip.com,mys";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["pm-with:ted@zulip.com,mys"];
|
2017-07-04 22:14:42 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2017-02-05 22:11:18 +01:00
|
|
|
// No superfluous suggestions should be generated.
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:bob@zulip.com,red";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["pm-with:bob@zulip.com,red"];
|
2017-02-05 22:11:18 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// is:private should be properly prepended to each suggestion if the pm-with
|
|
|
|
// operator is negated.
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-pm-with:bob@zulip.com,";
|
|
|
|
suggestions = 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);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-pm-with:bob@zulip.com,t";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-pm-with:bob@zulip.com,t", "is:private -pm-with:bob@zulip.com,ted@zulip.com"];
|
2017-02-05 22:11:18 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-pm-with:bob@zulip.com,Smit";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-pm-with:bob@zulip.com,Smit", "is:private -pm-with:bob@zulip.com,ted@zulip.com"];
|
2017-02-05 22:11:18 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-pm-with:bob@zulip.com,red";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-pm-with:bob@zulip.com,red"];
|
2017-02-05 22:11:18 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-06-03 09:19:57 +02:00
|
|
|
|
|
|
|
// Test multiple operators
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:bob@zulip.com,Smit";
|
|
|
|
let base_query = "is:starred has:link";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["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);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:bob@zulip.com,Smit";
|
|
|
|
base_query = "stream:Denmark has:link";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["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
|
|
|
|
2020-05-26 14:25:21 +02:00
|
|
|
function message(user_ids, timestamp) {
|
|
|
|
return {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2020-07-02 01:41:40 +02:00
|
|
|
display_recipient: user_ids.map((id) => ({
|
2020-07-20 22:18:43 +02:00
|
|
|
id,
|
2020-07-02 01:41:40 +02:00
|
|
|
})),
|
2020-07-20 22:18:43 +02:00
|
|
|
timestamp,
|
2020-05-26 14:25:21 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
huddle_data.process_loaded_messages([
|
|
|
|
message([bob.user_id, ted.user_id], 99),
|
|
|
|
message([bob.user_id, ted.user_id, jeff.user_id], 98),
|
|
|
|
]);
|
2017-07-05 02:58:05 +02:00
|
|
|
|
|
|
|
// Simulate a past huddle which should now prioritize ted over alice
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:bob@zulip.com,";
|
|
|
|
suggestions = 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
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:bob@zulip.com,ted@zulip.com,";
|
|
|
|
suggestions = 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);
|
|
|
|
|
2020-05-26 15:40:46 +02:00
|
|
|
// bob,ted,jeff is already an existing huddle, but if we start with just jeff,
|
2017-07-05 02:58:05 +02:00
|
|
|
// then don't prioritize ted over alice because it doesn't complete the full huddle.
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "pm-with:jeff@zulip.com,";
|
|
|
|
suggestions = 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",
|
2020-05-26 15:40:46 +02:00
|
|
|
"pm-with:jeff@zulip.com,bob@zulip.com",
|
2017-07-05 02:58:05 +02:00
|
|
|
"pm-with:jeff@zulip.com,ted@zulip.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2019-06-27 19:16:55 +02:00
|
|
|
|
|
|
|
query = "pm-with:jeff@zulip.com,ted@zulip.com hi";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["pm-with:jeff@zulip.com,ted@zulip.com hi"];
|
2019-06-27 19:16:55 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-02-05 22:11:18 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("empty_query_suggestions", ({override_rewire}) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
const query = "";
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const suggestions = get_suggestions("", query);
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected = [
|
2013-07-28 23:05:01 +02:00
|
|
|
"",
|
2019-08-13 20:20:36 +02:00
|
|
|
"streams:public",
|
2013-07-28 23:05:01 +02:00
|
|
|
"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",
|
2021-07-13 10:03:26 +02:00
|
|
|
"is:resolved",
|
2020-05-26 15:40:46 +02:00
|
|
|
"sender:myself@zulip.com",
|
2013-07-28 23:05:01 +02:00
|
|
|
"stream:devel",
|
2016-12-03 23:17:57 +01:00
|
|
|
"stream:office",
|
2020-07-15 01:29:15 +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) {
|
2020-02-12 06:58:20 +01:00
|
|
|
return suggestions.lookup_table.get(q).description;
|
2013-07-30 22:39:32 +02:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
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");
|
2021-07-13 10:03:26 +02:00
|
|
|
assert.equal(describe("is:resolved"), "Topics marked as resolved");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(describe("sender:myself@zulip.com"), "Sent by me");
|
|
|
|
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-18 10:10:49 +02:00
|
|
|
});
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("has_suggestions", ({override_rewire}) => {
|
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.
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "h";
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
|
|
|
override_rewire(narrow_state, "stream", () => {});
|
2018-05-18 10:10:49 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
let expected = ["h", "has:link", "has:image", "has:attachment"];
|
2018-05-18 10:10:49 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
function describe(q) {
|
2020-02-12 06:58:20 +01:00
|
|
|
return suggestions.lookup_table.get(q).description;
|
2018-05-18 10:10:49 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +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:30:06 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-h";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-h", "-has:link", "-has:image", "-has:attachment"];
|
2018-05-20 16:30:06 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2020-07-15 01:29:15 +02:00
|
|
|
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.
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "has:";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["has:link", "has:image", "has:attachment"];
|
2018-05-20 16:38:28 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "has:im";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["has:image"];
|
2018-05-20 16:38:28 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-has:im";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-has:image"];
|
2018-05-20 16:38:28 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "att";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["att", "has:attachment"];
|
2018-05-20 16:38:28 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "has:lin";
|
|
|
|
const base_query = "stream:Denmark is:alerted";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("check_is_suggestions", ({override_rewire}) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "i";
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
|
|
|
override_rewire(narrow_state, "stream", () => {});
|
2018-05-22 14:37:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let suggestions = get_suggestions("", query);
|
2019-11-02 00:06:25 +01:00
|
|
|
let expected = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"i",
|
|
|
|
"is:private",
|
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
|
|
|
"is:alerted",
|
|
|
|
"is:unread",
|
2021-07-13 10:03:26 +02:00
|
|
|
"is:resolved",
|
2020-07-15 01:29:15 +02:00
|
|
|
"sender:alice@zulip.com",
|
|
|
|
"pm-with:alice@zulip.com",
|
|
|
|
"group-pm-with:alice@zulip.com",
|
|
|
|
"has:image",
|
2018-05-22 14:37:51 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
function describe(q) {
|
2020-02-12 06:58:20 +01:00
|
|
|
return suggestions.lookup_table.get(q).description;
|
2018-05-22 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
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");
|
2021-07-13 10:03:26 +02:00
|
|
|
assert.equal(describe("is:resolved"), "Topics marked as resolved");
|
2018-05-22 14:37:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-i";
|
|
|
|
suggestions = get_suggestions("", query);
|
2021-07-13 10:03:26 +02:00
|
|
|
expected = [
|
|
|
|
"-i",
|
|
|
|
"-is:private",
|
|
|
|
"-is:starred",
|
|
|
|
"-is:mentioned",
|
|
|
|
"-is:alerted",
|
|
|
|
"-is:unread",
|
|
|
|
"-is:resolved",
|
|
|
|
];
|
2018-05-22 14:37:51 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
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");
|
2021-07-13 10:03:26 +02:00
|
|
|
assert.equal(describe("-is:resolved"), "Exclude topics marked as resolved");
|
2018-05-22 14:37:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "";
|
|
|
|
suggestions = get_suggestions("", query);
|
2018-07-04 01:48:10 +02:00
|
|
|
expected = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"",
|
|
|
|
"streams:public",
|
|
|
|
"is:private",
|
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
|
|
|
"is:alerted",
|
|
|
|
"is:unread",
|
2021-07-13 10:03:26 +02:00
|
|
|
"is:resolved",
|
2020-07-15 01:29:15 +02:00
|
|
|
"sender:myself@zulip.com",
|
|
|
|
"stream:devel",
|
|
|
|
"stream:office",
|
|
|
|
"has:link",
|
|
|
|
"has:image",
|
|
|
|
"has:attachment",
|
2018-07-04 01:48:10 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "";
|
|
|
|
let base_query = "is:private";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2018-07-04 01:48:10 +02:00
|
|
|
expected = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
|
|
|
"is:alerted",
|
|
|
|
"is:unread",
|
2021-07-13 10:03:26 +02:00
|
|
|
"is:resolved",
|
2020-07-15 01:29:15 +02:00
|
|
|
"sender:myself@zulip.com",
|
|
|
|
"has:link",
|
|
|
|
"has:image",
|
|
|
|
"has:attachment",
|
2018-07-04 01:48:10 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2018-05-22 14:37:51 +02:00
|
|
|
// operand suggestions follow.
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "is:";
|
|
|
|
suggestions = get_suggestions("", query);
|
2021-07-13 10:03:26 +02:00
|
|
|
expected = [
|
|
|
|
"is:private",
|
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
|
|
|
"is:alerted",
|
|
|
|
"is:unread",
|
|
|
|
"is:resolved",
|
|
|
|
];
|
2018-05-22 14:37:51 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "is:st";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["is:starred"];
|
2018-05-22 14:37:51 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-is:st";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-is:starred"];
|
2018-05-22 14:37:51 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "st";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["st", "streams:public", "is:starred", "stream:"];
|
2018-05-22 14:37:51 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "is:sta";
|
|
|
|
base_query = "stream:Denmark has:link";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["is:starred"];
|
2018-05-22 14:37:51 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("sent_by_me_suggestions", ({override_rewire}) => {
|
|
|
|
override_rewire(stream_data, "subscribed_streams", () => []);
|
2017-01-11 19:20:31 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(narrow_state, "stream", () => {});
|
2017-01-11 19:20:31 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "";
|
|
|
|
let suggestions = get_suggestions("", query);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(suggestions.strings.includes("sender:myself@zulip.com"));
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(suggestions.lookup_table.get("sender:myself@zulip.com").description, "Sent by me");
|
2017-01-11 19:20:31 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
let expected = ["sender", "sender:myself@zulip.com", "sender:"];
|
2017-01-11 19:20:31 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-sender";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-sender", "-sender:myself@zulip.com", "-sender:"];
|
2018-05-21 07:35:27 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "from";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["from", "from:myself@zulip.com", "from:"];
|
2017-01-11 19:20:31 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-from";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-from", "-from:myself@zulip.com", "-from:"];
|
2018-05-21 07:35:27 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:bob@zulip.com";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:bob@zulip.com"];
|
2017-01-11 19:20:31 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "from:bob@zulip.com";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["from:bob@zulip.com"];
|
2017-01-11 19:20:31 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sent";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sent", "sender:myself@zulip.com"];
|
2017-01-11 19:20:31 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-06-03 05:33:02 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-sent";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-sent", "-sender:myself@zulip.com"];
|
2018-05-21 07:35:27 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sent";
|
|
|
|
let base_query = "stream:Denmark topic:Denmark1";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sent", "sender:myself@zulip.com"];
|
2017-06-03 05:33:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:m";
|
|
|
|
base_query = "is:starred";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:m", "sender:myself@zulip.com"];
|
2017-06-03 05:33:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:";
|
|
|
|
base_query = "is:starred";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2017-06-03 05:33:02 +02:00
|
|
|
expected = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"sender:",
|
|
|
|
"sender:myself@zulip.com",
|
|
|
|
"sender:alice@zulip.com",
|
|
|
|
"sender:bob@zulip.com",
|
|
|
|
"sender:jeff@zulip.com",
|
|
|
|
"sender:ted@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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("topic_suggestions", ({override, override_rewire}) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let suggestions;
|
|
|
|
let expected;
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2021-04-20 00:11:23 +02:00
|
|
|
override(stream_topic_history_util, "get_server_history", () => {});
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_data, "subscribed_streams", () => ["office"]);
|
|
|
|
override_rewire(narrow_state, "stream", () => "office");
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const devel_id = 44;
|
|
|
|
const office_id = 77;
|
2017-05-14 15:39:02 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_data, "get_stream_id", (stream_name) => {
|
2017-05-14 15:39:02 +02:00
|
|
|
switch (stream_name) {
|
2020-07-15 00:34:28 +02:00
|
|
|
case "office":
|
|
|
|
return office_id;
|
|
|
|
case "devel":
|
|
|
|
return devel_id;
|
2020-09-24 07:50:36 +02:00
|
|
|
default:
|
|
|
|
return undefined;
|
2017-05-14 15:39:02 +02:00
|
|
|
}
|
2021-02-28 00:53:59 +01:00
|
|
|
});
|
2017-05-14 15:39:02 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("", "te");
|
2017-07-24 15:15:28 +02:00
|
|
|
expected = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"te",
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
"pm-with:ted@zulip.com",
|
|
|
|
"group-pm-with:ted@zulip.com",
|
2017-07-24 15:15:28 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2017-05-14 15:39:02 +02:00
|
|
|
|
2020-03-22 18:40:05 +01:00
|
|
|
stream_topic_history.add_message({
|
2017-07-24 22:16:13 +02:00
|
|
|
stream_id: devel_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic_name: "REXX",
|
2017-07-24 22:16:13 +02:00
|
|
|
});
|
2017-05-14 15:39:02 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
for (const topic_name of ["team", "ignore", "test"]) {
|
2020-03-22 18:40:05 +01:00
|
|
|
stream_topic_history.add_message({
|
2017-07-24 22:16:13 +02:00
|
|
|
stream_id: office_id,
|
2020-07-20 22:18:43 +02:00
|
|
|
topic_name,
|
2017-07-24 22:16:13 +02:00
|
|
|
});
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("", "te");
|
2014-02-20 17:29:14 +01:00
|
|
|
expected = [
|
2020-07-15 01:29:15 +02:00
|
|
|
"te",
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
"pm-with:ted@zulip.com",
|
|
|
|
"group-pm-with:ted@zulip.com",
|
|
|
|
"stream:office topic:team",
|
|
|
|
"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) {
|
2020-02-12 06:58:20 +01:00
|
|
|
return suggestions.lookup_table.get(q).description;
|
2013-07-30 22:39:32 +02:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(describe("te"), "Search for te");
|
|
|
|
assert.equal(describe("stream:office topic:team"), "Stream office > team");
|
2013-07-30 22:39:32 +02:00
|
|
|
|
2020-07-16 23:29:01 +02:00
|
|
|
suggestions = get_suggestions("topic:staplers", "stream:office");
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["stream:office"];
|
2014-02-20 17:29:14 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("stream:devel", "topic:");
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["topic:", "topic:REXX"];
|
2014-02-20 17:29:14 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2014-03-04 22:52:13 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("stream:devel", "-topic:");
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-topic:", "-topic:REXX"];
|
2014-03-04 22:52:13 +01:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("", "-topic:te");
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-topic:te", "stream:office -topic:team", "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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("is:alerted stream:devel is:starred", "topic:");
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["topic:", "topic:REXX"];
|
2017-06-03 22:54:35 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("is:private stream:devel", "topic:");
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["topic:"];
|
2017-06-03 22:54:35 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("topic:REXX stream:devel", "topic:");
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["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
|
|
|
|
2022-01-27 14:39:19 +01:00
|
|
|
test("topic_suggestions (limits)", () => {
|
|
|
|
let candidate_topics = [];
|
|
|
|
|
|
|
|
function assert_result(guess, expected_topics) {
|
|
|
|
assert.deepEqual(
|
|
|
|
search.get_topic_suggestions_from_candidates({candidate_topics, guess}),
|
|
|
|
expected_topics,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_result("", []);
|
|
|
|
assert_result("zzz", []);
|
|
|
|
|
|
|
|
candidate_topics = ["a", "b", "c"];
|
|
|
|
assert_result("", ["a", "b", "c"]);
|
|
|
|
assert_result("b", ["b"]);
|
|
|
|
assert_result("z", []);
|
|
|
|
|
|
|
|
candidate_topics = [
|
|
|
|
"a1",
|
|
|
|
"a2",
|
|
|
|
"b1",
|
|
|
|
"b2",
|
|
|
|
"a3",
|
|
|
|
"a4",
|
|
|
|
"a5",
|
|
|
|
"c1",
|
|
|
|
"a6",
|
|
|
|
"a7",
|
|
|
|
"a8",
|
|
|
|
"c2",
|
|
|
|
"a9",
|
|
|
|
"a10",
|
|
|
|
"a11",
|
|
|
|
"a12",
|
|
|
|
];
|
|
|
|
// We max out at 10 topics, so as not to overwhelm the user.
|
|
|
|
assert_result("", ["a1", "a2", "b1", "b2", "a3", "a4", "a5", "c1", "a6", "a7"]);
|
|
|
|
assert_result("a", ["a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10"]);
|
|
|
|
assert_result("b", ["b1", "b2"]);
|
|
|
|
assert_result("z", []);
|
|
|
|
});
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("whitespace_glitch", ({override_rewire}) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
const query = "stream:office "; // note trailing space
|
2013-08-06 19:08:39 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(stream_data, "subscribed_streams", () => ["office"]);
|
2013-08-06 19:08:39 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const suggestions = get_suggestions("", query);
|
2013-08-06 19:08:39 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const expected = ["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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("stream_completion", ({override_rewire}) => {
|
|
|
|
override_rewire(stream_data, "subscribed_streams", () => ["office", "dev help"]);
|
2014-02-20 16:28:52 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(narrow_state, "stream", () => {});
|
2014-02-20 16:28:52 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "stream:of";
|
|
|
|
let suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
let expected = ["stream:of", "stream:office"];
|
2017-06-23 08:39:37 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-05-21 06:23:08 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-stream:of";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-stream:of", "-stream:office"];
|
2018-05-21 06:23:08 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2014-02-20 16:28:52 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "hel";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +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() {
|
|
|
|
const ted = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "ted@zulip.com",
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 201,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Ted Smith",
|
2016-11-01 19:37:19 +01:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(ted);
|
2016-11-01 19:37:19 +01:00
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
const bob = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "bob@zulip.com",
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 202,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Bob Térry",
|
2016-11-01 19:37:19 +01:00
|
|
|
};
|
|
|
|
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(bob);
|
2019-04-23 18:02:06 +02:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@zulip.com",
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 203,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice Ignore",
|
2016-11-01 19:37:19 +01:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(alice);
|
2019-04-23 18:02:06 +02:00
|
|
|
}
|
2013-07-28 23:05:01 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("people_suggestions", ({override_rewire}) => {
|
|
|
|
override_rewire(narrow_state, "stream", noop);
|
2019-04-23 18:02:06 +02:00
|
|
|
people_suggestion_setup();
|
2021-03-12 19:26:23 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "te";
|
|
|
|
let suggestions = get_suggestions("", query);
|
2019-04-23 18:02:06 +02:00
|
|
|
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
|
|
|
|
2020-02-12 06:58:20 +01:00
|
|
|
const describe = (q) => suggestions.lookup_table.get(q).description;
|
2019-04-23 18:02:06 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
describe("pm-with:ted@zulip.com"),
|
|
|
|
"Private messages with <strong>Te</strong>d Smith <<strong>te</strong>d@zulip.com>",
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
describe("sender:ted@zulip.com"),
|
|
|
|
"Sent by <strong>Te</strong>d Smith <<strong>te</strong>d@zulip.com>",
|
|
|
|
);
|
2013-07-30 22:39:32 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = 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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted sm";
|
|
|
|
let base_query = "";
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:ted+sm", "sender:ted@zulip.com"];
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2018-05-25 17:03:13 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "new";
|
|
|
|
base_query = "sender:ted@zulip.com";
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["new"];
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2018-05-25 17:03:13 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted@tulip.com new";
|
|
|
|
base_query = "";
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:ted@tulip.com+new"];
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2018-07-02 22:30:18 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "new";
|
|
|
|
base_query = "sender:ted@tulip.com";
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["new"];
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = 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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("people_suggestion (Admin only email visibility)", ({override_rewire}) => {
|
2019-04-23 18:02:06 +02:00
|
|
|
/* Suggestions when realm_email_address_visibility is set to admin
|
|
|
|
only */
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(narrow_state, "stream", noop);
|
2019-04-23 18:02:06 +02:00
|
|
|
people_suggestion_setup();
|
2021-03-12 19:26:23 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const query = "te";
|
2021-03-12 19:26:23 +01:00
|
|
|
const suggestions = with_field(page_params, "is_admin", false, () =>
|
|
|
|
get_suggestions("", query),
|
|
|
|
);
|
|
|
|
|
2019-04-23 18:02:06 +02:00
|
|
|
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);
|
|
|
|
|
2020-02-12 06:58:20 +01:00
|
|
|
const describe = (q) => suggestions.lookup_table.get(q).description;
|
2019-04-23 18:02:06 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
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");
|
2019-04-23 18:02:06 +02:00
|
|
|
});
|
|
|
|
|
2021-03-12 19:42:25 +01:00
|
|
|
test("operator_suggestions", () => {
|
2017-06-15 09:07:12 +02:00
|
|
|
// Completed operator should return nothing
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "stream:";
|
|
|
|
let suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
let expected = ["stream:"];
|
2017-06-15 09:07:12 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "st";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["st", "streams:public", "is:starred", "stream:"];
|
2017-06-15 09:07:12 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "group-";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["group-", "group-pm-with:"];
|
2017-09-24 18:02:56 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-s";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-s", "-streams:public", "-sender:myself@zulip.com", "-stream:", "-sender:"];
|
2017-06-15 09:07:12 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-f";
|
|
|
|
const base_query = "stream:Denmark is:alerted";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-f", "-from:myself@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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("queries_with_spaces", ({override_rewire}) => {
|
|
|
|
override_rewire(stream_data, "subscribed_streams", () => ["office", "dev help"]);
|
2017-07-12 08:44:41 +02:00
|
|
|
|
|
|
|
// test allowing spaces with quotes surrounding operand
|
2019-11-02 00:06:25 +01:00
|
|
|
let query = 'stream:"dev he"';
|
2020-07-15 01:29:15 +02:00
|
|
|
let suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
let expected = ["stream:dev+he", "stream:dev+help"];
|
2017-07-12 08:44:41 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// test mismatched quote
|
|
|
|
query = 'stream:"dev h';
|
2020-07-15 01:29:15 +02:00
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["stream:dev+h", "stream:dev+help"];
|
2017-07-12 08:44:41 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// test extra space after operator still works
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "stream: offi";
|
|
|
|
suggestions = get_suggestions("", query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["stream:offi", "stream:office"];
|
2017-07-12 08:44:41 +02:00
|
|
|
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.
|
2021-03-12 19:42:25 +01:00
|
|
|
test("multiple_operators_without_pills", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "is:private al";
|
|
|
|
let base_query = "";
|
2019-12-24 00:17:39 +01:00
|
|
|
let suggestions = get_suggestions(base_query, query);
|
2019-11-02 00:06:25 +01:00
|
|
|
let expected = [
|
2018-07-02 22:30:18 +02:00
|
|
|
"is:private al",
|
2020-06-19 18:09:37 +02:00
|
|
|
"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",
|
2018-07-02 22:30:18 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "abc is:alerted sender:ted@zulip.com";
|
|
|
|
base_query = "";
|
2019-12-24 00:17:39 +01:00
|
|
|
suggestions = get_suggestions(base_query, query);
|
2021-08-12 18:55:55 +02:00
|
|
|
expected = ["abc is:alerted sender:ted@zulip.com"];
|
2018-07-02 22:30:18 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|