Skip to content

Commit

Permalink
Merge pull request consuldemocracy#54 from democrateam/hide_comments_…
Browse files Browse the repository at this point in the history
…order

Show comments order only if there are comments
  • Loading branch information
decabeza committed Feb 20, 2022
2 parents 8a23e23 + 9df1cb2 commit 11274d2
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/components/shared/comments_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
<%= render "shared/login_to_comment" %>
<% end %>
<%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %>
<% if comment_tree.comments.any? %>
<%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %>
<% end %>
<%= render "comments/comment_list", comments: comment_tree.root_comments %>
<%= paginate comment_tree.root_comments, params: { anchor: "comments" } %>
<% end %>
Expand Down
5 changes: 4 additions & 1 deletion app/views/comments/_comment_tree.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
<%= render "shared/login_to_comment" %>
<% end %>
<%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %>
<% if comment_tree.comments.any? %>
<%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %>
<% end %>
<%= render "comments/comment_list", comments: comment_tree.root_comments, valuation: valuation %>
<%= paginate comment_tree.root_comments, params: { anchor: "comments" } %>
</div>
Expand Down
19 changes: 19 additions & 0 deletions spec/system/comments/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@
expect(page).to have_current_path(comment_path(comment))
end

scenario "Show order links only if there are comments" do
visit budget_investment_path(investment.budget, investment)

within "#tab-comments" do
expect(page).not_to have_link "Most voted"
expect(page).not_to have_link "Newest first"
expect(page).not_to have_link "Oldest first"
end

create(:comment, commentable: investment, user: user)
visit budget_investment_path(investment.budget, investment)

within "#tab-comments" do
expect(page).to have_link "Most voted"
expect(page).to have_link "Newest first"
expect(page).to have_link "Oldest first"
end
end

scenario "Collapsable comments" do
parent_comment = create(:comment, body: "Main comment", commentable: investment)
child_comment = create(:comment, body: "First subcomment", commentable: investment, parent: parent_comment)
Expand Down
19 changes: 19 additions & 0 deletions spec/system/comments/debates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@
expect(page).to have_current_path(comment_path(comment))
end

scenario "Show order links only if there are comments" do
visit debate_path(debate)

within "#comments" do
expect(page).not_to have_link "Most voted"
expect(page).not_to have_link "Newest first"
expect(page).not_to have_link "Oldest first"
end

create(:comment, commentable: debate, user: user)
visit debate_path(debate)

within "#comments" do
expect(page).to have_link "Most voted"
expect(page).to have_link "Newest first"
expect(page).to have_link "Oldest first"
end
end

scenario "Collapsable comments" do
parent_comment = create(:comment, body: "Main comment", commentable: debate)
child_comment = create(:comment, body: "First subcomment", commentable: debate, parent: parent_comment)
Expand Down
19 changes: 19 additions & 0 deletions spec/system/comments/legislation_questions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@
expect(page).to have_current_path(comment_path(comment))
end

scenario "Show order links only if there are comments" do
visit legislation_process_question_path(legislation_question.process, legislation_question)

within "#comments" do
expect(page).not_to have_link "Most voted"
expect(page).not_to have_link "Newest first"
expect(page).not_to have_link "Oldest first"
end

create(:comment, commentable: legislation_question, user: user)
visit legislation_process_question_path(legislation_question.process, legislation_question)

within "#comments" do
expect(page).to have_link "Most voted"
expect(page).to have_link "Newest first"
expect(page).to have_link "Oldest first"
end
end

scenario "Collapsable comments" do
parent_comment = create(:comment, body: "Main comment", commentable: legislation_question)
child_comment = create(:comment, body: "First subcomment", commentable: legislation_question, parent: parent_comment)
Expand Down
19 changes: 19 additions & 0 deletions spec/system/comments/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@
expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1)
end

scenario "Show order links only if there are comments" do
visit poll_path(poll)

within "#tab-comments" do
expect(page).not_to have_link "Most voted"
expect(page).not_to have_link "Newest first"
expect(page).not_to have_link "Oldest first"
end

create(:comment, commentable: poll, user: user)
visit poll_path(poll)

within "#tab-comments" do
expect(page).to have_link "Most voted"
expect(page).to have_link "Newest first"
expect(page).to have_link "Oldest first"
end
end

scenario "Link to comment show" do
comment = create(:comment, commentable: poll, user: user)

Expand Down
19 changes: 19 additions & 0 deletions spec/system/comments/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@
expect(page).to have_current_path(comment_path(comment))
end

scenario "Show order links only if there are comments" do
visit proposal_path(proposal)

within "#tab-comments" do
expect(page).not_to have_link "Most voted"
expect(page).not_to have_link "Newest first"
expect(page).not_to have_link "Oldest first"
end

create(:comment, commentable: proposal, user: user)
visit proposal_path(proposal)

within "#tab-comments" do
expect(page).to have_link "Most voted"
expect(page).to have_link "Newest first"
expect(page).to have_link "Oldest first"
end
end

scenario "Collapsable comments" do
parent_comment = create(:comment, body: "Main comment", commentable: proposal)
child_comment = create(:comment, body: "First subcomment", commentable: proposal, parent: parent_comment)
Expand Down
22 changes: 22 additions & 0 deletions spec/system/comments/topics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@
expect(page).to have_current_path(comment_path(comment))
end

scenario "Show order links only if there are comments" do
community = proposal.community
topic = create(:topic, community: community)

visit community_topic_path(community, topic)

within "#tab-comments" do
expect(page).not_to have_link "Most voted"
expect(page).not_to have_link "Newest first"
expect(page).not_to have_link "Oldest first"
end

create(:comment, commentable: topic, user: user)
visit community_topic_path(community, topic)

within "#tab-comments" do
expect(page).to have_link "Most voted"
expect(page).to have_link "Newest first"
expect(page).to have_link "Oldest first"
end
end

scenario "Collapsable comments" do
community = proposal.community
topic = create(:topic, community: community)
Expand Down

0 comments on commit 11274d2

Please sign in to comment.