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)
This commit is contained in:
Senén Rodero Rodríguez
2020-05-15 15:10:55 +02:00
parent 014fa6eb1c
commit dcff7e8a33
9 changed files with 147 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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

View File

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

View File

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

View File

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

View File

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