Skip to content

Commit

Permalink
Add an "Outstanding Requests" card to org dashboard
Browse files Browse the repository at this point in the history
Lists the pending and started requests right on the main page so that
the user has an idea of what they need to work on now.

resolves #3669
  • Loading branch information
Benabik committed Jul 29, 2023
1 parent a7e46c6 commit 3052d09
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions app/views/dashboard/_outstanding_requests.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<table class="table table-hover striped">
<thead>
<tr>
<th>Date</th>
<th>Partner</th>
<th>Requestor</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<% outstanding_requests.each do |item| %>
<tr>
<td class="date"><%= link_to item.created_at.strftime("%m/%d/%Y"), item %></td>
<td><%= item.partner.name %></td>
<td><%= item.partner_user&.name %></td>
<td><%= item.comments %></td>
</tr>
<% end %>
</tbody>
</table>
19 changes: 19 additions & 0 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@
</div>
<% end %>
<%=
outstanding_type = @outstanding_requests.empty? ? :box : :table
render(
"card",
id: "outstanding",
gradient: "warning",
title: "Outstanding Requests",
type: outstanding_type,
footer: link_to("See more...", requests_path),
footer_options: { class: "text-center" },
) do
if @outstanding_requests.empty?
"No outstanding requests!"
else
render "outstanding_requests", outstanding_requests: @outstanding_requests
end
end
%>
<%= render(
"card",
id: "distributions",
Expand Down
24 changes: 24 additions & 0 deletions spec/support/pages/organization_dashboard_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -201,4 +221,8 @@ def org_logo_selector
def purchases_section
find "#purchases"
end

def outstanding_selector
"#outstanding"
end
end
74 changes: 74 additions & 0 deletions spec/system/dashboard_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,80 @@ 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
end
end

def valid_bracketing_dates(date_range_info)
Expand Down

0 comments on commit 3052d09

Please sign in to comment.