mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user