diff --git a/app/views/articles/_comment_tree.html.erb b/app/views/articles/_comment_tree.html.erb index e46f155c7..07f30ccb2 100644 --- a/app/views/articles/_comment_tree.html.erb +++ b/app/views/articles/_comment_tree.html.erb @@ -1,2 +1,4 @@ <% comment, sub_comments = comment_node %> -<%= nested_comments(tree: { comment => sub_comments }, commentable: @article, is_view_root: true) %> +<% unless comment.decorate.low_quality && sub_comments.empty? %> + <%= nested_comments(tree: { comment => sub_comments }, commentable: @article, is_view_root: true) %> +<% end %> diff --git a/app/views/comments/_comment_proper.html.erb b/app/views/comments/_comment_proper.html.erb index c621d8258..b19eb4fc1 100644 --- a/app/views/comments/_comment_proper.html.erb +++ b/app/views/comments/_comment_proper.html.erb @@ -5,7 +5,7 @@
- <% if comment.deleted %> + <% if comment.deleted || decorated_comment.low_quality %>
<%= t("views.comments.delete.comment_deleted") %> diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb index f29095536..620806a9a 100644 --- a/app/views/comments/index.html.erb +++ b/app/views/comments/index.html.erb @@ -6,43 +6,43 @@ <% end %> <% if @commentable %> -<%= content_for :page_meta do %> - "> - <%= meta_keywords_article %> + <%= content_for :page_meta do %> + "> + <%= meta_keywords_article %> - - " /> - " /> - - - "> - - - "> + + " /> + " /> + + + "> + + + "> - <% if @root_comment.present? %> - - - " /> - "> - - - <% if @root_comment.score < 0 || @commentable.score < 0 %> - - - <% end %> - <% else %> - " /> - " /> - " /> - "> - <% if @commentable.class.name == "Article" && @commentable.published %> + <% if @root_comment.present? %> + + + " /> + "> + <% if @root_comment.score < 0 || @commentable.score < 0 %> + + + <% end %> + <% else %> + " /> + " /> + " /> + "> + <% if @commentable.class.name == "Article" && @commentable.published %> + + + <% end %> <% end %> <% end %> <% end %> -<% end %> <%= javascript_packs_with_chunks_tag "commentDropdowns", "followButtons", defer: true %> @@ -92,15 +92,15 @@ <%= javascript_packs_with_chunks_tag "commentsDisplay", defer: true %>
<% if @commentable %> -

- <%= t("views.comments.parent.subtitle_html", - start: tag("span", { class: %w[fw-normal color-base-60] }, true), - end: "".html_safe, - title: tag.span(@commentable.title)) %> -

- +

+ <%= t("views.comments.parent.subtitle_html", + start: tag("span", { class: %w[fw-normal color-base-60] }, true), + end: "".html_safe, + title: tag.span(@commentable.title)) %> +

+ <% else %> <%= t("views.comments.orphan.deleted") %> <% end %> diff --git a/spec/requests/articles/articles_show_spec.rb b/spec/requests/articles/articles_show_spec.rb index 58abbbaff..d06502ebe 100644 --- a/spec/requests/articles/articles_show_spec.rb +++ b/spec/requests/articles/articles_show_spec.rb @@ -181,6 +181,67 @@ RSpec.describe "ArticlesShow" do end end + context "with comments" do + let!(:spam_comment) { create(:comment, score: -80, commentable: article, body_markdown: "Spam comment") } + + before do + create(:comment, score: 10, commentable: article, body_markdown: "Good comment") + create(:comment, score: -10, commentable: article, body_markdown: "Bad comment") + end + + context "when user signed in" do + before do + sign_in user + end + + it "shows positive comments" do + get article.path + expect(response.body).to include("Good comment") + end + + it "shows comments with score from -75 (low quality threshold) to 0" do + get article.path + expect(response.body).to include("Bad comment") + end + + it "hides comments with score < -75 and no comment deleted message" do + get article.path + expect(response.body).not_to include("Spam comment") + expect(response.body).not_to include("Comment deleted") + end + + it "displays children of a low-quality comment and comment deleted message" do + create(:comment, score: 0, commentable: article, parent: spam_comment, body_markdown: "Child comment") + get article.path + expect(response.body).to include("Child comment") + expect(response.body).to include("Comment deleted") # instead of the low quality one + end + end + + context "when user not signed in" do + it "shows positive comments" do + get article.path + expect(response.body).to include("Good comment") + end + + it "hides comments with score from -75 to 0" do + get article.path + expect(response.body).not_to include("Bad comment") + end + + it "hides comments with score < -75" do + get article.path + expect(response.body).not_to include("Spam comment") + end + + it "doesn't show children of a low-quality comment" do + create(:comment, score: 0, commentable: article, parent: spam_comment, body_markdown: "Child comment") + get article.path + expect(response.body).not_to include("Child comment") + end + end + end + context "when user not signed in but internal nav triggered" do before do get "#{article.path}?i=i" diff --git a/spec/views/comments/_comment.html.erb_spec.rb b/spec/views/comments/_comment.html.erb_spec.rb index 9457a2fd2..9ccbdd3c4 100644 --- a/spec/views/comments/_comment.html.erb_spec.rb +++ b/spec/views/comments/_comment.html.erb_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" RSpec.describe "rendering locals in a partial" do context "when comment is low-quality" do - it "renders the comment with low-quality marker" do + it "renders the comment with low-quality marker", skip: "hiding low-quality for now" do allow(Settings::General).to receive(:mascot_image_url).and_return("https://i.imgur.com/fKYKgo4.png") comment = create(:comment, processed_html: "hi", score: CommentDecorator::LOW_QUALITY_THRESHOLD - 100) article = create(:article)