+
+
+
- <%= simple_form_for :filters, url: distributions_by_county_report_path(current_organization), method: :get do |f| %>
- <%= render partial: "shared/date_range_picker", locals: {css_class: "form-control"} %>
- <%= filter_button %>
+ <%= form_tag(distributions_by_county_report_path(current_organization), method: :get) do |f| %>
+
+ <% if @dbc_info.items.present? %>
+
+ <%= filter_select(label: "Item", scope: :by_item_id, collection: @dbc_info.items, selected: @dbc_info.selected_item) %>
+
+ <% end %>
+
+ <%= filter_select(label: "Reporting Category", scope: :by_reporting_category, collection: @dbc_info.reporting_categories, selected: @dbc_info.selected_reporting_category) %>
+
+
+
+ <%= label_tag "Date Range", "Date Range" %>
+ <%= render partial: "shared/date_range_picker", locals: {css_class: "form-control"} %>
+
+
+
<% end %>
-
-
+
@@ -48,7 +66,7 @@
- <% @breakdown.each do |bd| %>
+ <% @dbc_info.breakdown.each do |bd| %>
| <%= bd.name %> |
<%= number_with_delimiter(bd.quantity) %> |
@@ -65,4 +83,5 @@
+
diff --git a/db/schema.rb b/db/schema.rb
index b1ce1c0540..50b213bbed 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.0].define(version: 2025_10_07_141240) do
+ActiveRecord::Schema[8.0].define(version: 2025_10_17_194543) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
diff --git a/docs/user_guide/bank/images/reports/reports_distributions_by_county_1.png b/docs/user_guide/bank/images/reports/reports_distributions_by_county_1.png
index 8756a12557..50b45f4500 100644
Binary files a/docs/user_guide/bank/images/reports/reports_distributions_by_county_1.png and b/docs/user_guide/bank/images/reports/reports_distributions_by_county_1.png differ
diff --git a/docs/user_guide/bank/images/reports/reports_distributions_by_county_2.png b/docs/user_guide/bank/images/reports/reports_distributions_by_county_2.png
index 44ffa58dab..c69458747c 100644
Binary files a/docs/user_guide/bank/images/reports/reports_distributions_by_county_2.png and b/docs/user_guide/bank/images/reports/reports_distributions_by_county_2.png differ
diff --git a/docs/user_guide/bank/images/reports/reports_distributions_by_county_3.png b/docs/user_guide/bank/images/reports/reports_distributions_by_county_3.png
new file mode 100644
index 0000000000..0a42d6c239
Binary files /dev/null and b/docs/user_guide/bank/images/reports/reports_distributions_by_county_3.png differ
diff --git a/docs/user_guide/bank/reports_distributions_by_county.md b/docs/user_guide/bank/reports_distributions_by_county.md
index 4c0648dd45..a86576467f 100644
--- a/docs/user_guide/bank/reports_distributions_by_county.md
+++ b/docs/user_guide/bank/reports_distributions_by_county.md
@@ -3,17 +3,24 @@

-This report shows the total items and estimated total market value of the distributed Items for the time period.
+This report initially shows the total items and estimated total market value of the distributed Items for the time period.
We use the area served information entered in each partner's [profile](pm_partner_profiles.md) to allocate the items that have been distributed to them. If that information has not been provided, the items you've distributed are put into the 'Unspecified' category.
-
-**N.B.** If you are using Kits, please note that this treats each Kit as an item, rather than counting the items within the Kits separately.
+**N.B. If you are using Kits, please note that this counts the items within the kits, rather than the kits. You can not use this report to determine the number of kits that have been distributed to each county.**
If you want to see a time period other than the default of 60 days prior to 30 days forward from today, change the date range and click "Filter". We recommend you use the little pop-up gizmo to enter your date range, as the format of the date range is very fussy.

+
+Similarly, you can also filter by a single item, or by a reporting category, if, for example, you wanted to see distribution of disposable diapers, you would select "Disposalbe Diapers" from the Reporting Category menu, and then click "Filter"
+
+
+
+
+To go back to the default values, click "Clear filters".
+
[Back to Annual Survey](reports_annual_survey.md)
[Next: Manufacturer Donations Report](reports_manufacturers_donations.md)
\ No newline at end of file
diff --git a/spec/queries/distribution_summary_by_county_query_spec.rb b/spec/queries/distribution_summary_by_county_query_spec.rb
index ec34cf0e6f..497a7bb898 100644
--- a/spec/queries/distribution_summary_by_county_query_spec.rb
+++ b/spec/queries/distribution_summary_by_county_query_spec.rb
@@ -5,7 +5,9 @@
let(:organization_id) { organization.id }
let(:start_date) { nil }
let(:end_date) { nil }
- let(:params) { {organization_id:, start_date:, end_date:} }
+ let(:reporting_category) { nil }
+ let(:item_id) { nil }
+ let(:params) { {organization_id:, start_date:, end_date:, reporting_category:} }
include_examples "distribution_by_county"
@@ -64,4 +66,122 @@
expect(num_with_0).to eq 0
end
end
+
+ describe "handling reporting categories" do
+ context "with loose items only" do
+ let(:reporting_category) { :cloth_diapers }
+ let(:params) { {organization_id:, start_date:, end_date:, reporting_category:} }
+
+ it "divides the item numbers and values according to the partner profile" do
+ create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1)
+ create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1)
+
+ breakdown = DistributionSummaryByCountyQuery.call(**params)
+ expect(breakdown.size).to eq(5)
+ expect(breakdown[4].quantity).to eq(0)
+ expect(breakdown[4].value).to be_within(0.01).of(0)
+ 4.times do |i|
+ expect(breakdown[i].quantity).to eq(25)
+ expect(breakdown[i].value).to be_within(0.01).of(26250.0)
+ end
+ end
+ end
+
+ context "with kits only" do
+ let(:reporting_category) { :pads }
+ let(:params) { {organization_id:, start_date:, end_date:, reporting_category:} }
+
+ it "divides the item numbers and values according to the partner profile" do
+ create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1)
+ create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1)
+
+ breakdown = DistributionSummaryByCountyQuery.call(**params)
+ expect(breakdown.size).to eq(5)
+ expect(breakdown[-1].quantity).to eq(0)
+ expect(breakdown[-1].value).to be_within(0.01).of(0)
+ 4.times do |i|
+ expect(breakdown[i].quantity).to eq(500)
+ expect(breakdown[i].value).to be_within(0.01).of(37500.0)
+ end
+ end
+ end
+
+ context "with an item that is in a kit and loose, and another item that is in the reporting category" do
+ let(:reporting_category) { :pads }
+ let(:params) { {organization_id:, start_date:, end_date:, reporting_category:} }
+
+ it "divides the item numbers and values according to the partner profile" do
+ create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1)
+ create(:distribution, :with_items, item: item_3, organization: user.organization, partner: partner_1)
+ create(:distribution, :with_items, item: item_4, organization: user.organization, partner: partner_1)
+ breakdown = DistributionSummaryByCountyQuery.call(**params)
+ expect(breakdown.size).to eq(5)
+ expect(breakdown[-1].quantity).to eq(0)
+ expect(breakdown[-1].value).to be_within(0.01).of(0)
+ 4.times do |i|
+ expect(breakdown[i].quantity).to eq(550)
+ expect(breakdown[i].value).to be_within(0.01).of(40625.0)
+ end
+ end
+ end
+ end
+
+ describe "handling filtering by item" do
+ context "with loose items only" do
+ let(:item_id) { item_1.id }
+ let(:params) { {organization_id:, start_date:, end_date:, reporting_category:, item_id:} }
+
+ it "divides the item numbers and values according to the partner profile" do
+ create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1)
+ create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1)
+
+ breakdown = DistributionSummaryByCountyQuery.call(**params)
+ expect(breakdown.size).to eq(5)
+ expect(breakdown[4].quantity).to eq(0)
+ expect(breakdown[4].value).to be_within(0.01).of(0)
+ 4.times do |i|
+ expect(breakdown[i].quantity).to eq(25)
+ expect(breakdown[i].value).to be_within(0.01).of(26250.0)
+ end
+ end
+ end
+
+ context "with kits only" do
+ let(:item_id) { item_3.id }
+ let(:params) { {organization_id:, start_date:, end_date:, reporting_category:, item_id:} }
+
+ it "divides the item numbers and values according to the partner profile" do
+ create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1)
+ create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1)
+
+ breakdown = DistributionSummaryByCountyQuery.call(**params)
+ expect(breakdown.size).to eq(5)
+ expect(breakdown[-1].quantity).to eq(0)
+ expect(breakdown[-1].value).to be_within(0.01).of(0)
+ 4.times do |i|
+ expect(breakdown[i].quantity).to eq(500)
+ expect(breakdown[i].value).to be_within(0.01).of(37500.0)
+ end
+ end
+ end
+
+ context "with an item that is in a kit and loose, and another item that is in the reporting category" do
+ let(:item_id) { item_3.id }
+ let(:params) { {organization_id:, start_date:, end_date:, reporting_category:, item_id:} }
+
+ it "divides the item numbers and values according to the partner profile" do
+ create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1)
+ create(:distribution, :with_items, item: item_3, organization: user.organization, partner: partner_1)
+ create(:distribution, :with_items, item: item_4, organization: user.organization, partner: partner_1)
+ breakdown = DistributionSummaryByCountyQuery.call(**params)
+ expect(breakdown.size).to eq(5)
+ expect(breakdown[-1].quantity).to eq(0)
+ expect(breakdown[-1].value).to be_within(0.01).of(0)
+ 4.times do |i|
+ expect(breakdown[i].quantity).to eq(525)
+ expect(breakdown[i].value).to be_within(0.01).of(39375.0)
+ end
+ end
+ end
+ end
end
diff --git a/spec/requests/distributions_by_county_spec.rb b/spec/requests/distributions_by_county_spec.rb
index dce023af09..b5bc9a88c2 100644
--- a/spec/requests/distributions_by_county_spec.rb
+++ b/spec/requests/distributions_by_county_spec.rb
@@ -6,44 +6,85 @@
get distributions_by_county_report_path
expect(response).to be_redirect
end
+ end
+
+ context "While signed in as bank" do
+ before do
+ sign_in(user)
+ end
+
+ it "shows 'Unspecified 100%' if no served_areas" do
+ create(:distribution, :with_items, item: item_1, organization: organization)
+ get distributions_by_county_report_path
+ expect(response.body).to include("Unspecified")
+ expect(response.body).to include("100")
+ expect(response.body).to include("$1,050.00")
+ end
- context "While signed in as bank" do
+ it "includes loose items, but not kits in item dropdown" do
+ create(:distribution, :with_items, item: kit_a.item, organization: organization, partner: partner_1, issued_at: issued_at_present) # This is just to make sure the system creates the kit and items within it
+ get distributions_by_county_report_path
+ expect(response.body).to include item_3.name
+ expect(response.body).to_not include(kit_a.item.name)
+ end
+
+ context "basic behaviour with served areas" do
+ it "handles multiple partners with overlapping service areas properly" do
+ create(:distribution, :with_items, item: item_1, organization: organization, partner: partner_1, issued_at: issued_at_present)
+ create(:distribution, :with_items, item: item_1, organization: organization, partner: partner_2, issued_at: issued_at_present)
+
+ get distributions_by_county_report_path
+
+ expect(response.body).to include("45") # First ones are definitely combined
+ expect(response.body).to include("$472.50")
+ expect(response.body).to include("20")
+ expect(response.body).to include("$210.00")
+
+ # The distribution_by_county shared examples give each partner a unique set of counties,
+ # except the second partner shares the first partner's first county.
+ expect(response.body).to include("Partner 1 Test County 1")
+ expect(response.body).to include("Partner 1 Test County 2")
+ expect(response.body).to include("Partner 1 Test County 3")
+ expect(response.body).to include("Partner 1 Test County 4")
+
+ expect(response.body).to include("Partner 2 Test County 2")
+ expect(response.body).to include("Partner 2 Test County 3")
+ expect(response.body).to include("Partner 2 Test County 4")
+ expect(response.body).to include("Partner 2 Test County 5")
+ end
+ end
+
+ context "filtration, kits" do
before do
- sign_in(user)
+ current_year = Time.current.year
+ issued_at_last_year = Time.current.change(year: current_year - 1).to_datetime
+ @distribution_last_year = create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
+ @distribution_current_1 = create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_current_2 = create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_current_3 = create(:distribution, :with_items, item: item_4, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @all_time_string = "January 1,1909 - January 1,9999"
end
+ it("works for all time with a reporting category") do
+ reporting_category_params = {filters: {date_range: @all_time_string, by_reporting_category: "pads", by_item_id: nil}}
+ get distributions_by_county_report_path, params: reporting_category_params
- it "shows 'Unspecified 100%' if no served_areas" do
- create(:distribution, :with_items, item: item_1, organization: organization)
- get distributions_by_county_report_path
- expect(response.body).to include("Unspecified")
- expect(response.body).to include("100")
- expect(response.body).to include("$1,050.00")
+ partner_1.profile.served_areas.each do |served_area|
+ expect(response.body).to include(served_area.county.name)
+ end
+
+ expect(response.body).to include("1,025").at_least(4).times
+ expect(response.body).to include("$762.50").exactly(4).times
end
+ it("works for all time with an item") do
+ params = {filters: {date_range: @all_time_string, by_reporting_category: nil, by_item_id: item_3.id}}
+ get distributions_by_county_report_path, params: params
- context "basic behaviour with served areas" do
- it "handles multiple partners with overlapping service areas properly" do
- create(:distribution, :with_items, item: item_1, organization: organization, partner: partner_1, issued_at: issued_at_present)
- create(:distribution, :with_items, item: item_1, organization: organization, partner: partner_2, issued_at: issued_at_present)
-
- get distributions_by_county_report_path
-
- expect(response.body).to include("45") # First ones are definitely combined
- expect(response.body).to include("$472.50")
- expect(response.body).to include("20")
- expect(response.body).to include("$210.00")
-
- # The distribution_by_county shared examples give each partner a unique set of counties,
- # except the second partner shares the first partner's first county.
- expect(response.body).to include("Partner 1 Test County 1")
- expect(response.body).to include("Partner 1 Test County 2")
- expect(response.body).to include("Partner 1 Test County 3")
- expect(response.body).to include("Partner 1 Test County 4")
-
- expect(response.body).to include("Partner 2 Test County 2")
- expect(response.body).to include("Partner 2 Test County 3")
- expect(response.body).to include("Partner 2 Test County 4")
- expect(response.body).to include("Partner 2 Test County 5")
+ partner_1.profile.served_areas.each do |served_area|
+ expect(response.body).to include(served_area.county.name)
end
+
+ expect(response.body).to include("1,000").at_least(4).times
+ expect(response.body).to include("$750.00").exactly(4).times
end
end
end
diff --git a/spec/support/distribution_by_county_shared_example.rb b/spec/support/distribution_by_county_shared_example.rb
index 53751f7dd8..1f72934219 100644
--- a/spec/support/distribution_by_county_shared_example.rb
+++ b/spec/support/distribution_by_county_shared_example.rb
@@ -4,8 +4,20 @@
let(:organization) { create(:organization, name: "Some Unique Name") }
let(:user) { create(:user, organization: organization) }
let(:organization_admin) { create(:organization_admin, organization: organization) }
+ let(:item_1) { create(:item, value_in_cents: 1050, organization: organization, reporting_category: :cloth_diapers) }
+ let(:item_2) { create(:item, value_in_cents: 20, organization: organization, reporting_category: :tampons) }
+ let(:item_3) { create(:item, value_in_cents: 75, organization: organization, reporting_category: :pads) }
+ let(:item_4) { create(:item, value_in_cents: 50, organization: organization, reporting_category: :pads) }
+
+ let(:kit_a) {
+ kita = create_kit(name: "Kit A", organization: organization, line_items_attributes: [
+ {item_id: item_2.id, quantity: 40},
+ {item_id: item_3.id, quantity: 20}
+ ])
+
+ kita
+ }
- let(:item_1) { create(:item, value_in_cents: 1050, organization: organization) }
let(:issued_at_present) { Time.current.to_datetime }
let(:partner_1) {
p1 = create(:partner, organization: organization)
diff --git a/spec/system/distributions_by_county_system_spec.rb b/spec/system/distributions_by_county_system_spec.rb
index 808e7fa29a..9b1ebe6a8a 100644
--- a/spec/system/distributions_by_county_system_spec.rb
+++ b/spec/system/distributions_by_county_system_spec.rb
@@ -10,79 +10,155 @@
setup_storage_location(@storage_location)
end
- context "handles time ranges properly" do
- it("works for all time") do
- @distribution_last_year = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
- @distribution_current = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
- visit_distribution_by_county_with_specified_date_range("All Time")
- partner_1.profile.served_areas.each do |served_area|
- expect(page).to have_text(served_area.county.name)
+ context "with only 'loose' items" do
+ context "handles time ranges properly" do
+ context "all time" do
+ before do
+ @distribution_last_year = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
+ @distribution_current_1 = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_current_2 = create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ end
+
+ it("works for all time with no reporting categories") do
+ visit_distribution_by_county_with_specified_filters("All Time", nil, nil)
+ partner_1.profile.served_areas.each do |served_area|
+ expect(page).to have_text(served_area.county.name)
+ end
+
+ expect(page).to have_css("table tbody tr td", text: "75", exact_text: true, count: 4)
+ expect(page).to have_css("table tbody tr td", text: "$530.00", exact_text: true, count: 4)
+ end
end
- expect(page).to have_css("table tbody tr td", text: "50", exact_text: true, count: 4)
- expect(page).to have_css("table tbody tr td", text: "$525.00", exact_text: true, count: 4)
- end
+ it("works for this year with no reporting categories") do
+ @distribution_current = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_last_year = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
- it("works for this year") do
- @distribution_current = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
- @distribution_last_year = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
+ visit_distribution_by_county_with_specified_filters("This Year", nil, nil)
- visit_distribution_by_county_with_specified_date_range("This Year")
+ partner_1.profile.served_areas.each do |served_area|
+ expect(page).to have_text(served_area.county.name)
+ end
- partner_1.profile.served_areas.each do |served_area|
- expect(page).to have_text(served_area.county.name)
+ expect(page).to have_css("table tbody tr td", text: "25", exact_text: true, count: 4)
+ expect(page).to have_css("table tbody tr td", text: "$262.50", exact_text: true, count: 4)
end
- expect(page).to have_css("table tbody tr td", text: "25", exact_text: true, count: 4)
- expect(page).to have_css("table tbody tr td", text: "$262.50", exact_text: true, count: 4)
- end
+ it("works for this year with reporting categories") do
+ @distribution_current_1 = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_current_2 = create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+
+ @distribution_last_year = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
+
+ visit_distribution_by_county_with_specified_filters("This Year", "Cloth Diapers", nil)
+
+ partner_1.profile.served_areas.each do |served_area|
+ expect(page).to have_text(served_area.county.name)
+ end
+
+ expect(page).to have_css("table tbody tr td", text: "25", exact_text: true, count: 4)
+ expect(page).to have_css("table tbody tr td", text: "$262.50", exact_text: true, 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.beginning_of_day.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)
+ it("works for all time with reporting categories") do
+ @distribution_current_1 = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_current_2 = create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
- # 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)
+ @distribution_last_year = create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
- # Should NOT return distribution issued after previous calendar year
- first_day_of_current_year = Time.current.end_of_day.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_filters("All Time", "Cloth Diapers", nil)
- 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
- partner_1.profile.served_areas.each do |served_area|
- expect(page).to have_text(served_area.county.name)
+ expect(page).to have_css("table tbody tr td", text: "50", exact_text: true, count: 4)
+ expect(page).to have_css("table tbody tr td", text: "$525.00", exact_text: true, 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.beginning_of_day.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.end_of_day.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_filters("Prior Year", nil, nil)
+
+ partner_1.profile.served_areas.each do |served_area|
+ expect(page).to have_text(served_area.county.name)
+ end
+ expect(page).to have_css("table tbody tr td", text: "25", exact_text: true, count: 4)
+ expect(page).to have_css("table tbody tr td", text: "$262.50", exact_text: true, count: 4)
end
- expect(page).to have_css("table tbody tr td", text: "25", exact_text: true, count: 4)
- expect(page).to have_css("table tbody tr td", text: "$262.50", exact_text: true, 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.beginning_of_day.to_datetime
- create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: one_year_and_one_day_ago)
+ 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.beginning_of_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 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.end_of_day.to_datetime
- create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1, issued_at: tomorrow)
+ # Should NOT return distribution issued in the future
+ tomorrow = 1.day.from_now.end_of_day.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")
+ visit_distribution_by_county_with_specified_filters("Last 12 Months", nil, nil)
- partner_1.profile.served_areas.each do |served_area|
- expect(page).to have_text(served_area.county.name)
+ partner_1.profile.served_areas.each do |served_area|
+ expect(page).to have_text(served_area.county.name)
+ end
+ expect(page).to have_css("table tbody tr td", text: "25", exact_text: true, count: 4)
+ expect(page).to have_css("table tbody tr td", text: "$262.50", exact_text: true, count: 4)
end
- expect(page).to have_css("table tbody tr td", text: "25", exact_text: true, count: 4)
- expect(page).to have_css("table tbody tr td", text: "$262.50", exact_text: true, count: 4)
end
end
- def visit_distribution_by_county_with_specified_date_range(date_range_string)
+ context "with kits" do
+ context "with reporting category" do
+ it "works for all time" do
+ @distribution_current_1 = create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_current_2 = create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_last_year_1 = create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
+ @distribution_last_year_2 = create(:distribution, :with_items, item: item_4, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
+ visit_distribution_by_county_with_specified_filters("All Time", "Pads", nil)
+
+ partner_1.profile.served_areas.each do |served_area|
+ expect(page).to have_text(served_area.county.name)
+ end
+
+ expect(page).to have_css("table tbody tr td", text: "1,025", exact_text: true, count: 4)
+ expect(page).to have_css("table tbody tr td", text: "$762.50", exact_text: true, count: 4)
+ end
+ end
+
+ context "with item filter" do
+ it "works for all time" do
+ @distribution_current_1 = create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_current_2 = create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1, issued_at: issued_at_present)
+ @distribution_last_year_1 = create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
+ @distribution_last_year_2 = create(:distribution, :with_items, item: item_4, organization: user.organization, partner: partner_1, issued_at: issued_at_last_year)
+ visit_distribution_by_county_with_specified_filters("All Time", nil, item_3.name)
+
+ partner_1.profile.served_areas.each do |served_area|
+ expect(page).to have_text(served_area.county.name)
+ end
+
+ expect(page).to have_css("table tbody tr td", text: "1,000", exact_text: true, count: 4)
+ expect(page).to have_css("table tbody tr td", text: "$750.00", exact_text: true, count: 4)
+ end
+ end
+ end
+
+ def visit_distribution_by_county_with_specified_filters(date_range_string, reporting_category, item_name)
visit dashboard_path
click_on "Reports"
@@ -95,6 +171,14 @@ def visit_distribution_by_county_with_specified_date_range(date_range_string)
find("button", text: date_range_string).click
end
+ if reporting_category
+ select reporting_category, from: "Reporting Category"
+ end
+
+ if item_name
+ select item_name, from: "Item"
+ end
+
click_on "Filter"
end
end