|
| 1 | +RSpec.describe "Reports Distributions", type: :system, js: true do |
| 2 | + let(:organization) { create(:organization) } |
| 3 | + let(:user) { create(:user, organization: organization) } |
| 4 | + let(:organization_admin) { create(:organization_admin, organization: organization) } |
| 5 | + let!(:partner) { create(:partner, organization: organization, name: "Test Partner") } |
| 6 | + let!(:storage_location) { create(:storage_location, organization: organization, name: "Test Storage Location") } |
| 7 | + |
| 8 | + context "while logged in" do |
| 9 | + before do |
| 10 | + sign_in(user) |
| 11 | + end |
| 12 | + |
| 13 | + context "Distributions - Itemized" do |
| 14 | + before do |
| 15 | + create(:item, organization: organization) |
| 16 | + create(:storage_location, organization: organization) |
| 17 | + create(:donation_site, organization: organization) |
| 18 | + create(:product_drive, organization: organization) |
| 19 | + create(:product_drive_participant, organization: organization) |
| 20 | + create(:product_drive_participant, organization: organization, contact_name: "contact without business name", business_name: "") |
| 21 | + create(:manufacturer, organization: organization) |
| 22 | + organization.reload |
| 23 | + |
| 24 | + visit new_donation_path |
| 25 | + |
| 26 | + select Donation::SOURCES[:misc], from: "donation_source" |
| 27 | + select StorageLocation.first.name, from: "donation_storage_location_id" |
| 28 | + select Item.alphabetized.first.name, from: "donation_line_items_attributes_0_item_id" |
| 29 | + fill_in "donation_line_items_attributes_0_quantity", with: "5" |
| 30 | + fill_in "donation_issued_at", with: "2001-01-01" |
| 31 | + |
| 32 | + click_button "Save" |
| 33 | + |
| 34 | + visit new_distribution_path |
| 35 | + end |
| 36 | + |
| 37 | + it "Ensuring that the result of the distribution index is zero instead of Unknow" do |
| 38 | + select "Test Partner", from: "Partner" |
| 39 | + select "Test Storage Location", from: "From storage location" |
| 40 | + fill_in "distribution_line_items_attributes_0_quantity", with: "5" |
| 41 | + choose "Pick up" |
| 42 | + |
| 43 | + click_button "Save", match: :first |
| 44 | + within "#distributionConfirmationModal" do |
| 45 | + click_button "Yes, it's correct" |
| 46 | + end |
| 47 | + |
| 48 | + visit reports_itemized_distributions_path |
| 49 | + |
| 50 | + expect(page).to have_selector(:table_row, "Total On Hand" => "0") |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + context "Donations - Itemized" do |
| 55 | + let(:donation) { create :donation, :with_items } |
| 56 | + |
| 57 | + before do |
| 58 | + create(:item, organization: organization) |
| 59 | + create(:storage_location, organization: organization) |
| 60 | + create(:donation_site, organization: organization) |
| 61 | + create(:product_drive, organization: organization) |
| 62 | + create(:product_drive_participant, organization: organization) |
| 63 | + create(:product_drive_participant, organization: organization, contact_name: "contact without business name", business_name: "") |
| 64 | + create(:manufacturer, organization: organization) |
| 65 | + organization.reload |
| 66 | + end |
| 67 | + |
| 68 | + it "Ensuring that the result of the donation index is zero instead of Unknow" do |
| 69 | + visit new_donation_path |
| 70 | + select Donation::SOURCES[:misc], from: "donation_source" |
| 71 | + select StorageLocation.first.name, from: "donation_storage_location_id" |
| 72 | + select Item.alphabetized.first.name, from: "donation_line_items_attributes_0_item_id" |
| 73 | + fill_in "donation_line_items_attributes_0_quantity", with: "20" |
| 74 | + fill_in "donation_issued_at", with: "2025-04-15" |
| 75 | + |
| 76 | + click_button "Save" |
| 77 | + |
| 78 | + visit new_distribution_path |
| 79 | + |
| 80 | + select "Test Partner", from: "Partner" |
| 81 | + select "Test Storage Location", from: "From storage location" |
| 82 | + fill_in "distribution_line_items_attributes_0_quantity", with: "20" |
| 83 | + choose "Pick up" |
| 84 | + |
| 85 | + click_button "Save", match: :first |
| 86 | + |
| 87 | + within "#distributionConfirmationModal" do |
| 88 | + click_button "Yes, it's correct" |
| 89 | + end |
| 90 | + |
| 91 | + visit reports_itemized_donations_path |
| 92 | + expect(page).to have_selector(:table_row, "Total On Hand" => "0") |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | +end |
0 commit comments