diff --git a/Changelog.md b/Changelog.md index 913572c28..f8d6cea31 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,8 +6,10 @@ * Make the session cookies HttpOnly again [#7041](https://github.com/diaspora/diaspora/pull/7041) ## Bug fixes +* Post comments no longer get collapsed when interacting with a post [#7045](https://github.com/diaspora/diaspora/pull/7045) ## Features +* The "subscribe" indicator on a post now gets toggled when you like or rehsare a post [#7045](https://github.com/diaspora/diaspora/pull/7045) # 0.6.0.0 diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index 6c3293c84..24f05ee93 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -20,7 +20,8 @@ app.views.CommentStream = app.views.Base.extend({ }, setupBindings: function() { - this.model.comments.bind('add', this.appendComment, this); + this.model.comments.bind("add", this.appendComment, this); + this.model.comments.bind("remove", this.removeComment, this); }, postRenderTemplate : function() { @@ -95,6 +96,10 @@ app.views.CommentStream = app.views.Base.extend({ } }, + removeComment: function(comment) { + this.$("#" + comment.get("guid")).closest(".comment.media").remove(); + }, + commentTextareaFocused: function(){ this.$("form").removeClass('hidden').addClass("open"); }, diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index c0f3f20fb..93e20c55f 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -11,6 +11,14 @@ describe("app.views.CommentStream", function(){ this.view.model.comments.push(factory.comment()); expect(this.view.appendComment).toHaveBeenCalled(); }); + + it("calls removeComment on removal from the comments collection", function() { + this.view.model.comments.push(factory.comment()); + spyOn(this.view, "removeComment"); + this.view.setupBindings(); + this.view.model.comments.pop(); + expect(this.view.removeComment).toHaveBeenCalled(); + }); }); describe("createComment", function() { @@ -85,16 +93,64 @@ describe("app.views.CommentStream", function(){ }); }); + describe("removeComment", function() { + it("removes the comment from the stream", function() { + this.view.model.comments.push(factory.comment()); + this.view.model.comments.push(factory.comment()); + var comment = factory.comment(); + this.view.model.comments.push(comment); + this.view.model.comments.push(factory.comment()); + this.view.render(); + expect(this.view.$(".comments div.comment.media").length).toBe(4); + expect(this.view.$("#" + comment.get("guid")).length).toBe(1); + this.view.removeComment(comment); + expect(this.view.$(".comments div.comment.media").length).toBe(3); + expect(this.view.$("#" + comment.get("guid")).length).toBe(0); + }); + }); + describe("expandComments", function() { it("doesn't drop the comment textbox value on success", function() { this.view.render(); this.view.$("textarea").val("great post!"); this.view.expandComments(); - jasmine.Ajax.requests.mostRecent().respondWith({ comments : [] }); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + responseText: JSON.stringify([factory.comment()]) + }); expect(this.view.$("textarea").val()).toEqual("great post!"); }); + + it("adds and removes comments in the right order", function() { + var comments = _.range(42).map(function(_, index) { + return factory.comment({"text": "" + index, "created_at": new Date(index).toJSON()}); + }); + var evenComments = comments.filter(function(_, index) { return index % 2 === 0; }); + this.view.model.comments.reset(evenComments); + this.view.render(); + expect(this.view.$(".comments div.comment.media").length).toBe(21); + expect(this.view.$(".comments div.comment.media div.comment-content p").text()).toEqual( + evenComments.map(function(c) { return c.get("text"); }).join("") + ); + + var randomComments = _.shuffle(comments).slice(0, 23); + this.view.expandComments(); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + responseText: JSON.stringify(randomComments) + }); + + expect(this.view.$(".comments div.comment.media").length).toBe(23); + expect(this.view.$(".comments div.comment.media div.comment-content p").text()).toEqual( + _.sortBy(randomComments, function(c) { + return c.get("created_at"); + }).map(function(c) { + return c.get("text"); + }).join("") + ); + }); }); describe("pressing a key when typing on the new comment box", function(){