diff --git a/app/assets/javascripts/app/collections/comments.js b/app/assets/javascripts/app/collections/comments.js index 55ffcd425..52f98d181 100644 --- a/app/assets/javascripts/app/collections/comments.js +++ b/app/assets/javascripts/app/collections/comments.js @@ -20,7 +20,7 @@ app.collections.Comments = Backbone.Collection.extend({ comment.set({author: app.currentUser.toJSON(), parent: self.post }); // Need interactions after make - comment.interactions = new app.models.Post.LikeInteractions( + comment.interactions = new app.models.LikeInteractions( _.extend({comment: comment, post: self.post}, comment.get("interactions")) ); self.add(comment); diff --git a/app/assets/javascripts/app/models/comment.js b/app/assets/javascripts/app/models/comment.js index fb4c268f5..5b4b19598 100644 --- a/app/assets/javascripts/app/models/comment.js +++ b/app/assets/javascripts/app/models/comment.js @@ -6,7 +6,7 @@ app.models.Comment = Backbone.Model.extend({ initialize: function(model, options) { options = options || {}; this.post = model.post || options.post || this.collection.post; - this.interactions = new app.models.Post.LikeInteractions( + this.interactions = new app.models.LikeInteractions( _.extend({comment: this, post: this.post}, this.get("interactions")) ); this.likes = this.interactions.likes; diff --git a/app/assets/javascripts/app/models/post/like_interactions.js b/app/assets/javascripts/app/models/like_interactions.js similarity index 96% rename from app/assets/javascripts/app/models/post/like_interactions.js rename to app/assets/javascripts/app/models/like_interactions.js index 29b102b67..c2df4c806 100644 --- a/app/assets/javascripts/app/models/post/like_interactions.js +++ b/app/assets/javascripts/app/models/like_interactions.js @@ -1,6 +1,6 @@ // This class contains code extracted from interactions.js to factorize likes management between posts and comments -app.models.Post.LikeInteractions = Backbone.Model.extend({ +app.models.LikeInteractions = Backbone.Model.extend({ initialize: function(options) { this.likes = new app.collections.Likes(this.get("likes"), options); diff --git a/app/assets/javascripts/app/models/post.js b/app/assets/javascripts/app/models/post.js index b693d7b2d..3289fcc57 100644 --- a/app/assets/javascripts/app/models/post.js +++ b/app/assets/javascripts/app/models/post.js @@ -4,7 +4,7 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, urlRoot : "/posts", initialize : function() { - this.interactions = new app.models.Post.Interactions(_.extend({post : this}, this.get("interactions"))); + this.interactions = new app.models.PostInteractions(_.extend({post: this}, this.get("interactions"))); this.delegateToInteractions(); }, diff --git a/app/assets/javascripts/app/models/post/interactions.js b/app/assets/javascripts/app/models/post_interactions.js similarity index 93% rename from app/assets/javascripts/app/models/post/interactions.js rename to app/assets/javascripts/app/models/post_interactions.js index d07f075bc..8380ba974 100644 --- a/app/assets/javascripts/app/models/post/interactions.js +++ b/app/assets/javascripts/app/models/post_interactions.js @@ -1,10 +1,8 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later -//= require ./like_interactions - -app.models.Post.Interactions = app.models.Post.LikeInteractions.extend({ +app.models.PostInteractions = app.models.LikeInteractions.extend({ initialize: function(options) { - app.models.Post.LikeInteractions.prototype.initialize.apply(this, arguments); + app.models.LikeInteractions.prototype.initialize.apply(this, arguments); this.post = options.post; this.comments = new app.collections.Comments(this.get("comments"), {post: this.post}); this.reshares = new app.collections.Reshares(this.get("reshares"), {post: this.post}); diff --git a/app/assets/javascripts/mobile/mobile_comments.js b/app/assets/javascripts/mobile/mobile_comments.js index 78fed45da..a6948b7a4 100644 --- a/app/assets/javascripts/mobile/mobile_comments.js +++ b/app/assets/javascripts/mobile/mobile_comments.js @@ -52,6 +52,8 @@ $.post(form.attr("action") + "?format=mobile", form.serialize(), function(data){ Diaspora.Mobile.Comments.updateStream(form, data); + // Register new comments + $(".stream").trigger("comments.loaded"); }, "html").fail(function(response) { Diaspora.Mobile.Alert.handleAjaxError(response); Diaspora.Mobile.Comments.resetCommentBox(form); diff --git a/app/presenters/comment_presenter.rb b/app/presenters/comment_presenter.rb index 7556c448f..c02c1a6a2 100644 --- a/app/presenters/comment_presenter.rb +++ b/app/presenters/comment_presenter.rb @@ -20,7 +20,7 @@ class CommentPresenter < BasePresenter author: PersonPresenter.new(author).as_api_json, created_at: created_at, mentioned_people: build_mentioned_people_json, - reported: current_user.present? && reports.where(user: current_user).exists?, + reported: current_user.present? && reports.exists?(user: current_user), interactions: build_interactions_json } end diff --git a/features/desktop/comments.feature b/features/desktop/comments.feature index 0ef2ca6c8..748a7cb57 100644 --- a/features/desktop/comments.feature +++ b/features/desktop/comments.feature @@ -86,3 +86,14 @@ Feature: commenting When I click on selector ".toggle_post_comments" Then I should see "Comment 2" + + Scenario: Like a comment in stream view + When "alice@alice.alice" has commented "That's cool" on "Look at this dog" + And I am on "alice@alice.alice"'s page + And I like the comment "That's cool" + Then I should see a heart within comment "That's cool" + + When I expand likes within comment "That's cool" + Then I should see a micro avatar within comment "That's cool" + When I unlike comment "That's cool" + Then I should not see a micro avatar within comment "That's cool" diff --git a/features/mobile/reactions.feature b/features/mobile/reactions.feature index 81133e871..0dcc0e246 100644 --- a/features/mobile/reactions.feature +++ b/features/mobile/reactions.feature @@ -43,3 +43,14 @@ Feature: reactions mobile post And I click on selector "a.comment-action" And I confirm the alert after I click on selector "a.remove" Then I should see "0 comments" within ".show-comments" + + Scenario: liking and unliking a comment + When I click on selector "a.comment-action.inactive" + And I fill in the following: + | text | is that a poodle? | + And I press "Comment" + Then I should see "is that a poodle?" within ".comment-container" + When I toggle like on comment with text "is that a poodle?" + Then I should see a like on comment with text "is that a poodle?" + When I toggle like on comment with text "is that a poodle?" + Then I should see an unliked comment with text "is that a poodle?" diff --git a/features/step_definitions/comment_steps.rb b/features/step_definitions/comment_steps.rb index 9a8ad9eeb..e2587830d 100644 --- a/features/step_definitions/comment_steps.rb +++ b/features/step_definitions/comment_steps.rb @@ -44,3 +44,38 @@ end When /^I enter "([^"]*)" in the comment field$/ do |comment_text| find("textarea.comment-box.mention-textarea").native.send_keys(comment_text) end + +Then /^I like the comment "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + # Find like like-link within comment-block + find(id: comment_guid).click_link("Like") +end + +Then /^I should see a heart within comment "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + block = find(id: comment_guid) + expect(block).to have_css(".entypo-heart") +end + +When /^I expand likes within comment "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + find(id: comment_guid).click_link("1 Like") + find(id: comment_guid).find(".entypo-heart").hover # unfocus avatar to get rid of tooltip +end + +When /^I unlike comment "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + find(id: comment_guid).click_link("Unlike") +end + +Then /^I should see a micro avatar within comment "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + block = find(id: comment_guid) + expect(block).to have_css(".micro.avatar") +end + +Then /^I should not see a micro avatar within comment "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + block = find(id: comment_guid) + expect(block).not_to have_css(".micro.avatar") +end diff --git a/features/step_definitions/mobile_steps.rb b/features/step_definitions/mobile_steps.rb index abb121444..27ce0db3e 100644 --- a/features/step_definitions/mobile_steps.rb +++ b/features/step_definitions/mobile_steps.rb @@ -23,3 +23,26 @@ Then /^the aspect dropdown within "([^"]*)" should be labeled "([^"]*)"/ do |sel current_scope.should have_css("option.list_cover", text: label) end end + +When /^I toggle like on comment with text "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + within(id: comment_guid) do + find(".entypo-heart.like-action").click + end +end + +Then /^I should see a like on comment with text "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + within(id: comment_guid) do + find(".entypo-heart.like-action.active") + expect(find(".count.like-count")).to have_text "1" + end +end + +Then /^I should see an unliked comment with text "([^"]*)"$/ do |comment_text| + comment_guid = Comment.find_by(text: comment_text).guid + within(id: comment_guid) do + find(".entypo-heart.like-action.inactive") + expect(find(".count.like-count")).to have_text "0" + end +end