fixing commenting

Added jamisne tests for comments

Added 2 jasmine tests for fixing commenting

Bugfix: #4005 added changelog entry
This commit is contained in:
PallaviTS 2013-08-31 12:56:53 +05:30 committed by Jonne Haß
parent 5a821efa18
commit 5caa46cc83
3 changed files with 37 additions and 17 deletions

View file

@ -20,6 +20,8 @@
* Disable submit button in sign up form after submission to avoid email already exists error [#4506](https://github.com/diaspora/diaspora/issues/4506)
* Do not pull the 404 pages assets from Amazon S3 [#4501](https://github.com/diaspora/diaspora/pull/4501)
* Fix counter background does not cover more than 2 digits on profile [#4499](https://github.com/diaspora/diaspora/issues/4499)
* Fix commenting upon submission fail [#4005] (https://github.com/diaspora/diaspora/issues/4005)
## Features
* Add oEmbed content to the mobile view [#4343](https://github.com/diaspora/diaspora/pull/4353)

View file

@ -13,12 +13,18 @@ app.collections.Comments = Backbone.Collection.extend({
var self = this
var comment = new app.models.Comment({text: text })
, deferred = comment.save({}, {url : self.url()})
comment.set({author: app.currentUser.toJSON(), parent: self.post })
var deferred = comment.save({}, {
url : self.url(),
success: function() {
comment.set({author: app.currentUser.toJSON(), parent: self.post })
self.add(comment)
},
error: function() {
this.add(comment)
}
})
return deferred
}
});
});

View file

@ -28,26 +28,38 @@ describe("app.views.CommentStream", function(){
expect($.fn.autoResize.mostRecentCall.object.selector).toBe("textarea")
})
})
describe("createComment", function() {
beforeEach(function() {
jasmine.Ajax.useMock();
this.view.render();
this.view.expandComments();
})
it("submits the new comment when comment text is not empty", function() {
this.view.$(".comment_box").val('a new comment');
this.view.createComment();
expect(this.view.$(".comment-content p").text()).toEqual("a new comment");
comments = mostRecentAjaxRequest();
params = JSON.parse(comments.params)
expect(params.text).toEqual("a new comment");
})
it("comment doesn't get added if the submission fails", function(){
this.view.render();
var form = this.view.$("form")
var submitCallback = jasmine.createSpy().andReturn(false);form.submit(submitCallback);
var e = $.Event("keydown", { keyCode: 13 });
e.shiftKey = false;
this.view.keyDownOnCommentBox(e);
expect(submitCallback).not.toHaveBeenCalled();
})
it("clears the comment box when there are only spaces", function() {
this.view.$(".comment_box").val(' ');
this.view.createComment();
expect(this.view.$(".comment_box").val()).toEqual("");
})
it("resets comment box height", function() {
this.view.$(".comment_box").val('a new comment');
this.view.createComment();
@ -80,32 +92,32 @@ describe("app.views.CommentStream", function(){
expect(this.view.$("textarea").val()).toEqual("great post!");
})
})
describe("pressing a key when typing on the new comment box", function(){
it("should not submit the form when enter key is pressed", function(){
this.view.render();
var form = this.view.$("form")
var submitCallback = jasmine.createSpy().andReturn(false);form.submit(submitCallback);
var e = $.Event("keydown", { keyCode: 13 });
e.shiftKey = false;
this.view.keyDownOnCommentBox(e);
expect(submitCallback).not.toHaveBeenCalled();
})
it("should submit the form when enter is pressed with ctrl", function(){
this.view.render();
var form = this.view.$("form")
var submitCallback = jasmine.createSpy().andReturn(false);
form.submit(submitCallback);
var e = $.Event("keydown", { keyCode: 13 });
e.ctrlKey = true;
this.view.keyDownOnCommentBox(e);
expect(submitCallback).toHaveBeenCalled();
})
})
})
})