From f7d1abaa2563b15dad6aaa9ca0706196a74c1f3a Mon Sep 17 00:00:00 2001 From: hollywoodno Date: Fri, 7 Jul 2017 10:31:32 -0700 Subject: [PATCH] compose.js: Prevent sending empty messages in preview mode. This commit specifically addresses the issue when in preview mode, while "enter sends" is enabled. Previously the messages were just sent, now they must pass validation. Fixes #5574. --- frontend_tests/node_tests/compose.js | 13 +++++++++++++ static/js/compose.js | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index 218869d9e6..2d5d994985 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -540,6 +540,8 @@ people.add(bob); }()); (function test_enter_with_preview_open() { + // Test sending a message with content. + $("#new_message_content").val('message me'); $("#new_message_content").hide(); $("#undo_markdown_preview").show(); $("#preview_message_area").show(); @@ -560,6 +562,17 @@ people.add(bob); $("#new_message_content").blur(); compose.enter_with_preview_open(); assert($("#new_message_content").is_focused()); + + // Test sending a message without content. + $("#new_message_content").val(''); + $("#preview_message_area").show(); + $("#enter_sends").prop("checked", true); + page_params.enter_sends = true; + + compose.enter_with_preview_open(); + + assert($("#enter_sends").prop("checked")); + assert.equal($("#error-msg").html(), i18n.t('You have nothing to send!')); }()); (function test_finish() { diff --git a/static/js/compose.js b/static/js/compose.js index 110051ec71..a20d29e99b 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -360,8 +360,8 @@ exports.send_message = function send_message(request) { exports.enter_with_preview_open = function () { exports.clear_preview_area(); if (page_params.enter_sends) { - // If enter_sends is enabled, we just send the message - exports.send_message(); + // If enter_sends is enabled, we attempt to send the message + exports.finish(); } else { // Otherwise, we return to the compose box and focus it $("#new_message_content").focus();