The personal finance app for everyone (by everyone)
Ruby
Build the bills notices and review queues like the bill sections (#3957)
Guillem Arias Faustefe2c7b6db7f2
diff --git a/app/components/DS/disclosure.rb b/app/components/DS/disclosure.rbindex ea1c9ec08e..e31c71b3f5 100644--- a/app/components/DS/disclosure.rb+++ b/app/components/DS/disclosure.rb@@ -22,8 +22,8 @@ class DS::Disclosure < DesignSystemComponent# `:inline` — no surface, no padding, no shadow. The disclosure reads# as a plain text-link-style toggle (e.g. "Alternative auth" inside# a form, or a "Manage connections" lazy-load opener). Caller provides- # the summary text (and optional chevron) via the `summary_content`- # slot.+ # the summary text (and optional chevron, `disclosure_chevron`) via the+ # `summary_content` slot.## `:bare` — like `:default` on the `<details>` element (`group` only),# but content is yielded without the in-flow body wrapper. Use fordiff --git a/app/components/DS/section.html.erb b/app/components/DS/section.html.erbnew file mode 100644index 0000000000..9b867dcc53--- /dev/null+++ b/app/components/DS/section.html.erb@@ -0,0 +1,36 @@+<% heading = capture do %>+ <div class="flex items-center justify-between gap-3 px-4 py-2">+ <div class="flex items-center gap-1.5 text-xs font-medium uppercase text-secondary">+ <% if collapsible %>+ <%= helpers.disclosure_chevron %>+ <% end %>+ <h2><%= title %></h2>+ <span class="text-subdued" aria-hidden="true">·</span>+ <p><%= count %></p>+ </div>+ <%= aside %>+ </div>+<% end %>+<% card = capture do %>+ <div class="@container bg-container rounded-lg shadow-border-xs divide-y divide-subdued">+ <%= content %>+ </div>+<% end %>++<%= tag.section class: container_classes do %>+ <% if collapsible %>+ <%= render DS::Disclosure.new(+ variant: :inline,+ open: true,+ summary_class: "list-none cursor-pointer focus-ring rounded-lg select-none",+ body_class: nil,+ data: persist_data+ ) do |disclosure| %>+ <% disclosure.with_summary_content { heading } %>+ <%= card %>+ <% end %>+ <% else %>+ <%= heading %>+ <%= card %>+ <% end %>+<% end %>diff --git a/app/components/DS/section.rb b/app/components/DS/section.rbnew file mode 100644index 0000000000..96e435d7e4--- /dev/null+++ b/app/components/DS/section.rb@@ -0,0 +1,45 @@+class DS::Section < DesignSystemComponent+ # A titled list: a heading row (the title, "· N" and an optional aside on+ # the right) over a card that holds the rows. Extracted from the Bills+ # overview, whose notices, review queues and bill sections each built it by+ # hand (#3957).+ #+ # <%= render DS::Section.new(title: t(".needs_review"), count: rows.size) do |section| %>+ # <% section.with_aside { tag.p(total, class: "text-xs text-secondary") } %>+ # <% rows.each do |row| %>...<% end %>+ # <% end %>+ #+ # The card is the rows' query container. With both sidebars open a list is+ # phone-width at a desktop viewport, so rows size themselves against the+ # card, not the screen.+ renders_one :aside++ attr_reader :title, :count, :collapsible, :persist_key, :inset++ # @param title [String] an h2, so the sections join the page's outline+ # @param count [Integer] the "· N" after the title+ # @param collapsible [Boolean] make the heading row a summary with a chevron,+ # for a list that can run long. It starts open.+ # @param persist_key [String, nil] remember a collapsed section on this device+ # (persisted-disclosure); only for a collapsible section+ # @param inset [Boolean] frame the section in container-inset, which is the+ # default here, unlike on DS::Table. Pass false when a parent's shell+ # already frames it, such as one that stacks several sections.+ def initialize(title:, count:, collapsible: false, persist_key: nil, inset: true)+ @title = title+ @count = count+ @collapsible = collapsible+ @persist_key = persist_key+ @inset = inset++ raise ArgumentError, "persist_key: needs collapsible: true" if persist_key && !collapsible+ end++ def container_classes+ "rounded-xl bg-container-inset p-1" if inset+ end++ def persist_data+ { controller: "persisted-disclosure", persisted_disclosure_key_value: persist_key } if persist_key+ end+enddiff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 6394521db0..5e6ac0cdd3 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -55,6 +55,11 @@ module ApplicationHelperendend+ # The chevron for a DS::Disclosure summary_content slot; it turns as the disclosure opens.+ def disclosure_chevron+ icon "chevron-right", size: "sm", class: "motion-safe:transition-transform group-open:rotate-90"+ end+# Convert alpha (0-1) to 8-digit hex (00-FF)def hex_with_alpha(hex, alpha)alpha_hex = (alpha * 255).round.to_s(16).rjust(2, "0")diff --git a/app/views/bills/_notice.html.erb b/app/views/bills/_notice.html.erbindex 33e8743bb0..dc895bbc5f 100644--- a/app/views/bills/_notice.html.erb+++ b/app/views/bills/_notice.html.erb@@ -1,6 +1,6 @@<%# locals: (notice:, urgent: false) %>-<div class="flex items-center justify-between gap-3 <%= urgent ? "px-4 py-2.5" : "py-2" %>">+<div class="flex items-center justify-between gap-3 px-4 py-2.5"><p class="<%= urgent ? "text-sm text-primary font-medium" : "text-sm text-secondary" %>"><% case notice.kind %><% when :trial %>diff --git a/app/views/bills/_occurrence_section.html.erb b/app/views/bills/_occurrence_section.html.erbindex edc46f0f70..8ba8412540 100644--- a/app/views/bills/_occurrence_section.html.erb+++ b/app/views/bills/_occurrence_section.html.erb@@ -1,37 +1,20 @@-<%# locals: (title:, occurrences:, tone: :default, suggestions: {}, meta: nil, pay_periods: []) %>+<%# locals: (title:, occurrences:, suggestions: {}, meta: nil, pay_periods: [], inset: false) %><% return if occurrences.empty? %><% markers = bills_pay_period_markers(occurrences, pay_periods) %>-<div>- <div class="flex items-baseline justify-between gap-3 px-4 py-2">- <div class="flex items-center gap-1.5 text-xs font-medium uppercase <%= tone == :destructive ? "text-destructive" : "text-secondary" %>">- <p><%= title %></p>- <span class="text-subdued">·</span>- <p><%= occurrences.size %></p>- </div>- <% if meta %>- <p class="text-xs text-secondary privacy-sensitive shrink-0"><%= meta %></p>+<%# No shell by default: bills/index stacks the month sections in one. %>+<%= render DS::Section.new(title: title, count: occurrences.size, inset: inset) do |section| %>+ <% section.with_aside { tag.p(meta, class: "text-xs text-secondary privacy-sensitive shrink-0") } if meta %>+ <% occurrences.each do |occurrence| %>+ <%# The marker belongs to the first row of its period, so it lands+ between groups without the section having to pre-bucket the rows. %>+ <% if (marker = markers[occurrence.id]) %>+ <%= render "bills/pay_period_marker",+ period: marker[:period],+ currency: Current.family.currency,+ due_total: marker[:due_total] %><% end %>- </div>-- <%# The divider is half its old weight: the rows are separated by a hairline- and by the hover state, not by a rule competing with the content. %>- <%# A container query, not a media query. The app shell has two sidebars, so- main is ~420px wide at a 1280px viewport -- "desktop" by any breakpoint- and phone-width in practice. The row has to size itself against the space- it actually has. %>- <div class="@container bg-container rounded-lg shadow-border-xs divide-y divide-subdued">- <% occurrences.each do |occurrence| %>- <%# The marker belongs to the first row of its period, so it lands- between groups without the section having to pre-bucket the rows. %>- <% if (marker = markers[occurrence.id]) %>- <%= render "bills/pay_period_marker",- period: marker[:period],- currency: Current.family.currency,- due_total: marker[:due_total] %>- <% end %>- <%= render "bills/occurrence", occurrence: occurrence, suggestion: suggestions[occurrence.id] %>- <% end %>- </div>-</div>+ <%= render "bills/occurrence", occurrence: occurrence, suggestion: suggestions[occurrence.id] %>+ <% end %>+<% end %>diff --git a/app/views/bills/index.html.erb b/app/views/bills/index.html.erbindex 8dc17220d5..35f3374471 100644--- a/app/views/bills/index.html.erb+++ b/app/views/bills/index.html.erb@@ -38,83 +38,77 @@worklist off screen. %><% if @notices.any? %><% urgent, routine = @notices.partition(&:urgent?) %>- <div class="bg-container rounded-xl shadow-border-xs divide-y divide-subdued">+ <%= render DS::Section.new(title: t(".notices_heading"), count: @notices.size) do %><% urgent.each do |notice| %><%= render "bills/notice", notice: notice, urgent: true %><% end %>- <% if routine.any? %>- <div class="px-4 py-2">- <% if urgent.any? %>- <%= render DS::Disclosure.new(title: t(".notices_routine", count: routine.size), align: "left") do %>- <div class="divide-y divide-subdued">- <% routine.each do |notice| %>- <%= render "bills/notice", notice: notice, urgent: false %>- <% end %>- </div>- <% end %>- <% else %>- <div class="divide-y divide-subdued">- <% routine.each do |notice| %>- <%= render "bills/notice", notice: notice, urgent: false %>- <% end %>+ <% if routine.any? && urgent.any? %>+ <%# A row of the card like the notices around it. Its old grey+ summary read as a box inside the card. %>+ <%= render DS::Disclosure.new(variant: :inline, body_class: nil) do |disclosure| %>+ <% disclosure.with_summary_content do %>+ <div class="flex items-center gap-2 px-4 py-2.5 text-sm text-secondary">+ <%= disclosure_chevron %>+ <span><%= t(".notices_routine", count: routine.size) %></span></div><% end %>- </div>+ <div class="divide-y divide-subdued border-t border-subdued">+ <% routine.each do |notice| %>+ <%= render "bills/notice", notice: notice, urgent: false %>+ <% end %>+ </div>+ <% end %>+ <% else %>+ <% routine.each do |notice| %>+ <%= render "bills/notice", notice: notice, urgent: false %>+ <% end %><% end %>- </div>+ <% end %><% end %><% if @suggested_allocations.any? %>- <div class="rounded-xl bg-container-inset space-y-1 p-1">- <div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase">- <p><%= t(".needs_review") %></p>- <span class="text-subdued">·</span>- <p><%= @suggested_allocations.size %></p>- </div>-- <div class="bg-container rounded-lg shadow-border-xs divide-y divide-subdued">- <% @suggested_allocations.each do |suggestion| %>- <% series = suggestion.recurring_occurrence.recurring_transaction %>- <%= render DS::ReviewRow.new do |row| %>- <% row.with_actions do %>- <%= render DS::Link.new(- text: t("recurring_occurrences.show.link_payment"),- variant: "primary",- href: confirm_recurring_allocation_path(suggestion),- method: :post- ) %>- <%= render DS::Link.new(- text: t("recurring_occurrences.show.not_this_one"),- variant: "ghost",- href: reject_recurring_allocation_path(suggestion),- method: :post- ) %>- <% end %>- <p class="text-sm text-primary @md:truncate">- <%= t(".suggestion_line",- entry: suggestion.entry&.name.presence || t(".suggestion_unknown_entry"),- bill: series.display_name) %>- </p>- <%# The matcher stores WHY it proposed each of these. This line- used to show a bare percentage of that reasoning instead of- the reasoning, which told nobody anything they could judge. %>- <% reasons = bills_match_reasons(- suggestion.match_signals,- currency: suggestion.recurring_occurrence.currency,- expected: suggestion.recurring_occurrence.resolved_expected_amount,- actual: suggestion.entry&.amount&.abs,- due_on: suggestion.recurring_occurrence.effective_due_on,- paid_on: suggestion.paid_on- ) %>- <p class="text-xs text-secondary privacy-sensitive">- <%= format_money(suggestion.allocated_amount_money) %>- · <%= l(suggestion.paid_on, format: :short_with_year) %><%= " · #{reasons.join(" · ")}" if reasons.any? %>- </p>+ <%= render DS::Section.new(title: t(".needs_review"), count: @suggested_allocations.size) do %>+ <% @suggested_allocations.each do |suggestion| %>+ <% series = suggestion.recurring_occurrence.recurring_transaction %>+ <%= render DS::ReviewRow.new do |row| %>+ <% row.with_actions do %>+ <%= render DS::Link.new(+ text: t("recurring_occurrences.show.link_payment"),+ variant: "primary",+ href: confirm_recurring_allocation_path(suggestion),+ method: :post+ ) %>+ <%= render DS::Link.new(+ text: t("recurring_occurrences.show.not_this_one"),+ variant: "ghost",+ href: reject_recurring_allocation_path(suggestion),+ method: :post+ ) %><% end %>+ <p class="text-sm text-primary @md:truncate">+ <%= t(".suggestion_line",+ entry: suggestion.entry&.name.presence || t(".suggestion_unknown_entry"),+ bill: series.display_name) %>+ </p>+ <%# The matcher stores WHY it proposed each of these. This line+ used to show a bare percentage of that reasoning instead of+ the reasoning, which told nobody anything they could judge. %>+ <% reasons = bills_match_reasons(+ suggestion.match_signals,+ currency: suggestion.recurring_occurrence.currency,+ expected: suggestion.recurring_occurrence.resolved_expected_amount,+ actual: suggestion.entry&.amount&.abs,+ due_on: suggestion.recurring_occurrence.effective_due_on,+ paid_on: suggestion.paid_on+ ) %>+ <p class="text-xs text-secondary privacy-sensitive">+ <%= format_money(suggestion.allocated_amount_money) %>+ · <%= l(suggestion.paid_on, format: :short_with_year) %><%= " · #{reasons.join(" · ")}" if reasons.any? %>+ </p><% end %>- </div>- </div>+ <% end %>+ <% end %><% end %><%# Series-level review: detection found these, nobody confirmed them yet.@@ -168,17 +162,14 @@<%# Anything late is pulled out of the chronological run. Inside it, anoverdue bill was distinguishable only by a word in the date column, sothe most urgent rows were the easiest ones to scroll past. %>- <% if @overdue.any? %>- <div class="rounded-xl bg-container-inset space-y-1 p-1">- <%# The section says how much is at stake, not just how many rows: a- count alone is alarming without being informative. %>- <%= render "bills/occurrence_section",- title: t(".needs_attention"),- occurrences: @overdue,- suggestions: @suggestions_by_occurrence,- meta: (@past_due_total && @past_due_total.amount.positive? ? t(".attention_overdue_total", amount: format_money(@past_due_total)) : nil) %>- </div>- <% end %>+ <%# The section says how much is at stake, not just how many rows: a+ count alone is alarming without being informative. %>+ <%= render "bills/occurrence_section",+ title: t(".needs_attention"),+ occurrences: @overdue,+ inset: true,+ suggestions: @suggestions_by_occurrence,+ meta: (@past_due_total && @past_due_total.amount.positive? ? t(".attention_overdue_total", amount: format_money(@past_due_total)) : nil) %><div class="rounded-xl bg-container-inset space-y-1 p-1"><%= render "bills/occurrence_section", title: t(".this_month"), occurrences: @month_rows, suggestions: @suggestions_by_occurrence, pay_periods: @month_pay_periods %>diff --git a/app/views/recurring_transactions/_suggested_series.html.erb b/app/views/recurring_transactions/_suggested_series.html.erbindex c20a8f2f49..27e6c7eb43 100644--- a/app/views/recurring_transactions/_suggested_series.html.erb+++ b/app/views/recurring_transactions/_suggested_series.html.erb@@ -5,55 +5,35 @@Collapsible because this sits above the bills the user actually came tosee. Someone who is not ready to triage nine guesses should be able to foldthem away and still find their rent, and have that stick. %>-<%= render DS::Disclosure.new(- variant: :card_inset,- open: true,- data: {- controller: "persisted-disclosure",- persisted_disclosure_key_value: "bills-suggested"- }-) do |disclosure| %>- <% disclosure.with_summary_content do %>- <div class="flex items-center gap-2 select-none">- <%= icon "chevron-right", size: "sm",- class: "transition-transform group-open:rotate-90" %>-- <p class="text-xs font-medium text-secondary uppercase">- <%= t("recurring_transactions.suggested.title") %>- </p>-- <%= render DS::Pill.new(label: suggested.size.to_s, tone: :neutral, marker: false) %>-- <p class="ml-auto text-xs text-subdued group-open:hidden">- <%= t("recurring_transactions.suggested.collapsed_hint") %>- </p>- </div>- <% end %>-- <div class="bg-container rounded-lg divide-y divide-subdued">- <% suggested.each do |suggestion| %>- <%= render DS::ReviewRow.new do |row| %>- <% row.with_actions do %>- <%= render DS::Link.new(- text: t("recurring_transactions.suggested.confirm"),- variant: "primary",- href: confirm_recurring_transaction_path(suggestion),- method: :post- ) %>- <%= render DS::Link.new(- text: t("recurring_transactions.suggested.dismiss"),- variant: "ghost",- href: dismiss_recurring_transaction_path(suggestion),- method: :post- ) %>- <% end %>- <p class="text-sm font-medium text-primary @md:truncate"><%= suggestion.display_name %></p>- <p class="text-xs text-secondary">- <span class="privacy-sensitive"><%= format_money(suggestion.amount_money.abs) %></span>- · <%= frequency_label(suggestion) %>- · <%= t("recurring_transactions.suggested.seen_count", count: suggestion.occurrence_count) %>- </p>+<%= render DS::Section.new(+ title: t("recurring_transactions.suggested.title"),+ count: suggested.size,+ collapsible: true,+ persist_key: "bills-suggested"+) do |section| %>+ <% section.with_aside { tag.p(t("recurring_transactions.suggested.collapsed_hint"), class: "text-xs text-subdued group-open:hidden") } %>+ <% suggested.each do |suggestion| %>+ <%= render DS::ReviewRow.new do |row| %>+ <% row.with_actions do %>+ <%= render DS::Link.new(+ text: t("recurring_transactions.suggested.confirm"),+ variant: "primary",+ href: confirm_recurring_transaction_path(suggestion),+ method: :post+ ) %>+ <%= render DS::Link.new(+ text: t("recurring_transactions.suggested.dismiss"),+ variant: "ghost",+ href: dismiss_recurring_transaction_path(suggestion),+ method: :post+ ) %><% end %>+ <p class="text-sm font-medium text-primary @md:truncate"><%= suggestion.display_name %></p>+ <p class="text-xs text-secondary">+ <span class="privacy-sensitive"><%= format_money(suggestion.amount_money.abs) %></span>+ · <%= frequency_label(suggestion) %>+ · <%= t("recurring_transactions.suggested.seen_count", count: suggestion.occurrence_count) %>+ </p><% end %>- </div>+ <% end %><% end %>diff --git a/config/locales/views/bills/ca.yml b/config/locales/views/bills/ca.ymlindex 4706734520..5bf196d34c 100644--- a/config/locales/views/bills/ca.yml+++ b/config/locales/views/bills/ca.yml@@ -259,6 +259,7 @@ ca:one: Hem trobat %{count} pagament recurrent a les teves transaccions. Revisa'l perquè els totals d'aquí coincideixin amb el que pagues realment.other: Hem trobat %{count} pagaments recurrents a les teves transaccions. Revisa'ls perquè els totals d'aquí coincideixin amb el que pagues realment.detected_review_action: Revisa'ls+ notices_heading: Canvisneeds_review: Cal revisarnotice_trial: La prova de %{name} acaba el %{date}notice_renewal: '%{name} es renova el %{date}'diff --git a/config/locales/views/bills/de.yml b/config/locales/views/bills/de.ymlindex 8efeb9fabd..f0ec0d4685 100644--- a/config/locales/views/bills/de.yml+++ b/config/locales/views/bills/de.yml@@ -23,3 +23,4 @@ de:add_bill: Rechnung hinzufügenadd_income: Einkommen hinzufügenreview_with_ai: Mit KI prüfen+ notices_heading: Änderungendiff --git a/config/locales/views/bills/en.yml b/config/locales/views/bills/en.ymlindex e6a684d511..c791177f9a 100644--- a/config/locales/views/bills/en.yml+++ b/config/locales/views/bills/en.yml@@ -273,6 +273,7 @@ en:one: We found 1 recurring payment in your transactions. Check it over so the totals here match what you actually pay.other: We found %{count} recurring payments in your transactions. Check them over so the totals here match what you actually pay.detected_review_action: Review them+ notices_heading: Changesneeds_review: Needs reviewnotice_trial: "%{name}'s trial ends %{date}"notice_renewal: "%{name} renews %{date}"diff --git a/config/locales/views/bills/fr.yml b/config/locales/views/bills/fr.ymlindex 641ad4107a..16eb8d2bf6 100644--- a/config/locales/views/bills/fr.yml+++ b/config/locales/views/bills/fr.yml@@ -146,6 +146,7 @@ fr:one: 1 requiert votre attentionother: "%{count} requièrent votre attention"needs_attention: Requiert votre attention+ notices_heading: Changementsneeds_review: À vérifiernotice_price: "%{name} a changé de prix : %{from} → %{to} (%{percent})"notice_renewal: "%{name} se renouvelle le %{date}"diff --git a/config/locales/views/bills/pl.yml b/config/locales/views/bills/pl.ymlindex 2c2f5dbfef..6a3d5fe628 100644--- a/config/locales/views/bills/pl.yml+++ b/config/locales/views/bills/pl.yml@@ -170,6 +170,7 @@ pl:one: 1 wymaga uwagiother: "%{count} wymaga uwagi"needs_attention: Wymaga uwagi+ notices_heading: Zmianyneeds_review: Wymaga sprawdzenianotice_price: "%{name}: zmiana ceny %{from} → %{to} (%{percent})"notice_renewal: "%{name} odnawia się %{date}"diff --git a/config/locales/views/bills/ru.yml b/config/locales/views/bills/ru.ymlindex c66f83388d..d6996f71c0 100644--- a/config/locales/views/bills/ru.yml+++ b/config/locales/views/bills/ru.yml@@ -289,6 +289,7 @@ ru:many: Мы нашли %{count} регулярных платежей в ваших операциях. Проверьте их, чтобы итоги здесь соответствовали тому, что вы действительно платите.other: Мы нашли %{count} регулярного платежа в ваших операциях. Проверьте их, чтобы итоги здесь соответствовали тому, что вы действительно платите.detected_review_action: Проверить+ notices_heading: Измененияneeds_review: Требует проверкиnotice_trial: Пробный период «%{name}» заканчивается %{date}notice_renewal: «%{name}» продлевается %{date}diff --git a/config/locales/views/bills/tr.yml b/config/locales/views/bills/tr.ymlindex 4a844933ec..73be4aaabf 100644--- a/config/locales/views/bills/tr.yml+++ b/config/locales/views/bills/tr.yml@@ -259,6 +259,7 @@ tr:one: İşlemlerinizde %{count} yinelenen ödeme bulduk. Buradaki toplamların gerçekte ödediğinizle eşleşmesi için gözden geçirin.other: İşlemlerinizde %{count} yinelenen ödeme bulduk. Buradaki toplamların gerçekte ödediğinizle eşleşmesi için gözden geçirin.detected_review_action: Gözden geçir+ notices_heading: Değişikliklerneeds_review: İnceleme gerekiyornotice_trial: '%{name} deneme süresi %{date} tarihinde bitiyor'notice_renewal: '%{name} %{date} tarihinde yenileniyor'diff --git a/config/locales/views/bills/uk.yml b/config/locales/views/bills/uk.ymlindex 1406ed1704..2b7d1da858 100644--- a/config/locales/views/bills/uk.yml+++ b/config/locales/views/bills/uk.yml@@ -289,6 +289,7 @@ uk:many: Ми знайшли у ваших транзакціях %{count} регулярних платежів. Перевірте їх, щоб підсумки тут відповідали тому, що ви фактично платите.other: Ми знайшли у ваших транзакціях %{count} регулярного платежу. Перевірте їх, щоб підсумки тут відповідали тому, що ви фактично платите.detected_review_action: Переглянути+ notices_heading: Зміниneeds_review: Потребує перевіркиnotice_trial: Пробний період %{name} закінчується %{date}notice_renewal: '%{name} поновлюється %{date}'diff --git a/test/components/DS/section_test.rb b/test/components/DS/section_test.rbnew file mode 100644index 0000000000..4349adeb33--- /dev/null+++ b/test/components/DS/section_test.rb@@ -0,0 +1,58 @@+require "test_helper"++class DS::SectionTest < ViewComponent::TestCase+ test "heads a card of rows with the title and count, in an inset shell" do+ render_inline(DS::Section.new(title: "Needs review", count: 2)) { "<p>Netflix</p>".html_safe }++ assert_selector "section.rounded-xl.bg-container-inset.p-1 .uppercase.text-secondary", text: /Needs review\s*·\s*2/+ assert_selector "h2", text: "Needs review"+ assert_selector "[aria-hidden='true']", text: "·"+ # Straight in the shell, with nothing padding it narrower than other cards.+ assert_selector "section.bg-container-inset.p-1 > div.bg-container.rounded-lg.shadow-border-xs > p", text: "Netflix"+ assert_no_selector "details, svg"+ end++ test "ends the heading row with the aside" do+ render_inline(DS::Section.new(title: "Needs attention", count: 1)) do |section|+ section.with_aside { "<p>$120.00 overdue</p>".html_safe }+ "<p>Rent</p>".html_safe+ end++ assert_selector :xpath, "//div[h2]/following-sibling::*[1]", text: "$120.00 overdue"+ end++ test "leaves the shell to a parent that stacks several sections" do+ render_inline(DS::Section.new(title: "Later", count: 1, inset: false)) { "<p>Rent</p>".html_safe }++ assert_no_selector ".bg-container-inset"+ assert_selector "section h2", text: "Later"+ assert_selector "div.bg-container.rounded-lg > p", text: "Rent"+ end++ # With both sidebars open a list is phone-width at a desktop viewport, so+ # rows size themselves against the card, not the screen.+ test "makes the card the query container for its rows" do+ render_inline(DS::Section.new(title: "This month", count: 1)) { "<p>Rent</p>".html_safe }++ assert_selector "div.\\@container.bg-container > p", text: "Rent"+ end++ # A list that can run long folds away under its heading, and stays folded.+ test "a collapsible section folds its card under the heading and remembers it" do+ render_inline(DS::Section.new(title: "Possible new bills", count: 4, collapsible: true, persist_key: "bills-suggested")) do |section|+ section.with_aside { "<p>Tap to review</p>".html_safe }+ "<p>Hulu</p>".html_safe+ end++ assert_selector "section.bg-container-inset.p-1 > details[open][data-controller='persisted-disclosure'][data-persisted-disclosure-key-value='bills-suggested']"+ assert_selector "summary svg"+ assert_selector "summary h2", text: "Possible new bills"+ assert_selector "summary p", text: "Tap to review"+ assert_selector "details .bg-container p", text: "Hulu"+ assert_no_selector "summary .bg-container"+ end++ test "refuses a persist key on a section that can't collapse" do+ assert_raises(ArgumentError) { DS::Section.new(title: "Needs review", count: 1, persist_key: "bills-review") }+ end+enddiff --git a/test/components/previews/section_component_preview.rb b/test/components/previews/section_component_preview.rbnew file mode 100644index 0000000000..bac196fe69--- /dev/null+++ b/test/components/previews/section_component_preview.rb@@ -0,0 +1,26 @@+class SectionComponentPreview < ViewComponent::Preview+ BILLS = [ "Rent", "Streaming", "Car insurance" ].freeze++ # @display container_classes max-w-[640px]+ def default+ render DS::Section.new(title: "This month", count: BILLS.size) do |section|+ section.with_aside { content_tag(:p, "$1,927.29 due", class: "text-xs text-secondary") }+ rows+ end+ end++ # A list that can run long folds away under its heading. Pass persist_key to+ # keep it folded across reloads.+ # @display container_classes max-w-[640px]+ def collapsible+ render DS::Section.new(title: "Possible new bills", count: BILLS.size, collapsible: true) do |section|+ section.with_aside { content_tag(:p, "Tap to review", class: "text-xs text-subdued group-open:hidden") }+ rows+ end+ end++ private+ def rows+ safe_join(BILLS.map { |name| content_tag(:p, name, class: "px-4 py-3 text-sm text-primary") })+ end+enddiff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rbindex 020ab8568d..8137b870fd 100644--- a/test/controllers/bills_controller_test.rb+++ b/test/controllers/bills_controller_test.rb@@ -1778,6 +1778,63 @@ class BillsControllerTest < ActionDispatch::IntegrationTest3.times { |i| assert_match "Utility #{i}", response.body }end+ # The cards above the bill list each looked different. Needs review had the+ # bill sections' inset shell and heading, Possible new bills was an inset+ # panel 12px narrower with a pill for its count, and the notices had no+ # heading, with a grey box for their quieter half.+ test "the notices, both review queues and the bill sections share one recipe" do+ trial = create_bill(name: "Streamflix", amount: 20)+ trial.update!(bill_type: "subscription", trial_ends_on: Date.current + 1)+ 2.times do |i|+ quiet = create_bill(name: "Utility #{i}", amount: 60 + i)+ quiet.recurring_price_changes.create!(effective_on: (20 + i).days.ago.to_date,+ previous_amount: 60 + i, new_amount: 61 + i, currency: "USD", source: "detected")+ end+ water = declare_bill(name: "CITY WATER", amount: 80, due: Date.current - 3)+ charge = create_transaction_entry(name: "CITY WATER", amount: 85.50, date: Date.current - 3)+ RecurringTransaction::Allocator.new(water.recurring_occurrences.order(:due_on).first).allocate_matched!(+ entry: charge, state: "suggested", confidence: 0.7, signals: { name: 0.35 }+ )+ create_suggested(name: "Hulu", account: accounts(:depository))++ get bills_url+ assert_response :success++ shells = css_select(".rounded-xl.bg-container-inset.p-1")+ headings = shells.flat_map { |shell| css_select(shell, "div.uppercase") }+ [ "#{I18n.t("bills.index.notices_heading")} · 3", "#{I18n.t("bills.index.needs_review")} · 1",+ "#{I18n.t("recurring_transactions.suggested.title")} · 1", "#{I18n.t("bills.index.this_month")} · " ].each do |heading|+ assert headings.any? { |node| node.text.squish.start_with?(heading) },+ "no inset shell heads with #{heading.inspect}: #{headings.map { |node| node.text.squish }.inspect}"+ end+ # One heading row, not copies that drift apart.+ rows = headings.map { |node| node.parent["class"] }.uniq+ assert_equal 1, rows.size, "the shells' heading rows differ: #{rows.inspect}"+ # Each card sits straight in its shell, so they all have one width.+ shells.each do |shell|+ cards = css_select(shell, ".bg-container.rounded-lg.shadow-border-xs")+ assert cards.any?, "a shell without its card"+ cards.each do |card|+ assert card.parent == shell || card.parent["class"].blank?, "a card is inset by #{card.parent["class"].inspect}"+ end+ end++ # Possible new bills still collapses and remembers it, inside the shell.+ assert_select ".rounded-xl.bg-container-inset.p-1 > details[data-controller='persisted-disclosure'][data-persisted-disclosure-key-value='bills-suggested']"+ # Needs review can't run long, so it doesn't collapse.+ assert_select "details", text: /#{I18n.t("bills.index.needs_review")}/, count: 0+ # The quieter notices fold behind a row of the card, padded like the notices+ # and with no surface of its own: it used to read as a grey box.+ routine = ".bg-container.rounded-lg > details > summary"+ assert_select "#{routine} .px-4.py-2\\.5", text: /#{I18n.t("bills.index.notices_routine", count: 2)}/+ assert_select "#{routine}[class^='bg-'], #{routine}[class*=' bg-']", count: 0+ # One chevron for both folds, not copies that drift apart.+ chevron = "svg[class*='group-open:rotate-90']"+ chevrons = css_select("[data-persisted-disclosure-key-value='bills-suggested'] > summary #{chevron}, #{routine} #{chevron}")+ assert_equal 2, chevrons.size+ assert_equal 1, chevrons.map(&:to_html).uniq.size, "the folds' chevrons differ: #{chevrons.map { |svg| svg["class"] }.inspect}"+ end+test "a price notice says how big the change was" dobill = create_bill(name: "Gym", amount: 90)bill.recurring_price_changes.create!(effective_on: 5.days.ago.to_date,diff --git a/test/controllers/recurring_transactions_controller_test.rb b/test/controllers/recurring_transactions_controller_test.rbindex 0a0f4374dc..c994844611 100644--- a/test/controllers/recurring_transactions_controller_test.rb+++ b/test/controllers/recurring_transactions_controller_test.rb@@ -1061,6 +1061,21 @@ class RecurringTransactionsControllerTest < ActionDispatch::IntegrationTestassert suggestion.reload.suggested?end+ # The suggestion strip is shared with the Bills overview, whose section+ # recipe it now follows.+ test "settings list the suggestions under the overview's heading, collapsible" do+ create_series(name: "Maybe A Bill", status: "suggested")++ get recurring_transactions_url+ assert_response :success++ assert_select ".bg-container-inset > details[data-persisted-disclosure-key-value='bills-suggested']" do+ assert_select "summary div.uppercase", text: /#{I18n.t("recurring_transactions.suggested.title")}\s*·\s*1/+ assert_select ".bg-container.rounded-lg", text: /Maybe A Bill/+ assert_select "a", text: I18n.t("recurring_transactions.suggested.confirm")+ end+ end+test "the pre-bills settings actions stay reachable without the preview flag" do@user.update!(preferences: (@user.preferences || {}).merge("preview_features_enabled" => false))diff --git a/test/i18n_test.rb b/test/i18n_test.rbindex 2592a88e8f..fbcef29417 100644--- a/test/i18n_test.rb+++ b/test/i18n_test.rb@@ -121,6 +121,17 @@ class I18nTest < ActiveSupport::TestCaseassert_empty padded, "short_with_year pads the day for: #{padded.join(", ")}"end+ # The bills overview's notices card heads with this. Fallbacks would show the+ # English "Changes", so check each bills locale file without them.+ def test_bills_notices_heading_exists_for_each_bills_locale+ locales = Dir[File.expand_path("../config/locales/views/bills/*.yml", __dir__)].map { |file| File.basename(file, ".yml") }+ missing = locales.sort.reject do |locale|+ I18n.t("bills.index.notices_heading", locale: locale, fallback: false, default: nil)+ end++ assert_empty missing, "bills.index.notices_heading is missing for: #{missing.join(", ")}"+ end+def test_trade_republic_activity_labels_exist_for_each_localerequired_labels = %w[contribution withdrawal interest dividend card_payment cash_withdrawaldiff --git a/test/system/bills_mobile_test.rb b/test/system/bills_mobile_test.rbindex 677e17b4c8..1f17ef66d7 100644--- a/test/system/bills_mobile_test.rb+++ b/test/system/bills_mobile_test.rb@@ -153,7 +153,7 @@ class BillsMobileTest < ApplicationSystemTestCase(() => {const visibleChild = (el) => [...el.children].find((c) => c.getClientRects().length > 0);return [...document.querySelectorAll(".\\\\@container a[href*='display=drawer']")].map((link) => {- const header = link.closest(".\\\\@container").previousElementSibling.querySelector("p");+ const header = link.closest(".\\\\@container").previousElementSibling.querySelector("h2");return Math.round(visibleChild(link).getBoundingClientRect().left - header.getBoundingClientRect().left);});})()