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)