From 23f3386f3f4b3b59075baf76e08370365ae3fac8 Mon Sep 17 00:00:00 2001 From: Arit Amana <32520970+msarit@users.noreply.github.com> Date: Wed, 27 Jan 2021 11:13:10 -0500 Subject: [PATCH] Don't display '0 reactions' on article feed (#12425) * Implement for Feed Card only * update snapshot * write tests * Implement changes in other article-feed-card views * modify failing spec * Address code review comments --- .../javascripts/utilities/buildArticleHTML.js | 8 +-- .../__snapshots__/Article.test.jsx.snap | 52 ------------------- .../__tests__/utilities/articleUtilities.js | 5 ++ .../articles/components/ReactionsCount.jsx | 4 ++ .../__tests__/ReactionsCount.test.jsx | 26 ++++++++++ app/views/articles/_single_story.html.erb | 22 ++++---- .../search/display_articles_search_spec.rb | 12 ++++- 7 files changed, 62 insertions(+), 67 deletions(-) create mode 100644 app/javascript/articles/components/__tests__/ReactionsCount.test.jsx diff --git a/app/assets/javascripts/utilities/buildArticleHTML.js b/app/assets/javascripts/utilities/buildArticleHTML.js index acfa943fc..3da961a8d 100644 --- a/app/assets/javascripts/utilities/buildArticleHTML.js +++ b/app/assets/javascripts/utilities/buildArticleHTML.js @@ -88,17 +88,17 @@ function buildArticleHTML(article) { ''; } - var rc = article.public_reactions_count; - var reactionsCount = rc || '0'; + var reactionsCount = article.public_reactions_count; var reactionsDisplay = ''; + var reactionsText = reactionsCount === 1 ? 'reaction' : 'reactions'; - if (article.class_name !== 'User') { + if (article.class_name !== 'User' && reactionsCount > 0) { reactionsDisplay = '' + reactionsCount + - ''; + ``; } var picUrl; diff --git a/app/javascript/articles/__tests__/__snapshots__/Article.test.jsx.snap b/app/javascript/articles/__tests__/__snapshots__/Article.test.jsx.snap index c3d8fb0a1..f5f0f8bab 100644 --- a/app/javascript/articles/__tests__/__snapshots__/Article.test.jsx.snap +++ b/app/javascript/articles/__tests__/__snapshots__/Article.test.jsx.snap @@ -138,32 +138,6 @@ Object {
- - - - - - 0 - - - - - - - - - 0 - - - { ); + if (totalReactions === 0) { + return; + } + return (
- - <%= inline_svg_tag("small-heart.svg", aria: true, width: 24, height: 24, class: "crayons-icon", title: "Reactions") %> - <%= story.public_reactions_count %> - - + <% if story.public_reactions_count > 0 %> + + <%= inline_svg_tag("small-heart.svg", aria: true, width: 24, height: 24, class: "crayons-icon", title: "Reactions") %> + <%= story.public_reactions_count %> + + + <% end %> <% if story.comments_count > 0 %> - - <%= inline_svg_tag("small-comment.svg", aria: true, width: 24, height: 24, class: "crayons-icon", title: "Comments") %> - <%= story.comments_count %> - - + + <%= inline_svg_tag("small-comment.svg", aria: true, width: 24, height: 24, class: "crayons-icon", title: "Comments") %> + <%= story.comments_count %> + + <% end %>
diff --git a/spec/system/search/display_articles_search_spec.rb b/spec/system/search/display_articles_search_spec.rb index e29c6f724..e25e9d7be 100644 --- a/spec/system/search/display_articles_search_spec.rb +++ b/spec/system/search/display_articles_search_spec.rb @@ -21,6 +21,7 @@ RSpec.describe "Display articles search spec", type: :system, js: true, elastics it "returns all expected article fields" do allow(found_article_one).to receive(:reading_time).and_return(5) allow(found_article_one).to receive(:comments_count).and_return(2) + allow(found_article_one).to receive(:public_reactions_count).and_return(3) found_article_one.tags << create(:tag, name: "ruby") index_documents_for_search_class([found_article_one], Search::FeedContent) visit "/search?q=ruby&filters=class_name:Article" @@ -31,7 +32,16 @@ RSpec.describe "Display articles search spec", type: :system, js: true, elastics expect(page).to have_content("5 min read") expect(find_link("#ruby")["href"]).to include("/t/ruby") expect(find_link(found_article_one.user.name)["href"]).to include(found_article_one.username) - expect(page).to have_content("0 reactions") + expect(page).to have_content("3 reactions") expect(page).to have_content("2 comments") end + + it "does not show reaction data if article has no reactions" do + allow(found_article_one).to receive(:public_reactions_count).and_return(0) + found_article_one.tags << create(:tag, name: "ruby") + index_documents_for_search_class([found_article_one], Search::FeedContent) + visit "/search?q=ruby&filters=class_name:Article" + + expect(page).not_to have_content("0 reactions") + end end