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: Inline return_true and return_false.

Steve Howell3035d1790bdb
diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js
index ea7b9c2b881..669e3a90852 100644
--- a/frontend_tests/node_tests/compose_actions.js
+++ b/frontend_tests/node_tests/compose_actions.js
@@ -7,8 +7,6 @@ const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const noop = () => {};
-const return_false = () => false;
-const return_true = () => true;
set_global("page_params", {});
@@ -22,7 +20,7 @@ const compose_pm_pill = set_global("compose_pm_pill", {});
const hash_util = set_global("hash_util", {});
set_global("reload_state", {
- is_in_progress: return_false,
+ is_in_progress: () => false,
});
set_global("notifications", {
@@ -404,12 +402,12 @@ run_test("focus_in_empty_compose", () => {
return $("#compose-textarea").is_focused;
};
- compose_state.composing = return_true;
+ compose_state.composing = () => true;
$("#compose-textarea").val("");
$("#compose-textarea").trigger("focus");
assert(compose_state.focus_in_empty_compose());
- compose_state.composing = return_false;
+ compose_state.composing = () => false;
assert(!compose_state.focus_in_empty_compose());
$("#compose-textarea").val("foo");
diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js
index 3b1cd52fc6c..69c6c36422a 100644
--- a/frontend_tests/node_tests/hotkey.js
+++ b/frontend_tests/node_tests/hotkey.js
@@ -82,13 +82,6 @@ emoji.initialize({
emoji_codes,
});
-function return_true() {
- return true;
-}
-function return_false() {
- return false;
-}
-
function stubbing(module, func_name_to_stub, test_function) {
with_overrides((override) => {
const stub = make_stub();
@@ -215,33 +208,33 @@ run_test("basic_chars", () => {
// We have to skip some checks due to the way the code is
// currently organized for mapped keys.
- hotkey.in_content_editable_widget = return_false;
- overlays.settings_open = return_false;
+ hotkey.in_content_editable_widget = () => false;
+ overlays.settings_open = () => false;
const popovers = set_global("popovers", {
- actions_popped: return_false,
- message_info_popped: return_false,
- user_sidebar_popped: return_false,
- user_info_popped: return_false,
+ actions_popped: () => false,
+ message_info_popped: () => false,
+ user_sidebar_popped: () => false,
+ user_info_popped: () => false,
});
set_global("stream_popover", {
- stream_popped: return_false,
- topic_popped: return_false,
- all_messages_popped: return_false,
- starred_messages_popped: return_false,
+ stream_popped: () => false,
+ topic_popped: () => false,
+ all_messages_popped: () => false,
+ starred_messages_popped: () => false,
});
const emoji_picker = set_global("emoji_picker", {
- reactions_popped: return_false,
+ reactions_popped: () => false,
});
set_global("hotspots", {
- is_open: return_false,
+ is_open: () => false,
});
const gear_menu = set_global("gear_menu", {
- is_open: return_false,
+ is_open: () => false,
});
// All letters should return false if we are composing text.
- hotkey.processing_text = return_true;
+ hotkey.processing_text = () => true;
function test_normal_typing() {
assert_unmapped("abcdefghijklmnopqrsuvwxyz");
@@ -251,9 +244,9 @@ run_test("basic_chars", () => {
assert_unmapped('~!@#$%^*()_+{}:"<>');
}
- for (const settings_open of [return_true, return_false]) {
- for (const is_active of [return_true, return_false]) {
- for (const info_overlay_open of [return_true, return_false]) {
+ for (const settings_open of [() => true, () => false]) {
+ for (const is_active of [() => true, () => false]) {
+ for (const info_overlay_open of [() => true, () => false]) {
overlays = set_global("overlays", {
is_active,
settings_open,
@@ -265,23 +258,23 @@ run_test("basic_chars", () => {
}
// Ok, now test keys that work when we're viewing messages.
- hotkey.processing_text = return_false;
- overlays.settings_open = return_false;
- overlays.streams_open = return_false;
- overlays.lightbox_open = return_false;
- overlays.drafts_open = return_false;
+ hotkey.processing_text = () => false;
+ overlays.settings_open = () => false;
+ overlays.streams_open = () => false;
+ overlays.lightbox_open = () => false;
+ overlays.drafts_open = () => false;
page_params.can_create_streams = true;
- overlays.streams_open = return_true;
- overlays.is_active = return_true;
+ overlays.streams_open = () => true;
+ overlays.is_active = () => true;
assert_mapping("S", subs, "keyboard_sub");
assert_mapping("V", subs, "view_stream");
assert_mapping("n", subs, "open_create_stream");
page_params.can_create_streams = false;
assert_unmapped("n");
- overlays.streams_open = return_false;
+ overlays.streams_open = () => false;
test_normal_typing();
- overlays.is_active = return_false;
+ overlays.is_active = () => false;
assert_mapping("?", hashchange, "go_to_location");
assert_mapping("/", search, "initiate_search");
@@ -296,27 +289,27 @@ run_test("basic_chars", () => {
assert_mapping("P", narrow, "by");
assert_mapping("g", gear_menu, "open");
- overlays.is_active = return_true;
- overlays.drafts_open = return_true;
+ overlays.is_active = () => true;
+ overlays.drafts_open = () => true;
assert_mapping("d", overlays, "close_overlay");
- overlays.drafts_open = return_false;
+ overlays.drafts_open = () => false;
test_normal_typing();
- overlays.is_active = return_false;
+ overlays.is_active = () => false;
assert_mapping("d", drafts, "launch");
// Next, test keys that only work on a selected message.
const message_view_only_keys = "@+>RjJkKsSuvi:GM";
// Check that they do nothing without a selected message
- current_msg_list.empty = return_true;
+ current_msg_list.empty = () => true;
assert_unmapped(message_view_only_keys);
- current_msg_list.empty = return_false;
+ current_msg_list.empty = () => false;
// Check that they do nothing while in the settings overlay
- overlays.settings_open = return_true;
+ overlays.settings_open = () => true;
assert_unmapped("@*+->rRjJkKsSuvi:GM");
- overlays.settings_open = return_false;
+ overlays.settings_open = () => false;
// TODO: Similar check for being in the subs page
@@ -337,17 +330,17 @@ run_test("basic_chars", () => {
assert_mapping(">", compose_actions, "quote_and_reply");
assert_mapping("e", message_edit, "start");
- overlays.is_active = return_true;
- overlays.lightbox_open = return_true;
+ overlays.is_active = () => true;
+ overlays.lightbox_open = () => true;
assert_mapping("v", overlays, "close_overlay");
- overlays.lightbox_open = return_false;
+ overlays.lightbox_open = () => false;
test_normal_typing();
- overlays.is_active = return_false;
+ overlays.is_active = () => false;
assert_mapping("v", lightbox, "show_from_selected_message");
- emoji_picker.reactions_popped = return_true;
+ emoji_picker.reactions_popped = () => true;
assert_mapping(":", emoji_picker, "navigate", true);
- emoji_picker.reactions_popped = return_false;
+ emoji_picker.reactions_popped = () => false;
assert_mapping("G", navigate, "to_end");
assert_mapping("M", muting_ui, "toggle_topic_mute");
@@ -357,9 +350,9 @@ run_test("basic_chars", () => {
assert_mapping("n", narrow, "narrow_to_next_topic");
assert_mapping("p", narrow, "narrow_to_next_pm_string");
- current_msg_list.empty = return_true;
+ current_msg_list.empty = () => true;
assert_mapping("n", narrow, "narrow_to_next_topic");
- current_msg_list.empty = return_false;
+ current_msg_list.empty = () => false;
});
run_test("motion_keys", () => {
@@ -406,11 +399,11 @@ run_test("motion_keys", () => {
});
}
- list_util.inside_list = return_false;
- current_msg_list.empty = return_true;
- overlays.settings_open = return_false;
- overlays.streams_open = return_false;
- overlays.lightbox_open = return_false;
+ list_util.inside_list = () => false;
+ current_msg_list.empty = () => true;
+ overlays.settings_open = () => false;
+ overlays.streams_open = () => false;
+ overlays.lightbox_open = () => false;
assert_unmapped("down_arrow");
assert_unmapped("end");
@@ -420,12 +413,12 @@ run_test("motion_keys", () => {
assert_unmapped("spacebar");
assert_unmapped("up_arrow");
- list_util.inside_list = return_true;
+ list_util.inside_list = () => true;
assert_mapping("up_arrow", list_util, "go_up");
assert_mapping("down_arrow", list_util, "go_down");
- list_util.inside_list = return_false;
+ list_util.inside_list = () => false;
- current_msg_list.empty = return_false;
+ current_msg_list.empty = () => false;
assert_mapping("down_arrow", navigate, "down");
assert_mapping("end", navigate, "to_end");
assert_mapping("home", navigate, "to_home");
@@ -435,39 +428,39 @@ run_test("motion_keys", () => {
assert_mapping("spacebar", navigate, "page_down");
assert_mapping("up_arrow", navigate, "up");
- overlays.info_overlay_open = return_true;
+ overlays.info_overlay_open = () => true;
assert_unmapped("down_arrow");
assert_unmapped("up_arrow");
- overlays.info_overlay_open = return_false;
+ overlays.info_overlay_open = () => false;
- overlays.streams_open = return_true;
+ overlays.streams_open = () => true;
assert_mapping("up_arrow", subs, "switch_rows");
assert_mapping("down_arrow", subs, "switch_rows");
- overlays.streams_open = return_false;
+ overlays.streams_open = () => false;
- overlays.lightbox_open = return_true;
+ overlays.lightbox_open = () => true;
assert_mapping("left_arrow", lightbox, "prev");
assert_mapping("right_arrow", lightbox, "next");
- overlays.lightbox_open = return_false;
+ overlays.lightbox_open = () => false;
- hotkey.in_content_editable_widget = return_true;
+ hotkey.in_content_editable_widget = () => true;
assert_unmapped("down_arrow");
assert_unmapped("up_arrow");
- hotkey.in_content_editable_widget = return_false;
+ hotkey.in_content_editable_widget = () => false;
- overlays.settings_open = return_true;
+ overlays.settings_open = () => true;
assert_unmapped("end");
assert_unmapped("home");
assert_unmapped("left_arrow");
assert_unmapped("page_up");
assert_unmapped("page_down");
assert_unmapped("spacebar");
- overlays.settings_open = return_false;
+ overlays.settings_open = () => false;
- overlays.is_active = return_true;
- overlays.drafts_open = return_true;
+ overlays.is_active = () => true;
+ overlays.drafts_open = () => true;
assert_mapping("up_arrow", drafts, "drafts_handle_events");
assert_mapping("down_arrow", drafts, "drafts_handle_events");
- overlays.is_active = return_false;
- overlays.drafts_open = return_false;
+ overlays.is_active = () => false;
+ overlays.drafts_open = () => false;
});
diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js
index 23895e38952..20b696b69bc 100644
--- a/frontend_tests/node_tests/people_errors.js
+++ b/frontend_tests/node_tests/people_errors.js
@@ -5,10 +5,8 @@ const {strict: assert} = require("assert");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-const return_false = () => false;
-const return_true = () => true;
const reload_state = set_global("reload_state", {
- is_in_progress: return_false,
+ is_in_progress: () => false,
});
const people = zrequire("people");
@@ -29,7 +27,7 @@ run_test("report_late_add", () => {
people.report_late_add(55, "[email protected]");
blueslip.expect("log", "Added user late: user_id=55 [email protected]");
- reload_state.is_in_progress = return_true;
+ reload_state.is_in_progress = () => true;
people.report_late_add(55, "[email protected]");
});
diff --git a/frontend_tests/node_tests/poll_widget.js b/frontend_tests/node_tests/poll_widget.js
index d125937972b..fee9cb62a24 100644
--- a/frontend_tests/node_tests/poll_widget.js
+++ b/frontend_tests/node_tests/poll_widget.js
@@ -11,9 +11,6 @@ const poll_widget = zrequire("poll_widget");
const people = zrequire("people");
-const return_false = () => false;
-const return_true = () => true;
-
run_test("PollData my question", () => {
const is_my_poll = true;
const question = "Favorite color?";
@@ -140,7 +137,7 @@ run_test("PollData my question", () => {
});
run_test("activate another person poll", () => {
- people.is_my_user_id = return_false;
+ people.is_my_user_id = () => false;
stub_templates((template_name) => {
if (template_name === "widgets/poll_widget") {
return "widgets/poll_widget";
@@ -263,7 +260,7 @@ run_test("activate another person poll", () => {
});
run_test("activate own poll", () => {
- people.is_my_user_id = return_true;
+ people.is_my_user_id = () => true;
stub_templates((template_name) => {
if (template_name === "widgets/poll_widget") {
return "widgets/poll_widget";
diff --git a/frontend_tests/node_tests/presence.js b/frontend_tests/node_tests/presence.js
index 4ae375a2167..928a6442d87 100644
--- a/frontend_tests/node_tests/presence.js
+++ b/frontend_tests/node_tests/presence.js
@@ -5,11 +5,9 @@ const {strict: assert} = require("assert");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-const return_false = () => false;
-
const server_events = set_global("server_events", {});
const reload_state = set_global("reload_state", {
- is_in_progress: return_false,
+ is_in_progress: () => false,
});
const people = zrequire("people");
diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js
index 29e63dfa206..adafdffaa7b 100644
--- a/frontend_tests/node_tests/search.js
+++ b/frontend_tests/node_tests/search.js
@@ -11,10 +11,8 @@ set_global("page_params", {
});
const noop = () => {};
-const return_true = () => true;
-const return_false = () => false;
-const narrow_state = set_global("narrow_state", {filter: return_false});
+const narrow_state = set_global("narrow_state", {filter: () => false});
const search_suggestion = set_global("search_suggestion", {});
set_global("ui_util", {
change_tab_to: noop,
@@ -23,7 +21,7 @@ set_global("ui_util", {
const narrow = set_global("narrow", {});
set_global("search_pill_widget", {
widget: {
- getByID: return_true,
+ getByID: () => true,
},
});
@@ -50,30 +48,30 @@ run_test("update_button_visibility", () => {
const search_query = $("#search_query");
const search_button = $(".search_button");
- search_query.is = return_false;
+ search_query.is = () => false;
search_query.val("");
- narrow_state.active = return_false;
+ narrow_state.active = () => false;
search_button.prop("disabled", true);
search.update_button_visibility();
assert(search_button.prop("disabled"));
- search_query.is = return_true;
+ search_query.is = () => true;
search_query.val("");
- narrow_state.active = return_false;
+ narrow_state.active = () => false;
search_button.prop("disabled", true);
search.update_button_visibility();
assert(!search_button.prop("disabled"));
- search_query.is = return_false;
+ search_query.is = () => false;
search_query.val("Test search term");
- narrow_state.active = return_false;
+ narrow_state.active = () => false;
search_button.prop("disabled", true);
search.update_button_visibility();
assert(!search_button.prop("disabled"));
- search_query.is = return_false;
+ search_query.is = () => false;
search_query.val("");
- narrow_state.active = return_true;
+ narrow_state.active = () => true;
search_button.prop("disabled", true);
search.update_button_visibility();
assert(!search_button.prop("disabled"));
@@ -228,7 +226,7 @@ run_test("initialize", () => {
default_prevented = true;
},
};
- search_query_box.is = return_false;
+ search_query_box.is = () => false;
assert.equal(keydown(ev), undefined);
assert(!default_prevented);
@@ -237,13 +235,13 @@ run_test("initialize", () => {
assert(!default_prevented);
ev.which = 13;
- search_query_box.is = return_true;
+ search_query_box.is = () => true;
assert.equal(keydown(ev), undefined);
assert(default_prevented);
let operators;
let is_blurred;
- narrow_state.active = return_false;
+ narrow_state.active = () => false;
search_query_box.off("blur");
search_query_box.on("blur", () => {
is_blurred = true;
@@ -277,21 +275,21 @@ run_test("initialize", () => {
type: "keyup",
which: 15,
};
- search_query_box.is = return_false;
+ search_query_box.is = () => false;
searchbox_form.trigger(ev);
assert(!is_blurred);
assert(!search_button.prop("disabled"));
ev.which = 13;
- search_query_box.is = return_false;
+ search_query_box.is = () => false;
searchbox_form.trigger(ev);
assert(!is_blurred);
assert(!search_button.prop("disabled"));
ev.which = 13;
- search_query_box.is = return_true;
+ search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
@@ -304,7 +302,7 @@ run_test("initialize", () => {
_setup("ver");
ev.which = 13;
- search_query_box.is = return_true;
+ search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
assert(!search_button.prop("disabled"));
diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.js
index 33133276e03..b59e245f75a 100644
--- a/frontend_tests/node_tests/search_legacy.js
+++ b/frontend_tests/node_tests/search_legacy.js
@@ -11,8 +11,6 @@ set_global("page_params", {
});
const noop = () => {};
-const return_true = () => true;
-const return_false = () => false;
const narrow_state = set_global("narrow_state", {});
const search_suggestion = set_global("search_suggestion", {});
@@ -31,30 +29,30 @@ run_test("update_button_visibility", () => {
const search_query = $("#search_query");
const search_button = $(".search_button");
- search_query.is = return_false;
+ search_query.is = () => false;
search_query.val("");
- narrow_state.active = return_false;
+ narrow_state.active = () => false;
search_button.prop("disabled", true);
search.update_button_visibility();
assert(search_button.prop("disabled"));
- search_query.is = return_true;
+ search_query.is = () => true;
search_query.val("");
- narrow_state.active = return_false;
+ narrow_state.active = () => false;
search_button.prop("disabled", true);
search.update_button_visibility();
assert(!search_button.prop("disabled"));
- search_query.is = return_false;
+ search_query.is = () => false;
search_query.val("Test search term");
- narrow_state.active = return_false;
+ narrow_state.active = () => false;
search_button.prop("disabled", true);
search.update_button_visibility();
assert(!search_button.prop("disabled"));
- search_query.is = return_false;
+ search_query.is = () => false;
search_query.val("");
- narrow_state.active = return_true;
+ narrow_state.active = () => true;
search_button.prop("disabled", true);
search.update_button_visibility();
assert(!search_button.prop("disabled"));
@@ -186,7 +184,7 @@ run_test("initialize", () => {
default_prevented = true;
},
};
- search_query_box.is = return_false;
+ search_query_box.is = () => false;
assert.equal(keydown(ev), undefined);
assert(!default_prevented);
@@ -195,7 +193,7 @@ run_test("initialize", () => {
assert(!default_prevented);
ev.which = 13;
- search_query_box.is = return_true;
+ search_query_box.is = () => true;
assert.equal(keydown(ev), undefined);
assert(default_prevented);
@@ -204,7 +202,7 @@ run_test("initialize", () => {
};
let operators;
let is_blurred;
- narrow_state.active = return_false;
+ narrow_state.active = () => false;
search_query_box.off("blur");
search_query_box.on("blur", () => {
is_blurred = true;
@@ -234,21 +232,21 @@ run_test("initialize", () => {
_setup("");
ev.which = 15;
- search_query_box.is = return_false;
+ search_query_box.is = () => false;
searchbox_form.trigger(ev);
assert(!is_blurred);
assert(!search_button.prop("disabled"));
ev.which = 13;
- search_query_box.is = return_false;
+ search_query_box.is = () => false;
searchbox_form.trigger(ev);
assert(!is_blurred);
assert(!search_button.prop("disabled"));
ev.which = 13;
- search_query_box.is = return_true;
+ search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
@@ -261,7 +259,7 @@ run_test("initialize", () => {
_setup("ver");
ev.which = 13;
- search_query_box.is = return_true;
+ search_query_box.is = () => true;
searchbox_form.trigger(ev);
assert(is_blurred);
assert(!search_button.prop("disabled"));
@@ -272,7 +270,7 @@ run_test("initiate_search", () => {
// this implicitly expects the code to used the chained
// function calls, which is something to keep in mind if
// this test ever fails unexpectedly.
- narrow_state.filter = () => ({is_search: return_true});
+ narrow_state.filter = () => ({is_search: () => true});
let typeahead_forced_open = false;
let is_searchbox_text_selected = false;
$("#search_query").typeahead = (lookup) => {
@@ -291,7 +289,7 @@ run_test("initiate_search", () => {
assert.equal($("#search_query").val(), "ver");
// test that we append space for user convenience
- narrow_state.filter = () => ({is_search: return_false});
+ narrow_state.filter = () => ({is_search: () => false});
search.initiate_search();
assert.equal($("#search_query").val(), "ver ");
});
diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js
index de1fc4483ec..940bb84d6da 100644
--- a/frontend_tests/node_tests/stream_events.js
+++ b/frontend_tests/node_tests/stream_events.js
@@ -8,7 +8,6 @@ const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const noop = () => {};
-const return_true = () => true;
const _settings_notifications = {
update_page: () => {},
};
@@ -34,7 +33,7 @@ set_global("message_list", {
});
subs = set_global("subs", {update_settings_for_subscribed: noop});
-set_global("overlays", {streams_open: return_true});
+set_global("overlays", {streams_open: () => true});
const peer_data = zrequire("peer_data");
const people = zrequire("people");
diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js
index 004102d60ee..f7c3036ad35 100644
--- a/frontend_tests/node_tests/stream_list.js
+++ b/frontend_tests/node_tests/stream_list.js
@@ -15,8 +15,6 @@ const page_params = set_global("page_params", {
});
const noop = () => {};
-const return_false = () => false;
-const return_true = () => true;
const topic_list = set_global("topic_list", {});
set_global("overlays", {});
@@ -170,11 +168,11 @@ test_ui("create_sidebar_row", (override) => {
assert(!social_li.hasClass("out_of_home_view"));
const row = stream_list.stream_sidebar.get_row(stream_id);
- stream_data.is_active = return_true;
+ stream_data.is_active = () => true;
row.update_whether_active();
assert(!social_li.hasClass("inactive_stream"));
- stream_data.is_active = return_false;
+ stream_data.is_active = () => false;
row.update_whether_active();
assert(social_li.hasClass("inactive_stream"));
@@ -200,16 +198,16 @@ test_ui("pinned_streams_never_inactive", (override) => {
const social_sidebar = $("<social sidebar row>");
let stream_id = social.stream_id;
let row = stream_list.stream_sidebar.get_row(stream_id);
- stream_data.is_active = return_false;
+ stream_data.is_active = () => false;
stream_list.build_stream_list();
assert(social_sidebar.hasClass("inactive_stream"));
- stream_data.is_active = return_true;
+ stream_data.is_active = () => true;
row.update_whether_active();
assert(!social_sidebar.hasClass("inactive_stream"));
- stream_data.is_active = return_false;
+ stream_data.is_active = () => false;
row.update_whether_active();
assert(social_sidebar.hasClass("inactive_stream"));
@@ -217,7 +215,7 @@ test_ui("pinned_streams_never_inactive", (override) => {
const devel_sidebar = $("<devel sidebar row>");
stream_id = devel.stream_id;
row = stream_list.stream_sidebar.get_row(stream_id);
- stream_data.is_active = return_false;
+ stream_data.is_active = () => false;
stream_list.build_stream_list();
assert(!devel_sidebar.hasClass("inactive_stream"));
@@ -730,7 +728,7 @@ test_ui("create_initial_sidebar_rows", () => {
const html_dict = new Map();
stream_list.stream_sidebar = {
- has_row_for: return_false,
+ has_row_for: () => false,
set_row(stream_id, widget) {
html_dict.set(stream_id, widget.get_li().html());
},