node tests: Introduce test_ui wrappers.

These are a prep step for the next commit.
This commit is contained in:
Steve Howell
2021-02-23 11:09:35 +00:00
committed by Steve Howell
parent 2fae9dc0a2
commit 81fd1a5e6a
2 changed files with 39 additions and 31 deletions

View File

@@ -148,7 +148,11 @@ people.initialize_current_user(me.user_id);
people.add_active_user(alice); people.add_active_user(alice);
people.add_active_user(bob); people.add_active_user(bob);
run_test("validate_stream_message_address_info", () => { function test_ui(label, f) {
run_test(label, f);
}
test_ui("validate_stream_message_address_info", () => {
const sub = { const sub = {
stream_id: 101, stream_id: 101,
name: "social", name: "social",
@@ -203,7 +207,7 @@ run_test("validate_stream_message_address_info", () => {
assert.equal($("#compose-error-msg").html(), i18n.t("Error checking subscription")); assert.equal($("#compose-error-msg").html(), i18n.t("Error checking subscription"));
}); });
run_test("validate", () => { test_ui("validate", () => {
function initialize_pm_pill() { function initialize_pm_pill() {
reset_jquery(); reset_jquery();
@@ -313,7 +317,7 @@ run_test("validate", () => {
assert.equal($("#compose-error-msg").html(), i18n.t("Please specify a topic")); assert.equal($("#compose-error-msg").html(), i18n.t("Please specify a topic"));
}); });
run_test("get_invalid_recipient_emails", () => { test_ui("get_invalid_recipient_emails", () => {
const welcome_bot = { const welcome_bot = {
email: "welcome-bot@example.com", email: "welcome-bot@example.com",
user_id: 124, user_id: 124,
@@ -333,7 +337,7 @@ run_test("get_invalid_recipient_emails", () => {
assert.deepEqual(compose.get_invalid_recipient_emails(), []); assert.deepEqual(compose.get_invalid_recipient_emails(), []);
}); });
run_test("test_wildcard_mention_allowed", () => { test_ui("test_wildcard_mention_allowed", () => {
page_params.realm_wildcard_mention_policy = page_params.realm_wildcard_mention_policy =
settings_config.wildcard_mention_policy_values.by_everyone.code; settings_config.wildcard_mention_policy_values.by_everyone.code;
page_params.is_guest = true; page_params.is_guest = true;
@@ -375,7 +379,7 @@ run_test("test_wildcard_mention_allowed", () => {
assert(!compose.wildcard_mention_allowed()); assert(!compose.wildcard_mention_allowed());
}); });
run_test("validate_stream_message", () => { test_ui("validate_stream_message", () => {
// This test is in kind of continuation to test_validate but since it is // This test is in kind of continuation to test_validate but since it is
// primarily used to get coverage over functions called from validate() // primarily used to get coverage over functions called from validate()
// we are separating it up in different test. Though their relative position // we are separating it up in different test. Though their relative position
@@ -426,7 +430,7 @@ run_test("validate_stream_message", () => {
); );
}); });
run_test("test_validate_stream_message_post_policy_admin_only", () => { test_ui("test_validate_stream_message_post_policy_admin_only", () => {
// This test is in continuation with test_validate but it has been separated out // This test is in continuation with test_validate but it has been separated out
// for better readability. Their relative position of execution should not be changed. // for better readability. Their relative position of execution should not be changed.
// Although the position with respect to test_validate_stream_message does not matter // Although the position with respect to test_validate_stream_message does not matter
@@ -463,7 +467,7 @@ run_test("test_validate_stream_message_post_policy_admin_only", () => {
); );
}); });
run_test("test_validate_stream_message_post_policy_full_members_only", () => { test_ui("test_validate_stream_message_post_policy_full_members_only", () => {
page_params.is_admin = false; page_params.is_admin = false;
page_params.is_guest = true; page_params.is_guest = true;
const sub = { const sub = {
@@ -489,7 +493,7 @@ run_test("test_validate_stream_message_post_policy_full_members_only", () => {
page_params.is_guest = false; page_params.is_guest = false;
}); });
run_test("markdown_rtl", () => { test_ui("markdown_rtl", () => {
const textarea = $("#compose-textarea"); const textarea = $("#compose-textarea");
const event = { const event = {
@@ -513,7 +517,7 @@ run_test("markdown_rtl", () => {
// us back to the "normal" ltr case. // us back to the "normal" ltr case.
rtl.get_direction = () => "ltr"; rtl.get_direction = () => "ltr";
run_test("markdown_ltr", () => { test_ui("markdown_ltr", () => {
const textarea = $("#compose-textarea"); const textarea = $("#compose-textarea");
const event = { const event = {
@@ -527,7 +531,7 @@ run_test("markdown_ltr", () => {
assert.equal(textarea.hasClass("rtl"), false); assert.equal(textarea.hasClass("rtl"), false);
}); });
run_test("markdown_shortcuts", () => { test_ui("markdown_shortcuts", () => {
let queryCommandEnabled = true; let queryCommandEnabled = true;
const event = { const event = {
keyCode: 66, keyCode: 66,
@@ -691,7 +695,7 @@ run_test("markdown_shortcuts", () => {
_navigator.userAgent = ""; _navigator.userAgent = "";
}); });
run_test("send_message_success", () => { test_ui("send_message_success", () => {
$("#compose-textarea").val("foobarfoobar"); $("#compose-textarea").val("foobarfoobar");
$("#compose-textarea").trigger("blur"); $("#compose-textarea").trigger("blur");
$("#compose-send-status").show(); $("#compose-send-status").show();
@@ -716,7 +720,7 @@ run_test("send_message_success", () => {
assert(reify_message_id_checked); assert(reify_message_id_checked);
}); });
run_test("send_message", () => { test_ui("send_message", () => {
// This is the common setup stuff for all of the four tests. // This is the common setup stuff for all of the four tests.
let stub_state; let stub_state;
function initialize_state_stub_dict() { function initialize_state_stub_dict() {
@@ -876,7 +880,7 @@ run_test("send_message", () => {
set_global("document", "document-stub"); set_global("document", "document-stub");
run_test("enter_with_preview_open", () => { test_ui("enter_with_preview_open", () => {
// Test sending a message with content. // Test sending a message with content.
compose_state.set_message_type("stream"); compose_state.set_message_type("stream");
$("#compose-textarea").val("message me"); $("#compose-textarea").val("message me");
@@ -913,7 +917,7 @@ run_test("enter_with_preview_open", () => {
assert.equal($("#compose-error-msg").html(), i18n.t("You have nothing to send!")); assert.equal($("#compose-error-msg").html(), i18n.t("You have nothing to send!"));
}); });
run_test("finish", () => { test_ui("finish", () => {
(function test_when_compose_validation_fails() { (function test_when_compose_validation_fails() {
$("#compose_invite_users").show(); $("#compose_invite_users").show();
$("#compose-send-button").prop("disabled", false); $("#compose-send-button").prop("disabled", false);
@@ -959,7 +963,7 @@ run_test("finish", () => {
})(); })();
}); });
run_test("warn_if_private_stream_is_linked", () => { test_ui("warn_if_private_stream_is_linked", () => {
const test_sub = { const test_sub = {
name: compose_state.stream_name(), name: compose_state.stream_name(),
stream_id: 99, stream_id: 99,
@@ -1032,7 +1036,7 @@ run_test("warn_if_private_stream_is_linked", () => {
} }
}); });
run_test("initialize", () => { test_ui("initialize", () => {
// In this test we mostly do the setup stuff in addition to testing the // In this test we mostly do the setup stuff in addition to testing the
// normal workflow of the function. All the tests for the on functions are // normal workflow of the function. All the tests for the on functions are
// done in subsequent tests directly below this test. // done in subsequent tests directly below this test.
@@ -1149,7 +1153,7 @@ run_test("initialize", () => {
})(); })();
}); });
run_test("update_fade", () => { test_ui("update_fade", () => {
const selector = const selector =
"#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient"; "#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient";
const keyup_handler_func = $(selector).get_on_handler("keyup"); const keyup_handler_func = $(selector).get_on_handler("keyup");
@@ -1178,7 +1182,7 @@ run_test("update_fade", () => {
assert(update_all_called); assert(update_all_called);
}); });
run_test("trigger_submit_compose_form", () => { test_ui("trigger_submit_compose_form", () => {
let prevent_default_checked = false; let prevent_default_checked = false;
let compose_finish_checked = false; let compose_finish_checked = false;
const e = { const e = {
@@ -1198,7 +1202,7 @@ run_test("trigger_submit_compose_form", () => {
assert(compose_finish_checked); assert(compose_finish_checked);
}); });
run_test("needs_subscribe_warning", () => { test_ui("needs_subscribe_warning", () => {
const invalid_user_id = 999; const invalid_user_id = 999;
const test_bot = { const test_bot = {
@@ -1233,7 +1237,7 @@ run_test("needs_subscribe_warning", () => {
assert.equal(compose.needs_subscribe_warning(bob.user_id, sub.stream_id), true); assert.equal(compose.needs_subscribe_warning(bob.user_id, sub.stream_id), true);
}); });
run_test("warn_if_mentioning_unsubscribed_user", () => { test_ui("warn_if_mentioning_unsubscribed_user", () => {
let mentioned = { let mentioned = {
email: "foo@bar.com", email: "foo@bar.com",
}; };
@@ -1357,7 +1361,7 @@ run_test("warn_if_mentioning_unsubscribed_user", () => {
assert(looked_for_existing); assert(looked_for_existing);
}); });
run_test("on_events", () => { test_ui("on_events", () => {
function setup_parents_and_mock_remove(container_sel, target_sel, parent) { function setup_parents_and_mock_remove(container_sel, target_sel, parent) {
const container = $.create("fake " + container_sel); const container = $.create("fake " + container_sel);
let container_removed = false; let container_removed = false;
@@ -1841,7 +1845,7 @@ run_test("on_events", () => {
})(); })();
}); });
run_test("create_message_object", () => { test_ui("create_message_object", () => {
const sub = { const sub = {
stream_id: 101, stream_id: 101,
name: "social", name: "social",
@@ -1889,7 +1893,7 @@ run_test("create_message_object", () => {
people.email_list_to_user_ids_string = email_list_to_user_ids_string; people.email_list_to_user_ids_string = email_list_to_user_ids_string;
}); });
run_test("nonexistent_stream_reply_error", () => { test_ui("nonexistent_stream_reply_error", () => {
reset_jquery(); reset_jquery();
const actions = []; const actions = [];
@@ -1905,7 +1909,7 @@ run_test("nonexistent_stream_reply_error", () => {
assert.deepEqual(actions, ["show", "hide"]); assert.deepEqual(actions, ["show", "hide"]);
}); });
run_test("narrow_button_titles", () => { test_ui("narrow_button_titles", () => {
util.is_mobile = () => false; util.is_mobile = () => false;
compose.update_closed_compose_buttons_for_private(); compose.update_closed_compose_buttons_for_private();
@@ -1917,7 +1921,7 @@ run_test("narrow_button_titles", () => {
assert.equal($("#left_bar_compose_private_button_big").text(), i18n.t("New private message")); assert.equal($("#left_bar_compose_private_button_big").text(), i18n.t("New private message"));
}); });
run_test("test_video_chat_button_toggle", () => { test_ui("test_video_chat_button_toggle", () => {
reset_jquery(); reset_jquery();
stub_out_video_calls(); stub_out_video_calls();

View File

@@ -48,7 +48,11 @@ function reset_test_setup(pill_container_stub) {
}); });
} }
run_test("can_edit", () => { function test_ui(label, f) {
run_test(label, f);
}
test_ui("can_edit", () => {
page_params.is_guest = false; page_params.is_guest = false;
page_params.is_admin = true; page_params.is_admin = true;
assert(settings_user_groups.can_edit(1)); assert(settings_user_groups.can_edit(1));
@@ -95,7 +99,7 @@ const name_selector = `#user-groups #${CSS.escape(1)} .name`;
const description_selector = `#user-groups #${CSS.escape(1)} .description`; const description_selector = `#user-groups #${CSS.escape(1)} .description`;
const instructions_selector = `#user-groups #${CSS.escape(1)} .save-instructions`; const instructions_selector = `#user-groups #${CSS.escape(1)} .save-instructions`;
run_test("populate_user_groups", () => { test_ui("populate_user_groups", () => {
const realm_user_group = { const realm_user_group = {
id: 1, id: 1,
name: "Mobile", name: "Mobile",
@@ -358,7 +362,7 @@ run_test("populate_user_groups", () => {
"function", "function",
); );
}); });
run_test("with_external_user", () => { test_ui("with_external_user", () => {
const realm_user_group = { const realm_user_group = {
id: 1, id: 1,
name: "Mobile", name: "Mobile",
@@ -507,7 +511,7 @@ run_test("with_external_user", () => {
assert.equal(turned_off["click/whole"], true); assert.equal(turned_off["click/whole"], true);
}); });
run_test("reload", () => { test_ui("reload", () => {
$("#user-groups").html("Some text"); $("#user-groups").html("Some text");
let populate_user_groups_called = false; let populate_user_groups_called = false;
settings_user_groups.populate_user_groups = function () { settings_user_groups.populate_user_groups = function () {
@@ -518,13 +522,13 @@ run_test("reload", () => {
assert.equal($("#user-groups").html(), ""); assert.equal($("#user-groups").html(), "");
}); });
run_test("reset", () => { test_ui("reset", () => {
settings_user_groups.reset(); settings_user_groups.reset();
const result = settings_user_groups.reload(); const result = settings_user_groups.reload();
assert.equal(result, undefined); assert.equal(result, undefined);
}); });
run_test("on_events", () => { test_ui("on_events", () => {
settings_user_groups.can_edit = function () { settings_user_groups.can_edit = function () {
return true; return true;
}; };