From eea4dca2ab65864deb89ad8ddd820e1fd4225745 Mon Sep 17 00:00:00 2001 From: Robert Fletcher Date: Fri, 27 Nov 2026 16:21:40 -0800 Subject: [PATCH] Spin the refresh icon while a story refreshes **What** Spin a story's refresh icon while its refresh request is in flight, using the `aria-busy` attribute Turbo sets on the submitting form. Add a system spec for it, with an optional `delay` on the test feed server so the loading state lasts long enough to check. **Why** Refreshing gave no feedback until the new content appeared. This also gives the tutorial page a refresh state it can imitate later. **Notes** Reorder the `.story-refresh` properties to match stylelint's expected order, so the stylelint baseline's offense count is accurate again. Pin the clock in the sample story component spec. It compared local time with UTC and failed every evening. --- app/assets/stylesheets/application.css | 9 +++++++-- spec/components/story_spec.rb | 6 ++++-- spec/support/feed_server.rb | 4 +++- spec/system/stories_index_spec.rb | 27 +++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 6 deletions(-) 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)