diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 9a01ea102..685b2ce0a 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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 { diff --git a/spec/components/story_spec.rb b/spec/components/story_spec.rb index ec3ed8563..526a4d3b0 100644 --- a/spec/components/story_spec.rb +++ b/spec/components/story_spec.rb @@ -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 diff --git a/spec/support/feed_server.rb b/spec/support/feed_server.rb index 0fd60f524..83f187882 100644 --- a/spec/support/feed_server.rb +++ b/spec/support/feed_server.rb @@ -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 diff --git a/spec/system/stories_index_spec.rb b/spec/system/stories_index_spec.rb index 0b1b8de4e..c71db71ad 100644 --- a/spec/system/stories_index_spec.rb +++ b/spec/system/stories_index_spec.rb @@ -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. @@ -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)