1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-21 06:09:38 +02:00
Maybe/test/models/trend_test.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

require "test_helper"
class TrendTest < ActiveSupport::TestCase
test "handles money trend" do
trend = 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 = Trend.new(current: 100, previous: 50)
assert_equal "up", trend.direction
assert_equal "var(--color-success)", trend.color
end
test "down" do
trend = Trend.new(current: 50, previous: 100)
assert_equal "down", trend.direction
assert_equal "var(--color-destructive)", trend.color
end
test "flat" do
trend1 = Trend.new(current: 100, previous: 100)
trend2 = Trend.new(current: 100, previous: nil)
assert_equal "flat", trend1.direction
assert_equal "up", trend2.direction
assert_equal "var(--color-gray)", trend1.color
end
test "infinitely up" do
trend = Trend.new(current: 100, previous: 0)
assert_equal "up", trend.direction
end
test "infinitely down" do
trend = Trend.new(current: 0, previous: 100)
assert_equal "down", trend.direction
end
end