Unverified Commit cab0e010 authored by Hank Grabowski's avatar Hank Grabowski Committed by Dennis Schubert

7841 Post Unlike sets status icon correctly

closes #7882
fixes #7841
parent 935ff66c
......@@ -8,6 +8,7 @@
## Bug fixes
* Ignore invalid URLs for camo [#7922](https://github.com/diaspora/diaspora/pull/7922)
* Unlinking a post did not update the participation icon without a reload [#7882](https://github.com/diaspora/diaspora/pull/7882)
## Features
* Add the ability to assign roles in the admin panel [#7868](https://github.com/diaspora/diaspora/pull/7868)
......
......@@ -60,9 +60,13 @@ app.models.Post.Interactions = Backbone.Model.extend({
unlike : function() {
var self = this;
this.userLike().destroy({success : function() {
self.post.set({participation: false});
self.trigger('change');
self.set({"likes_count" : self.get("likes_count") - 1});
self.likes.trigger("change");
},
error: function(model, response) {
app.flashMessages.handleAjaxError(response);
}});
},
......
describe("app.models.Post.Interactions", function(){
var ajaxSuccess = {status: 200, responseText: "{\"id\": 1}"};
var ajaxNoContent = {status: 204};
beforeEach(function(){
this.post = factory.post();
......@@ -9,7 +10,7 @@ describe("app.models.Post.Interactions", function(){
spec.content().append($("<div id='flash-container'>"));
app.flashMessages = new app.views.FlashMessages({el: spec.content().find("#flash-container")});
this.userLike = new app.models.Like({author : this.author});
this.userLike = new app.models.Like({author: this.author, id: "id01"});
});
describe("toggleLike", function(){
......@@ -62,12 +63,41 @@ describe("app.models.Post.Interactions", function(){
});
describe("unlike", function(){
it("calls destroy on the likes collection", function(){
beforeEach(function() {
this.interactions.likes.add(this.userLike);
this.interactions.unlike();
this.post.set({participation: true});
spyOn(this.interactions, "userLike").and.returnValue(this.userLike);
});
it("calls delete on the likes collection for the post", function() {
expect(this.interactions.likes.length).toEqual(1);
this.interactions.unlike();
expect(this.interactions.likes.length).toEqual(0);
});
it("sets the participation flag for the post", function() {
expect(this.post.get("participation")).toBeTruthy();
this.interactions.unlike();
jasmine.Ajax.requests.mostRecent().respondWith(ajaxNoContent);
expect(this.post.get("participation")).toBeFalsy();
});
it("triggers a change on the likes collection", function() {
spyOn(this.interactions.likes, "trigger");
this.interactions.unlike();
jasmine.Ajax.requests.mostRecent().respondWith(ajaxNoContent);
expect(this.interactions.likes.trigger).toHaveBeenCalledWith("change");
});
it("displays a flash message on errors", function() {
spyOn(app.flashMessages, "handleAjaxError").and.callThrough();
this.interactions.unlike();
jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "error message"});
expect(app.flashMessages.handleAjaxError).toHaveBeenCalled();
expect(app.flashMessages.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("error message");
expect(spec.content().find(".flash-message")).toBeErrorFlashMessage("error message");
});
});
describe("reshare", function() {
......
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