The personal finance app for everyone (by everyone)
Ruby
fix(insights): correct the budget card's figure, badge noise and toast a11y (#2799)
Guillem Arias Faustec40e7f4807cc
diff --git a/app/controllers/insights_controller.rb b/app/controllers/insights_controller.rbindex 9ba67c9fae..6b07137bd2 100644--- a/app/controllers/insights_controller.rb+++ b/app/controllers/insights_controller.rb@@ -1,6 +1,6 @@class InsightsController < ApplicationControllerbefore_action :require_preview_features!- before_action :set_insight, only: %i[dismiss undismiss]+ before_action :set_insight, only: %i[acknowledge unacknowledge]def indexload_feed@@ -15,8 +15,9 @@ class InsightsController < ApplicationControllerendend- def dismiss- @insight.dismiss!+ def acknowledge+ @insight.acknowledge!+ load_widget_feedrespond_to do |format|format.turbo_stream@@ -24,9 +25,10 @@ class InsightsController < ApplicationControllerendend- def undismiss- @insight.undismiss!+ def unacknowledge+ @insight.unacknowledge!load_feed+ load_widget_feedrespond_to do |format|format.turbo_stream@@ -55,6 +57,13 @@ class InsightsController < ApplicationController@unread_ids = @insights.select(&:active?).map(&:id).to_setend+ # Acknowledging is reachable from the dashboard widget as well as this page,+ # so the response re-renders the widget's top three. Removing a row there+ # should promote the next insight into the freed slot, not leave a gap.+ def load_widget_feed+ @feed_insights = Current.family.insights.visible.ordered.limit(Insight::FEED_LIMIT).to_a+ end+# Turbo sends X-Sec-Purpose (the fetch spec forbids setting Sec-Purpose# from JS) on hover-prefetch requests.def prefetch_request?diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rbindex e1dc1a5d77..6cc87f5e5f 100644--- a/app/controllers/pages_controller.rb+++ b/app/controllers/pages_controller.rb@@ -53,7 +53,7 @@ class PagesController < ApplicationController@outflows_data = build_outflows_donut_data(net_totals)# Preview-gated: skip the query outright rather than loading rows the# section won't be built from.- @feed_insights = preview_features_enabled? ? Current.family.insights.visible.ordered.limit(3) : Insight.none+ @feed_insights = preview_features_enabled? ? Current.family.insights.visible.ordered.limit(Insight::FEED_LIMIT) : Insight.none@money_flow_accounts = income_statement.eligible_accounts@money_flow_month = money_flow_month_paramdiff --git a/app/helpers/insights_helper.rb b/app/helpers/insights_helper.rbindex 349d660f17..33ac31d851 100644--- a/app/helpers/insights_helper.rb+++ b/app/helpers/insights_helper.rb@@ -45,7 +45,14 @@ module InsightsHelperfacts["amount"] && [ facts["amount"], t("insights.figures.days_overdue", count: facts["days_overdue"].to_i) ]when "idle_cash"facts["balance"] && [ facts["balance"], t("insights.figures.idle_days", count: facts["idle_days"].to_i) ]- when "budget_at_risk", "budget_on_track"+ when "budget_at_risk"+ # Not budget_spent_pct: this card's headline is "N categories need+ # attention", and total consumption ("14% of budget") reads as reassurance+ # next to it — a focal figure arguing against its own card. The flagged+ # count is what the card is actually about.+ facts["count"] && [ facts["count"].to_s, t("insights.figures.need_attention") ]+ when "budget_on_track"+ # Still the right figure here, where overall usage *is* the subject.facts["budget_spent_pct"] && [ "#{facts["budget_spent_pct"]}%", t("insights.figures.of_budget") ]endenddiff --git a/app/models/insight.rb b/app/models/insight.rbindex 02d562c4d4..21fb6052c1 100644--- a/app/models/insight.rb+++ b/app/models/insight.rb@@ -3,9 +3,17 @@# the LLM (when configured) only writes the `body` prose from pre-computed# numbers, so rows are safe to render verbatim.#-# Status semantics: `read` and `dismissed` are user actions; `expired` is the+# Status semantics: `read` and `acknowledged` are user actions; `expired` is the# system's — set when a signal stops being generated (the condition cleared).-# A returning condition reactivates an expired row but never a dismissed one.+#+# "Acknowledged" rather than "dismissed" because that is what the state has+# always actually meant. GenerateInsightsJob resurfaces a row whose bucketed+# metadata changes materially even if the user acknowledged the stale version,+# and 6 of 8 generators scope `dedup_key` to a month, so acknowledging July's+# budget card says nothing about August's. The contract is: acknowledgement+# covers the numbers you saw; new numbers are a new insight. The DB value stays+# `"dismissed"` (and the `dismissed_at` column keeps its name) so this needed no+# migration — only the vocabulary the code and the UI speak was wrong.class Insight < ApplicationRecordbelongs_to :family@@ -20,7 +28,11 @@ class Insight < ApplicationRecordbudget_on_track].freeze- enum :status, { active: "active", read: "read", dismissed: "dismissed", expired: "expired" }+ # How many the dashboard widget shows. Shared so PagesController (first render)+ # and InsightsController (re-render after acknowledging) can't drift apart.+ FEED_LIMIT = 3++ enum :status, { active: "active", read: "read", acknowledged: "dismissed", expired: "expired" }enum :priority, { high: "high", medium: "medium", low: "low" }, prefix: truevalidates :insight_type, presence: true, inclusion: { in: TYPES }@@ -29,7 +41,7 @@ class Insight < ApplicationRecord# instead of ActiveRecord::RecordNotUnique; races still hit the index.validates :dedup_key, uniqueness: { scope: :family_id }- # Everything the user hasn't dismissed; what the feed renders.+ # Everything the user hasn't acknowledged; what the feed renders.scope :visible, -> { where(status: [ :active, :read ]) }scope :ordered, -> {order(Arel.sql("CASE insights.priority WHEN 'high' THEN 0 WHEN 'medium' THEN 1 ELSE 2 END"))@@ -42,13 +54,19 @@ class Insight < ApplicationRecordupdate!(status: :read, read_at: Time.current)end- def dismiss!- update!(status: :dismissed, dismissed_at: Time.current)+ def acknowledge!+ update!(status: :acknowledged, dismissed_at: Time.current)end- # Undoes a dismissal without re-badging the insight as new — the user has- # obviously seen it, so it returns as read.- def undismiss!+ # Undoes an acknowledgement without re-badging the insight as new — the user+ # has obviously seen it, so it returns as read. Guarded to only reverse an+ # actual acknowledgement: a stale/replayed undo (e.g. an old toast link+ # clicked after GenerateInsightsJob has since expired or resurrected this+ # insight) would otherwise force it back to :read from whatever state it's+ # really in, including bringing an :expired insight back into view.+ def unacknowledge!+ return unless acknowledged?+update!(status: :read, dismissed_at: nil, read_at: read_at || Time.current)endenddiff --git a/app/views/insights/_insight_card.html.erb b/app/views/insights/_insight_card.html.erbindex 95d211f057..ef3cba58c3 100644--- a/app/views/insights/_insight_card.html.erb+++ b/app/views/insights/_insight_card.html.erb@@ -1,46 +1,62 @@<%# locals: (insight:, unread: false) %>-<div id="<%= dom_id(insight) %>" class="bg-container rounded-xl shadow-border-xs p-4 flex gap-3">- <div class="shrink-0 mt-0.5">- <%= icon(insight_icon_key(insight), color: insight_icon_color(insight)) %>- </div>+<div id="<%= dom_id(insight) %>" class="bg-container rounded-xl shadow-border-xs">+ <div class="p-4 flex gap-3">+ <div class="shrink-0 mt-0.5">+ <%= icon(insight_icon_key(insight), color: insight_icon_color(insight)) %>+ </div>- <div class="min-w-0 grow space-y-1">- <p class="text-xs text-secondary"><%= insight_meta_line(insight) %></p>+ <div class="min-w-0 grow space-y-1">+ <p class="text-xs text-secondary"><%= insight_meta_line(insight) %></p>- <div class="flex items-start justify-between gap-3">- <h3 class="text-sm font-medium text-primary inline-flex items-center gap-2 min-w-0">- <%= insight.title %>- <% if unread %>- <%= render DS::Pill.new(label: t("insights.card.new"), tone: :info, size: :sm) %>- <% end %>- </h3>+ <div class="flex items-start justify-between gap-3">+ <h3 class="text-sm font-medium text-primary inline-flex items-center gap-2 min-w-0">+ <%= insight.title %>+ <% if unread %>+ <%# A dot, not a labelled chip. Visiting this page marks every insight+ read in one go, so at first paint the badge is on *every* row and+ differentiates nothing — an uppercase tracked chip that heavy just+ steals weight from the title it sits beside. %>+ <%= render DS::Pill.new(label: t("insights.card.new"), tone: :info, dot_only: true) %>+ <% end %>+ </h3>- <div class="flex items-start gap-1 shrink-0">+ <%# The figure now owns this corner outright. It used to share it with the+ acknowledge control, so the card's data and its escape hatch competed+ for the same spot. %><% if (figure = insight_key_figure(insight)) %>- <div class="text-right mr-1">+ <div class="text-right shrink-0"><p class="text-sm font-mono font-medium privacy-sensitive <%= insight_sentiment(insight) == :positive ? "text-success" : "text-primary" %>"><%= figure.first %></p><p class="text-xs text-subdued"><%= figure.last %></p></div><% end %>-- <%= render DS::Button.new(- variant: "icon",- icon: "x",- href: dismiss_insight_path(insight),- method: :patch,- title: t("insights.card.dismiss"),- aria_label: t("insights.card.dismiss")- ) %></div>- </div>- <p class="text-sm text-secondary"><%= insight.body %></p>+ <p class="text-sm text-secondary"><%= insight.body %></p>+ </div>+ </div>+ <%# Both actions in a footer strip, which fixes an inverted action pyramid: the+ escape hatch used to be a chromed icon button in the top-right corner while+ the card's actual purpose ("View budget") was a borderless ghost link+ buried under the body text. The subject action gets the chrome now, and+ acknowledging is labelled text beside it — quieter, and honest about being+ an acknowledgement rather than a deletion. %>+ <div class="px-4 py-2.5 bg-container-inset rounded-b-xl flex items-center justify-between gap-3"><% if (action = insight_action(insight)) %>- <div class="pt-1">- <%= render DS::Link.new(text: action[:text], href: action[:href], variant: "ghost", size: "sm") %>- </div>+ <%= render DS::Link.new(text: action[:text], href: action[:href], variant: "outline", size: "sm") %>+ <% else %>+ <span></span><% end %>++ <%= render DS::Button.new(+ text: t("insights.card.acknowledge"),+ icon: "check",+ variant: "ghost",+ size: "sm",+ href: acknowledge_insight_path(insight),+ method: :patch,+ title: t("insights.card.acknowledge_title")+ ) %></div></div>diff --git a/app/views/insights/_undo_toast.html.erb b/app/views/insights/_undo_toast.html.erbindex 203f19e777..273e54fbd3 100644--- a/app/views/insights/_undo_toast.html.erb+++ b/app/views/insights/_undo_toast.html.erb@@ -1,19 +1,35 @@<%# locals: (insight:) %>+<%# The card leaves the page via a Turbo `remove`, which is silent to a screen+ reader — this toast is the only announcement of what happened, so it carries+ the live region (same contract as shared/notifications/_sync_toast). %><div id="<%= dom_id(insight, :undo) %>"+ role="status"+ aria-live="polite"class="relative flex items-center gap-3 rounded-lg bg-container p-4 group w-full md:max-w-80 shadow-border-xs"data-controller="element-removal">- <p class="text-primary text-sm font-medium grow"><%= t("insights.card.dismissed") %></p>+ <p class="text-primary text-sm font-medium grow"><%= t("insights.card.acknowledged") %></p>+ <%# autofocus so Undo is one keystroke away: the acknowledged card is gone from+ the DOM, which drops focus to <body>, and Turbo focuses the first+ [autofocus] element in stream-rendered content. %><%= render DS::Button.new(text: t("insights.card.undo"),variant: "ghost",size: "sm",- href: undismiss_insight_path(insight),- method: :patch+ href: unacknowledge_insight_path(insight),+ method: :patch,+ autofocus: true) %>- <%= icon "x",- class: "p-0.5 rounded-lg text-subdued hover:text-primary cursor-pointer shrink-0",- data: { action: "click->element-removal#remove" } %>+ <%# A real button, not a bare icon with a click action: the glyph alone is+ neither focusable nor named, so the toast could only be closed by mouse. %>+ <%= render DS::Button.new(+ variant: "icon",+ size: "sm",+ icon: "x",+ type: "button",+ "aria-label": t("defaults.common.close"),+ data: { action: "click->element-removal#remove" }+ ) %></div>diff --git a/app/views/insights/acknowledge.turbo_stream.erb b/app/views/insights/acknowledge.turbo_stream.erbnew file mode 100644index 0000000000..f0a9cfa843--- /dev/null+++ b/app/views/insights/acknowledge.turbo_stream.erb@@ -0,0 +1,16 @@+<%# Acknowledging is reachable from two surfaces now, so this response carries+ the update for both and each applies only the streams whose targets it has —+ Turbo silently ignores a stream whose target is absent. %>++<%# /insights: drop the card. %>+<%= turbo_stream.remove dom_id(@insight) %>++<%# Dashboard: re-render the well rather than removing a row, so the next+ insight is promoted into the freed slot instead of leaving a gap. %>+<%= turbo_stream.replace "insights-feed" do %>+ <%= render "pages/dashboard/insights_feed", insights: @feed_insights %>+<% end %>++<%= turbo_stream.append "notification-tray" do %>+ <%= render "insights/undo_toast", insight: @insight %>+<% end %>diff --git a/app/views/insights/dismiss.turbo_stream.erb b/app/views/insights/dismiss.turbo_stream.erbdeleted file mode 100644index 8b51de9292..0000000000--- a/app/views/insights/dismiss.turbo_stream.erb+++ /dev/null@@ -1,5 +0,0 @@-<%= turbo_stream.remove dom_id(@insight) %>--<%= turbo_stream.append "notification-tray" do %>- <%= render "insights/undo_toast", insight: @insight %>-<% end %>diff --git a/app/views/insights/unacknowledge.turbo_stream.erb b/app/views/insights/unacknowledge.turbo_stream.erbnew file mode 100644index 0000000000..0428fc2e2c--- /dev/null+++ b/app/views/insights/unacknowledge.turbo_stream.erb@@ -0,0 +1,11 @@+<%= turbo_stream.remove dom_id(@insight, :undo) %>++<%= turbo_stream.replace "insights-list" do %>+ <%= render "insights/list", insights: @insights, unread_ids: @unread_ids %>+<% end %>++<%# Undo can be pressed from the dashboard, where the toast is the only part of+ this flow on screen — so the well needs restoring there too. %>+<%= turbo_stream.replace "insights-feed" do %>+ <%= render "pages/dashboard/insights_feed", insights: @feed_insights %>+<% end %>diff --git a/app/views/insights/undismiss.turbo_stream.erb b/app/views/insights/undismiss.turbo_stream.erbdeleted file mode 100644index d572c8da3e..0000000000--- a/app/views/insights/undismiss.turbo_stream.erb+++ /dev/null@@ -1,5 +0,0 @@-<%= turbo_stream.remove dom_id(@insight, :undo) %>--<%= turbo_stream.replace "insights-list" do %>- <%= render "insights/list", insights: @insights, unread_ids: @unread_ids %>-<% end %>diff --git a/app/views/pages/dashboard/_insights_feed.html.erb b/app/views/pages/dashboard/_insights_feed.html.erbindex f2772ee607..3113c9b3cc 100644--- a/app/views/pages/dashboard/_insights_feed.html.erb+++ b/app/views/pages/dashboard/_insights_feed.html.erb@@ -2,8 +2,8 @@<%# Mirrors the outflows/balance-sheet list idiom: an inset well with anuppercase mini-header, white rows inside, tinted icon circles, and- right-aligned figures. Dismissal lives on /insights; here each row just- links through. Prefetch is disabled because Turbo would serve the+ right-aligned figures. Each row links through to /insights and carries its+ own acknowledge control. Prefetch is disabled because Turbo would serve thehover-prefetched response on click, skipping the mark-as-read inInsightsController#index (it deliberately ignores prefetch requests). %><%# -mt-2 evens the frame: the section shell gives 24px above the content but@@ -34,23 +34,28 @@<div class="py-1.5 shadow-border-xs rounded-lg bg-container text-sm"><% insights.each do |insight| %>- <%# No hover background, matching the outflows rows — the affordance is- the cursor plus the icon's gentle scale. %>- <%= link_to insights_path,- data: { turbo_prefetch: false },- class: "flex items-center mx-3 px-3 py-2.5 rounded-lg gap-3 cursor-pointer group" do %>- <div class="h-7 w-7 shrink-0 rounded-full flex justify-center items-center group-hover:scale-105 transition-all duration-300"+ <%# Stretched link rather than a link wrapping the row, because the+ acknowledge control is a button_to — a <form>, which cannot be+ nested inside an <a>. Same idiom as the outflows rows. %>+ <div class="relative flex items-center mx-3 px-3 py-2.5 rounded-lg gap-3 group/insight">+ <%# Empty body with an aria-label: the visible title is a sibling, and+ passing a name would render it as link text on top of the row. %>+ <%= link_to "", insights_path,+ class: "absolute inset-0 rounded-lg cursor-pointer",+ aria: { label: insight.title },+ data: { turbo_prefetch: false } %>++ <div class="h-7 w-7 shrink-0 rounded-full flex justify-center items-center group-hover/insight:scale-105 transition-all duration-300"style="background-color: color-mix(in oklab, <%= insight_icon_css_color(insight) %> 10%, transparent); color: <%= insight_icon_css_color(insight) %>;"><%= icon(insight_icon_key(insight), color: "current", size: "sm") %></div><div class="min-w-0 grow">- <div class="flex items-center gap-2">- <span class="text-sm font-medium text-primary truncate"><%= insight.title %></span>- <% if insight.active? %>- <%= render DS::Pill.new(label: t("insights.card.new"), tone: :info, size: :sm) %>- <% end %>- </div>+ <%# No per-row "New" pill: the well's header already counts the+ unread ones ("New · 3"), and with only three rows the pill was+ usually on all of them — saying the same thing twice while+ crowding the title. %>+ <span class="text-sm font-medium text-primary truncate block"><%= insight.title %></span><p class="text-sm text-secondary truncate"><%= insight.body %></p></div>@@ -60,7 +65,30 @@<p class="text-xs text-secondary whitespace-nowrap"><%= figure.last %></p></div><% end %>- <% end %>++ <%# Acknowledging used to be possible only on /insights, so the surface+ people actually look at couldn't clear anything. `relative z-10`+ lifts this above the stretched link. Visibility is progressive and+ never hover-only: pointer hover, keyboard focus, and always shown+ on touch, where there is no hover to reveal it. No gesture, so the+ section's drag-to-reorder handlers are untouched.++ The group is *named*: the dashboard <section> wrapping this widget+ is itself a `.group` (for its header controls), and a bare+ `group-hover:` matches any ancestor group — so hovering one row, or+ even the section header, revealed the control on every row. %>+ <div class="relative z-10 shrink-0 opacity-0 group-hover/insight:opacity-100 group-focus-within/insight:opacity-100 pointer-coarse:opacity-100 transition-opacity">+ <%= render DS::Button.new(+ variant: "icon",+ size: "sm",+ icon: "check",+ href: acknowledge_insight_path(insight),+ method: :patch,+ title: t("insights.card.acknowledge"),+ aria_label: t("insights.feed.acknowledge_aria", title: insight.title)+ ) %>+ </div>+ </div><% end %></div></div>diff --git a/config/locales/views/insights/en.yml b/config/locales/views/insights/en.ymlindex fccc31a064..2ed0fb64fa 100644--- a/config/locales/views/insights/en.yml+++ b/config/locales/views/insights/en.yml@@ -12,14 +12,16 @@ en:queued: We're generating fresh insights. Check back in a minute.checking: Checking…card:- dismiss: Dismiss+ acknowledge: Got it+ acknowledge_title: Hide this until the numbers changenew: New- dismissed: Insight dismissed+ acknowledged: Got it — hidden until this changesundo: Undofeed:view_all: View all insightsheader: Latestheader_new: New+ acknowledge_aria: "Got it: %{title}"types:spending_anomaly: Spendingcash_flow_warning: Cash flow@@ -42,6 +44,7 @@ en:today: todayon_pace: on paceof_budget: of budget+ need_attention: need attentiondays_overdue:one: "%{count} day overdue"other: "%{count} days overdue"diff --git a/config/routes.rb b/config/routes.rbindex b0c4f0052c..11a140882c 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -503,8 +503,8 @@ Rails.application.routes.draw doendmember do- patch :dismiss- patch :undismiss+ patch :acknowledge+ patch :unacknowledgeendenddiff --git a/test/controllers/insights_controller_test.rb b/test/controllers/insights_controller_test.rbindex 41c2573ab4..01b252c1f6 100644--- a/test/controllers/insights_controller_test.rb+++ b/test/controllers/insights_controller_test.rb@@ -23,12 +23,16 @@ class InsightsControllerTest < ActionDispatch::IntegrationTestassert @insight.reload.active?end- test "dashboard renders the insights feed section with unread badges" do+ # Unread state is carried by the well's header count, not by a pill on every+ # row. The widget shows three rows, so the pill was usually on all of them,+ # repeating what the header already says and crowding each title.+ test "dashboard insights feed counts unread in its header, without per-row badges" doget root_urlassert_response :successassert_select "#insights-feed", count: 1- assert_select "#insights-feed span", text: I18n.t("insights.card.new")+ assert_select "#insights-feed p", text: /#{Regexp.escape(I18n.t("insights.feed.header_new"))}/+ assert_select "#insights-feed span", text: I18n.t("insights.card.new"), count: 0endtest "insights feed leads the dashboard for users with a saved order that predates it" do@@ -45,19 +49,19 @@ class InsightsControllerTest < ActionDispatch::IntegrationTest"insights_feed should be prepended, not appended, for saved orders that predate it"end- test "dismiss removes the insight from the feed and offers undo via turbo stream" do- patch dismiss_insight_url(@insight), as: :turbo_stream+ test "acknowledge removes the insight from the feed and offers undo via turbo stream" do+ patch acknowledge_insight_url(@insight), as: :turbo_streamassert_response :successassert_match "turbo-stream", response.body- assert_match undismiss_insight_path(@insight), response.body- assert @insight.reload.dismissed?+ assert_match unacknowledge_insight_path(@insight), response.body+ assert @insight.reload.acknowledged?end- test "undismiss restores the insight as read and re-renders the list" do- @insight.dismiss!+ test "unacknowledge restores the insight as read and re-renders the list" do+ @insight.acknowledge!- patch undismiss_insight_url(@insight), as: :turbo_stream+ patch unacknowledge_insight_url(@insight), as: :turbo_streamassert_response :successassert_match "insights-list", response.body@@ -66,6 +70,43 @@ class InsightsControllerTest < ActionDispatch::IntegrationTestassert_nil @insight.dismissed_atend+ # Acknowledging used to be reachable only from /insights, so the dashboard —+ # the surface people actually look at — could show an insight but not clear it.+ test "dashboard feed rows carry an acknowledge control" do+ get root_url++ assert_response :success+ assert_select "#insights-feed form[action=?]", acknowledge_insight_path(@insight)+ end++ # The widget shows the top N, so clearing one has to promote the next into the+ # freed slot rather than leave a gap — hence a re-render, not a row removal.+ test "acknowledge re-renders the dashboard feed so the next insight backfills" do+ family = @user.family+ family.insights.destroy_all++ # One more than the well holds, same priority so `ordered` falls through to+ # generated_at and the sequence is predictable.+ rows = (Insight::FEED_LIMIT + 1).times.map do |i|+ family.insights.create!(+ insight_type: "idle_cash",+ priority: "high",+ status: "active",+ title: "Test insight #{i}",+ body: "body",+ dedup_key: "idle_cash:test:#{i}",+ generated_at: (i + 1).minutes.ago+ )+ end++ patch acknowledge_insight_url(rows.first), as: :turbo_stream++ assert_response :success+ assert_match "insights-feed", response.body+ assert_no_match(/Test insight 0/, response.body)+ assert_match(/Test insight #{Insight::FEED_LIMIT}/, response.body)+ end+test "refresh swaps the button into a pending state via turbo stream" doassert_enqueued_with(job: GenerateInsightsJob, args: [ { family_id: @user.family_id } ]) dopost refresh_insights_url, as: :turbo_stream@@ -76,7 +117,7 @@ class InsightsControllerTest < ActionDispatch::IntegrationTestassert_match CGI.escapeHTML(I18n.t("insights.refresh.checking")), response.bodyend- test "cannot dismiss another family's insight" do+ test "cannot acknowledge another family's insight" doother_insight = families(:empty).insights.create!(insight_type: "idle_cash",priority: "low",@@ -85,7 +126,7 @@ class InsightsControllerTest < ActionDispatch::IntegrationTestdedup_key: "idle_cash:other:2026-07")- patch dismiss_insight_url(other_insight), as: :turbo_stream+ patch acknowledge_insight_url(other_insight), as: :turbo_streamassert_response :not_foundassert other_insight.reload.active?@@ -122,10 +163,10 @@ class InsightsControllerTest < ActionDispatch::IntegrationTestassert_redirected_to root_pathend- test "dismiss is blocked for users without preview access" do+ test "acknowledge is blocked for users without preview access" dodisable_preview_features- patch dismiss_insight_url(@insight), as: :turbo_stream+ patch acknowledge_insight_url(@insight), as: :turbo_streamassert_redirected_to root_pathassert @insight.reload.active?diff --git a/test/helpers/insights_helper_test.rb b/test/helpers/insights_helper_test.rbindex 038fcbcad3..fbf199ce73 100644--- a/test/helpers/insights_helper_test.rb+++ b/test/helpers/insights_helper_test.rb@@ -119,6 +119,28 @@ class InsightsHelperTest < ActionView::TestCaseassert_nil insight_key_figure(without_facts)end+ # The two budget cards share `budget_spent_pct` in facts but not a subject:+ # at-risk is about how many categories are in trouble, on-track is about+ # overall consumption. Showing consumption on the at-risk card put a+ # reassuring figure next to a warning headline.+ test "budget at risk leads with the flagged count, not overall consumption" do+ insight = build_insight("budget_at_risk", facts: { "count" => 2, "budget_spent_pct" => 14 })++ figure, caption = insight_key_figure(insight)++ assert_equal "2", figure+ assert_equal "need attention", caption+ end++ test "budget on track still leads with overall consumption" do+ insight = build_insight("budget_on_track", facts: { "budget_spent_pct" => 62 })++ figure, caption = insight_key_figure(insight)++ assert_equal "62%", figure+ assert_equal "of budget", caption+ end+test "action link resolves the stored subject and disappears when it cannot" doaccount = families(:dylan_family).accounts.visible.firstresolvable = build_insight("idle_cash", metadata: { "account_id" => account.id })diff --git a/test/jobs/generate_insights_job_test.rb b/test/jobs/generate_insights_job_test.rbindex 55ef3ce211..16e16026ed 100644--- a/test/jobs/generate_insights_job_test.rb+++ b/test/jobs/generate_insights_job_test.rb@@ -121,24 +121,24 @@ class GenerateInsightsJobTest < ActiveJob::TestCaseassert insight.read?end- test "dismissed insight stays dismissed when numbers are unchanged" do+ test "acknowledged insight stays acknowledged when numbers are unchanged" dostub_generated([ generated_insight ])GenerateInsightsJob.perform_now(family_id: @family.id)insight = @family.insights.find_by(dedup_key: "idle_cash:test-account:2026-07")- insight.dismiss!+ insight.acknowledge!GenerateInsightsJob.perform_now(family_id: @family.id)- assert insight.reload.dismissed?+ assert insight.reload.acknowledged?end- test "dismissed insight reactivates when numbers change materially" do+ test "acknowledged insight reactivates when numbers change materially" dostub_generated([ generated_insight ])GenerateInsightsJob.perform_now(family_id: @family.id)insight = @family.insights.find_by(dedup_key: "idle_cash:test-account:2026-07")- insight.dismiss!+ insight.acknowledge!stub_generated([ generated_insight(balance: 9000.0) ])GenerateInsightsJob.perform_now(family_id: @family.id)@@ -169,14 +169,14 @@ class GenerateInsightsJobTest < ActiveJob::TestCaseassert insight.reload.active?end- test "does not touch dismissed insights when their condition clears" do+ test "does not touch acknowledged insights when their condition clears" doinsight = insights(:cash_flow_warning)- insight.dismiss!+ insight.acknowledge!stub_generated([], succeeded_types: [ "cash_flow_warning" ])GenerateInsightsJob.perform_now(family_id: @family.id)- assert insight.reload.dismissed?+ assert insight.reload.acknowledged?endtest "expired insight reactivates without a body rewrite when the condition returns unchanged" dodiff --git a/test/models/insight_test.rb b/test/models/insight_test.rbindex b7fc32d3d7..a40484c239 100644--- a/test/models/insight_test.rb+++ b/test/models/insight_test.rb@@ -14,28 +14,28 @@ class InsightTest < ActiveSupport::TestCaseassert @insight.read_at.present?end- test "mark_read! does not touch dismissed insights" do- @insight.dismiss!+ test "mark_read! does not touch acknowledged insights" do+ @insight.acknowledge!@insight.mark_read!- assert @insight.reload.dismissed?+ assert @insight.reload.acknowledged?assert_nil @insight.read_atend- test "dismiss! removes insight from visible scope" do+ test "acknowledge! removes insight from visible scope" doassert_includes Insight.visible, @insight- @insight.dismiss!+ @insight.acknowledge!assert_not_includes Insight.visible, @insightassert @insight.dismissed_at.present?end- test "undismiss! restores a dismissed insight as read, not new" do- @insight.dismiss!+ test "unacknowledge! restores an acknowledged insight as read, not new" do+ @insight.acknowledge!- @insight.undismiss!+ @insight.unacknowledge!assert @insight.reload.read?assert_nil @insight.dismissed_at@@ -43,6 +43,18 @@ class InsightTest < ActiveSupport::TestCaseassert_includes Insight.visible, @insightend+ # A stale/replayed undo (e.g. an old toast link clicked after the insight+ # has since expired or resurrected) must not force a non-acknowledged+ # insight back to :read — that would wrongly pull an :expired insight back+ # into view.+ test "unacknowledge! is a no-op on an insight that isn't acknowledged" do+ @insight.update!(status: :expired)++ @insight.unacknowledge!++ assert @insight.reload.expired?+ end+test "duplicate dedup_key within a family is rejected" doassert_raises ActiveRecord::RecordInvalid do@insight.family.insights.create!(