From bc5848fe9eb01304ac0a7c535b89b7bab0a2ce2d Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sat, 26 Nov 2016 19:29:15 +0100 Subject: [PATCH] Use new ajax error handling for reshare failures --- .../javascripts/mobile/mobile_post_actions.js | 6 +----- spec/javascripts/mobile/mobile_post_actions_spec.js | 13 ++++--------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/mobile/mobile_post_actions.js b/app/assets/javascripts/mobile/mobile_post_actions.js index 56df0e533..f7064baef 100644 --- a/app/assets/javascripts/mobile/mobile_post_actions.js +++ b/app/assets/javascripts/mobile/mobile_post_actions.js @@ -99,11 +99,7 @@ Diaspora.Mobile.PostActions.toggleActive(link); }, error: function(response) { - if (response.status === 0) { - alert(Diaspora.I18n.t("errors.connection")); - } else { - alert(response.responseText); - } + Diaspora.Mobile.Alert.handleAjaxError(response); }, complete: function() { Diaspora.Mobile.PostActions.hideLoader(link); diff --git a/spec/javascripts/mobile/mobile_post_actions_spec.js b/spec/javascripts/mobile/mobile_post_actions_spec.js index 80d410ea3..c2e158202 100644 --- a/spec/javascripts/mobile/mobile_post_actions_spec.js +++ b/spec/javascripts/mobile/mobile_post_actions_spec.js @@ -198,7 +198,6 @@ describe("Diaspora.Mobile.PostActions", function(){ Diaspora.Mobile.PostActions.initialize(); this.reshareLink = $(".stream .reshare-action"); spyOn(window, "confirm").and.returnValue(true); - spyOn(window, "alert"); }); it("always calls showLoader before sending request and hideLoader after receiving response", function(){ @@ -223,16 +222,12 @@ describe("Diaspora.Mobile.PostActions", function(){ expect(Diaspora.Mobile.PostActions.toggleActive).toHaveBeenCalledWith(this.reshareLink); }); - it("pops an alert on server errors", function() { + it("lets Diaspora.Mobile.Alert handle AJAX errors", function() { + spyOn(Diaspora.Mobile.Alert, "handleAjaxError"); this.reshareLink.click(); jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "reshare failed"}); - expect(window.alert).toHaveBeenCalledWith("reshare failed"); - }); - - it("pops an alert on network errors", function() { - this.reshareLink.click(); - jasmine.Ajax.requests.mostRecent().abort(); - expect(window.alert).toHaveBeenCalledWith(Diaspora.I18n.t("errors.connection")); + expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled(); + expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("reshare failed"); }); }); });