From 956f002738f125eb04c11a55ae1c10b82a989e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Fri, 8 May 2020 07:00:30 +0200 Subject: [PATCH 1/4] Update parent comment responses count when a new reply is created Extract the needed portion of code to a new partial to be able to update only the elements needed when a new comment is added keeping UI properly updated. --- app/assets/javascripts/comments.js | 3 +++ app/views/comments/_comment.html.erb | 12 +++--------- app/views/comments/_responses_count.html.erb | 9 +++++++++ app/views/comments/create.js.erb | 2 ++ .../comments/budget_investments_spec.rb | 15 +++++++++++++++ .../budget_investments_valuation_spec.rb | 15 +++++++++++++++ spec/system/comments/debates_spec.rb | 15 +++++++++++++++ .../comments/legislation_annotations_spec.rb | 19 +++++++++++++++++++ .../comments/legislation_questions_spec.rb | 16 ++++++++++++++++ spec/system/comments/polls_spec.rb | 15 +++++++++++++++ spec/system/comments/proposals_spec.rb | 15 +++++++++++++++ spec/system/comments/topics_spec.rb | 17 +++++++++++++++++ 12 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 app/views/comments/_responses_count.html.erb diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 05229bce5..73cd64218 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -14,6 +14,9 @@ $(this).text(new_val); }); }, + update_responses_count: function(comment_id, responses_count_html) { + $(comment_id + "_reply .responses-count").html(responses_count_html); + }, display_error: function(field_with_errors, error_html) { $(error_html).insertAfter($("" + field_with_errors)); }, diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 382555b62..545b379b4 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -85,15 +85,9 @@ <% end %> - <% if comment.children.size > 0 %> - <%= link_to "", class: "js-toggle-children relative" do %> - - - <%= t("comments.comment.responses_collapse", count: comment.children.size) %> - <% end %> - <% else %> - <%= t("comments.comment.responses", count: 0) %> - <% end %> + + <%= render "comments/responses_count", count: comment.children.size %> + <% if user_signed_in? && !comments_closed_for_commentable?(comment.commentable) && !require_verified_resident_for_commentable?(comment.commentable, current_user) %>  |  diff --git a/app/views/comments/_responses_count.html.erb b/app/views/comments/_responses_count.html.erb new file mode 100644 index 000000000..62b4103ac --- /dev/null +++ b/app/views/comments/_responses_count.html.erb @@ -0,0 +1,9 @@ +<% if count > 0 %> + <%= link_to "", class: "js-toggle-children relative" do %> + + + <%= t("comments.comment.responses_collapse", count: count) %> + <% end %> +<% else %> + <%= t("comments.comment.responses", count: 0) %> +<% end %> diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index 1492140f0..a57b91126 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -2,6 +2,8 @@ var parent_id = ""; <% else -%> var parent_id = "#" + "<%= "comment_#{@comment.parent_id}" %>"; + var responses_count_html = "<%= j(render "comments/responses_count", count: @comment.parent.children.size) %>" + App.Comments.update_responses_count(parent_id, responses_count_html); <% end -%> App.Comments.reset_form(parent_id); diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index 7364c4698..e268004d0 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -242,6 +242,21 @@ describe "Commenting Budget::Investments" do expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end + scenario "Reply update parent comment responses count", :js do + comment = create(:comment, commentable: investment) + + login_as(create(:user)) + visit budget_investment_path(investment.budget, investment) + + within ".comment", text: comment.body do + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("1 response (collapse)") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: investment, user: user) diff --git a/spec/system/comments/budget_investments_valuation_spec.rb b/spec/system/comments/budget_investments_valuation_spec.rb index c4d3c7990..bf605a928 100644 --- a/spec/system/comments/budget_investments_valuation_spec.rb +++ b/spec/system/comments/budget_investments_valuation_spec.rb @@ -216,6 +216,21 @@ describe "Internal valuation comments on Budget::Investments" do expect(page).not_to have_content("It will be done next week.") end + scenario "Reply update parent comment responses count", :js do + comment = create(:comment, :valuation, author: admin_user, commentable: investment) + + login_as(valuator_user) + visit valuation_budget_budget_investment_path(budget, investment) + + within ".comment", text: comment.body do + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("1 response (collapse)") + end + end + scenario "Errors on reply without comment text", :js do comment = create(:comment, :valuation, author: admin_user, commentable: investment) diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index 2b8bbc3e8..963a74e54 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -281,6 +281,21 @@ describe "Commenting debates" do end end + scenario "Reply update parent comment responses count", :js do + comment = create(:comment, commentable: debate) + + login_as(create(:user)) + visit debate_path(debate) + + within ".comment", text: comment.body do + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("1 response (collapse)") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: debate, user: user) diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index bb1788660..7060fd3ad 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -278,6 +278,25 @@ describe "Commenting legislation questions" do expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end + scenario "Reply update parent comment responses count", :js do + manuela = create(:user, :level_two, username: "Manuela") + legislation_annotation = create(:legislation_annotation) + comment = legislation_annotation.comments.first + + login_as(manuela) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) + + within ".comment", text: comment.body do + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("1 response (collapse)") + end + end + scenario "Errors on reply", :js do comment = legislation_annotation.comments.first diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 87167555f..f7a10b02a 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -260,6 +260,22 @@ describe "Commenting legislation questions" do expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end + scenario "Reply update parent comment responses count", :js do + manuela = create(:user, :level_two, username: "Manuela") + comment = create(:comment, commentable: legislation_question) + + login_as(manuela) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + within ".comment", text: comment.body do + click_link "Reply" + fill_in "Leave your answer", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("1 response (collapse)") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: legislation_question, user: user) diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index 298e8cb1f..745c8a3be 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -240,6 +240,21 @@ describe "Commenting polls" do expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end + scenario "Reply update parent comment responses count", :js do + comment = create(:comment, commentable: poll) + + login_as(create(:user)) + visit poll_path(poll) + + within ".comment", text: comment.body do + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("1 response (collapse)") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: poll, user: user) diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index d23aad2b4..1f1e5a38b 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -238,6 +238,21 @@ describe "Commenting proposals" do expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end + scenario "Reply update parent comment responses count", :js do + comment = create(:comment, commentable: proposal) + + login_as(create(:user)) + visit proposal_path(proposal) + + within ".comment", text: comment.body do + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("1 response (collapse)") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: proposal, user: user) diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index a00698047..5001927c2 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -264,6 +264,23 @@ describe "Commenting topics from proposals" do expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end + scenario "Reply update parent comment responses count", :js do + community = proposal.community + topic = create(:topic, community: community) + comment = create(:comment, commentable: topic) + + login_as(create(:user)) + visit community_topic_path(community, topic) + + within ".comment", text: comment.body do + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("1 response (collapse)") + end + end + scenario "Errors on reply", :js do community = proposal.community topic = create(:topic, community: community) From 014fa6eb1cf7e45b92e404dee902e786887c81da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 14 May 2020 18:43:53 +0200 Subject: [PATCH 2/4] Add mutations observer to initialize user initials added through ajax --- app/assets/javascripts/users.js | 7 +++++++ spec/system/users_spec.rb | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js index 8f8f8ccfa..8608f4d30 100644 --- a/app/assets/javascripts/users.js +++ b/app/assets/javascripts/users.js @@ -2,7 +2,14 @@ "use strict"; App.Users = { initialize: function() { + var observer; $(".initialjs-avatar").initial(); + observer = new MutationObserver(function(mutations) { + $.each(mutations, function(index, mutation) { + $(mutation.addedNodes).find(".initialjs-avatar").initial(); + }); + }); + observer.observe(document.body, { childList: true, subtree: true }); } }; }).call(this); diff --git a/spec/system/users_spec.rb b/spec/system/users_spec.rb index 778ecdb7b..d15cb7330 100644 --- a/spec/system/users_spec.rb +++ b/spec/system/users_spec.rb @@ -515,4 +515,18 @@ describe "Users" do end end end + + describe "Initials" do + scenario "display SVG avatars when loaded into the DOM", :js do + login_as(create(:user)) + visit debate_path(create(:debate)) + + fill_in "Leave your comment", with: "I'm awesome" + click_button "Publish comment" + + within ".comment", text: "I'm awesome" do + expect(page).to have_css "img.initialjs-avatar[src^='data:image/svg']" + end + end + end end From dcff7e8a335df96b6813811bd9b593896099106c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Fri, 15 May 2020 15:10:55 +0200 Subject: [PATCH 3/4] Show parent comment responses when a new reply is added When a user replies to a comment whose responses was hidden at the moment of reply form submission and although the reply were correctly added to the DOM it was hidden because was added to a collapsed list. This solution is about showing all responses of parent comment after adding the new comment to the DOM so the user can see new reply into the screen. (This is not applicable to root comments which cannot be collapsed) --- app/assets/javascripts/comments.js | 4 ++++ .../comments/budget_investments_spec.rb | 17 +++++++++++++++ .../budget_investments_valuation_spec.rb | 17 +++++++++++++++ spec/system/comments/debates_spec.rb | 17 +++++++++++++++ .../comments/legislation_annotations_spec.rb | 21 +++++++++++++++++++ .../comments/legislation_questions_spec.rb | 18 ++++++++++++++++ spec/system/comments/polls_spec.rb | 17 +++++++++++++++ spec/system/comments/proposals_spec.rb | 17 +++++++++++++++ spec/system/comments/topics_spec.rb | 19 +++++++++++++++++ 9 files changed, 147 insertions(+) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 73cd64218..44d70bb38 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -3,6 +3,10 @@ App.Comments = { add_comment: function(parent_selector, response_html) { $(parent_selector + " .comment-list:first").prepend($(response_html)); + var hidden_responses = $(parent_selector + " .comment-list:first").is(":hidden"); + if (parent_selector && hidden_responses) { + $(parent_selector).find(".comment-list:first").toggle("slow"); + } this.update_comments_count(); }, update_comments_count: function() { diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index e268004d0..c2adbbbb4 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -257,6 +257,23 @@ describe "Commenting Budget::Investments" do end end + scenario "Reply show parent comments responses when hidden", :js do + comment = create(:comment, commentable: investment) + create(:comment, commentable: investment, parent: comment) + + login_as(create(:user)) + visit budget_investment_path(investment.budget, investment) + + within ".comment", text: comment.body do + click_link text: "1 response (collapse)" + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("It will be done next week.") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: investment, user: user) diff --git a/spec/system/comments/budget_investments_valuation_spec.rb b/spec/system/comments/budget_investments_valuation_spec.rb index bf605a928..87792acbd 100644 --- a/spec/system/comments/budget_investments_valuation_spec.rb +++ b/spec/system/comments/budget_investments_valuation_spec.rb @@ -231,6 +231,23 @@ describe "Internal valuation comments on Budget::Investments" do end end + scenario "Reply show parent comments responses when hidden", :js do + comment = create(:comment, :valuation, author: admin_user, commentable: investment) + create(:comment, :valuation, author: admin_user, commentable: investment, parent: comment) + + login_as(valuator_user) + visit valuation_budget_budget_investment_path(budget, investment) + + within ".comment", text: comment.body do + click_link text: "1 response (collapse)" + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("It will be done next week.") + end + end + scenario "Errors on reply without comment text", :js do comment = create(:comment, :valuation, author: admin_user, commentable: investment) diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index 963a74e54..740258b8b 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -296,6 +296,23 @@ describe "Commenting debates" do end end + scenario "Reply show parent comments responses when hidden", :js do + comment = create(:comment, commentable: debate) + create(:comment, commentable: debate, parent: comment) + + login_as(create(:user)) + visit debate_path(debate) + + within ".comment", text: comment.body do + click_link text: "1 response (collapse)" + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("It will be done next week.") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: debate, user: user) diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index 7060fd3ad..4e0663ca6 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -297,6 +297,27 @@ describe "Commenting legislation questions" do end end + scenario "Reply show parent comments responses when hidden", :js do + manuela = create(:user, :level_two, username: "Manuela") + legislation_annotation = create(:legislation_annotation) + comment = legislation_annotation.comments.first + create(:comment, commentable: legislation_annotation, parent: comment) + + login_as(manuela) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, + legislation_annotation.draft_version, + legislation_annotation) + + within ".comment", text: comment.body do + click_link text: "1 response (collapse)" + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("It will be done next week.") + end + end + scenario "Errors on reply", :js do comment = legislation_annotation.comments.first diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index f7a10b02a..6f55c7d49 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -276,6 +276,24 @@ describe "Commenting legislation questions" do end end + scenario "Reply show parent comments responses when hidden", :js do + manuela = create(:user, :level_two, username: "Manuela") + comment = create(:comment, commentable: legislation_question) + create(:comment, commentable: legislation_question, parent: comment) + + login_as(manuela) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + within ".comment", text: comment.body do + click_link text: "1 response (collapse)" + click_link "Reply" + fill_in "Leave your answer", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("It will be done next week.") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: legislation_question, user: user) diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index 745c8a3be..ded564fac 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -255,6 +255,23 @@ describe "Commenting polls" do end end + scenario "Reply show parent comments responses when hidden", :js do + comment = create(:comment, commentable: poll) + create(:comment, commentable: poll, parent: comment) + + login_as(create(:user)) + visit poll_path(poll) + + within ".comment", text: comment.body do + click_link text: "1 response (collapse)" + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("It will be done next week.") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: poll, user: user) diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index 1f1e5a38b..02b08440d 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -253,6 +253,23 @@ describe "Commenting proposals" do end end + scenario "Reply show parent comments responses when hidden", :js do + comment = create(:comment, commentable: proposal) + create(:comment, commentable: proposal, parent: comment) + + login_as(create(:user)) + visit proposal_path(proposal) + + within ".comment", text: comment.body do + click_link text: "1 response (collapse)" + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("It will be done next week.") + end + end + scenario "Errors on reply", :js do comment = create(:comment, commentable: proposal, user: user) diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index 5001927c2..377fc7236 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -281,6 +281,25 @@ describe "Commenting topics from proposals" do end end + scenario "Reply show parent comments responses when hidden", :js do + community = proposal.community + topic = create(:topic, community: community) + comment = create(:comment, commentable: topic) + create(:comment, commentable: topic, parent: comment) + + login_as(create(:user)) + visit community_topic_path(community, topic) + + within ".comment", text: comment.body do + click_link text: "1 response (collapse)" + click_link "Reply" + fill_in "Leave your comment", with: "It will be done next week." + click_button "Publish reply" + + expect(page).to have_content("It will be done next week.") + end + end + scenario "Errors on reply", :js do community = proposal.community topic = create(:topic, community: community) From 31c0b4360dc6dc048d0074e0df61f69e2c028159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Fri, 15 May 2020 17:09:02 +0200 Subject: [PATCH 4/4] Improve the way to toggle comment responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Javi Martín --- app/assets/javascripts/comments.js | 10 ++---- app/assets/stylesheets/layout.scss | 37 +++++++++++++++----- app/views/comments/_responses_count.html.erb | 6 ++-- spec/system/comments/debates_spec.rb | 5 ++- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 44d70bb38..4e9012f1e 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -2,11 +2,8 @@ "use strict"; App.Comments = { add_comment: function(parent_selector, response_html) { - $(parent_selector + " .comment-list:first").prepend($(response_html)); - var hidden_responses = $(parent_selector + " .comment-list:first").is(":hidden"); - if (parent_selector && hidden_responses) { - $(parent_selector).find(".comment-list:first").toggle("slow"); - } + $(parent_selector + " .comment-list:first").prepend($(response_html)).show("slow"); + $(parent_selector + " .responses-count:first").removeClass("collapsed"); this.update_comments_count(); }, update_comments_count: function() { @@ -45,8 +42,7 @@ $("body").on("click", ".js-toggle-children", function() { $(this).closest(".comment").find(".comment-list:first").toggle("slow"); - $(this).children(".far").toggleClass("fa-minus-square fa-plus-square"); - $(this).children(".js-child-toggle").toggle(); + $(this).closest(".responses-count").toggleClass("collapsed"); return false; }); } diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 3c195b1d8..9eb5c734b 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -2121,14 +2121,6 @@ table { padding-left: rem-calc(18); } - .far { - font-size: $small-font-size; - left: 0; - position: absolute; - text-decoration: none; - top: 2px; - } - .divider { color: $text-light; display: inline-block; @@ -2139,6 +2131,35 @@ table { } } + .responses-count { + .far { + @extend .fa-minus-square; + font-size: $small-font-size; + left: 0; + position: absolute; + text-decoration: none; + top: 2px; + } + + .show-children { + display: none; + } + + &.collapsed { + .far { + @extend .fa-plus-square; + } + + .collapse-children { + display: none; + } + + .show-children { + display: inline; + } + } + } + .comment-user { margin-top: $line-height / 4; padding: $line-height / 4 0; diff --git a/app/views/comments/_responses_count.html.erb b/app/views/comments/_responses_count.html.erb index 62b4103ac..3915b5495 100644 --- a/app/views/comments/_responses_count.html.erb +++ b/app/views/comments/_responses_count.html.erb @@ -1,8 +1,8 @@ <% if count > 0 %> <%= link_to "", class: "js-toggle-children relative" do %> - - - <%= t("comments.comment.responses_collapse", count: count) %> + + <%= t("comments.comment.responses_show", count: count) %> + <%= t("comments.comment.responses_collapse", count: count) %> <% end %> <% else %> <%= t("comments.comment.responses", count: 0) %> diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index 740258b8b..ceaeede4f 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -91,8 +91,7 @@ describe "Commenting debates" do end scenario "can collapse comments after adding a reply", :js do - parent_comment = create(:comment, body: "Main comment", commentable: debate) - create(:comment, body: "First subcomment", commentable: debate, parent: parent_comment) + create(:comment, body: "Main comment", commentable: debate) login_as(user) visit debate_path(debate) @@ -104,7 +103,7 @@ describe "Commenting debates" do expect(page).to have_content("It will be done next week.") - find(".fa-minus-square").click + click_link text: "1 response (collapse)" expect(page).not_to have_content("It will be done next week.") end