Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more date range selection options #4518 #4533

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/helpers/date_range_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def date_range_label
"this month"
when "last month"
"last month"
when "last 12 months"
"last 12 months"
when "prior year"
"prior year"
else
selected_range_described
end
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ $(document).ready(function(){
'This Month': [today.startOf('month').toJSDate(), today.endOf('month').toJSDate()],
'Last Month': [today.minus({'months': 1}).startOf('month').toJSDate(),
today.minus({'month': 1}).endOf('month').toJSDate()],
'This Year': [today.startOf('year').toJSDate(), today.endOf('year').toJSDate()]
'Last 12 Months': [today.minus({'months': 12}).plus({'days': 1}).toJSDate(), today.toJSDate()],
'Prior Year': [today.startOf('year').minus({'years': 1}).toJSDate(), today.minus({'year': 1}).endOf('year').toJSDate()],
'This Year': [today.startOf('year').toJSDate(), today.endOf('year').toJSDate()],
}
}
});
Expand Down
48 changes: 46 additions & 2 deletions spec/system/distributions_by_county_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
RSpec.feature "Distributions by County", type: :system do
include_examples "distribution_by_county"

let(:year) { Time.current.year }
let(:issued_at_last_year) { Time.current.utc.change(year: year - 1).to_datetime }
let(:current_year) { Time.current.year }
let(:issued_at_last_year) { Time.current.utc.change(year: current_year - 1).to_datetime }

before do
sign_in(user)
Expand Down Expand Up @@ -34,6 +34,50 @@
expect(page).to have_text("25", count: 4)
expect(page).to have_text("$262.50", count: 4)
end

it("works for prior year") do
# Should NOT return distribution issued before previous calendar year
last_day_of_two_years_ago = Time.current.utc.change(year: current_year - 2, month: 12, day: 31).to_datetime
create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: last_day_of_two_years_ago)

# Should return distribution issued during previous calendar year
one_year_ago = issued_at_last_year
create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: one_year_ago)

# Should NOT return distribution issued after previous calendar year
first_day_of_current_year = Time.current.utc.change(year: current_year, month: 1, day: 1).to_datetime
create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: first_day_of_current_year)

visit_distribution_by_county_with_specified_date_range("Prior Year")

partner_1.profile.served_areas.each do |served_area|
expect(page).to have_text(served_area.county.name)
end
expect(page).to have_text("25", count: 4)
expect(page).to have_text("$262.50", count: 4)
end

it("works for last 12 months") do
# Should NOT return disitribution issued before 12 months ago
one_year_and_one_day_ago = 1.year.ago.prev_day.to_datetime
create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: one_year_and_one_day_ago)

# Should return distribution issued during previous 12 months
today = issued_at_present
create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: today)

# Should NOT return distribution issued in the future
tomorrow = 1.day.from_now.to_datetime
create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: tomorrow)

visit_distribution_by_county_with_specified_date_range("Last 12 Months")

partner_1.profile.served_areas.each do |served_area|
expect(page).to have_text(served_area.county.name)
end
expect(page).to have_text("25", count: 4)
expect(page).to have_text("$262.50", count: 4)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these tests identical? Ideally to test this we'd want to have a distribution that is included and one that's not included, specifically for these 2 blocks of time.

Copy link
Collaborator Author

@pshong79 pshong79 Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.... I was curious about those expects. I will dig in a bit deeper to see what I can figure out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! I haven't forgotten about this.... Work has picked up a bit so been eating up a lot of my time at the moment!

end

def visit_distribution_by_county_with_specified_date_range(date_range_string)
Expand Down