Fix irregular comment count buttons (#12724)

* Fix irregular comment count buttons

* Fix irregular comments button on tag and user page

* Add regression tests for irregular comment buttons
This commit is contained in:
Jacob Herrington 2021-02-22 12:11:44 -06:00 committed by GitHub
parent 57bc51e65f
commit 0c6f4113f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View file

@ -83,9 +83,15 @@ function buildArticleHTML(article) {
commentsDisplay =
'<a href="' +
article.path +
'#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left "><svg class="crayons-icon" width="24" height="24" xmlns="http://www.w3.org/2000/svg"><path d="M10.5 5h3a6 6 0 110 12v2.625c-3.75-1.5-9-3.75-9-8.625a6 6 0 016-6zM12 15.5h1.5a4.501 4.501 0 001.722-8.657A4.5 4.5 0 0013.5 6.5h-3A4.5 4.5 0 006 11c0 2.707 1.846 4.475 6 6.36V15.5z"/></svg>' +
commentsCount +
'<span class="hidden s:inline">&nbsp;comments</span></a>';
'#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left "><svg class="crayons-icon" width="24" height="24" xmlns="http://www.w3.org/2000/svg"><path d="M10.5 5h3a6 6 0 110 12v2.625c-3.75-1.5-9-3.75-9-8.625a6 6 0 016-6zM12 15.5h1.5a4.501 4.501 0 001.722-8.657A4.5 4.5 0 0013.5 6.5h-3A4.5 4.5 0 006 11c0 2.707 1.846 4.475 6 6.36V15.5z"/></svg>';
if (commentsCount > 0) {
commentsDisplay +=
commentsCount +
'<span class="hidden s:inline">&nbsp;comments</span></a>';
} else {
commentsDisplay +=
'<span class="hidden s:inline">Add&nbsp;Comment</span></a>';
}
}
var reactionsCount = article.public_reactions_count;

View file

@ -83,6 +83,11 @@
<%= story.comments_count %>
<span class="hidden s:inline">&nbsp;<%= story.comments_count == 1 ? "comment" : "comments" %></span>
</a>
<% else %>
<a href="<%= story.path %>#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left">
<%= inline_svg_tag("small-comment.svg", aria: true, width: 24, height: 24, class: "crayons-icon", title: "Comments") %>
<span class="hidden s:inline">Add&nbsp;Comment</span>
</a>
<% end %>
</div>
<div class="crayons-story__save">

View file

@ -26,6 +26,12 @@ RSpec.describe "User visits articles by tag", type: :system do
within("header.tag-header") { expect(page).to have_button("Follow") }
end
# Regression test for https://github.com/forem/forem/pull/12724
it "does not display a comment count of 0", js: true, stub_elasticsearch: true do
expect(page).to have_text("Add Comment")
expect(page).not_to have_text("0 comments")
end
it "shows correct articles count" do
expect(page).to have_selector(".crayons-story", count: 2)
end

View file

@ -19,6 +19,15 @@ RSpec.describe "User visits a homepage", type: :system do
expect(page).to have_selector(".crayons-story--featured", visible: :visible)
end
# Regression test for https://github.com/forem/forem/pull/12724
it "does not display a comment count of 0", js: true, stub_elasticsearch: true do
expect(page).to have_text("Add Comment")
expect(page).not_to have_text("0 comments")
article.update_column(:comments_count, 50)
visit "/"
expect(page).to have_text(/50\s*comments/)
end
it "shows the main article readable date and time", js: true, stub_elasticsearch: true do
expect(page).to have_selector(".crayons-story--featured time", text: published_date)
selector = ".crayons-story--featured time[datetime='#{timestamp}']"