From 5fab2f86b03f31c041da00149365a5543d02c4f2 Mon Sep 17 00:00:00 2001
From: Andy Zhao <17884966+Zhao-Andy@users.noreply.github.com>
Date: Tue, 22 Mar 2022 12:56:54 -0400
Subject: [PATCH] Always show the browse section of podcasts regardless of
featured (#16329)
* Always show the browse section regardless of featured
* Add tests for /pod
* Use safe operator if there are no episodes to show
* Fix test for new podcast page
* Fix test again for podcast page
---
app/views/podcast_episodes/index.html.erb | 28 +++++++--------
spec/factories/podcast_episodes.rb | 2 ++
spec/factories/podcasts.rb | 1 +
.../user_visits_podcast_episode_spec.rb | 1 -
.../podcasts/user_visits_podcast_page_spec.rb | 4 +--
.../user_visits_podcasts_root_page_spec.rb | 4 +--
.../podcast_episodes/index.html.erb_spec.rb | 34 +++++++++++++++++++
7 files changed, 55 insertions(+), 19 deletions(-)
create mode 100644 spec/views/podcast_episodes/index.html.erb_spec.rb
diff --git a/app/views/podcast_episodes/index.html.erb b/app/views/podcast_episodes/index.html.erb
index 45338addd..e2271df2b 100644
--- a/app/views/podcast_episodes/index.html.erb
+++ b/app/views/podcast_episodes/index.html.erb
@@ -81,21 +81,21 @@
<% end %>
-
<%= t("views.podcasts.browse") %>
-
<% end %>
+ <%= t("views.podcasts.browse") %>
+
<%= javascript_packs_with_chunks_tag "storiesList", "followButtons", defer: true %>
diff --git a/spec/factories/podcast_episodes.rb b/spec/factories/podcast_episodes.rb
index ef079e7e7..0f16d527b 100644
--- a/spec/factories/podcast_episodes.rb
+++ b/spec/factories/podcast_episodes.rb
@@ -8,5 +8,7 @@ FactoryBot.define do
website_url { Faker::Internet.url }
body { Faker::Hipster.paragraph(sentence_count: 1) }
podcast
+ reachable { true }
+ published_at { Time.current }
end
end
diff --git a/spec/factories/podcasts.rb b/spec/factories/podcasts.rb
index 333d6714f..663333c3c 100644
--- a/spec/factories/podcasts.rb
+++ b/spec/factories/podcasts.rb
@@ -11,5 +11,6 @@ FactoryBot.define do
feed_url { Faker::Internet.url }
main_color_hex { "ffffff" }
published { true }
+ featured { false }
end
end
diff --git a/spec/system/podcasts/user_visits_podcast_episode_spec.rb b/spec/system/podcasts/user_visits_podcast_episode_spec.rb
index 1f33ba782..3e73e5531 100644
--- a/spec/system/podcasts/user_visits_podcast_episode_spec.rb
+++ b/spec/system/podcasts/user_visits_podcast_episode_spec.rb
@@ -19,7 +19,6 @@ RSpec.describe "User visits podcast show page", type: :system, js: true do
expect(page).to have_text(podcast_episode.title)
expect(page).to have_css ".record"
- expect(page).not_to have_css ".published-at"
end
it "see the new comment box on the page" do
diff --git a/spec/system/podcasts/user_visits_podcast_page_spec.rb b/spec/system/podcasts/user_visits_podcast_page_spec.rb
index 65d8abac5..2f8e5e7fc 100644
--- a/spec/system/podcasts/user_visits_podcast_page_spec.rb
+++ b/spec/system/podcasts/user_visits_podcast_page_spec.rb
@@ -20,8 +20,8 @@ RSpec.describe "User visits a podcast page", type: :system do
end
it "displays podcast publish_at" do
- expect(page).to have_selector("time.published-at", count: 1)
- expect(page).to have_selector("span.time-ago-indicator-initial-placeholder", count: 1)
+ expect(page).to have_selector("time.published-at")
+ expect(page).to have_selector("span.time-ago-indicator-initial-placeholder")
end
it "displays correct episodes" do
diff --git a/spec/system/podcasts/user_visits_podcasts_root_page_spec.rb b/spec/system/podcasts/user_visits_podcasts_root_page_spec.rb
index b24444aad..74c4607c1 100644
--- a/spec/system/podcasts/user_visits_podcasts_root_page_spec.rb
+++ b/spec/system/podcasts/user_visits_podcasts_root_page_spec.rb
@@ -21,8 +21,8 @@ RSpec.describe "User visits /pod page", type: :system do
it "displays the podcasts with published_at" do
within "#main-content" do
- expect(page).to have_selector("time.published-at", count: 2)
- expect(page).to have_selector("span.time-ago-indicator-initial-placeholder", count: 2)
+ expect(page).to have_selector("time.published-at")
+ expect(page).to have_selector("span.time-ago-indicator-initial-placeholder")
end
end
diff --git a/spec/views/podcast_episodes/index.html.erb_spec.rb b/spec/views/podcast_episodes/index.html.erb_spec.rb
new file mode 100644
index 000000000..0fedd350c
--- /dev/null
+++ b/spec/views/podcast_episodes/index.html.erb_spec.rb
@@ -0,0 +1,34 @@
+require "rails_helper"
+
+RSpec.describe "podcast_episodes/index.html.erb", type: :view do
+ let(:podcast) { create(:podcast) }
+ let(:podcast_episodes) { create_list(:podcast_episode, 5, podcast: podcast) }
+
+ before do
+ assign(:podcast_episodes, podcast_episodes)
+ assign(:more_podcasts, Podcast.available.order(title: :asc))
+ end
+
+ it "shows the Browse section with the title of the only podcast" do
+ render
+
+ expect(rendered).to have_content("Browse")
+ expect(rendered).to have_content(podcast.title)
+ end
+
+ context "when there are featured podcasts" do
+ let(:featured_podcast) { create(:podcast, featured: true) }
+
+ before do
+ create_list(:podcast_episode, 2, podcast: featured_podcast)
+ assign(:featured_podcasts, Podcast.available.featured.order(title: :asc).limit(4))
+ end
+
+ it "shows the Featured podcasts section" do
+ render
+
+ expect(rendered).to have_content("Featured")
+ expect(rendered).to have_content(featured_podcast.title)
+ end
+ end
+end