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.

tests: Use typed helpers in search_suggestion.test.cjs.

Tim Abbott7c87917244b1
diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjs
index eaae22df241..cd4fa1281c9 100644
--- a/web/tests/search_suggestion.test.cjs
+++ b/web/tests/search_suggestion.test.cjs
@@ -3,6 +3,8 @@
const assert = require("node:assert/strict");
const {make_realm} = require("./lib/example_realm.cjs");
+const {make_stream} = require("./lib/example_stream.cjs");
+const {make_user} = require("./lib/example_user.cjs");
const {mock_esm, zrequire} = require("./lib/namespace.cjs");
const {run_test, noop} = require("./lib/test.cjs");
const {page_params} = require("./lib/zpage_params.cjs");
@@ -24,36 +26,36 @@ set_current_user(current_user);
const realm = make_realm();
set_realm(realm);
-const me = {
+const me = make_user({
- full_name: "Me Myself",
user_id: 41,
-};
+ full_name: "Me Myself",
+});
-const bob = {
+const bob = make_user({
- full_name: "Bob Roberts",
user_id: 42,
-};
+ full_name: "Bob Roberts",
+});
-const ted = {
+const ted = make_user({
delivery_email: "[email protected]",
user_id: 101,
full_name: "Ted Smith",
-};
+});
-const alice = {
+const alice = make_user({
user_id: 102,
full_name: "Alice Ignore",
-};
+});
-const jeff = {
+const jeff = make_user({
user_id: 103,
full_name: "Jeff Zoolipson",
-};
+});
const example_avatar_url = "http://example.com/example.png";
@@ -110,7 +112,12 @@ test("basic_get_suggestions", ({override}) => {
test("basic_get_suggestions_for_spectator", () => {
page_params.is_spectator = true;
const web_public_id = new_stream_id();
- const sub = {name: "Web public", stream_id: web_public_id, is_web_public: true};
+ const sub = make_stream({
+ name: "Web public",
+ stream_id: web_public_id,
+ is_web_public: true,
+ subscribed: false,
+ });
stream_data.add_sub_for_tests(sub);
let query = "";
@@ -349,7 +356,7 @@ test("group_suggestions", () => {
// Doesn't show dms because it's invalid in combination
// with a channel. (Random channel id.)
- stream_data.add_sub_for_tests({stream_id: 66, name: "misc", subscribed: true});
+ stream_data.add_sub_for_tests(make_stream({stream_id: 66, name: "misc", subscribed: true}));
query = `channel:66 has:link dm:${bob.user_id},Smit`;
suggestions = get_suggestions(query);
expected = [];
@@ -367,13 +374,17 @@ test("empty_query_suggestions", () => {
const devel_id = new_stream_id();
const office_id = new_stream_id();
- stream_data.add_sub_for_tests({
- stream_id: devel_id,
- name: "devel",
- subscribed: true,
- is_web_public: true,
- });
- stream_data.add_sub_for_tests({stream_id: office_id, name: "office", subscribed: true});
+ stream_data.add_sub_for_tests(
+ make_stream({
+ stream_id: devel_id,
+ name: "devel",
+ subscribed: true,
+ is_web_public: true,
+ }),
+ );
+ stream_data.add_sub_for_tests(
+ make_stream({stream_id: office_id, name: "office", subscribed: true}),
+ );
const suggestions = get_suggestions(query);
@@ -405,8 +416,8 @@ test("has_suggestions", ({override}) => {
// Checks that category wise suggestions are displayed instead of a single
// default suggestion when suggesting `has` operator.
let query = "h";
- stream_data.add_sub_for_tests({stream_id: 44, name: "devel", subscribed: true});
- stream_data.add_sub_for_tests({stream_id: 77, name: "office", subscribed: true});
+ stream_data.add_sub_for_tests(make_stream({stream_id: 44, name: "devel", subscribed: true}));
+ stream_data.add_sub_for_tests(make_stream({stream_id: 77, name: "office", subscribed: true}));
override(narrow_state, "stream_id", noop);
let suggestions = get_suggestions(query);
@@ -440,7 +451,7 @@ test("has_suggestions", ({override}) => {
expected = ["att", "has:attachment"];
assert.deepEqual(suggestions, expected);
- stream_data.add_sub_for_tests({stream_id: 66, name: "misc", subscribed: true});
+ stream_data.add_sub_for_tests(make_stream({stream_id: 66, name: "misc", subscribed: true}));
query = "channel:66 is:alerted has:lin";
suggestions = get_suggestions(query);
expected = ["channel:66 is:alerted has:link"];
@@ -517,7 +528,7 @@ test("check_is_suggestions", ({override}) => {
expected = ["st", "channels:", "channel:", "is:starred"];
assert.deepEqual(suggestions, expected);
- stream_data.add_sub_for_tests({stream_id: 66, name: "misc", subscribed: true});
+ stream_data.add_sub_for_tests(make_stream({stream_id: 66, name: "misc", subscribed: true}));
query = "channel:66 has:link is:sta";
suggestions = get_suggestions(query);
expected = ["channel:66 has:link is:starred"];
@@ -572,7 +583,7 @@ test("sent_by_me_suggestions", ({override}) => {
assert.deepEqual(suggestions, expected);
const denmark_id = new_stream_id();
- const sub = {name: "Denmark", stream_id: denmark_id};
+ const sub = make_stream({name: "Denmark", stream_id: denmark_id});
stream_data.add_sub_for_tests(sub);
query = `channel:${denmark_id} topic:Denmark1 sent`;
suggestions = get_suggestions(query);
@@ -594,12 +605,18 @@ test("topic_suggestions", ({override}) => {
override(stream_topic_history_util, "get_server_history", noop);
const office_id = new_stream_id();
- stream_data.add_sub_for_tests({stream_id: office_id, name: "office", subscribed: true});
+ stream_data.add_sub_for_tests(
+ make_stream({stream_id: office_id, name: "office", subscribed: true}),
+ );
override(narrow_state, "stream_id", () => office_id);
const devel_id = new_stream_id();
- stream_data.add_sub_for_tests({stream_id: devel_id, name: "devel", subscribed: true});
- stream_data.add_sub_for_tests({stream_id: office_id, name: "office", subscribed: true});
+ stream_data.add_sub_for_tests(
+ make_stream({stream_id: devel_id, name: "devel", subscribed: true}),
+ );
+ stream_data.add_sub_for_tests(
+ make_stream({stream_id: office_id, name: "office", subscribed: true}),
+ );
suggestions = get_suggestions("te");
expected = ["te", `dm:${ted.user_id}`, `sender:${ted.user_id}`, `dm-including:${ted.user_id}`];
@@ -811,7 +828,9 @@ test("whitespace_glitch", ({override}) => {
const query = "channel:office "; // note trailing space
override(stream_topic_history_util, "get_server_history", noop);
- stream_data.add_sub_for_tests({stream_id: office_stream_id, name: "office", subscribed: true});
+ stream_data.add_sub_for_tests(
+ make_stream({stream_id: office_stream_id, name: "office", subscribed: true}),
+ );
const suggestions = get_suggestions(query);
@@ -822,13 +841,17 @@ test("whitespace_glitch", ({override}) => {
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});
+ stream_data.add_sub_for_tests(
+ make_stream({stream_id: office_stream_id, name: "office", subscribed: true}),
+ );
const dev_help_stream_id = new_stream_id();
- stream_data.add_sub_for_tests({
- stream_id: dev_help_stream_id,
- name: "dev help",
- subscribed: true,
- });
+ stream_data.add_sub_for_tests(
+ make_stream({
+ stream_id: dev_help_stream_id,
+ name: "dev help",
+ subscribed: true,
+ }),
+ );
override(narrow_state, "stream_id", noop);
@@ -960,7 +983,7 @@ test("operator_suggestions", ({override}) => {
expected = ["-s", "-sender:", "-channels:", "-channel:", `-sender:${me.user_id}`];
assert.deepEqual(suggestions, expected);
- stream_data.add_sub_for_tests({stream_id: 66, name: "misc", subscribed: true});
+ stream_data.add_sub_for_tests(make_stream({stream_id: 66, name: "misc", subscribed: true}));
query = "channel:66 is:alerted -f";
suggestions = get_suggestions(query);
expected = [
@@ -973,9 +996,13 @@ test("operator_suggestions", ({override}) => {
test("queries_with_spaces", () => {
const office_id = new_stream_id();
- stream_data.add_sub_for_tests({stream_id: office_id, name: "office", subscribed: true});
+ stream_data.add_sub_for_tests(
+ make_stream({stream_id: office_id, name: "office", subscribed: true}),
+ );
const dev_help_id = new_stream_id();
- stream_data.add_sub_for_tests({stream_id: dev_help_id, name: "dev help", subscribed: true});
+ stream_data.add_sub_for_tests(
+ make_stream({stream_id: dev_help_id, name: "dev help", subscribed: true}),
+ );
// test allowing spaces with quotes surrounding operand
let query = 'channel:"dev he"';