Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Frame the bills lists so their shells show in light mode (#4091)

Guillem Arias Fausteac9bf2f76360
diff --git a/app/components/DS/section.rb b/app/components/DS/section.rb
index 96e435d7e4..81cf5000c8 100644
--- a/app/components/DS/section.rb
+++ b/app/components/DS/section.rb
@@ -22,9 +22,14 @@ class DS::Section < DesignSystemComponent
# 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
+ # @param inset [Boolean] frame the section in a surface-inset shell, 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.
+ #
+ # The shell is surface-inset because a section sits on the page, not in a
+ # card. container-inset is the page's own colour in light mode, so the shell
+ # vanished there: headings floated, and the cards sat 4px inside every other
+ # card's edge. Dark mode showed it, so the page changed shape with the theme.
def initialize(title:, count:, collapsible: false, persist_key: nil, inset: true)
@title = title
@count = count
@@ -36,7 +41,7 @@ class DS::Section < DesignSystemComponent
end
def container_classes
- "rounded-xl bg-container-inset p-1" if inset
+ "rounded-xl bg-surface-inset p-1" if inset
end
def persist_data
diff --git a/app/views/bills/_paycheck_bridge.html.erb b/app/views/bills/_paycheck_bridge.html.erb
index dc402be98e..4ef49bd755 100755
--- a/app/views/bills/_paycheck_bridge.html.erb
+++ b/app/views/bills/_paycheck_bridge.html.erb
@@ -9,7 +9,7 @@
Deliberately quiet. Nothing is wrong here, and the window still has to be
visible. %>
-<div class="rounded-lg bg-container-inset px-4 py-3 space-y-1">
+<div class="rounded-lg bg-surface-inset px-4 py-3 space-y-1">
<div class="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
<p class="text-sm text-primary tabular-nums privacy-sensitive">
<span class="font-medium"><%= t("bills.paycheck.bridge_label") %></span>
diff --git a/app/views/bills/all.html.erb b/app/views/bills/all.html.erb
index aa3b3f61bf..f1c0853ac4 100644
--- a/app/views/bills/all.html.erb
+++ b/app/views/bills/all.html.erb
@@ -81,7 +81,7 @@
shell's sidebars can squeeze a desktop window to phone-list widths,
and a viewport breakpoint cannot see that. %>
<div class="@container">
- <div class="@3xl:hidden bg-container rounded-lg shadow-border-xs divide-y divide-subdued">
+ <div class="@3xl:hidden bg-container rounded-xl shadow-border-xs divide-y divide-subdued">
<% @all_series.each do |series| %>
<div class="flex items-center gap-3 p-3">
<%= link_to bill_path(series), data: { turbo_frame: "drawer", turbo_prefetch: false }, class: "flex items-center gap-3 min-w-0 flex-1 group" do %>
@@ -186,26 +186,21 @@
<%# Across every bill, not just the one you have open. Per-bill history lives
in the bill's own detail. %>
<% if @recent_price_changes&.any? %>
- <div class="rounded-xl bg-container-inset space-y-1 p-1">
- <div class="px-4 py-2 text-xs font-medium text-secondary uppercase">
- <p><%= t(".subscription_price_changes") %></p>
- </div>
- <div class="bg-container rounded-lg shadow-border-xs divide-y divide-subdued">
- <% @recent_price_changes.each do |change| %>
- <div class="flex items-center justify-between gap-3 px-4 py-2">
- <div>
- <p class="text-sm text-primary"><%= change.recurring_transaction.display_name %></p>
- <p class="text-xs text-secondary"><%= l(change.effective_on, format: :long) %></p>
- </div>
- <p class="text-sm privacy-sensitive <%= change.new_amount > change.previous_amount ? "text-warning" : "text-success" %>">
- <%= t(".subscription_price_change_line",
- from: format_money(change.previous_amount_money),
- to: format_money(change.new_amount_money),
- percent: change.previous_amount.positive? ? ((change.new_amount - change.previous_amount) / change.previous_amount * 100).round(1) : 0) %>
- </p>
+ <%= render DS::Section.new(title: t(".subscription_price_changes"), count: @recent_price_changes.size) do %>
+ <% @recent_price_changes.each do |change| %>
+ <div class="flex items-center justify-between gap-3 px-4 py-2">
+ <div>
+ <p class="text-sm text-primary"><%= change.recurring_transaction.display_name %></p>
+ <p class="text-xs text-secondary"><%= l(change.effective_on, format: :long) %></p>
</div>
- <% end %>
- </div>
- </div>
+ <p class="text-sm privacy-sensitive <%= change.new_amount > change.previous_amount ? "text-warning" : "text-success" %>">
+ <%= t(".subscription_price_change_line",
+ from: format_money(change.previous_amount_money),
+ to: format_money(change.new_amount_money),
+ percent: change.previous_amount.positive? ? ((change.new_amount - change.previous_amount) / change.previous_amount * 100).round(1) : 0) %>
+ </p>
+ </div>
+ <% end %>
+ <% end %>
<% end %>
</div>
diff --git a/app/views/bills/calendar.html.erb b/app/views/bills/calendar.html.erb
index 4a8a9680e5..d44066da90 100644
--- a/app/views/bills/calendar.html.erb
+++ b/app/views/bills/calendar.html.erb
@@ -74,7 +74,7 @@
<%# Mobile: an agenda list of the month's days that actually have bills,
not a shrunken grid. %>
- <div class="md:hidden space-y-1 rounded-xl bg-container-inset p-1">
+ <div class="md:hidden space-y-1 rounded-xl bg-surface-inset p-1">
<% month_days = (@[email protected]_of_month).select { |day| @by_day[day].present? } %>
<% if month_days.empty? %>
<div class="bg-container rounded-lg p-4">
diff --git a/app/views/bills/index.html.erb b/app/views/bills/index.html.erb
index 35f3374471..357313fbb0 100644
--- a/app/views/bills/index.html.erb
+++ b/app/views/bills/index.html.erb
@@ -171,7 +171,7 @@
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">
+ <div class="rounded-xl bg-surface-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 %>
<%= render "bills/occurrence_section", title: t(".later"), occurrences: @later, suggestions: @suggestions_by_occurrence %>
<%= render "bills/occurrence_section", title: t(".dormant"), occurrences: @dormant, suggestions: @suggestions_by_occurrence %>
diff --git a/test/components/DS/section_test.rb b/test/components/DS/section_test.rb
index 4349adeb33..5fbf054ac4 100644
--- a/test/components/DS/section_test.rb
+++ b/test/components/DS/section_test.rb
@@ -4,11 +4,11 @@ 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 "section.rounded-xl.bg-surface-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_selector "section.bg-surface-inset.p-1 > div.bg-container.rounded-lg.shadow-border-xs > p", text: "Netflix"
assert_no_selector "details, svg"
end
@@ -24,7 +24,7 @@ class DS::SectionTest < ViewComponent::TestCase
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_no_selector ".bg-surface-inset"
assert_selector "section h2", text: "Later"
assert_selector "div.bg-container.rounded-lg > p", text: "Rent"
end
@@ -44,7 +44,7 @@ class DS::SectionTest < ViewComponent::TestCase
"<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 "section.bg-surface-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"
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index 8137b870fd..c514738c5f 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -40,6 +40,34 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
end
end
+ # container-inset is the page's own colour in light mode, so a list framed
+ # with it straight on the page lost its frame: headings floated, and its card
+ # sat 4px inside every other card's edge. Inside a card it does show.
+ test "no bills view frames a list in the page's own colour" do
+ @family.accounts.where(accountable_type: "Depository").update_all(balance: 5_000)
+ create_bill(name: "Rent", amount: 1200)
+ sub = create_bill(name: "STREAMFLIX", amount: 24.99, bill_type: "subscription")
+ sub.recurring_price_changes.create!(effective_on: 2.months.ago.to_date, previous_amount: 19.99,
+ new_amount: 24.99, currency: "USD", source: "detected")
+ declare_income(name: "Frito Lay", amount: -1200, payday: Date.current + 5)
+ declare_bill(name: "Curbside Cuts", amount: 150, due: Date.current + 2)
+
+ [ bills_url, bills_url(view: "calendar"), bills_url(view: "paycheck"),
+ bills_url(view: "all", q: { bill_type: "subscription" }) ].each do |url|
+ get url
+
+ assert_response :success
+ on_page = Nokogiri::HTML(response.body).xpath(
+ "//main//*[contains(concat(' ', @class, ' '), ' bg-container-inset ')]" \
+ "[not(ancestor::*[contains(concat(' ', @class, ' '), ' bg-container ')])]"
+ )
+ assert_empty on_page.map { |node| node["class"] }, "#{url} frames something in container-inset on the page"
+ end
+
+ get bills_url
+ assert_select "main .bg-surface-inset h2", text: I18n.t("bills.index.this_month")
+ end
+
test "bills page shell is localized in German" do
@user.update!(locale: "de")
Provider::Registry.stubs(:preferred_llm_provider).returns(Object.new)
@@ -1800,7 +1828,7 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
get bills_url
assert_response :success
- shells = css_select(".rounded-xl.bg-container-inset.p-1")
+ shells = css_select(".rounded-xl.bg-surface-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|
@@ -1820,7 +1848,7 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
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']"
+ assert_select ".rounded-xl.bg-surface-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
diff --git a/test/controllers/recurring_transactions_controller_test.rb b/test/controllers/recurring_transactions_controller_test.rb
index c994844611..b8b62b0f1b 100644
--- a/test/controllers/recurring_transactions_controller_test.rb
+++ b/test/controllers/recurring_transactions_controller_test.rb
@@ -1069,7 +1069,7 @@ class RecurringTransactionsControllerTest < ActionDispatch::IntegrationTest
get recurring_transactions_url
assert_response :success
- assert_select ".bg-container-inset > details[data-persisted-disclosure-key-value='bills-suggested']" do
+ assert_select ".bg-surface-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")