mirror of
https://github.com/we-promise/sure.git
synced 2026-09-07 23:54:25 +00:00
fix(goals): make the figure beside the ring agree with the ring (#3213)
* fix(goals): make the figure beside the ring agree with the ring Recording a spend left the goal page contradicting itself. The ring is drawn from `progress_percent`, which counts money still held plus money already spent on the goal; the figure beside it showed only the first half. A goal that had saved 5,000 and spent 2,000 of it rendered a 100% ring next to "3,000 of 5,000" — two answers on one card, with nothing to say which to believe. The model was never wrong: `progress_percent` and `remaining_amount` have both counted the two halves since the spend feature landed. Only the display took one of them. `progress_amount` names what progress actually counts, and both surfaces now read from it. The amount already used is reported as part of that total rather than beside it — "Including 2,000 already used" — so a reader has nothing to add up and no reason to read a completed goal as a shortfall. "Used" rather than "spent", matching the menu entry the user came through: it is the same gesture, and spending on the thing you saved for is the goal working, not failing. Shown only where there is something to show. The overwhelming majority of goals never record a spend, and a permanent "0 used" line would be noise on every card. A reserve refuses consumption outright, so this never appears on one. What is still sitting in each account keeps its place in the funding breakdown, which is where that question belongs — the view test asserts the headline specifically rather than the whole page, for exactly that reason. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016GTNba5qE5NwzaHzbp27ye * fix(goals): make the ring announce what it shows Review on #3213. The headline moved to the progress total; the ring's `aria-label` still read `current_balance_money`. A screen reader announced "$3,000 of $5,000 saved" while the line beside it said "$5,000, including $2,000 already used" — the same ring, two different numbers depending on whether you could see it. The wording moves with the figure. "Saved" stops being the whole truth once part of the total has been spent on the goal, so a goal that has recorded one gets the sentence that says so, and every other goal keeps the wording it had. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016GTNba5qE5NwzaHzbp27ye * style(goals): use the component's t() for the ring's labels Review on #3213. `I18n.t` works, but the component helper is what the rest of the codebase reaches for and it carries the view's locale context. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016GTNba5qE5NwzaHzbp27ye --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
8c10c1e410
commit
e7619cac89
@@ -1196,8 +1196,55 @@ class GoalTest < ActiveSupport::TestCase
|
||||
assert_equal 3_000, goal.reload.target_amount.to_d
|
||||
end
|
||||
|
||||
|
||||
# The ring is drawn from `progress_percent`, which counts money held plus
|
||||
# money already spent on the goal. The headline figure showed only the first
|
||||
# half, so a goal that had spent part of its savings sat at a 100% ring
|
||||
# beside "3,000 of 5,000" — the two disagreeing on the same card, with
|
||||
# nothing to say which one to believe.
|
||||
test "the headline figure agrees with the ring after a spend" do
|
||||
goal = spent_goal
|
||||
|
||||
assert_equal 100, goal.progress_percent
|
||||
assert_equal 5_000, goal.progress_amount_money.amount.to_d,
|
||||
"the figure beside the ring still reported the account balance"
|
||||
end
|
||||
|
||||
# The amount is part of the total above it, never a second figure beside it:
|
||||
# a reader should have nothing to add up.
|
||||
test "what was used is reported as part of the total, and only when there is some" do
|
||||
goal = spent_goal
|
||||
|
||||
assert goal.any_consumption?
|
||||
assert_equal 2_000, goal.consumed_amount_money.amount.to_d
|
||||
assert_equal goal.progress_amount_money.amount.to_d,
|
||||
goal.current_balance.to_d + goal.consumed_amount_money.amount.to_d
|
||||
end
|
||||
|
||||
test "a goal that has spent nothing says nothing about it" do
|
||||
account = Account.create!(family: @family, accountable: Depository.new,
|
||||
name: "Quiet pot", currency: @family.currency, balance: 1_000)
|
||||
goal = @family.goals.create!(name: "Quiet", target_amount: 1_000, currency: @family.currency) do |g|
|
||||
g.goal_accounts.build(account: account, allocated_amount: 1_000)
|
||||
end
|
||||
|
||||
assert_not goal.any_consumption?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# 5,000 saved, 2,000 of it since spent on the thing itself.
|
||||
def spent_goal
|
||||
account = Account.create!(family: @family, accountable: Depository.new,
|
||||
name: "Spent pot #{SecureRandom.hex(3)}",
|
||||
currency: @family.currency, balance: 5_000)
|
||||
goal = @family.goals.create!(name: "Trip", target_amount: 5_000, currency: @family.currency) do |g|
|
||||
g.goal_accounts.build(account: account, allocated_amount: 5_000)
|
||||
end
|
||||
goal.consume!(2_000)
|
||||
goal
|
||||
end
|
||||
|
||||
# Its own account, so the shared-pool haircut does not make the frozen
|
||||
# figure depend on what the fixtures happen to claim.
|
||||
def completable_goal
|
||||
|
||||
Reference in New Issue
Block a user