mirror of
https://github.com/we-promise/sure.git
synced 2026-05-12 15:15:01 +00:00
Budget page refactor: split into(All - Over Budget - On Track) (#1195)
* Optimize UI in budget * update locales * Optimize UI * optimize suggested_daily_spending * try over_budget and on_track * update locale * optimize * add budgets_helper.rb * fix * hide no buget and no expense sub-catogory * Optimize * Optimize button on phone * Fix Pipelock CI noise * using section to render both overbudget and onTrack * hide last ruler * fix * update test --------- Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -169,4 +169,90 @@ class BudgetCategoryTest < ActiveSupport::TestCase
|
||||
assert_equal 20, @subcategory_with_limit_bc.reload.budgeted_spending
|
||||
assert_equal 50, @subcategory_inheriting_bc.reload.budgeted_spending
|
||||
end
|
||||
|
||||
test "budgeted? returns true only when display_budgeted_spending > 0" do
|
||||
@subcategory_with_limit_bc.stubs(:display_budgeted_spending).returns(100)
|
||||
assert @subcategory_with_limit_bc.budgeted?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:display_budgeted_spending).returns(0)
|
||||
refute @subcategory_with_limit_bc.budgeted?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:display_budgeted_spending).returns(nil)
|
||||
refute @subcategory_with_limit_bc.budgeted?
|
||||
end
|
||||
|
||||
test "unbudgeted_with_spending? is true only when not budgeted and has spending" do
|
||||
@subcategory_with_limit_bc.stubs(:budgeted?).returns(false)
|
||||
@subcategory_with_limit_bc.stubs(:actual_spending).returns(10)
|
||||
assert @subcategory_with_limit_bc.unbudgeted_with_spending?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:budgeted?).returns(true)
|
||||
assert_not @subcategory_with_limit_bc.unbudgeted_with_spending?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:budgeted?).returns(false)
|
||||
@subcategory_with_limit_bc.stubs(:actual_spending).returns(0)
|
||||
assert_not @subcategory_with_limit_bc.unbudgeted_with_spending?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:actual_spending).returns(nil)
|
||||
assert_not @subcategory_with_limit_bc.unbudgeted_with_spending?
|
||||
end
|
||||
|
||||
test "over_budget_with_budget? requires both budgeted and over_budget" do
|
||||
@subcategory_with_limit_bc.stubs(:budgeted?).returns(true)
|
||||
@subcategory_with_limit_bc.stubs(:over_budget?).returns(true)
|
||||
assert @subcategory_with_limit_bc.over_budget_with_budget?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:over_budget?).returns(false)
|
||||
assert_not @subcategory_with_limit_bc.over_budget_with_budget?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:budgeted?).returns(false)
|
||||
@subcategory_with_limit_bc.stubs(:over_budget?).returns(true)
|
||||
assert_not @subcategory_with_limit_bc.over_budget_with_budget?
|
||||
end
|
||||
|
||||
test "on_track? is true only when budgeted and not over_budget" do
|
||||
@subcategory_with_limit_bc.stubs(:budgeted?).returns(true)
|
||||
@subcategory_with_limit_bc.stubs(:over_budget?).returns(false)
|
||||
assert @subcategory_with_limit_bc.on_track?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:over_budget?).returns(true)
|
||||
assert_not @subcategory_with_limit_bc.on_track?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:budgeted?).returns(false)
|
||||
@subcategory_with_limit_bc.stubs(:over_budget?).returns(false)
|
||||
assert_not @subcategory_with_limit_bc.on_track?
|
||||
end
|
||||
|
||||
test "any_over_budget? is true if either condition is true" do
|
||||
@subcategory_with_limit_bc.stubs(:unbudgeted_with_spending?).returns(true)
|
||||
@subcategory_with_limit_bc.stubs(:over_budget_with_budget?).returns(false)
|
||||
assert @subcategory_with_limit_bc.any_over_budget?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:unbudgeted_with_spending?).returns(false)
|
||||
@subcategory_with_limit_bc.stubs(:over_budget_with_budget?).returns(true)
|
||||
assert @subcategory_with_limit_bc.any_over_budget?
|
||||
|
||||
@subcategory_with_limit_bc.stubs(:unbudgeted_with_spending?).returns(false)
|
||||
@subcategory_with_limit_bc.stubs(:over_budget_with_budget?).returns(false)
|
||||
assert_not @subcategory_with_limit_bc.any_over_budget?
|
||||
end
|
||||
|
||||
test "visible_on_track? behavior for different category types" do
|
||||
# 1. not on_track => always false
|
||||
@subcategory_with_limit_bc.stubs(:on_track?).returns(false)
|
||||
assert_not @subcategory_with_limit_bc.visible_on_track?
|
||||
|
||||
# 2. normal category (not subcategory) => true if on_track
|
||||
@parent_budget_category.stubs(:on_track?).returns(true)
|
||||
assert @parent_budget_category.visible_on_track?
|
||||
|
||||
# 3. subcategory inheriting, no spending => hidden
|
||||
@subcategory_inheriting_bc.stubs(:on_track?).returns(true)
|
||||
@subcategory_inheriting_bc.stubs(:actual_spending).returns(0)
|
||||
assert_not @subcategory_inheriting_bc.visible_on_track?
|
||||
|
||||
# 4. subcategory inheriting, has spending => visible
|
||||
@subcategory_inheriting_bc.stubs(:actual_spending).returns(10)
|
||||
assert @subcategory_inheriting_bc.visible_on_track?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user