From aa7fffa5a2e32434136cf497fbfb2ca76d077799 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 16 Oct 2024 16:52:03 +1100 Subject: [PATCH] Filter reports by last 3 months by default The values are not shown on the screen and the user doesn't know which default dates are applied but the filtering works. --- .../admin/reports/_date_range_form.html.haml | 4 +-- .../admin/reports/customers_report_spec.rb | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/views/admin/reports/_date_range_form.html.haml b/app/views/admin/reports/_date_range_form.html.haml index 040344e622..8ccd074626 100644 --- a/app/views/admin/reports/_date_range_form.html.haml +++ b/app/views/admin/reports/_date_range_form.html.haml @@ -1,8 +1,8 @@ -# Field used for ransack search. This date range is mostly used for Spree::Order -# so default field is 'completed_at' - field ||= 'completed_at' -- start_date ||= params[:q].try(:[], :completed_at_gt) -- end_date ||= params[:q].try(:[], :completed_at_lt) +- start_date ||= params[:q].try(:[], :completed_at_gt) || 3.months.ago.beginning_of_day +- end_date ||= params[:q].try(:[], :completed_at_lt) || Time.zone.tomorrow.beginning_of_day .row.date-range-filter .alpha.two.columns= label_tag nil, t(:date_range) diff --git a/spec/system/admin/reports/customers_report_spec.rb b/spec/system/admin/reports/customers_report_spec.rb index a9fc0746c8..bd51a0a949 100644 --- a/spec/system/admin/reports/customers_report_spec.rb +++ b/spec/system/admin/reports/customers_report_spec.rb @@ -5,8 +5,11 @@ require "system_helper" RSpec.describe "Customers report" do include AuthenticationHelper + let(:enterprise_user) { create(:enterprise_user) } + let(:distributor) { enterprise_user.enterprises[0] } + it "can be rendered" do - login_as_admin + login_as enterprise_user visit admin_reports_path within "table.index" do @@ -24,4 +27,24 @@ RSpec.describe "Customers report" do ] ) end + + it "displays filtered data by default" do + old_order = create( + :completed_order_with_totals, distributor:, completed_at: 4.months.ago + ) + new_order = create(:completed_order_with_totals, distributor:) + future_order = create( + :completed_order_with_totals, distributor:, completed_at: 1.day.from_now + ) + + login_as enterprise_user + visit admin_report_path(report_type: :customers) + run_report + + rows = find("table.report__table").all("tbody tr") + expect(rows.count).to eq 1 + expect(rows[0].all("td")[3].text).to eq new_order.email + expect(page).not_to have_content old_order.email + expect(page).not_to have_content future_order.email + end end