mirror of
https://github.com/we-promise/sure.git
synced 2026-09-05 06:41:08 +00:00
fix(sparklines): prevent crash when trend is nil for empty series (#3171)
* fix(sparklines): prevent crash when trend is nil for empty series * Test sparklines without trend data --------- Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
co-authored by
sentry[bot] <39604003+sentry[bot]@users.noreply.github.com>
Juan José Mata
parent
c8c530d885
commit
db181eb84f
@@ -5,7 +5,7 @@
|
||||
</div>
|
||||
|
||||
<%# A previous value of zero makes the percentage infinite, with nothing useful to print %>
|
||||
<% if @series.trend.percent.finite? %>
|
||||
<% if @series.trend && @series.trend.percent.finite? %>
|
||||
<%= tag.p @series.trend.percent_formatted,
|
||||
style: "color: #{@series.trend.color}",
|
||||
class: "font-mono text-right text-xs font-medium text-primary" %>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</div>
|
||||
|
||||
<%# A previous value of zero makes the percentage infinite, with nothing useful to print %>
|
||||
<% if @sparkline_series.trend.percent.finite? %>
|
||||
<% if @sparkline_series.trend && @sparkline_series.trend.percent.finite? %>
|
||||
<%= tag.p @sparkline_series.trend.percent_formatted,
|
||||
style: "color: #{@sparkline_series.trend.color}",
|
||||
class: "font-mono text-right text-xs font-medium text-primary" %>
|
||||
|
||||
@@ -10,6 +10,22 @@ class AccountableSparklinesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "show renders an empty series without a trend" do
|
||||
empty_series = Series.new(
|
||||
start_date: 1.day.ago.to_date,
|
||||
end_date: Date.current,
|
||||
interval: "1 day",
|
||||
values: []
|
||||
)
|
||||
Rails.cache.clear
|
||||
Balance::ChartSeriesBuilder.any_instance.expects(:balance_series).returns(empty_series)
|
||||
|
||||
get accountable_sparkline_url("depository")
|
||||
|
||||
assert_response :success
|
||||
assert_select "p.font-mono", count: 0
|
||||
end
|
||||
|
||||
test "linked investment sparkline does not load full account records" do
|
||||
AccountProvider.create!(
|
||||
account: accounts(:investment),
|
||||
|
||||
@@ -345,6 +345,21 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "sparkline renders an empty series without a trend" do
|
||||
empty_series = Series.new(
|
||||
start_date: 1.day.ago.to_date,
|
||||
end_date: Date.current,
|
||||
interval: "1 day",
|
||||
values: []
|
||||
)
|
||||
Account.any_instance.expects(:sparkline_series).returns(empty_series)
|
||||
|
||||
get sparkline_account_url(@account)
|
||||
|
||||
assert_response :success
|
||||
assert_select "p.font-mono", count: 0
|
||||
end
|
||||
|
||||
test "destroys account" do
|
||||
delete account_url(@account)
|
||||
assert_redirected_to accounts_path
|
||||
|
||||
Reference in New Issue
Block a user