Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,14 @@ li.story > turbo-frame {

.story-refresh {
padding: 0;
border: 0;
background: none;
color: inherit;
background: none;
border: 0;
}

/* Turbo sets aria-busy on the refresh form while its request is in flight. */
.story-refresh-form[aria-busy="true"] .fa-refresh {
animation: fa-spin 1s infinite linear;
}

.story-preview .story-starred {
Expand Down
6 changes: 4 additions & 2 deletions spec/components/story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,14 @@ def values(element)
expect(form[:action]).to eq("/stories/#{story.id}/refresh")
end

# Midday UTC is the same date in the machine's local zone, which
# SampleStory uses.
it "renders tutorial sample stories" do
travel_to(Time.utc(2026, 6, 15, 12))
sample = SampleStory.new("Feed Name", "Sample title")
date = Time.current.strftime("%A, %B %d")

expect(render_story(sample))
.to have_css("turbo-frame#story_#{sample.id}")
.and have_css(".story-published", text: date)
.and have_css(".story-published", text: "Monday, June 15")
end
end
4 changes: 3 additions & 1 deletion spec/support/feed_server.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# frozen_string_literal: true

class FeedServer
attr_writer :response
attr_writer :response, :delay

def initialize
@server = Capybara::Server.new(method(:response)).boot
end

# `delay` (seconds) holds the response, for specs that check a loading state.
def response(_env)
sleep(@delay) if @delay
[200, {}, [@response]]
end

Expand Down
27 changes: 26 additions & 1 deletion spec/system/stories_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ def updated_feed_entry(entry_id:, enclosure_url:)
)
end

def serve_feed_with_entry(feed, **entry_options)
def serve_feed_with_entry(feed, delay: nil, **entry_options)
server = FeedServer.new
entry = updated_feed_entry(**entry_options)
server.response = GenerateXml.call(feed, [entry])
server.delay = delay
feed.update!(url: server.url)

# The local FeedServer binds to loopback, which the SSRF guard blocks.
Expand Down Expand Up @@ -211,6 +212,30 @@ def serve_feed_with_entry(feed, **entry_options)
expect(page).to have_no_link(href: "http://example.com/dead.mp3")
end

def spinning_refresh_icon?
page.evaluate_script(<<~JS)
getComputedStyle(
document.querySelector(".story-refresh-form[aria-busy] .fa-refresh")
).animationName === "fa-spin"
JS
end

it "spins the refresh icon while the refresh loads", :aggregate_failures do
story = create(:story, title: "Podcast Episode", entry_id: "episode-1")
serve_feed_with_entry(
story.feed, delay: 1, entry_id: "episode-1", enclosure_url: nil
)
login_as(default_user)
visit(news_path)
find(".story-preview", text: "Podcast Episode").click

find(".story-actions .story-refresh").click

expect(page).to have_css(".story-refresh-form[aria-busy='true']")
expect(spinning_refresh_icon?).to be(true)
expect(page).to have_no_css(".story-refresh-form[aria-busy]")
end

it "marks a story as read when opened" do
create(:story, title: "My Story")
login_as(default_user)
Expand Down
Loading