From 1680c0c9247615eb38c512165cdac462ce87ecfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Thu, 12 Nov 2015 02:44:10 +0100 Subject: [PATCH] Do not disable submit button if comment is empty in mobile view Fixes #5485 --- .../javascripts/mobile/mobile_comments.js | 21 +++++++++++++----- .../jasmine_fixtures/comments_spec.rb | 20 +++++++++++++++++ .../mobile/mobile_comments_spec.js | 22 +++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 spec/controllers/jasmine_fixtures/comments_spec.rb diff --git a/app/assets/javascripts/mobile/mobile_comments.js b/app/assets/javascripts/mobile/mobile_comments.js index 189b43f4b..293660655 100644 --- a/app/assets/javascripts/mobile/mobile_comments.js +++ b/app/assets/javascripts/mobile/mobile_comments.js @@ -30,13 +30,24 @@ self.scrollToOffset(commentContainer); }); - $(".stream").on("submit", ".new_comment", function(evt) { - evt.preventDefault(); - var form = $(this); + $(".stream").on("submit", ".new_comment", this.submitComment); + }, + + submitComment: function(evt) { + evt.preventDefault(); + var form = $(this); + var commentBox = form.find(".comment_box"); + var commentText = $.trim(commentBox.val()); + if (commentText) { $.post(form.attr("action")+"?format=mobile", form.serialize(), function(data) { - self.updateStream(form, data); + Diaspora.Mobile.Comments.updateStream(form, data); }, "html"); - }); + return true; + } + else { + commentBox.focus(); + return false; + } }, toggleComments: function(toggleReactionsLink) { diff --git a/spec/controllers/jasmine_fixtures/comments_spec.rb b/spec/controllers/jasmine_fixtures/comments_spec.rb new file mode 100644 index 000000000..f753e13f8 --- /dev/null +++ b/spec/controllers/jasmine_fixtures/comments_spec.rb @@ -0,0 +1,20 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require "spec_helper" + +describe CommentsController, type: :controller do + describe "#comments" do + before do + sign_in :user, alice + end + + context "jasmine fixtures" do + it "generates a jasmine fixture with the mobile comment box", fixture: true do + get :new, format: :mobile, post_id: 1 + save_fixture(html_for("div"), "comments_mobile_commentbox") + end + end + end +end diff --git a/spec/javascripts/mobile/mobile_comments_spec.js b/spec/javascripts/mobile/mobile_comments_spec.js index 24f4bdbcb..376642e5c 100644 --- a/spec/javascripts/mobile/mobile_comments_spec.js +++ b/spec/javascripts/mobile/mobile_comments_spec.js @@ -116,4 +116,26 @@ describe("Diaspora.Mobile.Comments", function(){ expect(jQuery.ajax).not.toHaveBeenCalled(); }); }); + + describe("createComment", function () { + beforeEach(function() { + spec.loadFixture("aspects_index_mobile_post_with_comments"); + var commentBoxHtml = spec.fixtureHtml("comments_mobile_commentbox"); + var link = $(".stream .comment-action").first(); + Diaspora.Mobile.Comments.showCommentBox(link); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: "text/html", + responseText: commentBoxHtml + }); + $(".stream .new_comment").submit(Diaspora.Mobile.Comments.submitComment); + }); + + it("doesn't submit an empty comment", function() { + var form = $(".stream .new_comment").first(); + spyOn(jQuery, "ajax"); + form.submit(); + expect(jQuery.ajax).not.toHaveBeenCalled(); + }); + }); });