Files
danbooru/test/components/comment_component_test.rb
evazion 07bdc6eab0 comments: rework thresholded comments.
Previously thresholded comments were hidden completely. You had to click
the "Show X hidden comments" button to unhide all hidden comments in a
thread. Now it works like this:

* When a comment is below your threshold, the comment text is hidden and
  replaced by a `[hidden]` link, which you can click to unhide the comment.

* When a comment is at half your threshold (for example, your threshold
  is -8 but the comment is at -4), then the comment is greyed out.

This means that comments aren't completely hidden, they're just
collapsed, so you can see the commenter and the score without unhiding
the comment. It also means you don't have to scroll back up to unhide a
comment, and threads aren't disrupted by comments being secretly
hidden (which is confusing when people are replying to hidden comments,
which forces you to go back up and unhide to find).
2021-01-19 04:07:33 -06:00

73 lines
2.1 KiB
Ruby

require "test_helper"
class CommentComponentTest < ViewComponent::TestCase
def render_comment(comment, current_user: User.anonymous, **options)
as(current_user) do
render_inline(CommentComponent.new(comment: comment, current_user: current_user, **options))
end
end
context "The CommentComponent" do
setup do
@comment = as(create(:user)) { create(:comment) }
end
context "for a regular comment" do
should "render for Anonymous" do
render_comment(@comment, current_user: User.anonymous)
assert_css("article#comment_#{@comment.id}")
end
should "render for a Member" do
render_comment(@comment, current_user: create(:user))
assert_css("article#comment_#{@comment.id}")
end
end
context "for a comment with moderation reports" do
should "show the report notice to moderators" do
create(:moderation_report, model: @comment)
render_comment(@comment, current_user: create(:moderator_user))
assert_css(".moderation-report-notice")
end
should "not show the report notice to regular users" do
render_comment(@comment, current_user: User.anonymous)
assert_no_css(".moderation-report-notice")
end
end
context "for a downvoted comment" do
setup do
@user = create(:user, comment_threshold: -8)
end
context "that is thresholded" do
should "hide the comment" do
as(@user) { @comment.update!(score: -9) }
render_comment(@comment, current_user: @user)
assert_css("article.comment[data-is-thresholded=true]")
assert_css("article.comment[data-is-dimmed=true]")
assert_css("article.comment .unhide-comment-link")
end
end
context "that is dimmed" do
should "dim the comment" do
as(@user) { @comment.update!(score: -5) }
render_comment(@comment, current_user: @user)
assert_css("article.comment[data-is-thresholded=false]")
assert_css("article.comment[data-is-dimmed=true]")
assert_no_css("article.comment .unhide-comment-link")
end
end
end
end
end