Optimization/Flaky Fix:Combine Spec Assertions and Use Timecop for Datetime Assertion (#10866)
Co-authored-by: Andy Zhao <17884966+Zhao-Andy@users.noreply.github.com>
This commit is contained in:
parent
0e712f77b0
commit
ba65b04cc8
1 changed files with 28 additions and 14 deletions
|
|
@ -9,48 +9,56 @@ RSpec.describe "User index", type: :system, stub_elasticsearch: true do
|
|||
|
||||
context "when user is unauthorized" do
|
||||
context "when 1 article" do
|
||||
before { visit "/#{user.username}" }
|
||||
before do
|
||||
Timecop.freeze
|
||||
visit "/#{user.username}"
|
||||
end
|
||||
|
||||
it "shows the header", js: true do
|
||||
after { Timecop.return }
|
||||
|
||||
it "shows all proper elements", :aggregate_failures, js: true do
|
||||
shows_header
|
||||
shows_title
|
||||
shows_articles
|
||||
shows_comments
|
||||
shows_comment_timestamp
|
||||
end
|
||||
|
||||
def shows_header
|
||||
within("h1") { expect(page).to have_content(user.name) }
|
||||
within(".profile-header__actions") do
|
||||
expect(page).to have_button("Follow")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows proper title tag" do
|
||||
def shows_title
|
||||
expect(page).to have_title("#{user.name} - #{SiteConfig.community_name}")
|
||||
end
|
||||
|
||||
it "shows user's articles" do
|
||||
def shows_articles
|
||||
within(".crayons-story") do
|
||||
expect(page).to have_content(article.title)
|
||||
expect(page).not_to have_content(other_article.title)
|
||||
end
|
||||
end
|
||||
|
||||
it "shows user's comments" do
|
||||
def shows_comments
|
||||
within("#substories div.index-comments") do
|
||||
expect(page).to have_content("Recent Comments")
|
||||
expect(page).to have_link(nil, href: comment.path)
|
||||
end
|
||||
end
|
||||
|
||||
it "shows user's comments once" do
|
||||
within("#substories") do
|
||||
expect(page).to have_selector(".index-comments", count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
it "shows comment date" do
|
||||
within("#substories .index-comments .single-comment") do
|
||||
# %e blank pads days from 1 to 9, the double space isn't in the HTML
|
||||
comment_date = comment.readable_publish_date.gsub(" ", " ")
|
||||
expect(page).to have_selector(".comment-date", text: comment_date)
|
||||
end
|
||||
end
|
||||
|
||||
it "embeds comment timestamp" do
|
||||
def shows_comment_timestamp
|
||||
within("#substories .index-comments .single-comment") do
|
||||
ts = comment.decorate.published_timestamp
|
||||
timestamp_selector = ".comment-date time[datetime='#{ts}']"
|
||||
|
|
@ -78,21 +86,27 @@ RSpec.describe "User index", type: :system, stub_elasticsearch: true do
|
|||
visit "/#{user.username}"
|
||||
end
|
||||
|
||||
it "shows the header", js: true do
|
||||
it "shows all proper elements", :aggregate_failures, js: true do
|
||||
shows_header
|
||||
shows_articles
|
||||
shows_comments
|
||||
end
|
||||
|
||||
def shows_header
|
||||
within("h1") { expect(page).to have_content(user.name) }
|
||||
within(".profile-header__actions") do
|
||||
expect(page).to have_button("Edit profile")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows user's articles" do
|
||||
def shows_articles
|
||||
within(".crayons-story") do
|
||||
expect(page).to have_content(article.title)
|
||||
expect(page).not_to have_content(other_article.title)
|
||||
end
|
||||
end
|
||||
|
||||
it "shows user's comments" do
|
||||
def shows_comments
|
||||
within("#substories div.index-comments") do
|
||||
expect(page).to have_content("Recent Comments")
|
||||
expect(page).to have_link(nil, href: comment.path)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue