Merge branch 'next-minor' into develop

This commit is contained in:
Dennis Schubert 2016-09-04 03:15:39 +02:00
commit 684d7d8312
No known key found for this signature in database
GPG key ID: 5A0304BEA7966D7E
3 changed files with 71 additions and 11 deletions

View file

@ -14,8 +14,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

View file

@ -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() {
@ -86,12 +87,17 @@ app.views.CommentStream = app.views.Base.extend({
var commentHtml = new app.views.Comment({model: comment}).render().el;
var commentBlocks = this.$(".comments div.comment.media");
this._moveInsertPoint(comment.get("created_at"), commentBlocks);
if (this._insertPoint === commentBlocks.length) {
if (this._insertPoint >= commentBlocks.length) {
this.$(".comments").append(commentHtml);
} else if (this._insertPoint <= 0) {
this.$(".comments").prepend(commentHtml);
} else {
commentBlocks.eq(this._insertPoint).before(commentHtml);
}
this._insertPoint++;
},
removeComment: function(comment) {
this.$("#" + comment.get("guid")).closest(".comment.media").remove();
},
commentTextareaFocused: function(){
@ -100,14 +106,10 @@ app.views.CommentStream = app.views.Base.extend({
expandComments: function(evt){
if(evt){ evt.preventDefault(); }
var self = this;
this.model.comments.fetch({
success : function(resp){
self.$("div.comment.show_comments").addClass("hidden");
self.model.trigger("commentsExpanded", self);
}
success: function() {
this.$("div.comment.show_comments").addClass("hidden");
}.bind(this)
});
}
});

View file

@ -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(){