* Add Percy to Gemfile, rails helper * Percy snapshots for using the editor * Add PERCY_TOKEN to sample_application.yml * Percy snapshots for visiting the homepage * Percy snapshots for viewing an article's comments * Percy snapshots for creating an article * Percy snapshots for editing an article * Percy snapshots for logged in/out user * Remove empty spec file * Percy snapshots for settings page * Percy snapshots for reading list * Percy snapshots for admin view * Percy snapshots for moderator view * Percy snapshots for authentication views * Percy snapshots for article and tag views * Percy snapshots for editing/deleting comment views * Percy snapshots for admin views * Percy snapshots for comment views * Percy snapshots for organization views * Percy snapshots for pro membership views * Percy snapshots for podcast views * Percy snapshots for user views * Percy snapshots for dashboard views * Percy snapshots for homepage views * Percy snapshots for video views * Add js: true in tests that require it for Percy * Percy dependency cleanup * Add the Percy agent * Remove the PERCY_TOKEN from sample_application.yml * Move the Percy gem into the "test" group in the Gemfile * Remove duplicate snapshots, provide unique names to snapshots * Set seed on Faker::Config for deterministic Percy snapshots * Freeze time in js: true tests for determinstic snapshots * Upgrade Percy to v0.26.3 * Add percy: true flag for Percy snapshotting tests * Add more percy: true flags
267 lines
9.1 KiB
Ruby
267 lines
9.1 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "User visits articles by timeframe", type: :system do
|
|
let(:author) { create(:user) }
|
|
let!(:article) { create(:article, user: author, published_at: Time.current) }
|
|
let!(:days_old_article) { create(:article, user: author, published_at: 2.days.ago) }
|
|
let!(:weeks_old_article) { create(:article, user: author, published_at: 2.weeks.ago) }
|
|
let!(:months_old_article) { create(:article, user: author, published_at: 2.months.ago) }
|
|
let!(:years_old_article) { create(:article, user: author, published_at: 2.years.ago) }
|
|
|
|
context "when user hasn't logged in" do
|
|
context "when viewing articles for week" do
|
|
before { visit "/top/week" }
|
|
|
|
it "renders the page", js: true, percy: true do
|
|
Percy.snapshot(page, name: "Articles: /top/week logged out user")
|
|
end
|
|
|
|
it "shows correct articles count" do
|
|
expect(page).to have_selector(".crayons-story", visible: :visible, count: 2)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when viewing articles for month" do
|
|
before { visit "/top/month" }
|
|
|
|
it "renders the page", js: true, percy: true do
|
|
Percy.snapshot(page, name: "Articles: /top/month logged out user")
|
|
end
|
|
|
|
it "shows correct articles count" do
|
|
expect(page).to have_selector(".crayons-story", visible: :visible, count: 3)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
expect(page).to have_text(weeks_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when viewing articles for year" do
|
|
before { visit "/top/year" }
|
|
|
|
it "renders the page", js: true, percy: true do
|
|
Percy.snapshot(page, name: "Articles: /top/year logged out user")
|
|
end
|
|
|
|
it "shows correct articles count" do
|
|
expect(page).to have_selector(".crayons-story", visible: :visible, count: 4)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
expect(page).to have_text(weeks_old_article.title)
|
|
expect(page).to have_text(months_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when viewing articles for infinity" do
|
|
before { visit "/top/infinity" }
|
|
|
|
it "renders the page", js: true, percy: true do
|
|
Percy.snapshot(page, name: "Articles: /top/infinity logged out user")
|
|
end
|
|
|
|
it "shows correct articles and cta count" do
|
|
expect(page).to have_selector(".crayons-story", visible: :visible, count: 5)
|
|
expect(page).to have_selector(".feed-cta", count: 1)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
expect(page).to have_text(weeks_old_article.title)
|
|
expect(page).to have_text(months_old_article.title)
|
|
expect(page).to have_text(years_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when viewing articles for latest" do
|
|
before { visit "/latest" }
|
|
|
|
it "renders the page", js: true, percy: true do
|
|
Percy.snapshot(page, name: "Articles: /latest logged out user")
|
|
end
|
|
|
|
it "shows correct articles and cta count" do
|
|
expect(page).to have_selector(".crayons-story", visible: :visible, count: 5)
|
|
expect(page).to have_selector(".feed-cta", count: 1)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
expect(page).to have_text(weeks_old_article.title)
|
|
expect(page).to have_text(months_old_article.title)
|
|
expect(page).to have_text(years_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when user has logged in", js: true, elasticsearch: "FeedContent" do
|
|
let(:user) { create(:user) }
|
|
|
|
before do
|
|
sign_in user
|
|
visit "/top/week"
|
|
end
|
|
|
|
it "renders the page", percy: true do
|
|
Percy.snapshot(page, name: "Articles: /top/week logged in user")
|
|
end
|
|
|
|
it "shows correct articles count" do
|
|
expect(page).to have_xpath("//article[contains(@class, 'crayons-story') and contains(@class, 'false')]", count: 1)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
end
|
|
end
|
|
|
|
context "when viewing articles for month" do
|
|
before { visit "/top/month" }
|
|
|
|
it "renders the page", percy: true do
|
|
Percy.snapshot(page, name: "Articles: /top/month logged in user")
|
|
end
|
|
|
|
it "shows correct articles count" do
|
|
expect(page).to have_xpath("//article[contains(@class, 'crayons-story') and contains(@class, 'false')]", count: 2)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
expect(page).to have_text(weeks_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when viewing articles for year" do
|
|
before { visit "/top/year" }
|
|
|
|
it "renders the page", percy: true do
|
|
Percy.snapshot(page, name: "Articles: /top/year logged in user")
|
|
end
|
|
|
|
it "shows correct articles count" do
|
|
expect(page).to have_xpath("//article[contains(@class, 'crayons-story') and contains(@class, 'false')]", count: 3)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
expect(page).to have_text(weeks_old_article.title)
|
|
expect(page).to have_text(months_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when viewing articles for infinity" do
|
|
before { visit "/top/infinity" }
|
|
|
|
it "renders the page", percy: true do
|
|
Percy.snapshot(page, name: "Articles: /top/infinity logged in user")
|
|
end
|
|
|
|
it "shows correct articles count" do
|
|
expect(page).to have_xpath("//article[contains(@class, 'crayons-story') and contains(@class, 'false')]", count: 4)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
expect(page).to have_text(weeks_old_article.title)
|
|
expect(page).to have_text(months_old_article.title)
|
|
expect(page).to have_text(years_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when viewing articles for latest" do
|
|
before { visit "/latest" }
|
|
|
|
it "renders the page", percy: true do
|
|
Percy.snapshot(page, name: "Articles: /latest logged in user")
|
|
end
|
|
|
|
it "shows correct articles" do
|
|
expect(page).to have_xpath("//article[contains(@class, 'crayons-story') and contains(@class, 'false')]", count: 4)
|
|
end
|
|
|
|
it "shows the main article" do
|
|
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
|
|
end
|
|
|
|
it "shows the correct articles" do
|
|
within("#articles-list") do
|
|
expect(page).to have_text(article.title)
|
|
expect(page).to have_text(days_old_article.title)
|
|
expect(page).to have_text(weeks_old_article.title)
|
|
expect(page).to have_text(months_old_article.title)
|
|
expect(page).to have_text(years_old_article.title)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|