diff --git a/app/assets/javascripts/mobile/mobile_post_actions.js b/app/assets/javascripts/mobile/mobile_post_actions.js index ed6bb16b9ffff19444939715d875bdb33a827956..76f1126d5d4f1ac9de393f73cd50bb4c49515fcb 100644 --- a/app/assets/javascripts/mobile/mobile_post_actions.js +++ b/app/assets/javascripts/mobile/mobile_post_actions.js @@ -103,6 +103,10 @@ }, success: function() { Diaspora.Mobile.PostActions.toggleActive(link); + var reshareCounter = $(evt.target).closest(".stream-element").find(".reshare-count"); + if (reshareCounter) { + reshareCounter.text(parseInt(reshareCounter.text(), 10) + 1); + } }, error: function(response) { Diaspora.Mobile.Alert.handleAjaxError(response); diff --git a/spec/javascripts/mobile/mobile_post_actions_spec.js b/spec/javascripts/mobile/mobile_post_actions_spec.js index a33a2999410d877627c183ff1f3389c8fb586e71..bbb65b23dd220dbbae208c3d017aa833977ad0c1 100644 --- a/spec/javascripts/mobile/mobile_post_actions_spec.js +++ b/spec/javascripts/mobile/mobile_post_actions_spec.js @@ -88,7 +88,7 @@ describe("Diaspora.Mobile.PostActions", function(){ spec.loadFixture("aspects_index_mobile_public_post"); Diaspora.Mobile.PostActions.initialize(); this.link = $(".stream .like-action").first(); - this.likeCounter = this.link.closest(".stream-element").find(".like-count"); + this.likeCounter = this.link.find(".like-count"); }); it("always calls showLoader before sending request", function(){ @@ -143,7 +143,7 @@ describe("Diaspora.Mobile.PostActions", function(){ spec.loadFixture("aspects_index_mobile_public_post"); Diaspora.Mobile.PostActions.initialize(); this.link = $(".stream .like-action").first(); - this.likeCounter = this.link.closest(".stream-element").find(".like-count"); + this.likeCounter = this.link.find(".like-count"); Diaspora.Mobile.PostActions.like(this.likeCounter, this.link); jasmine.Ajax.requests.mostRecent().respondWith({status: 201, responseText: "{\"id\": \"18\"}"}); }); @@ -238,6 +238,17 @@ describe("Diaspora.Mobile.PostActions", function(){ expect(Diaspora.Mobile.PostActions.toggleActive).toHaveBeenCalledWith(this.reshareLink); }); + it("increases the reshare count on success", function() { + spyOn(Diaspora.Mobile.PostActions, "toggleActive"); + var reshareCounter = this.reshareLink.find(".reshare-count"); + reshareCounter.text("8"); + + this.reshareLink.click(); + jasmine.Ajax.requests.mostRecent().respondWith({status: 201, responseText: "{}"}); + expect(Diaspora.Mobile.PostActions.toggleActive).toHaveBeenCalledWith(this.reshareLink); + expect(reshareCounter.text()).toBe("9"); + }); + it("lets Diaspora.Mobile.Alert handle AJAX errors", function() { spyOn(Diaspora.Mobile.Alert, "handleAjaxError"); this.reshareLink.click();