Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
search: Refactor to calculate description from single point of entry.
Pratik Chandad8d03654a246
diff --git a/web/src/search.ts b/web/src/search.tsindex d6ce6c10712..368c7e0c686 100644--- a/web/src/search.ts+++ b/web/src/search.ts@@ -171,10 +171,10 @@ export function initialize(opts: {on_narrow_search: OnNarrowSearch}): void {});// Data storage for the typeahead.- // This maps a search string to an object with a "description_html" field.- // (It's a bit of legacy that we have an object with only one important- // field. There's also a "search_string" field on each element that actually- // just represents the key of the hash, so it's redundant.)+ // TODO: This map has become very redundant now. We needed this earlier to+ // to associate search string to its respective "description_html". This currently+ // now just maps search string to "search_string". We should just remove this when+ // we change Suggestion object to simple strings.let search_map = new Map<string, search_suggestion.Suggestion>();const bootstrap_typeahead_input: TypeaheadInputElement = {diff --git a/web/src/search_pill.ts b/web/src/search_pill.tsindex a825bf1226d..7a9592b8dad 100644--- a/web/src/search_pill.ts+++ b/web/src/search_pill.ts@@ -109,11 +109,6 @@ function on_pill_exit($user_pill.remove();}-// TODO: We're calculating `description_html` every time, even though-// we only show it (in `generate_pills_html`) for lines with only one-// pill. We can probably simplify things by separating out a function-// that generates `description_html` from the information in a single-// search pill, and remove `description_html` from the `Suggestion` type.export function generate_pills_html(suggestion: Suggestion, text_query: string): string {const search_terms = Filter.parse(suggestion.search_string);@@ -205,9 +200,18 @@ export function generate_pills_html(suggestion: Suggestion, text_query: string):// are already set up to only display text and no pill. We also// don't show it for most user pills.if (render_data.type === "generic_operator" && render_data.operator !== "search") {+ let description_html: string;+ const is_operator_suggestion =+ search_terms[0]!.operator !== "" && !text_query.includes(":");+ description_html = Filter.search_description_as_html(+ search_terms,+ is_operator_suggestion,+ );+ const capitalized_first_letter = description_html.charAt(0).toUpperCase();+ description_html = capitalized_first_letter + description_html.slice(1);return render_search_list_item({pills: pill_render_data,- description_html: suggestion.description_html,+ description_html,});} else if (render_data.type === "search_user" && is_sent_by_me_pill(render_data)) {const description_html = render_data.negateddiff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.tsindex e28418c2dfd..f0793481094 100644--- a/web/src/search_suggestion.ts+++ b/web/src/search_suggestion.ts@@ -34,9 +34,9 @@ const channel_incompatible_patterns: TermPattern[] = [{operator: "channels"},];-// TODO: Expand this to support all available filters and its description-// when we move away from description_html and calculate description on the-// fly by directly looking into this. We can ultimately support i18n too.+// TODO: Expand this to support all available filters and its description.+// Also, we generate some descriptions in filter.ts too, we should look to+// refactor them together.// Note: This list only contains search_strings used in `get_special_filters_suggestion`// since only their corresponding descriptions are matched with search query.const descriptions: Record<string, string> = {@@ -137,12 +137,9 @@ const incompatible_patterns: Partial<Record<NarrowTerm["operator"], TermPattern["has:reaction": [{operator: "has", operand: "reaction"}],};+// TODO: We have stripped suggestion of all other attributes, we should now+// replace it with simple string in other places.export type Suggestion = {- // When there's a single pill on a suggestion line, we have space to provide- // help text (description_html) explaining what the operator does. If a- // suggestion will be parsed into multiple pills, then we don't include- // `description_html`.- description_html: string | undefined;search_string: string;};@@ -182,9 +179,8 @@ function check_validity(return true;}-function format_as_suggestion(terms: NarrowTerm[], is_operator_suggestion = false): Suggestion {+function format_as_suggestion(terms: NarrowTerm[]): Suggestion {return {- description_html: Filter.search_description_as_html(terms, is_operator_suggestion),search_string: Filter.unparse(terms),};}@@ -241,9 +237,6 @@ function get_channel_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestchannels = typeahead_helper.sorter(query, channels, (x) => x);return channels.map((channel_name) => {- const prefix = "messages in #";- const verb = last.negated ? "exclude " : "";- const description_html = verb + prefix + Handlebars.Utils.escapeExpression(channel_name);const channel = stream_data.get_sub_by_name(channel_name);assert(channel !== undefined);const term: NarrowTerm = {@@ -252,7 +245,7 @@ function get_channel_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestnegated: last.negated,};const search_string = Filter.unparse([term]);- return {description_html, search_string};+ return {search_string};});}@@ -346,8 +339,6 @@ function get_group_suggestions(// Take top 15 persons, since they're ordered by pm_recipient_count.persons = persons.slice(0, 15);- const prefix = Filter.operator_to_prefix(group_operator, negated);-return persons.map((person) => {const term: NarrowTerm = {operator: group_operator,@@ -361,7 +352,6 @@ function get_group_suggestions(}return {- description_html: prefix,search_string: Filter.unparse(terms),};});@@ -423,8 +413,6 @@ function get_person_suggestions(const persons = people_getter();- const prefix = Filter.operator_to_prefix(autocomplete_operator, last.negated);-return persons.map((person) => {const terms: NarrowTerm[] = [{@@ -445,7 +433,6 @@ function get_person_suggestions(}return {- description_html: prefix,search_string: Filter.unparse(terms),};});@@ -453,7 +440,7 @@ function get_person_suggestions(function get_default_suggestion_line(terms: NarrowTerm[]): SuggestionLine {if (terms.length === 0) {- return [{description_html: "", search_string: ""}];+ return [{search_string: ""}];}const suggestion_line = [];const suggestion_strings = new Set();@@ -700,13 +687,11 @@ function get_special_filter_suggestions(return {...suggestion,search_string: "-" + suggestion.search_string,- description_html: "unresolved topics",};}return {...suggestion,search_string: "-" + suggestion.search_string,- description_html: "exclude " + suggestion.description_html,};});}@@ -747,7 +732,6 @@ function get_channels_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]):if (!page_params.is_spectator) {suggestions.push({search_string: public_channels_search_string,- description_html: "all public channels",incompatible_patterns: incompatible_patterns.channels!,});}@@ -755,7 +739,6 @@ function get_channels_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]):if (stream_data.realm_has_web_public_streams()) {suggestions.push({search_string: web_public_channels_search_string,- description_html: "all web-public channels",incompatible_patterns: incompatible_patterns.channels!,});}@@ -769,12 +752,10 @@ function get_is_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggesuggestions = [{search_string: "is:resolved",- description_html: "resolved topics",incompatible_patterns: incompatible_patterns["is:resolved"],},{search_string: "-is:resolved",- description_html: "unresolved topics",incompatible_patterns: incompatible_patterns["-is:resolved"],},];@@ -782,47 +763,38 @@ function get_is_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggesuggestions = [{search_string: "is:dm",- description_html: "direct messages",incompatible_patterns: incompatible_patterns["is:dm"],},{search_string: "is:starred",- description_html: "starred messages",incompatible_patterns: incompatible_patterns["is:starred"],},{search_string: "is:mentioned",- description_html: "messages that mention you",incompatible_patterns: incompatible_patterns["is:mentioned"],},{search_string: "is:followed",- description_html: "followed topics",incompatible_patterns: incompatible_patterns["is:followed"],},{search_string: "is:alerted",- description_html: "alerted messages",incompatible_patterns: incompatible_patterns["is:alerted"],},{search_string: "is:unread",- description_html: "unread messages",incompatible_patterns: incompatible_patterns["is:unread"],},{search_string: "is:muted",- description_html: "muted messages",incompatible_patterns: incompatible_patterns["is:muted"],},{search_string: "is:resolved",- description_html: "resolved topics",incompatible_patterns: incompatible_patterns["is:resolved"],},{search_string: "-is:resolved",- description_html: "unresolved topics",incompatible_patterns: incompatible_patterns["-is:resolved"],},];@@ -848,22 +820,18 @@ function get_has_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggconst suggestions: SuggestionAndIncompatiblePatterns[] = [{search_string: "has:link",- description_html: "messages with links",incompatible_patterns: incompatible_patterns["has:link"],},{search_string: "has:image",- description_html: "messages with images",incompatible_patterns: incompatible_patterns["has:image"],},{search_string: "has:attachment",- description_html: "messages with attachments",incompatible_patterns: incompatible_patterns["has:attachment"],},{search_string: "has:reaction",- description_html: "messages with reactions",incompatible_patterns: incompatible_patterns["has:reaction"],},];@@ -875,13 +843,11 @@ function get_sent_by_me_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggconst negated =last.negated === true || (last.operator === "search" && last.operand.startsWith("-"));const negated_symbol = negated ? "-" : "";- const verb = negated ? "exclude " : "";const sender_query = negated_symbol + "sender:" + people.my_current_email();const sender_me_query = negated_symbol + "sender:me";const from_string = negated_symbol + "from";const sent_string = negated_symbol + "sent";- const description_html = verb + "sent by me";if (match_criteria(terms, incompatible_patterns.sender!)) {return [];@@ -897,7 +863,6 @@ function get_sent_by_me_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggreturn [{search_string: sender_query,- description_html,},];}@@ -962,7 +927,7 @@ function get_operator_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggeschoice = "channels";}const op = [{operator: choice, operand: "", negated}];- return format_as_suggestion(op, true);+ return format_as_suggestion(op);});}@@ -1076,21 +1041,13 @@ class Attacher {get_result(): Suggestion[] {return this.result.map((suggestion_line) => {- const description_htmls = [];const search_strings = [];for (const suggestion of suggestion_line) {- if (suggestion.description_html && suggestion.description_html !== "") {- description_htmls.push(suggestion.description_html);- }if (suggestion.search_string !== "") {search_strings.push(suggestion.search_string);}}return {- // We only display description_html for suggestion lines- // with only one suggestion.- description_html:- description_htmls.length === 1 ? util.the(description_htmls) : undefined,search_string: search_strings.join(" "),};});@@ -1155,7 +1112,6 @@ export function get_search_result(suggestion_line = [{search_string: last.operand,- description_html: search_term_description_html(last.operand),},];attacher.push([...attacher.base, ...suggestion_line]);@@ -1244,13 +1200,6 @@ export function finalize_search_result(result: Suggestion[]): {strings: string[];lookup_table: Map<string, Suggestion>;} {- for (const sug of result) {- if (sug.description_html) {- const first = sug.description_html.charAt(0).toUpperCase();- sug.description_html = first + sug.description_html.slice(1);- }- }-// Typeahead expects us to give it strings, not objects,// so we maintain our own hash back to our objectsconst lookup_table = new Map<string, Suggestion>();diff --git a/web/templates/search_description.hbs b/web/templates/search_description.hbsindex b288954926a..6ba3fe7f471 100644--- a/web/templates/search_description.hbs+++ b/web/templates/search_description.hbs@@ -19,8 +19,10 @@{{else if (eq this.type "prefix_for_operator")}}{{~#if is_empty_string_topic~}}{{this.prefix_for_operator}} <span class="empty-topic-display">{{this.operand}}</span>- {{~ else ~}}+ {{~ else if this.operand ~}}{{this.prefix_for_operator}} {{this.operand}}{{#if (or (eq this.operand "link") (eq this.operand "image") (eq this.operand "attachment") (eq this.operand "reaction"))}}s{{/if}}+ {{~ else ~}}+ {{this.prefix_for_operator}}{{~/if~}}{{else if (eq this.type "is_operator")}}{{#if (eq this.operand "mentioned")}}diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjsindex acf12c8cab6..cf3f5fe00ee 100644--- a/web/tests/filter.test.cjs+++ b/web/tests/filter.test.cjs@@ -1693,6 +1693,7 @@ test("unparse", () => {test("describe", ({mock_template, override}) => {let narrow;let string;+ let terms;mock_template("search_description.hbs", true, (_data, html) => html);narrow = [{operator: "channels", operand: "public"}];@@ -1879,9 +1880,26 @@ test("describe", ({mock_template, override}) => {string = `topic <span class="empty-topic-display">translated: general chat</span>`;assert.equal(Filter.search_description_as_html(narrow, false), string);- narrow = [{operator: "topic", operand: ""}];- string = "topic ";- assert.equal(Filter.search_description_as_html(narrow, true), string);+ /* Description for operator suggestion search terms */+ terms = [{operator: "channels", operand: ""}];+ string = "channel type";+ assert.equal(Filter.search_description_as_html(terms, true), string);++ terms = [{operator: "topic", operand: ""}];+ string = "topic";+ assert.equal(Filter.search_description_as_html(terms, true), string);++ terms = [{operator: "near", operand: ""}];+ string = "messages around";+ assert.equal(Filter.search_description_as_html(terms, true), string);++ terms = [{operator: "sender", operand: ""}];+ string = "sent by";+ assert.equal(Filter.search_description_as_html(terms, true), string);++ terms = [{operator: "dm-including", operand: ""}];+ string = "direct messages including";+ assert.equal(Filter.search_description_as_html(terms, true), string);});test("can_bucket_by", () => {diff --git a/web/tests/search.test.cjs b/web/tests/search.test.cjsindex 6c42f1aa84f..76bfbd3efe0 100644--- a/web/tests/search.test.cjs+++ b/web/tests/search.test.cjs@@ -48,6 +48,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {stub_pills();mock_template("search_list_item.hbs", true, (_data, html) => html);+ mock_template("search_description.hbs", true, (_data, html) => html);let expected_pill_display_value = "";let input_pill_displayed = false;@@ -87,13 +88,51 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {});{+ {+ const search_suggestions = {+ lookup_table: new Map([+ [+ "dm:",+ {+ description_html: "direct messages with",+ search_string: "dm:",+ },+ ],+ [+ "dm",+ {+ description_html: "Search for dm",+ search_string: "dm",+ },+ ],+ ]),+ strings: ["dm", "dm:"],+ };++ /* Test source */+ override_rewire(search_suggestion, "get_suggestions", () => search_suggestions);+ const expected_source_value = search_suggestions.strings;+ const source = opts.source("dm");+ assert.deepStrictEqual(source, expected_source_value);++ /* Test highlighter */+ let expected_value = `<div class="search_list_item">\n <div class="description">Search for dm</div>\n \n</div>\n`;+ assert.equal(opts.item_html(source[0], "dm"), expected_value);++ expected_value = `<div class="search_list_item">\n <span class="pill-container"><div class='pill ' tabindex=0>\n <span class="pill-label">\n <span class="pill-value">\n dm: \n </span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n</div>\n</span>\n <div class="description">Direct messages with</div>\n</div>\n`;+ assert.equal(opts.item_html(source[1], "dm"), expected_value);++ /* Test sorter */+ assert.equal(opts.sorter(search_suggestions.strings), search_suggestions.strings);+ }+{const search_suggestions = {lookup_table: new Map([["stream:Verona",{- description_html: "Stream Verona",+ description_html: "Messages in #Verona",search_string: "stream:Verona",},],@@ -117,12 +156,12 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {/* Test highlighter */let description_html = "Search for ver";let expected_value = `<div class="search_list_item">\n <div class="description">Search for ver</div>\n \n</div>\n`;- assert.equal(opts.item_html(source[0]), expected_value);+ assert.equal(opts.item_html(source[0], "ver"), expected_value);const search_string = "channel: Verona";- description_html = "Stream Verona";+ description_html = "Messages in #Verona";expected_value = `<div class="search_list_item">\n <span class="pill-container"><div class='pill ' tabindex=0>\n <span class="pill-label">\n <span class="pill-value">\n ${search_string}\n </span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n</div>\n</span>\n <div class="description">${description_html}</div>\n</div>\n`;- assert.equal(opts.item_html(source[1]), expected_value);+ assert.equal(opts.item_html(source[1], "ver"), expected_value);/* Test sorter */assert.equal(opts.sorter(search_suggestions.strings), search_suggestions.strings);@@ -172,7 +211,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {/* Test highlighter */const description_html = "Search for zo";let expected_value = `<div class="search_list_item">\n <div class="description">${description_html}</div>\n \n</div>\n`;- assert.equal(opts.item_html(source[0]), expected_value);+ assert.equal(opts.item_html(source[0], "zo"), expected_value);people.add_active_user({email: "[email protected]",@@ -181,13 +220,13 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {});override(realm, "realm_enable_guest_user_indicator", true);expected_value = `<div class="search_list_item">\n <span class="pill-container"><div class="user-pill-container pill" tabindex=0>\n <span class="pill-label">sender:\n </span>\n <div class="pill" data-user-id="3">\n <img class="pill-image" src="/avatar/3" />\n <div class="pill-image-border"></div>\n <span class="pill-label">\n <span class="pill-value">Zoe</span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n </div>\n</div>\n</span>\n \n</div>\n`;- assert.equal(opts.item_html(source[1]), expected_value);+ assert.equal(opts.item_html(source[1], "zo"), expected_value);expected_value = `<div class="search_list_item">\n <span class="pill-container"><div class="user-pill-container pill" tabindex=0>\n <span class="pill-label">dm:\n </span>\n <div class="pill" data-user-id="3">\n <img class="pill-image" src="/avatar/3" />\n <div class="pill-image-border"></div>\n <span class="pill-label">\n <span class="pill-value">Zoe</span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n </div>\n</div>\n</span>\n \n</div>\n`;- assert.equal(opts.item_html(source[2]), expected_value);+ assert.equal(opts.item_html(source[2], "zo"), expected_value);expected_value = `<div class="search_list_item">\n <span class="pill-container"><div class="user-pill-container pill" tabindex=0>\n <span class="pill-label">dm-including:\n </span>\n <div class="pill" data-user-id="3">\n <img class="pill-image" src="/avatar/3" />\n <div class="pill-image-border"></div>\n <span class="pill-label">\n <span class="pill-value">Zoe</span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n </div>\n</div>\n</span>\n \n</div>\n`;- assert.equal(opts.item_html(source[3]), expected_value);+ assert.equal(opts.item_html(source[3], "zo"), expected_value);/* Test sorter */assert.equal(opts.sorter(search_suggestions.strings), search_suggestions.strings);diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjsindex 4fd310e3e06..190b4d76f98 100644--- a/web/tests/search_suggestion.test.cjs+++ b/web/tests/search_suggestion.test.cjs@@ -283,9 +283,7 @@ test("dm_suggestions", ({override}) => {assert.deepEqual(suggestions.strings, expected);});-test("group_suggestions", ({mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);-+test("group_suggestions", () => {// If there's an existing completed user pill right before// the input string, we suggest a user group as one of the// suggestions.@@ -396,26 +394,9 @@ test("empty_query_suggestions", () => {];assert.deepEqual(suggestions.strings, expected);-- function describe(q) {- return suggestions.lookup_table.get(q).description_html;- }- assert.equal(describe("is:dm"), "Direct messages");- assert.equal(describe("is:starred"), "Starred messages");- assert.equal(describe("is:mentioned"), "Messages that mention you");- assert.equal(describe("is:alerted"), "Alerted messages");- assert.equal(describe("is:unread"), "Unread messages");- assert.equal(describe("is:resolved"), "Resolved topics");- assert.equal(describe("is:followed"), "Followed topics");- assert.equal(describe("sender:[email protected]"), "Sent by me");- assert.equal(describe("has:link"), "Messages with links");- assert.equal(describe("has:image"), "Messages with images");- assert.equal(describe("has:attachment"), "Messages with attachments");});-test("has_suggestions", ({override, mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);-+test("has_suggestions", ({override}) => {// Checks that category wise suggestions are displayed instead of a single// default suggestion when suggesting `has` operator.let query = "h";@@ -427,21 +408,10 @@ test("has_suggestions", ({override, mock_template}) => {let expected = ["h", "has:link", "has:image", "has:attachment", "has:reaction"];assert.deepEqual(suggestions.strings, expected);- function describe(q) {- return suggestions.lookup_table.get(q).description_html;- }-- assert.equal(describe("has:link"), "Messages with links");- assert.equal(describe("has:image"), "Messages with images");- assert.equal(describe("has:attachment"), "Messages with attachments");-query = "-h";suggestions = get_suggestions(query);expected = ["-h", "-has:link", "-has:image", "-has:attachment", "-has:reaction"];assert.deepEqual(suggestions.strings, expected);- 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");// operand suggestions follow.@@ -472,9 +442,7 @@ test("has_suggestions", ({override, mock_template}) => {assert.deepEqual(suggestions.strings, expected);});-test("check_is_suggestions", ({override, mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);-+test("check_is_suggestions", ({override}) => {override(narrow_state, "stream_id", noop);let query = "i";@@ -496,19 +464,6 @@ test("check_is_suggestions", ({override, mock_template}) => {];assert.deepEqual(suggestions.strings, expected);- function describe(q) {- return suggestions.lookup_table.get(q).description_html;- }-- assert.equal(describe("is:dm"), "Direct messages");- assert.equal(describe("is:starred"), "Starred messages");- assert.equal(describe("is:mentioned"), "Messages that mention you");- assert.equal(describe("is:alerted"), "Alerted messages");- assert.equal(describe("is:unread"), "Unread messages");- assert.equal(describe("is:resolved"), "Resolved topics");- assert.equal(describe("is:followed"), "Followed topics");- assert.equal(describe("is:muted"), "Muted messages");-query = "-i";suggestions = get_suggestions(query);expected = [@@ -524,15 +479,6 @@ test("check_is_suggestions", ({override, mock_template}) => {];assert.deepEqual(suggestions.strings, expected);- assert.equal(describe("-is:dm"), "Exclude direct messages");- assert.equal(describe("-is:starred"), "Exclude starred messages");- assert.equal(describe("-is:mentioned"), "Exclude messages that mention you");- assert.equal(describe("-is:alerted"), "Exclude alerted messages");- assert.equal(describe("-is:unread"), "Exclude unread messages");- assert.equal(describe("-is:resolved"), "Unresolved topics");- assert.equal(describe("-is:followed"), "Exclude followed topics");- assert.equal(describe("-is:muted"), "Exclude muted messages");-// operand suggestions follow.query = "is:";@@ -573,18 +519,12 @@ test("check_is_suggestions", ({override, mock_template}) => {assert.deepEqual(suggestions.strings, expected);});-test("sent_by_me_suggestions", ({override, mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);-+test("sent_by_me_suggestions", ({override}) => {override(narrow_state, "stream_id", noop);let query = "";let suggestions = get_suggestions(query);assert.ok(suggestions.strings.includes("sender:[email protected]"));- assert.equal(- suggestions.lookup_table.get("sender:[email protected]").description_html,- "Sent by me",- );query = "sender";suggestions = get_suggestions(query);@@ -643,8 +583,7 @@ test("sent_by_me_suggestions", ({override, mock_template}) => {assert.deepEqual(suggestions.strings, expected);});-test("topic_suggestions", ({override, mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);+test("topic_suggestions", ({override}) => {let suggestions;let expected;@@ -685,12 +624,6 @@ test("topic_suggestions", ({override, mock_template}) => {];assert.deepEqual(suggestions.strings, expected);- function describe(q) {- return suggestions.lookup_table.get(q).description_html;- }- assert.equal(describe("te"), "Search for te");- assert.equal(describe(`channel:${office_id} topic:team`), "Messages in #office > team");-suggestions = get_suggestions(`topic:staplers channel:${office_id}`);expected = [`topic:staplers channel:${office_id}`];assert.deepEqual(suggestions.strings, expected);@@ -867,8 +800,7 @@ test("topic_suggestions (limits)", () => {assert_result("z", []);});-test("whitespace_glitch", ({override, mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);+test("whitespace_glitch", ({override}) => {const office_stream_id = new_stream_id();const query = "channel:office "; // note trailing space@@ -883,18 +815,6 @@ test("whitespace_glitch", ({override, mock_template}) => {assert.deepEqual(suggestions.strings, expected);});-test("xss_channel_name", () => {- const stream_id = new_stream_id();- stream_data.add_sub_for_tests({stream_id, name: "<em> Italics </em>", subscribed: true});-- const query = "channel:ita";- const suggestions = get_suggestions(query);- assert.deepEqual(- suggestions.lookup_table.get(`channel:${stream_id}`).description_html,- "Messages in #<em> Italics </em>",- );-});-test("channel_completion", ({override}) => {const office_stream_id = new_stream_id();stream_data.add_sub_for_tests({stream_id: office_stream_id, name: "office", subscribed: true});@@ -923,9 +843,7 @@ test("channel_completion", ({override}) => {assert.deepEqual(suggestions.strings, expected);});-test("people_suggestions", ({override, mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);-+test("people_suggestions", ({override}) => {let query = "te";override(narrow_state, "stream_id", noop);@@ -1001,33 +919,6 @@ test("people_suggestions", ({override, mock_template}) => {];assert.deepEqual(suggestions.strings, expected);- function test_describe(q, description_html_start) {- assert.ok(- suggestions.lookup_table.get(q).description_html.startsWith(description_html_start),- );- }- test_describe("dm:[email protected]", "Direct messages with");- test_describe("sender:[email protected]", "Sent by");- test_describe("dm-including:[email protected]", "Direct messages including");-- let expectedString = "Ted Smith";-- function test_full_name(q, full_name_html) {- return suggestions.lookup_table.get(q).description_html.includes(full_name_html);- }- test_full_name("sender:[email protected]", expectedString);- test_full_name("dm:[email protected]", expectedString);- test_full_name("dm-including:[email protected]", expectedString);-- expectedString = example_avatar_url;-- function test_avatar_url(q, avatar_url) {- return suggestions.lookup_table.get(q).description_html.includes(avatar_url);- }- test_avatar_url("dm:[email protected]", expectedString);- test_avatar_url("sender:[email protected]", expectedString);- test_avatar_url("dm-including:[email protected]", expectedString);-suggestions = get_suggestions("Ted "); // note spaceexpected = ["Ted", "dm:[email protected]", "sender:[email protected]", "dm-including:[email protected]"];@@ -1050,9 +941,7 @@ test("people_suggestions", ({override, mock_template}) => {assert.deepEqual(suggestions.strings, expected);});-test("operator_suggestions", ({override, mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);-+test("operator_suggestions", ({override}) => {override(stream_topic_history_util, "get_server_history", noop);override(narrow_state, "stream_id", () => undefined);