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 people suggestions.

Steve Howella9f83a5805b6
diff --git a/frontend_tests/node_tests/search_suggestion_now.js b/frontend_tests/node_tests/search_suggestion_now.js
index 4a66a9adf4b..b4f6f23772a 100644
--- a/frontend_tests/node_tests/search_suggestion_now.js
+++ b/frontend_tests/node_tests/search_suggestion_now.js
@@ -2,7 +2,7 @@
const {strict: assert} = require("assert");
-const {mock_esm, zrequire} = require("../zjsunit/namespace");
+const {mock_esm, with_field, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params");
@@ -877,3 +877,58 @@ test("queries_with_spaces", ({override_rewire}) => {
expected = ["stream:offi", "stream:office"];
assert.deepEqual(suggestions.strings, expected);
});
+
+function people_suggestion_setup() {
+ const ted = {
+ email: "[email protected]",
+ user_id: 201,
+ full_name: "Ted Smith",
+ };
+ people.add_active_user(ted);
+
+ const bob = {
+ email: "[email protected]",
+ user_id: 202,
+ full_name: "Bob Térry",
+ };
+
+ people.add_active_user(bob);
+ const alice = {
+ email: "[email protected]",
+ user_id: 203,
+ full_name: "Alice Ignore",
+ };
+ people.add_active_user(alice);
+}
+
+test("people_suggestion (Admin only email visibility)", ({override_rewire}) => {
+ /* Suggestions when realm_email_address_visibility is set to admin
+ only */
+ override_rewire(narrow_state, "stream", () => {});
+ people_suggestion_setup();
+
+ const query = "te";
+ const suggestions = with_field(page_params, "is_admin", false, () =>
+ get_suggestions("", query),
+ );
+
+ const expected = [
+ "te",
+ "sender:[email protected]",
+ "sender:[email protected]",
+ "pm-with:[email protected]", // bob térry
+ "pm-with:[email protected]",
+ "group-pm-with:[email protected]",
+ "group-pm-with:[email protected]",
+ ];
+
+ assert.deepEqual(suggestions.strings, expected);
+
+ const describe = (q) => suggestions.lookup_table.get(q).description;
+
+ assert.equal(
+ describe("pm-with:[email protected]"),
+ "Private messages with <strong>Te</strong>d Smith",
+ );
+ assert.equal(describe("sender:[email protected]"), "Sent by <strong>Te</strong>d Smith");
+});