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
This commit is contained in:
Andy Zhao 2022-03-22 12:56:54 -04:00 committed by GitHub
parent 8b8d14479b
commit 5fab2f86b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 19 deletions

View file

@ -81,21 +81,21 @@
</a>
<% end %>
</div>
<h2 class="crayons-subtitle-1 p-3 m:p-0"><%= t("views.podcasts.browse") %></h2>
<div class="grid gap-2 s:grid-cols-2 m:grid-cols-4 px-2 m:px-0">
<% @more_podcasts.each do |podcast| %>
<a href="/<%= podcast.slug %>" class="crayons-link flex items-center m:fs-l lh-tight">
<span class="crayons-logo crayons-logo--xl mr-3">
<img src="<%= Images::Optimizer.call(podcast.image_url, crop: "fill", width: 100, height: 100) %>"
alt="<%= podcast.title %>" aria-hidden="true" class="crayons-logo__image" />
</span>
<span class="truncate-at-2">
<%= podcast.title %>
</span>
</a>
<% end %>
</div>
<% end %>
<h2 class="crayons-subtitle-1 p-3 m:p-0"><%= t("views.podcasts.browse") %></h2>
<div class="grid gap-2 s:grid-cols-2 m:grid-cols-4 px-2 m:px-0">
<% @more_podcasts&.each do |podcast| %>
<a href="/<%= podcast.slug %>" class="crayons-link flex items-center m:fs-l lh-tight">
<span class="crayons-logo crayons-logo--xl mr-3">
<img src="<%= Images::Optimizer.call(podcast.image_url, crop: "fill", width: 100, height: 100) %>"
alt="<%= podcast.title %>" aria-hidden="true" class="crayons-logo__image" />
</span>
<span class="truncate-at-2">
<%= podcast.title %>
</span>
</a>
<% end %>
</div>
</main>
<%= javascript_packs_with_chunks_tag "storiesList", "followButtons", defer: true %>

View file

@ -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

View file

@ -11,5 +11,6 @@ FactoryBot.define do
feed_url { Faker::Internet.url }
main_color_hex { "ffffff" }
published { true }
featured { false }
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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