1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Add the ability to "rollup" values in a time series (#554)

* Clean up time series models

* Add value group rollup class for summarizing hierarchical data

* Integrate new classes

* Update UI to use new patterns

* Update D3 charts to expect new data format

* Clean up account model

* More cleanup

* Money improvements

* Use new money fields

* Remove invalid fixture data to avoid orphaned accountables

* Update time series to work better with collections

* Fix tests and UI bugs
This commit is contained in:
Zach Gollwitzer 2024-03-19 09:10:40 -04:00 committed by GitHub
parent 0a8518506c
commit f904d9d062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 687 additions and 391 deletions

View file

@ -0,0 +1,45 @@
require "test_helper"
class TimeSeries::TrendTest < ActiveSupport::TestCase
test "handles money trend" do
trend = TimeSeries::Trend.new(current: Money.new(100), previous: Money.new(50))
assert_equal "up", trend.direction
assert_equal Money.new(50), trend.value
assert_equal 100.0, trend.percent
end
test "up" do
trend = TimeSeries::Trend.new(current: 100, previous: 50)
assert_equal "up", trend.direction
end
test "down" do
trend = TimeSeries::Trend.new(current: 50, previous: 100)
assert_equal "down", trend.direction
end
test "flat" do
trend1 = TimeSeries::Trend.new(current: 100, previous: 100)
trend3 = TimeSeries::Trend.new(current: 100, previous: nil)
trend2 = TimeSeries::Trend.new(current: nil, previous: nil)
assert_equal "flat", trend1.direction
assert_equal "flat", trend2.direction
assert_equal "flat", trend3.direction
end
test "infinitely up" do
trend = TimeSeries::Trend.new(current: 100, previous: 0)
assert_equal "up", trend.direction
end
test "infinitely down" do
trend1 = TimeSeries::Trend.new(current: nil, previous: 100)
trend2 = TimeSeries::Trend.new(current: 0, previous: 100)
assert_equal "down", trend1.direction
assert_equal "down", trend2.direction
end
test "empty" do
trend =TimeSeries::Trend.new
assert_equal "flat", trend.direction
end
end