diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 8ec7d28c4..250efc340 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -39,9 +39,6 @@ toggle_form: function(id) { $("#js-comment-form-" + id).toggle(); }, - toggle_arrow: function(id) { - $("span#" + id + "_arrow").toggleClass("fa-minus-square fa-plus-square"); - }, initialize: function() { $("body").on("click", ".js-add-comment-link", function() { App.Comments.toggle_form($(this).data().id); @@ -49,10 +46,8 @@ }); $("body").on("click", ".js-toggle-children", function() { - var children_container_id; - children_container_id = ($(this).data().id) + "_children"; - $("#" + children_container_id).toggle("slow"); - App.Comments.toggle_arrow(children_container_id); + $("#" + $(this).data().id + "_children").toggle("slow"); + $(this).children(".far").toggleClass("fa-minus-square fa-plus-square"); $(this).children(".js-child-toggle").toggle(); return false; }); diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index d8bf131b3..991759e29 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -89,7 +89,7 @@ <%= link_to "", class: "js-toggle-children relative", data: { "id": "#{dom_id(comment)}" } do %> <%= t("shared.hide") %> - + <%= t("comments.comment.responses_collapse", count: comment.children.size) %> <% end %> diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index 2970da0df..8e58c0773 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -66,20 +66,26 @@ describe "Commenting Budget::Investments" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") diff --git a/spec/system/comments/budget_investments_valuation_spec.rb b/spec/system/comments/budget_investments_valuation_spec.rb index 9e43dda3b..c4d3c7990 100644 --- a/spec/system/comments/budget_investments_valuation_spec.rb +++ b/spec/system/comments/budget_investments_valuation_spec.rb @@ -61,7 +61,7 @@ describe "Internal valuation comments on Budget::Investments" do scenario "Collapsable comments", :js do parent_comment = create(:comment, :valuation, author: valuator_user, body: "Main comment", commentable: investment) - child_comment = create(:comment, :valuation, author: valuator_user, body: "First child", + child_comment = create(:comment, :valuation, author: valuator_user, body: "First subcomment", commentable: investment, parent: parent_comment) grandchild_comment = create(:comment, :valuation, author: valuator_user, parent: child_comment, @@ -73,20 +73,26 @@ describe "Internal valuation comments on Budget::Investments" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index 1b5db3283..78af230b1 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -63,20 +63,26 @@ describe "Commenting debates" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index 18b9f40d2..4354da1f8 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -71,20 +71,26 @@ describe "Commenting legislation questions" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: parent_comment.body do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 67510cae2..09cc165dd 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -69,20 +69,26 @@ describe "Commenting legislation questions" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index ad4db74ec..65fd9af57 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -64,20 +64,26 @@ describe "Commenting polls" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index e1b74613b..84aa7c219 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -62,20 +62,26 @@ describe "Commenting proposals" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index 4afc13ff1..4d5d48d46 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -67,20 +67,26 @@ describe "Commenting topics from proposals" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") @@ -625,17 +631,23 @@ describe "Commenting topics from budget investments" do expect(page).to have_css(".comment", count: 3) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).not_to have_content child_comment.body