2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const narrow_state = mock_esm("../src/narrow_state");
|
|
|
|
const stream_topic_history_util = mock_esm("../src/stream_topic_history_util");
|
2021-04-20 00:11:23 +02:00
|
|
|
|
2024-06-11 21:39:15 +02:00
|
|
|
const direct_message_group_data = zrequire("direct_message_group_data");
|
2020-05-26 14:25:21 +02:00
|
|
|
|
2024-07-29 04:23:00 +02:00
|
|
|
const {Filter} = zrequire("filter");
|
2021-02-10 04:53:22 +01:00
|
|
|
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");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {set_current_user, set_realm} = zrequire("state_data");
|
|
|
|
|
|
|
|
const current_user = {};
|
|
|
|
set_current_user(current_user);
|
|
|
|
const realm = {};
|
|
|
|
set_realm(realm);
|
2018-07-14 12:46:02 +02: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",
|
2018-07-14 12:46:02 +02: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",
|
2021-10-26 15:43:39 +02:00
|
|
|
delivery_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
|
|
|
};
|
|
|
|
|
2021-12-06 23:44:26 +01:00
|
|
|
const example_avatar_url = "http://example.com/example.png";
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
let _stream_id = 0;
|
|
|
|
function new_stream_id() {
|
|
|
|
_stream_id += 1;
|
|
|
|
return _stream_id;
|
|
|
|
}
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
function init({override}) {
|
|
|
|
override(current_user, "is_admin", true);
|
2021-04-03 19:07:13 +02:00
|
|
|
|
2018-07-14 12:46:02 +02: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();
|
2024-06-11 21:39:15 +02:00
|
|
|
direct_message_group_data.clear_for_testing();
|
2022-07-10 01:06:33 +02:00
|
|
|
stream_data.clear_subscriptions();
|
2018-07-14 12:46:02 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 06:15:50 +02:00
|
|
|
function get_suggestions(query, pill_query = "") {
|
2024-07-29 04:23:00 +02:00
|
|
|
return search.get_suggestions(Filter.parse(pill_query), Filter.parse(query));
|
2020-06-01 15:00:42 +02:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:42:25 +01:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2024-10-09 21:21:41 +02:00
|
|
|
init(helpers);
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-03-12 19:42:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-30 01:47:15 +02:00
|
|
|
test("basic_get_suggestions", ({override}) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
const query = "fred";
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
override(narrow_state, "stream_id", noop);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
const suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const expected = ["fred"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("basic_get_suggestions_for_spectator", () => {
|
2022-03-17 16:14:52 +01:00
|
|
|
page_params.is_spectator = true;
|
|
|
|
|
|
|
|
const query = "";
|
2023-06-29 21:36:02 +02:00
|
|
|
const suggestions = get_suggestions(query);
|
2024-02-28 12:24:44 +01:00
|
|
|
assert.deepEqual(suggestions.strings, [
|
|
|
|
"has:link",
|
|
|
|
"has:image",
|
|
|
|
"has:attachment",
|
|
|
|
"has:reaction",
|
|
|
|
]);
|
2022-03-17 16:14:52 +01:00
|
|
|
page_params.is_spectator = false;
|
|
|
|
});
|
|
|
|
|
2024-06-18 01:30:40 +02:00
|
|
|
test("get_is_suggestions_for_spectator", () => {
|
|
|
|
page_params.is_spectator = true;
|
|
|
|
|
|
|
|
const query = "is:";
|
|
|
|
const suggestions = get_suggestions(query);
|
|
|
|
// The list of suggestions should be empty for a spectator
|
|
|
|
assert.deepEqual(suggestions.strings, []);
|
|
|
|
page_params.is_spectator = false;
|
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("subset_suggestions", ({mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
const denmark_id = new_stream_id();
|
|
|
|
const sub = {name: "Denmark", stream_id: denmark_id};
|
|
|
|
stream_data.add_sub(sub);
|
|
|
|
const query = `channel:${denmark_id} topic:Hamlet shakespeare`;
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
const suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected = [
|
2024-08-03 03:05:34 +02:00
|
|
|
`channel:${denmark_id} topic:Hamlet shakespeare`,
|
|
|
|
`channel:${denmark_id} topic:Hamlet`,
|
|
|
|
`channel:${denmark_id}`,
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("dm_suggestions", ({override, mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
2024-04-29 21:55:42 +02:00
|
|
|
mock_template("user_pill.hbs", true, (_data, html) => html);
|
2023-06-30 01:45:08 +02:00
|
|
|
|
2023-04-07 14:03:34 +02:00
|
|
|
let query = "is:dm";
|
2023-06-29 21:36:02 +02:00
|
|
|
let suggestions = get_suggestions(query);
|
2019-11-02 00:06:25 +01:00
|
|
|
let expected = [
|
2023-04-07 14:03:34 +02:00
|
|
|
"is:dm",
|
2023-04-11 21:04:33 +02:00
|
|
|
"dm:alice@zulip.com",
|
|
|
|
"dm:bob@zulip.com",
|
|
|
|
"dm:jeff@zulip.com",
|
|
|
|
"dm:myself@zulip.com",
|
|
|
|
"dm:ted@zulip.com",
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-07 14:03:34 +02:00
|
|
|
query = "is:dm al";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
expected = [
|
2023-04-07 14:03:34 +02:00
|
|
|
"is:dm al",
|
|
|
|
"is:dm is:alerted",
|
2023-04-11 21:04:33 +02:00
|
|
|
"is:dm dm:alice@zulip.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"is:dm sender:alice@zulip.com",
|
2023-04-19 17:35:32 +02:00
|
|
|
"is:dm dm-including:alice@zulip.com",
|
2023-04-07 14:03:34 +02:00
|
|
|
"is:dm",
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-07 14:03:34 +02:00
|
|
|
// "is:private" was renamed to "is:dm", so
|
|
|
|
// we suggest "is:dm" to anyone with "is:private"
|
|
|
|
// in their muscle memory.
|
|
|
|
query = "is:pr";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2023-04-07 14:03:34 +02:00
|
|
|
expected = ["is:dm"];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = "is:private";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2023-04-07 14:03:34 +02:00
|
|
|
expected = ["is:dm"];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-11 21:04:33 +02:00
|
|
|
query = "dm:t";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["dm:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-11 21:04:33 +02:00
|
|
|
query = "-dm:t";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["is:dm -dm:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-11 21:04:33 +02:00
|
|
|
query = "dm:ted@zulip.com";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2023-04-11 21:04:33 +02:00
|
|
|
expected = ["dm:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["sender:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:te";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["sender:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-sender:te";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["-sender:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted@zulip.com";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "is:unread from:ted";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["is:unread sender:ted@zulip.com", "is:unread"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// Users can enter bizarre queries, and if they do, we want to
|
|
|
|
// be conservative with suggestions.
|
2023-04-07 14:03:34 +02:00
|
|
|
query = "is:dm near:3";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2023-04-07 14:03:34 +02:00
|
|
|
expected = ["is:dm near:3", "is:dm"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-11 21:04:33 +02:00
|
|
|
query = "dm:ted@zulip.com near:3";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2023-04-11 21:04:33 +02:00
|
|
|
expected = ["dm:ted@zulip.com near:3", "dm:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// Make sure suggestions still work if preceding tokens
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "is:alerted sender:ted@zulip.com";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["is:alerted sender:ted@zulip.com", "is:alerted"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-07 14:03:34 +02:00
|
|
|
query = "is:starred has:link is:dm al";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
expected = [
|
2023-04-07 14:03:34 +02:00
|
|
|
"is:starred has:link is:dm al",
|
|
|
|
"is:starred has:link is:dm is:alerted",
|
2023-04-11 21:04:33 +02:00
|
|
|
"is:starred has:link is:dm dm:alice@zulip.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"is:starred has:link is:dm sender:alice@zulip.com",
|
2023-04-19 17:35:32 +02:00
|
|
|
"is:starred has:link is:dm dm-including:alice@zulip.com",
|
2023-04-07 14:03:34 +02:00
|
|
|
"is:starred has:link is:dm",
|
2018-07-14 12:46:02 +02:00
|
|
|
"is:starred has:link",
|
|
|
|
"is:starred",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-07-02 02:43:31 +02:00
|
|
|
query = "from:ted@zulip.com";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["sender:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2023-04-11 21:04:33 +02:00
|
|
|
|
|
|
|
// "pm-with" operator returns search result
|
|
|
|
// and "dm" operator as a suggestions
|
2024-08-03 03:05:34 +02:00
|
|
|
override(narrow_state, "stream_id", () => undefined);
|
2023-04-11 21:04:33 +02:00
|
|
|
query = "pm-with";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2023-04-11 21:04:33 +02:00
|
|
|
expected = ["pm-with", "dm:"];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
query = "pm-with:t";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["dm:ted@zulip.com"];
|
2023-04-11 21:04:33 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-07-14 12:46:02 +02:00
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("group_suggestions", ({mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
2024-04-29 21:55:42 +02:00
|
|
|
mock_template("user_pill.hbs", true, (_data, html) => html);
|
2023-06-30 01:45:08 +02:00
|
|
|
|
2024-04-11 06:15:50 +02:00
|
|
|
// If there's an existing completed user pill right before
|
|
|
|
// the input string, we suggest a user group as one of the
|
|
|
|
// suggestions.
|
|
|
|
let pill_query = "dm:bob@zulip.com";
|
|
|
|
let query = "alice";
|
|
|
|
let suggestions = get_suggestions(query, pill_query);
|
2019-11-02 00:06:25 +01:00
|
|
|
let expected = [
|
2024-04-11 06:15:50 +02:00
|
|
|
"dm:bob@zulip.com alice",
|
2023-04-11 21:04:33 +02:00
|
|
|
"dm:bob@zulip.com,alice@zulip.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"dm:bob@zulip.com sender:alice@zulip.com",
|
|
|
|
"dm:bob@zulip.com dm-including:alice@zulip.com",
|
|
|
|
"dm:bob@zulip.com",
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-04-11 06:15:50 +02:00
|
|
|
// Do not suggest "myself@zulip.com" (the name of the current user) for dms
|
|
|
|
pill_query = "dm:ted@zulip.com";
|
|
|
|
query = "my";
|
|
|
|
suggestions = get_suggestions(query, pill_query);
|
|
|
|
expected = [
|
|
|
|
"dm:ted@zulip.com my",
|
|
|
|
"dm:ted@zulip.com sender:myself@zulip.com",
|
|
|
|
"dm:ted@zulip.com dm-including:myself@zulip.com",
|
|
|
|
"dm:ted@zulip.com",
|
|
|
|
];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-11 21:04:33 +02:00
|
|
|
// "is:dm" should be properly prepended to each suggestion
|
|
|
|
// if the "dm" operator is negated.
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-04-11 06:15:50 +02:00
|
|
|
query = "-dm:bob@zulip.co";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["is:dm -dm:bob@zulip.com"];
|
2023-04-11 21:04:33 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-04-11 06:15:50 +02:00
|
|
|
// If user types "pm-with" operator, show suggestions for
|
|
|
|
// group direct messages with the "dm" operator.
|
|
|
|
pill_query = "pm-with:bob@zulip.com";
|
|
|
|
query = "alice";
|
|
|
|
suggestions = get_suggestions(query, pill_query);
|
2023-04-11 21:04:33 +02:00
|
|
|
expected = [
|
2024-04-11 06:15:50 +02:00
|
|
|
"dm:bob@zulip.com alice",
|
2023-04-11 21:04:33 +02:00
|
|
|
"dm:bob@zulip.com,alice@zulip.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"dm:bob@zulip.com sender:alice@zulip.com",
|
|
|
|
"dm:bob@zulip.com dm-including:alice@zulip.com",
|
|
|
|
"dm:bob@zulip.com",
|
2023-04-11 21:04:33 +02:00
|
|
|
];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-12-22 00:26:14 +01:00
|
|
|
// Test multiple terms
|
2024-04-11 06:15:50 +02:00
|
|
|
pill_query = "is:starred has:link dm:bob@zulip.com";
|
|
|
|
query = "Smit";
|
|
|
|
suggestions = get_suggestions(query, pill_query);
|
2018-07-14 12:46:02 +02:00
|
|
|
expected = [
|
2024-04-11 06:15:50 +02:00
|
|
|
"is:starred has:link dm:bob@zulip.com Smit",
|
2023-04-11 21:04:33 +02:00
|
|
|
"is:starred has:link dm:bob@zulip.com,ted@zulip.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"is:starred has:link dm:bob@zulip.com sender:ted@zulip.com",
|
|
|
|
"is:starred has:link dm:bob@zulip.com dm-including:ted@zulip.com",
|
|
|
|
"is:starred has:link dm:bob@zulip.com",
|
2018-07-14 12:46:02 +02:00
|
|
|
"is:starred has:link",
|
|
|
|
"is:starred",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-07-02 02:43:31 +02:00
|
|
|
// Doesn't show dms because it's invalid in combination
|
2024-08-03 03:05:34 +02:00
|
|
|
// with a channel. (Random channel id.)
|
|
|
|
query = "channel:66 has:link dm:bob@zulip.com,Smit";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
expected = ["channel:66 has:link", "channel:66"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-04-29 21:55:42 +02:00
|
|
|
// Invalid emails don't give suggestions
|
|
|
|
query = "has:link dm:invalid@zulip.com,Smit";
|
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["has:link"];
|
2024-04-29 21:55:42 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2018-07-14 12:46:02 +02:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("empty_query_suggestions", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
const query = "";
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
const devel_id = new_stream_id();
|
|
|
|
const office_id = new_stream_id();
|
|
|
|
stream_data.add_sub({stream_id: devel_id, name: "devel", subscribed: true});
|
|
|
|
stream_data.add_sub({stream_id: office_id, name: "office", subscribed: true});
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
const suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected = [
|
2024-04-23 21:51:34 +02:00
|
|
|
"channels:public",
|
2023-04-07 14:03:34 +02:00
|
|
|
"is:dm",
|
2018-07-14 12:46:02 +02:00
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
2023-10-25 19:44:52 +02:00
|
|
|
"is:followed",
|
2018-07-14 12:46:02 +02:00
|
|
|
"is:alerted",
|
|
|
|
"is:unread",
|
2021-07-13 10:03:26 +02:00
|
|
|
"is:resolved",
|
2020-05-26 15:40:46 +02:00
|
|
|
"sender:myself@zulip.com",
|
2024-08-03 03:05:34 +02:00
|
|
|
`channel:${devel_id}`,
|
|
|
|
`channel:${office_id}`,
|
2020-07-15 01:29:15 +02:00
|
|
|
"has:link",
|
|
|
|
"has:image",
|
|
|
|
"has:attachment",
|
2024-02-28 12:24:44 +01:00
|
|
|
"has:reaction",
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
function describe(q) {
|
2022-06-19 07:17:16 +02:00
|
|
|
return suggestions.lookup_table.get(q).description_html;
|
2018-07-14 12:46:02 +02:00
|
|
|
}
|
2023-04-07 14:03:34 +02:00
|
|
|
assert.equal(describe("is:dm"), "Direct messages");
|
2020-07-15 01:29:15 +02:00
|
|
|
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");
|
2023-10-25 19:44:52 +02:00
|
|
|
assert.equal(describe("is:followed"), "Followed topics");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(describe("sender:myself@zulip.com"), "Sent by me");
|
2024-07-16 01:45:26 +02:00
|
|
|
assert.equal(describe("has:link"), "Messages with links");
|
|
|
|
assert.equal(describe("has:image"), "Messages with images");
|
|
|
|
assert.equal(describe("has:attachment"), "Messages with attachments");
|
2018-07-14 12:46:02 +02:00
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("has_suggestions", ({override, mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
|
|
|
|
2018-07-14 12:46:02 +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-07-10 01:06:33 +02:00
|
|
|
stream_data.add_sub({stream_id: 44, name: "devel", subscribed: true});
|
|
|
|
stream_data.add_sub({stream_id: 77, name: "office", subscribed: true});
|
2024-08-03 03:05:34 +02:00
|
|
|
override(narrow_state, "stream_id", noop);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
let suggestions = get_suggestions(query);
|
2024-02-28 12:24:44 +01:00
|
|
|
let expected = ["h", "has:link", "has:image", "has:attachment", "has:reaction"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
function describe(q) {
|
2022-06-19 07:17:16 +02:00
|
|
|
return suggestions.lookup_table.get(q).description_html;
|
2018-07-14 12:46:02 +02:00
|
|
|
}
|
|
|
|
|
2024-07-16 01:45:26 +02:00
|
|
|
assert.equal(describe("has:link"), "Messages with links");
|
|
|
|
assert.equal(describe("has:image"), "Messages with images");
|
|
|
|
assert.equal(describe("has:attachment"), "Messages with attachments");
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-h";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-02-28 12:24:44 +01:00
|
|
|
expected = ["-h", "-has:link", "-has:image", "-has:attachment", "-has:reaction"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2024-07-16 01:45:26 +02:00
|
|
|
assert.equal(describe("-has:link"), "Exclude messages with links");
|
|
|
|
assert.equal(describe("-has:image"), "Exclude messages with images");
|
|
|
|
assert.equal(describe("-has:attachment"), "Exclude messages with attachments");
|
2018-07-14 12:46:02 +02:00
|
|
|
|
|
|
|
// operand suggestions follow.
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "has:";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-02-28 12:24:44 +01:00
|
|
|
expected = ["has:link", "has:image", "has:attachment", "has:reaction"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "has:im";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["has:image"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-has:im";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-has:image"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "att";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["att", "has:attachment"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
// 66 is misc channel id.
|
|
|
|
query = "channel:66 is:alerted has:lin";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
expected = ["channel:66 is:alerted has:link", "channel:66 is:alerted", "channel:66"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("check_is_suggestions", ({override, mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
2024-04-29 21:55:42 +02:00
|
|
|
mock_template("user_pill.hbs", true, (_data, html) => html);
|
2023-06-30 01:45:08 +02:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
override(narrow_state, "stream_id", noop);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "i";
|
2023-06-29 21:36:02 +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",
|
2023-04-07 14:03:34 +02:00
|
|
|
"is:dm",
|
2020-07-15 01:29:15 +02:00
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
2023-10-25 19:44:52 +02:00
|
|
|
"is:followed",
|
2020-07-15 01:29:15 +02:00
|
|
|
"is:alerted",
|
|
|
|
"is:unread",
|
2021-07-13 10:03:26 +02:00
|
|
|
"is:resolved",
|
2023-04-11 21:04:33 +02:00
|
|
|
"dm:alice@zulip.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"sender:alice@zulip.com",
|
2023-04-19 17:35:32 +02:00
|
|
|
"dm-including:alice@zulip.com",
|
2020-07-15 01:29:15 +02:00
|
|
|
"has:image",
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
function describe(q) {
|
2022-06-19 07:17:16 +02:00
|
|
|
return suggestions.lookup_table.get(q).description_html;
|
2018-07-14 12:46:02 +02:00
|
|
|
}
|
|
|
|
|
2023-04-07 14:03:34 +02:00
|
|
|
assert.equal(describe("is:dm"), "Direct messages");
|
2020-07-15 01:29:15 +02:00
|
|
|
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");
|
2023-10-25 19:44:52 +02:00
|
|
|
assert.equal(describe("is:followed"), "Followed topics");
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-i";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2021-07-13 10:03:26 +02:00
|
|
|
expected = [
|
|
|
|
"-i",
|
2023-04-07 14:03:34 +02:00
|
|
|
"-is:dm",
|
2021-07-13 10:03:26 +02:00
|
|
|
"-is:starred",
|
|
|
|
"-is:mentioned",
|
2023-10-25 19:44:52 +02:00
|
|
|
"-is:followed",
|
2021-07-13 10:03:26 +02:00
|
|
|
"-is:alerted",
|
|
|
|
"-is:unread",
|
|
|
|
"-is:resolved",
|
|
|
|
];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-04-07 14:03:34 +02:00
|
|
|
assert.equal(describe("-is:dm"), "Exclude direct messages");
|
2020-07-15 01:29:15 +02:00
|
|
|
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");
|
2023-10-25 19:44:52 +02:00
|
|
|
assert.equal(describe("-is:followed"), "Exclude followed topics");
|
2018-07-14 12:46:02 +02:00
|
|
|
|
|
|
|
// operand suggestions follow.
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "is:";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2023-10-25 19:44:52 +02:00
|
|
|
expected = [
|
|
|
|
"is:dm",
|
|
|
|
"is:starred",
|
|
|
|
"is:mentioned",
|
|
|
|
"is:followed",
|
|
|
|
"is:alerted",
|
|
|
|
"is:unread",
|
|
|
|
"is:resolved",
|
|
|
|
];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "is:st";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["is:starred"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-is:st";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-is:starred"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-04-23 21:51:34 +02:00
|
|
|
// Still returns suggestions for "streams:public",
|
|
|
|
// but shows html description used for "channels:public"
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "st";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-04-23 21:51:34 +02:00
|
|
|
expected = ["st", "streams:public", "is:starred", "channel:"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
query = "channel:66 has:link is:sta";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
expected = ["channel:66 has:link is:starred", "channel:66 has:link", "channel:66"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("sent_by_me_suggestions", ({override, mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
override(narrow_state, "stream_id", noop);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "";
|
2023-06-29 21:36:02 +02:00
|
|
|
let suggestions = get_suggestions(query);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(suggestions.strings.includes("sender:myself@zulip.com"));
|
2022-06-19 07:17:16 +02:00
|
|
|
assert.equal(
|
|
|
|
suggestions.lookup_table.get("sender:myself@zulip.com").description_html,
|
|
|
|
"Sent by me",
|
|
|
|
);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
let expected = ["sender", "sender:myself@zulip.com", "sender:"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-sender";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-sender", "-sender:myself@zulip.com", "-sender:"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "from";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-04-23 21:51:34 +02:00
|
|
|
expected = ["from", "sender:myself@zulip.com", "sender:"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-from";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-04-23 21:51:34 +02:00
|
|
|
expected = ["-from", "-sender:myself@zulip.com", "-sender:"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:bob@zulip.com";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:bob@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "from:bob@zulip.com";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-04-23 21:51:34 +02:00
|
|
|
expected = ["sender:bob@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sent";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sent", "sender:myself@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-sent";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["-sent", "-sender:myself@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
const denmark_id = new_stream_id();
|
|
|
|
const sub = {name: "Denmark", stream_id: denmark_id};
|
|
|
|
stream_data.add_sub(sub);
|
|
|
|
query = `channel:${denmark_id} topic:Denmark1 sent`;
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
expected = [
|
2024-08-03 03:05:34 +02:00
|
|
|
`channel:${denmark_id} topic:Denmark1 sent`,
|
|
|
|
`channel:${denmark_id} topic:Denmark1 sender:myself@zulip.com`,
|
|
|
|
`channel:${denmark_id} topic:Denmark1`,
|
|
|
|
`channel:${denmark_id}`,
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "is:starred sender:m";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["is:starred sender:myself@zulip.com", "is:starred"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("topic_suggestions", ({override, mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
2024-04-29 21:55:42 +02:00
|
|
|
mock_template("user_pill.hbs", true, (_data, html) => html);
|
2019-11-02 00:06:25 +01:00
|
|
|
let suggestions;
|
|
|
|
let expected;
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
override(stream_topic_history_util, "get_server_history", noop);
|
2024-08-03 03:05:34 +02:00
|
|
|
const office_id = new_stream_id();
|
|
|
|
stream_data.add_sub({stream_id: office_id, name: "office", subscribed: true});
|
|
|
|
override(narrow_state, "stream_id", () => office_id);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
const devel_id = new_stream_id();
|
2022-07-10 01:06:33 +02:00
|
|
|
stream_data.add_sub({stream_id: devel_id, name: "devel", subscribed: true});
|
|
|
|
stream_data.add_sub({stream_id: office_id, name: "office", subscribed: true});
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions("te");
|
2024-04-11 06:15:50 +02:00
|
|
|
expected = ["te", "dm:ted@zulip.com", "sender:ted@zulip.com", "dm-including:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-03-22 18:40:05 +01:00
|
|
|
stream_topic_history.add_message({
|
2018-07-14 12:46:02 +02:00
|
|
|
stream_id: devel_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic_name: "REXX",
|
2018-07-14 12:46: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({
|
2018-07-14 12:46:02 +02:00
|
|
|
stream_id: office_id,
|
2020-07-20 22:18:43 +02:00
|
|
|
topic_name,
|
2018-07-14 12:46:02 +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
|
|
|
}
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions("te");
|
2018-07-14 12:46:02 +02:00
|
|
|
expected = [
|
|
|
|
"te",
|
2023-04-11 21:04:33 +02:00
|
|
|
"dm:ted@zulip.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"sender:ted@zulip.com",
|
2023-04-19 17:35:32 +02:00
|
|
|
"dm-including:ted@zulip.com",
|
2024-08-03 03:05:34 +02:00
|
|
|
`channel:${office_id} topic:team`,
|
|
|
|
`channel:${office_id} topic:test`,
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
function describe(q) {
|
2022-06-19 07:17:16 +02:00
|
|
|
return suggestions.lookup_table.get(q).description_html;
|
2018-07-14 12:46:02 +02:00
|
|
|
}
|
2023-06-30 01:47:15 +02:00
|
|
|
assert.equal(describe("te"), "Search for <strong>te</strong>");
|
2024-08-03 03:05:34 +02:00
|
|
|
assert.equal(describe(`channel:${office_id} topic:team`), "Channel office > team");
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
suggestions = get_suggestions(`topic:staplers channel:${office_id}`);
|
|
|
|
expected = [`topic:staplers channel:${office_id}`, "topic:staplers"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
suggestions = get_suggestions(`channel:${devel_id} topic:`);
|
|
|
|
expected = [
|
|
|
|
`channel:${devel_id} topic:`,
|
|
|
|
`channel:${devel_id} topic:REXX`,
|
|
|
|
`channel:${devel_id}`,
|
|
|
|
];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
suggestions = get_suggestions(`channel:${devel_id} -topic:`);
|
|
|
|
expected = [
|
|
|
|
`channel:${devel_id} -topic:`,
|
|
|
|
`channel:${devel_id} -topic:REXX`,
|
|
|
|
`channel:${devel_id}`,
|
|
|
|
];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions("-topic:te");
|
2024-08-03 03:05:34 +02:00
|
|
|
expected = [
|
|
|
|
"-topic:te",
|
|
|
|
`channel:${office_id} -topic:team`,
|
|
|
|
`channel:${office_id} -topic:test`,
|
|
|
|
];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
suggestions = get_suggestions(`is:alerted channel:${devel_id} is:starred topic:`);
|
2018-07-14 12:46:02 +02:00
|
|
|
expected = [
|
2024-08-03 03:05:34 +02:00
|
|
|
`is:alerted channel:${devel_id} is:starred topic:`,
|
|
|
|
`is:alerted channel:${devel_id} is:starred topic:REXX`,
|
|
|
|
`is:alerted channel:${devel_id} is:starred`,
|
|
|
|
`is:alerted channel:${devel_id}`,
|
2020-07-15 01:29:15 +02:00
|
|
|
"is:alerted",
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
suggestions = get_suggestions(`is:dm channel:${devel_id} topic:`);
|
|
|
|
expected = [`is:dm channel:${devel_id} topic:`, `is:dm channel:${devel_id}`, `is:dm`];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
suggestions = get_suggestions(`topic:REXX channel:${devel_id} topic:`);
|
|
|
|
expected = [
|
|
|
|
`topic:REXX channel:${devel_id} topic:`,
|
|
|
|
`topic:REXX channel:${devel_id}`,
|
|
|
|
"topic:REXX",
|
|
|
|
];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2022-03-17 15:59:25 +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", []);
|
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("whitespace_glitch", ({override, mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
2024-08-03 03:05:34 +02:00
|
|
|
const office_stream_id = new_stream_id();
|
2023-06-30 01:45:08 +02:00
|
|
|
|
2024-04-23 21:51:34 +02:00
|
|
|
const query = "channel:office "; // note trailing space
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
override(stream_topic_history_util, "get_server_history", noop);
|
2024-08-03 03:05:34 +02:00
|
|
|
stream_data.add_sub({stream_id: office_stream_id, name: "office", subscribed: true});
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
const suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
const expected = [`channel:${office_stream_id}`];
|
2018-07-14 12:46:02 +02:00
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2024-07-02 02:43:31 +02:00
|
|
|
test("channel_completion", ({override}) => {
|
2024-08-03 03:05:34 +02:00
|
|
|
const office_stream_id = new_stream_id();
|
|
|
|
stream_data.add_sub({stream_id: office_stream_id, name: "office", subscribed: true});
|
|
|
|
const dev_help_stream_id = new_stream_id();
|
|
|
|
stream_data.add_sub({stream_id: dev_help_stream_id, name: "dev help", subscribed: true});
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
override(narrow_state, "stream_id", noop);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-04-23 21:51:34 +02:00
|
|
|
let query = "channel:of";
|
2023-06-29 21:36:02 +02:00
|
|
|
let suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
let expected = [`channel:${office_stream_id}`];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-04-23 21:51:34 +02:00
|
|
|
query = "-channel:of";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
expected = [`-channel:${office_stream_id}`];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "hel";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
expected = ["hel", `channel:${dev_help_stream_id}`];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("people_suggestions", ({override, mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
2024-04-29 21:55:42 +02:00
|
|
|
mock_template("user_pill.hbs", true, (_data, html) => html);
|
2023-06-30 01:45:08 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let query = "te";
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
override(narrow_state, "stream_id", noop);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const ted = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "ted@zulip.com",
|
2018-07-14 12:46:02 +02:00
|
|
|
user_id: 201,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Ted Smith",
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "bob@zulip.com",
|
2018-07-14 12:46:02 +02:00
|
|
|
user_id: 202,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Bob Térry",
|
2021-12-06 23:44:26 +01:00
|
|
|
avatar_url: example_avatar_url,
|
2023-09-13 19:30:52 +02:00
|
|
|
is_guest: false,
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@zulip.com",
|
2018-07-14 12:46:02 +02:00
|
|
|
user_id: 203,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice Ignore",
|
2018-07-14 12:46:02 +02:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(ted);
|
|
|
|
people.add_active_user(bob);
|
|
|
|
people.add_active_user(alice);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2023-12-01 15:05:08 +01:00
|
|
|
// Add an inaccessible user to verify that it is not included in
|
|
|
|
// suggestions.
|
|
|
|
const inaccessible_user = {
|
|
|
|
user_id: 299,
|
|
|
|
// All inaccessible users are named as "Unknown user", but we name
|
|
|
|
// it differently here so that the name matches the search query.
|
|
|
|
full_name: "Test unknown user",
|
|
|
|
email: "user299@zulipdev.com",
|
|
|
|
is_inaccessible_user: true,
|
|
|
|
};
|
|
|
|
people._add_user(inaccessible_user);
|
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
let suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let expected = [
|
2018-07-14 12:46:02 +02:00
|
|
|
"te",
|
2023-04-11 21:04:33 +02:00
|
|
|
"dm:bob@zulip.com", // bob térry
|
|
|
|
"dm:ted@zulip.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"sender:bob@zulip.com",
|
|
|
|
"sender:ted@zulip.com",
|
2023-04-19 17:35:32 +02:00
|
|
|
"dm-including:bob@zulip.com",
|
|
|
|
"dm-including:ted@zulip.com",
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
2021-12-06 23:44:26 +01:00
|
|
|
|
2023-12-01 15:05:08 +01:00
|
|
|
const accessible_user = {
|
|
|
|
user_id: 299,
|
|
|
|
full_name: "Test unknown user",
|
|
|
|
email: "user299@zulipdev.com",
|
|
|
|
};
|
|
|
|
people.add_active_user(accessible_user);
|
|
|
|
suggestions = get_suggestions(query);
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
"te",
|
|
|
|
"dm:bob@zulip.com",
|
|
|
|
"dm:ted@zulip.com",
|
|
|
|
"dm:user299@zulipdev.com",
|
2024-04-11 06:15:50 +02:00
|
|
|
"sender:bob@zulip.com",
|
|
|
|
"sender:ted@zulip.com",
|
|
|
|
"sender:user299@zulipdev.com",
|
2023-12-01 15:05:08 +01:00
|
|
|
"dm-including:bob@zulip.com",
|
|
|
|
"dm-including:ted@zulip.com",
|
|
|
|
"dm-including:user299@zulipdev.com",
|
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2021-12-06 23:44:26 +01:00
|
|
|
function is_person(q) {
|
2024-04-29 21:55:42 +02:00
|
|
|
return suggestions.lookup_table.get(q).description_html.includes(`class="user-pill`);
|
2021-12-06 23:44:26 +01:00
|
|
|
}
|
2023-04-11 21:04:33 +02:00
|
|
|
assert.equal(is_person("dm:ted@zulip.com"), true);
|
2021-12-06 23:44:26 +01:00
|
|
|
assert.equal(is_person("sender:ted@zulip.com"), true);
|
2023-04-19 17:35:32 +02:00
|
|
|
assert.equal(is_person("dm-including:ted@zulip.com"), true);
|
2021-12-06 23:44:26 +01:00
|
|
|
|
|
|
|
function has_image(q) {
|
2024-04-29 21:55:42 +02:00
|
|
|
return suggestions.lookup_table.get(q).description_html.includes(`class="pill-image"`);
|
2021-12-06 23:44:26 +01:00
|
|
|
}
|
2023-04-11 21:04:33 +02:00
|
|
|
assert.equal(has_image("dm:bob@zulip.com"), true);
|
2021-12-06 23:44:26 +01:00
|
|
|
assert.equal(has_image("sender:bob@zulip.com"), true);
|
2023-04-19 17:35:32 +02:00
|
|
|
assert.equal(has_image("dm-including:bob@zulip.com"), true);
|
2021-12-06 23:44:26 +01:00
|
|
|
|
2024-04-29 21:55:42 +02:00
|
|
|
function test_describe(q, description_html_start) {
|
|
|
|
assert.ok(
|
|
|
|
suggestions.lookup_table.get(q).description_html.startsWith(description_html_start),
|
|
|
|
);
|
2018-07-14 12:46:02 +02:00
|
|
|
}
|
2024-04-29 21:55:42 +02:00
|
|
|
test_describe("dm:ted@zulip.com", "Direct messages with");
|
|
|
|
test_describe("sender:ted@zulip.com", "Sent by");
|
|
|
|
test_describe("dm-including:ted@zulip.com", "Direct messages including");
|
2021-12-06 23:44:26 +01:00
|
|
|
|
|
|
|
let expectedString = "<strong>Te</strong>d Smith";
|
|
|
|
|
2024-04-29 21:55:42 +02:00
|
|
|
function test_full_name(q, full_name_html) {
|
|
|
|
return suggestions.lookup_table.get(q).description_html.includes(full_name_html);
|
2021-12-06 23:44:26 +01:00
|
|
|
}
|
2024-04-29 21:55:42 +02:00
|
|
|
test_full_name("sender:ted@zulip.com", expectedString);
|
|
|
|
test_full_name("dm:ted@zulip.com", expectedString);
|
|
|
|
test_full_name("dm-including:ted@zulip.com", expectedString);
|
2021-12-06 23:44:26 +01:00
|
|
|
|
2024-08-02 20:00:55 +02:00
|
|
|
expectedString = example_avatar_url;
|
2021-12-06 23:44:26 +01:00
|
|
|
|
2024-04-29 21:55:42 +02:00
|
|
|
function test_avatar_url(q, avatar_url) {
|
|
|
|
return suggestions.lookup_table.get(q).description_html.includes(avatar_url);
|
2021-12-06 23:44:26 +01:00
|
|
|
}
|
2024-04-29 21:55:42 +02:00
|
|
|
test_avatar_url("dm:bob@zulip.com", expectedString);
|
|
|
|
test_avatar_url("sender:bob@zulip.com", expectedString);
|
|
|
|
test_avatar_url("dm-including:bob@zulip.com", expectedString);
|
|
|
|
|
|
|
|
const guest_html = "<i>(guest)</i>";
|
|
|
|
function test_guest_user_indicator(q, should_have_guest_indicator) {
|
|
|
|
const description_html = suggestions.lookup_table.get(q).description_html;
|
|
|
|
if (should_have_guest_indicator) {
|
|
|
|
assert.ok(description_html.includes(guest_html));
|
|
|
|
} else {
|
|
|
|
assert.ok(!description_html.includes(guest_html));
|
|
|
|
}
|
2023-09-13 19:30:52 +02:00
|
|
|
}
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_enable_guest_user_indicator", true);
|
2023-09-13 19:30:52 +02:00
|
|
|
suggestions = get_suggestions(query);
|
|
|
|
|
2024-04-29 21:55:42 +02:00
|
|
|
test_guest_user_indicator("dm:bob@zulip.com", false);
|
|
|
|
test_guest_user_indicator("sender:bob@zulip.com", false);
|
|
|
|
test_guest_user_indicator("dm-including:bob@zulip.com", false);
|
2023-09-13 19:30:52 +02:00
|
|
|
|
|
|
|
bob.is_guest = true;
|
|
|
|
suggestions = get_suggestions(query);
|
|
|
|
|
2024-04-29 21:55:42 +02:00
|
|
|
test_guest_user_indicator("dm:bob@zulip.com", true);
|
|
|
|
test_guest_user_indicator("sender:bob@zulip.com", true);
|
|
|
|
test_guest_user_indicator("dm-including:bob@zulip.com", true);
|
2023-09-13 19:30:52 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_enable_guest_user_indicator", false);
|
2023-09-13 19:30:52 +02:00
|
|
|
suggestions = get_suggestions(query);
|
|
|
|
|
2024-04-29 21:55:42 +02:00
|
|
|
test_guest_user_indicator("dm:bob@zulip.com", false);
|
|
|
|
test_guest_user_indicator("sender:bob@zulip.com", false);
|
|
|
|
test_guest_user_indicator("dm-including:bob@zulip.com", false);
|
2023-09-13 19:30:52 +02:00
|
|
|
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions("Ted "); // note space
|
2018-07-14 12:46:02 +02:00
|
|
|
|
2024-04-11 06:15:50 +02:00
|
|
|
expected = ["Ted", "dm:ted@zulip.com", "sender:ted@zulip.com", "dm-including:ted@zulip.com"];
|
2018-07-14 12:46:02 +02:00
|
|
|
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted sm";
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = ["sender:ted@zulip.com"];
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted@zulip.com new";
|
2020-07-15 00:34:28 +02:00
|
|
|
expected = ["sender:ted@zulip.com new", "sender:ted@zulip.com"];
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "sender:ted@tulip.com new";
|
2024-07-02 02:43:31 +02:00
|
|
|
expected = []; // Invalid email
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2023-06-30 01:45:08 +02:00
|
|
|
test("operator_suggestions", ({override, mock_template}) => {
|
|
|
|
mock_template("search_description.hbs", true, (_data, html) => html);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
override(narrow_state, "stream_id", () => undefined);
|
2022-07-10 01:06:33 +02:00
|
|
|
|
2018-07-14 12:46:02 +02:00
|
|
|
// Completed operator should return nothing
|
2024-04-23 21:51:34 +02:00
|
|
|
let query = "channel:";
|
2023-06-29 21:36:02 +02:00
|
|
|
let suggestions = get_suggestions(query);
|
2024-07-02 02:43:31 +02:00
|
|
|
let expected = [];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-04-23 21:51:34 +02:00
|
|
|
query = "ch";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-04-23 21:51:34 +02:00
|
|
|
expected = ["ch", "channels:public", "channel:"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
query = "-s";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-04-23 21:51:34 +02:00
|
|
|
expected = ["-s", "-sender:myself@zulip.com", "-sender:", "-channel:"];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
2024-08-03 03:05:34 +02:00
|
|
|
// 66 is a misc channel id.
|
|
|
|
query = "channel:66 is:alerted -f";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2018-07-14 12:46:02 +02:00
|
|
|
expected = [
|
2024-08-03 03:05:34 +02:00
|
|
|
"channel:66 is:alerted -f",
|
|
|
|
"channel:66 is:alerted -sender:myself@zulip.com",
|
|
|
|
"channel:66 is:alerted -sender:",
|
|
|
|
"channel:66 is:alerted",
|
|
|
|
"channel:66",
|
2018-07-14 12:46:02 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|
|
|
|
|
2024-07-02 02:43:31 +02:00
|
|
|
test("queries_with_spaces", () => {
|
2024-08-03 03:05:34 +02:00
|
|
|
const office_id = new_stream_id();
|
|
|
|
stream_data.add_sub({stream_id: office_id, name: "office", subscribed: true});
|
|
|
|
const dev_help_id = new_stream_id();
|
|
|
|
stream_data.add_sub({stream_id: dev_help_id, name: "dev help", subscribed: true});
|
2018-07-14 12:46:02 +02:00
|
|
|
|
|
|
|
// test allowing spaces with quotes surrounding operand
|
2024-04-23 21:51:34 +02:00
|
|
|
let query = 'channel:"dev he"';
|
2023-06-29 21:36:02 +02:00
|
|
|
let suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
let expected = [`channel:${dev_help_id}`];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// test mismatched quote
|
2024-04-23 21:51:34 +02:00
|
|
|
query = 'channel:"dev h';
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
expected = [`channel:${dev_help_id}`];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
|
|
|
|
// test extra space after operator still works
|
2024-04-23 21:51:34 +02:00
|
|
|
query = "channel: offi";
|
2023-06-29 21:36:02 +02:00
|
|
|
suggestions = get_suggestions(query);
|
2024-08-03 03:05:34 +02:00
|
|
|
expected = [`channel:${office_id}`];
|
2018-07-14 12:46:02 +02:00
|
|
|
assert.deepEqual(suggestions.strings, expected);
|
|
|
|
});
|