Commit 910e9e81 authored by Jonne Haß's avatar Jonne Haß

Merge pull request #6543 from manuelVo/5485-mobile-empty-comment-handling

Do not disable submit button if comment is empty in mobile view
parents 7fca5cf9 1680c0c9
......@@ -67,6 +67,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure.
* Display username and avatar for NSFW posts in mobile view [#6245](https://github.com/diaspora/diaspora/6245)
* Prevent multiple comment boxes on mobile [#6363](https://github.com/diaspora/diaspora/pull/6363)
* Correctly display location in post preview [#6429](https://github.com/diaspora/diaspora/pull/6429)
* Do not fail when submitting an empty comment in the mobile view [#6543](https://github.com/diaspora/diaspora/pull/6543)
## Features
* Support color themes [#6033](https://github.com/diaspora/diaspora/pull/6033)
......
......@@ -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) {
......
# 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
......@@ -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();
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment