Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

node tests: Add test for topic_suggestions.

Steve Howell599a70d6f41e
diff --git a/frontend_tests/node_tests/search_suggestion_now.js b/frontend_tests/node_tests/search_suggestion_now.js
index b4f6f23772a..8c77c64f772 100644
--- a/frontend_tests/node_tests/search_suggestion_now.js
+++ b/frontend_tests/node_tests/search_suggestion_now.js
@@ -709,6 +709,49 @@ test("topic_suggestions", ({override, override_rewire}) => {
assert.deepEqual(suggestions.strings, expected);
});
+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", []);
+});
+
test("whitespace_glitch", ({override_rewire}) => {
const query = "stream:office "; // note trailing space