Use new ajax error handling for like, unlike and comment failures
closes #7227
This commit is contained in:
parent
bc5848fe9e
commit
d0e70ccd6a
5 changed files with 78 additions and 20 deletions
|
|
@ -4,6 +4,7 @@
|
|||
* Increase the spacing above and below post contents [#7267](https://github.com/diaspora/diaspora/pull/7267)
|
||||
* Replace fileuploader-custom with FineUploader [#7083](https://github.com/diaspora/diaspora/pull/7083)
|
||||
* Always show mobile reaction counts [#7207](https://github.com/diaspora/diaspora/pull/7207)
|
||||
* Refactor mobile alerts for error responses [#7227](https://github.com/diaspora/diaspora/pull/7227)
|
||||
|
||||
## Bug fixes
|
||||
* Fix background color of year on notifications page with dark theme [#7263](https://github.com/diaspora/diaspora/pull/7263)
|
||||
|
|
|
|||
|
|
@ -50,8 +50,9 @@
|
|||
|
||||
$.post(form.attr("action") + "?format=mobile", form.serialize(), function(data){
|
||||
Diaspora.Mobile.Comments.updateStream(form, data);
|
||||
}, "html").fail(function(){
|
||||
Diaspora.Mobile.Comments.resetCommentBox(this);
|
||||
}, "html").fail(function(response) {
|
||||
Diaspora.Mobile.Alert.handleAjaxError(response);
|
||||
Diaspora.Mobile.Comments.resetCommentBox(form);
|
||||
});
|
||||
|
||||
autosize($(".add-comment-switcher:not(.hidden) textarea"));
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@
|
|||
Diaspora.Mobile.PostActions.showLoader(link);
|
||||
},
|
||||
success: onSuccess,
|
||||
error: function(response) {
|
||||
Diaspora.Mobile.Alert.handleAjaxError(response);
|
||||
},
|
||||
complete: function() {
|
||||
Diaspora.Mobile.PostActions.hideLoader(link);
|
||||
}
|
||||
|
|
@ -61,6 +64,9 @@
|
|||
Diaspora.Mobile.PostActions.showLoader(link);
|
||||
},
|
||||
success: onSuccess,
|
||||
error: function(response) {
|
||||
Diaspora.Mobile.Alert.handleAjaxError(response);
|
||||
},
|
||||
complete: function() {
|
||||
Diaspora.Mobile.PostActions.hideLoader(link);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,22 @@
|
|||
describe("Diaspora.Mobile.Comments", function(){
|
||||
beforeEach(function() {
|
||||
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
||||
this.bottomBar = $(".bottom-bar").first();
|
||||
this.link = $(".stream .show-comments").first();
|
||||
});
|
||||
|
||||
describe("initialize", function() {
|
||||
it("calls submitComment when the comment form has been submitted", function() {
|
||||
spyOn(Diaspora.Mobile.Comments, "submitComment");
|
||||
Diaspora.Mobile.Comments.initialize();
|
||||
Diaspora.Mobile.Comments.showCommentBox($(".stream .comment-action").first());
|
||||
$(".stream .new_comment").first().submit();
|
||||
expect(Diaspora.Mobile.Comments.submitComment).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("toggleComments", function() {
|
||||
beforeEach(function() {
|
||||
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
||||
this.link = $(".stream .show-comments").first();
|
||||
spyOn(Diaspora.Mobile.Comments, "showComments");
|
||||
spyOn(Diaspora.Mobile.Comments, "hideComments");
|
||||
});
|
||||
|
|
@ -30,9 +44,6 @@ describe("Diaspora.Mobile.Comments", function(){
|
|||
|
||||
describe("showUnloadedComments", function() {
|
||||
beforeEach(function() {
|
||||
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
||||
this.link = $(".stream .show-comments").first();
|
||||
this.bottomBar = this.link.closest(".bottom-bar").first();
|
||||
this.commentActionLink = this.bottomBar.find("a.comment-action");
|
||||
});
|
||||
|
||||
|
|
@ -79,26 +90,51 @@ describe("Diaspora.Mobile.Comments", function(){
|
|||
});
|
||||
});
|
||||
|
||||
describe("createComment", function () {
|
||||
describe("submitComment", function() {
|
||||
beforeEach(function() {
|
||||
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
||||
var link = $(".stream .comment-action").first();
|
||||
Diaspora.Mobile.Comments.showCommentBox(link);
|
||||
$(".stream .new_comment").submit(Diaspora.Mobile.Comments.submitComment);
|
||||
Diaspora.Mobile.Comments.initialize();
|
||||
Diaspora.Mobile.Comments.showCommentBox($(".stream .comment-action").first());
|
||||
});
|
||||
|
||||
it("doesn't submit an empty comment", function() {
|
||||
var form = $(".stream .new_comment").first();
|
||||
spyOn(jQuery, "ajax");
|
||||
form.submit();
|
||||
expect(jQuery.ajax).not.toHaveBeenCalled();
|
||||
$(".stream .new_comment").first().submit();
|
||||
expect(jasmine.Ajax.requests.count()).toBe(0);
|
||||
});
|
||||
|
||||
it("submits comments with text", function() {
|
||||
$(".stream .new_comment textarea").val("comment text");
|
||||
$(".stream .new_comment").first().submit();
|
||||
expect(jasmine.Ajax.requests.mostRecent().data().text).toEqual(["comment text"]);
|
||||
});
|
||||
|
||||
it("calls updateStream on success", function() {
|
||||
spyOn(Diaspora.Mobile.Comments, "updateStream");
|
||||
$(".stream .new_comment textarea").val("comment text");
|
||||
$(".stream .new_comment").first().submit();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 200, responseText: "foo"});
|
||||
expect(Diaspora.Mobile.Comments.updateStream).toHaveBeenCalledWith($(".stream .new_comment").first(), "foo");
|
||||
});
|
||||
|
||||
it("lets Diaspora.Mobile.Alert handle AJAX errors", function() {
|
||||
spyOn(Diaspora.Mobile.Alert, "handleAjaxError");
|
||||
$(".stream .new_comment textarea").val("comment text");
|
||||
$(".stream .new_comment").first().submit();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! comment failed!"});
|
||||
expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled();
|
||||
expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("oh noez! comment failed!");
|
||||
});
|
||||
|
||||
it("calls resetCommentBox on errors", function() {
|
||||
spyOn(Diaspora.Mobile.Comments, "resetCommentBox");
|
||||
$(".stream .new_comment textarea").val("comment text");
|
||||
$(".stream .new_comment").first().submit();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! comment failed!"});
|
||||
expect(Diaspora.Mobile.Comments.resetCommentBox).toHaveBeenCalledWith($(".stream .new_comment").first());
|
||||
});
|
||||
});
|
||||
|
||||
describe("increaseReactionCount", function(){
|
||||
beforeEach(function() {
|
||||
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
||||
this.bottomBar = $(".bottom-bar").first();
|
||||
this.toggleReactionsLink = this.bottomBar.find(".show-comments").first();
|
||||
});
|
||||
|
||||
|
|
@ -123,8 +159,6 @@ describe("Diaspora.Mobile.Comments", function(){
|
|||
|
||||
describe("bottomBarLazy", function(){
|
||||
beforeEach(function() {
|
||||
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
||||
this.bottomBar = $(".bottom-bar").first();
|
||||
this.bottomBarLazy = Diaspora.Mobile.Comments.bottomBarLazy(this.bottomBar);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -118,6 +118,14 @@ describe("Diaspora.Mobile.PostActions", function(){
|
|||
expect(this.likeCounter.text()).toBe("0");
|
||||
});
|
||||
|
||||
it("lets Diaspora.Mobile.Alert handle AJAX errors", function() {
|
||||
spyOn(Diaspora.Mobile.Alert, "handleAjaxError");
|
||||
Diaspora.Mobile.PostActions.like(this.likeCounter, this.link);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! like failed!"});
|
||||
expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled();
|
||||
expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("oh noez! like failed!");
|
||||
});
|
||||
|
||||
it("activates link on success", function(){
|
||||
spyOn(Diaspora.Mobile.PostActions, "toggleActive");
|
||||
var data = this.link.data("url");
|
||||
|
|
@ -166,6 +174,14 @@ describe("Diaspora.Mobile.PostActions", function(){
|
|||
expect(this.likeCounter.text()).toBe("1");
|
||||
});
|
||||
|
||||
it("lets Diaspora.Mobile.Alert handle AJAX errors", function() {
|
||||
spyOn(Diaspora.Mobile.Alert, "handleAjaxError");
|
||||
Diaspora.Mobile.PostActions.unlike(this.likeCounter, this.link);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! unlike failed!"});
|
||||
expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled();
|
||||
expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("oh noez! unlike failed!");
|
||||
});
|
||||
|
||||
it("deactivates link on success", function(){
|
||||
spyOn(Diaspora.Mobile.PostActions, "toggleActive");
|
||||
var data = this.link.data("url");
|
||||
|
|
|
|||
Loading…
Reference in a new issue