diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 45454f4ba9..990ff9ee2f 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -29,5 +29,7 @@ def index # passing nil here filters the announcements that didn't come from an organization @broadcast_announcements = BroadcastAnnouncement.filter_announcements(nil) + + @outstanding_requests = Request.where(status: %i[pending started]).order(:created_at) end end diff --git a/app/views/dashboard/_outstanding_requests.html.erb b/app/views/dashboard/_outstanding_requests.html.erb new file mode 100644 index 0000000000..1037e38dc1 --- /dev/null +++ b/app/views/dashboard/_outstanding_requests.html.erb @@ -0,0 +1,20 @@ + + + + + + + + + + + <% outstanding_requests.each do |item| %> + + + + + + + <% end %> + +
DatePartnerRequestorComments
<%= link_to item.created_at.strftime("%m/%d/%Y"), item %><%= item.partner.name %><%= item.partner_user&.name %><%= item.comments %>
diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 185404290a..fed9dbeb5f 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -115,6 +115,32 @@ <% end %> + <%= + outstanding_type = @outstanding_requests.empty? ? :box : :table + outstanding_footer = + if @outstanding_requests.count > 25 + "And #{@outstanding_requests.count - 25} more..." + else + "See more..." + end + render( + "card", + id: "outstanding", + gradient: "warning", + title: "Outstanding Requests", + type: outstanding_type, + footer: link_to(outstanding_footer, requests_path), + footer_options: { class: "text-center" }, + ) do + if @outstanding_requests.empty? + "No outstanding requests!" + else + render "outstanding_requests", + outstanding_requests: @outstanding_requests.take(25) + end + end + %> + <%= render( "card", id: "distributions", diff --git a/spec/support/pages/organization_dashboard_page.rb b/spec/support/pages/organization_dashboard_page.rb index 50fac9cc37..3e93161a4a 100644 --- a/spec/support/pages/organization_dashboard_page.rb +++ b/spec/support/pages/organization_dashboard_page.rb @@ -84,6 +84,10 @@ def has_organization_logo? has_selector? org_logo_selector end + def has_outstanding_section? + has_selector? outstanding_selector + end + def manufacturers_total_donations within manufacturers_section do parse_formatted_integer find(".total_received_donations").text @@ -164,6 +168,22 @@ def total_inventory end end + def outstanding_section + find outstanding_selector + end + + def outstanding_requests + within outstanding_section do + all('tbody > tr') + end + end + + def outstanding_requests_link + within outstanding_section do + find('.card-footer a') + end + end + private def product_drives_section @@ -201,4 +221,8 @@ def org_logo_selector def purchases_section find "#purchases" end + + def outstanding_selector + "#outstanding" + end end diff --git a/spec/system/dashboard_system_spec.rb b/spec/system/dashboard_system_spec.rb index ddd6bef210..1adb9ce7a7 100644 --- a/spec/system/dashboard_system_spec.rb +++ b/spec/system/dashboard_system_spec.rb @@ -812,6 +812,97 @@ def create_next_product_drive_distribution(date_picker:) end end end + + describe "Outstanding Requests" do + it "has a card" do + org_dashboard_page.visit + expect(org_dashboard_page).to have_outstanding_section + end + + context "when empty" do + before { org_dashboard_page.visit } + + it "displays a message" do + expect(org_dashboard_page.outstanding_section).to have_content "No outstanding requests!" + end + + it "has a See More link" do + expect(org_dashboard_page.outstanding_requests_link).to have_content "See more" + end + end + + context "with a pending request" do + let!(:request) { create :request, :pending } + let!(:outstanding_request) do + org_dashboard_page.visit + requests = org_dashboard_page.outstanding_requests + expect(requests.length).to eq 1 + requests.first + end + + it "displays the date" do + date = outstanding_request.find "td.date" + expect(date.text).to eq request.created_at.strftime("%m/%d/%Y") + end + + it "displays the partner" do + expect(outstanding_request).to have_content request.partner.name + end + + it "displays the requestor" do + expect(outstanding_request).to have_content request.partner_user.name + end + + it "displays the comment" do + expect(outstanding_request).to have_content request.comments + end + + it "links to the request" do + expect { outstanding_request.find('a').click } + .to change { page.current_path } + .to "/#{org_short_name}/requests/#{request.id}" + end + + it "has a See More link" do + expect(org_dashboard_page.outstanding_requests_link).to have_content "See more" + end + end + + it "does display a started request" do + create :request, :started + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests.length).to eq 1 + end + + it "does not display a fulfilled request" do + create :request, :fulfilled + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests).to be_empty + end + + it "does not display a discarded request" do + create :request, :discarded + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests).to be_empty + end + + context "with many pending requests" do + let(:num_requests) { 50 } + let(:limit) { 25 } + before do + create_list :request, num_requests, :pending + org_dashboard_page.visit + end + + it "displays a limited number of requests" do + expect(org_dashboard_page.outstanding_requests.length).to eq limit + end + + it "has a link with the number of other requests" do + expect(org_dashboard_page.outstanding_requests_link).to have_content num_requests - limit + end + end + end end def valid_bracketing_dates(date_range_info)