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).
This commit is contained in:
50
test/components/comment_section_component_test.rb
Normal file
50
test/components/comment_section_component_test.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
require "test_helper"
|
||||
|
||||
class CommentSectionComponentTest < ViewComponent::TestCase
|
||||
def render_comment_section(post, current_user: User.anonymous, **options)
|
||||
as(current_user) do
|
||||
render_inline(CommentSectionComponent.new(post: post, current_user: current_user, **options))
|
||||
end
|
||||
end
|
||||
|
||||
context "The CommentSectionComponent" do
|
||||
setup do
|
||||
as(create(:user)) do
|
||||
@post = create(:post)
|
||||
@comment = create_list(:comment, 7, post: @post)
|
||||
end
|
||||
end
|
||||
|
||||
context "for a comment section with comments" do
|
||||
context "without a comment limit" do
|
||||
should "render" do
|
||||
render_comment_section(@post, current_user: User.anonymous)
|
||||
|
||||
assert_css("div.comments-for-post")
|
||||
assert_css("article.comment", count: 7)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a comment limit" do
|
||||
context "higher than the actual number of comments" do
|
||||
should "render" do
|
||||
render_comment_section(@post, current_user: User.anonymous, limit: 8)
|
||||
|
||||
assert_css("div.comments-for-post")
|
||||
assert_css("article.comment", count: 7)
|
||||
end
|
||||
end
|
||||
|
||||
context "lower than the actual number of comments" do
|
||||
should "render" do
|
||||
render_comment_section(@post, current_user: User.anonymous, limit: 6)
|
||||
|
||||
assert_css("div.comments-for-post")
|
||||
assert_css("article.comment", count: 6)
|
||||
assert_css("a.show-all-comments-link", text: "Show 1 more comment")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user