docbrown/spec/system/articles/user_visits_articles_by_timeframe_spec.rb
Ridhwana 0771a5cd2e
Load post_comments billboard asynchronously (#19285)
* feat: add a route to the async_info for display ads

* feat: load the billboard asyncronously

* feat: move the methods to the display_ads controller

* feat: handle params better

* feat: cache control headers

* feat: test fastly caching headers on display ads

* fix: surrogate key test

* feat: use safe navigation operator to handle cases where there is no article id

* fix: article id present then find the article

* feat: add a response test

* Fragment caching

* feat: update the article decorator

* feat: update cache keys for fragment

* feat: remove an empty line

* feat: add article id

* feat: bust cache

* feat: setup dropdown for billboard

* chore: add chunk to same line

* feat: add to safe params for caching

* Update app/controllers/display_ads_controller.rb

Co-authored-by: Joshua Wehner <joshua@forem.com>

* feat: remove the cache deletion

* feat: update the routes to follow a new scope

* feat: update the cache params

---------

Co-authored-by: Joshua Wehner <joshua@forem.com>
2023-04-12 18:15:15 +02:00

150 lines
4.6 KiB
Ruby

require "rails_helper"
RSpec.describe "User visits articles by timeframe", js: true do
let(:author) { create(:user) }
let(:minimum_score) { Settings::UserExperience.home_feed_minimum_score + 1 }
let!(:article) { create(:article, score: minimum_score, user: author) }
let!(:days_old_article) { create(:article, :past, past_published_at: 2.days.ago, score: minimum_score, user: author) }
let!(:weeks_old_article) do
create(:article, :past, past_published_at: 2.weeks.ago, score: minimum_score, user: author)
end
let!(:months_old_article) do
create(:article, :past, past_published_at: 2.months.ago, score: minimum_score, user: author)
end
let!(:years_old_article) do
create(:article, :past, past_published_at: 2.years.ago, score: minimum_score, user: author)
end
before do
Timecop.freeze(Time.current)
end
after do
Timecop.return
end
def shows_correct_articles_count(count)
expect(page).to have_selector(".crayons-story", visible: :all, count: count)
end
def shows_main_article
expect(page).to have_selector(".crayons-story--featured", visible: :visible, count: 1)
end
it "shows correct articles for all tabs for logged out users", :aggregate_failures do
visit "/top/week"
shows_correct_articles_count(2)
shows_main_article
within("#main-content") do
expect(page).to have_text(article.title)
expect(page).to have_text(days_old_article.title)
end
visit "/top/month"
shows_correct_articles_count(3)
shows_main_article
within("#main-content") 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
visit "/top/year"
shows_correct_articles_count(4)
shows_main_article
within("#main-content") 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
visit "/top/infinity"
shows_correct_articles_count(5)
shows_main_article
within("#main-content") 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
visit "/latest"
shows_correct_articles_count(6)
shows_main_article
within("#main-content") 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
it "shows correct articles for signed_in user", :aggregate_failures do
sign_in create(:user)
visit "/top/week"
shows_correct_articles_count(2)
shows_main_article
within("#main-content") do
expect(page).to have_text(article.title)
expect(page).to have_text(days_old_article.title)
end
visit "/top/month"
shows_correct_articles_count(3)
shows_main_article
within("#main-content") 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
visit "/top/year"
shows_correct_articles_count(4)
shows_main_article
within("#main-content") 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
visit "/top/infinity"
shows_correct_articles_count(5)
shows_main_article
within("#main-content") 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
visit "/latest"
shows_correct_articles_count(5)
shows_main_article
within("#main-content") 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
# rubocop:enable RSpec/ExampleLength