Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Link Monthly Breakdown months to their monthly report (#5298)

Jakub Kottnauer5843ba61cef8
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb
index 6c12ae20b5..b837fdc951 100644
--- a/app/controllers/reports_controller.rb
+++ b/app/controllers/reports_controller.rb
@@ -419,6 +419,7 @@ class ReportsController < ApplicationController
trends << {
month: current_month.strftime("%b %Y"),
+ calendar_month: current_month,
is_current_month: (current_month.month == Date.current.month && current_month.year == Date.current.year),
income: income,
expenses: expenses,
diff --git a/app/views/reports/_trends_insights.html.erb b/app/views/reports/_trends_insights.html.erb
index fd450b8783..5a2747b976 100644
--- a/app/views/reports/_trends_insights.html.erb
+++ b/app/views/reports/_trends_insights.html.erb
@@ -9,7 +9,12 @@
<%= render DS::Table.new(rows: trends_data, inset: true, label: t("reports.trends.monthly_breakdown"), row_class: ->(_trend) { "text-secondary" }) do |table| %>
<% table.with_column(t("reports.trends.month")) do |trend| %>
<span class="<%= class_names("flex items-center gap-2", "font-medium" => trend[:is_current_month]) %>">
- <%= trend[:month] %>
+ <%= render DS::Link.new(
+ variant: :default,
+ text: trend[:month],
+ href: reports_path(period_type: :monthly, start_date: trend[:calendar_month], end_date: trend[:calendar_month].end_of_month, **reports_filter_params),
+ frame: :_top
+ ) %>
<% if trend[:is_current_month] %>
<span class="text-xs text-subdued">(<%= t("reports.trends.current") %>)</span>
<% end %>
diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb
index 64876cccc7..f8ccc18afa 100644
--- a/test/controllers/reports_controller_test.rb
+++ b/test/controllers/reports_controller_test.rb
@@ -513,6 +513,18 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
end
end
+ test "monthly breakdown month names link to that month's report with the selected tags" do
+ tag = @family.tags.create!(name: "Breakdown tag")
+
+ get reports_path(period_type: :custom, start_date: Date.new(2024, 1, 15), end_date: Date.new(2024, 3, 12), filter_tag_ids: [ tag.id ])
+
+ assert_response :ok
+ [ Date.new(2024, 1, 1), Date.new(2024, 2, 1), Date.new(2024, 3, 1) ].each do |month|
+ href = reports_path(period_type: :monthly, start_date: month, end_date: month.end_of_month, filter_tag_ids: [ tag.id ])
+ assert_select "[data-section-key=trends_insights] a[href=?][data-turbo-frame=_top]", href, text: month.strftime("%b %Y")
+ end
+ end
+
test "index handles invalid date parameters gracefully" do
get reports_path(
period_type: :custom,
@@ -1163,10 +1175,15 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
)
assert_response :ok
- prev_start = 1.month.ago.to_date.beginning_of_month - 1.month
- next_start = 1.month.ago.to_date.beginning_of_month + 1.month
- assert_select "a[href*=?]", "start_date=#{prev_start}", count: 0
- assert_select "a[href*=?]", "start_date=#{next_start}", count: 0
+ assert_select "a[aria-label=?]", I18n.t("reports.index.previous_period"), count: 0
+ assert_select "a[aria-label=?]", I18n.t("reports.index.next_period"), count: 0
+ end
+
+ test "monthly period shows previous period navigation" do
+ get reports_path(period_type: :monthly)
+ assert_response :ok
+
+ assert_select "a[aria-label=?]", I18n.t("reports.index.previous_period"), count: 1
end
test "ytd period navigation shows previous year link" do