Skip to content

Commit

Permalink
Merge pull request #3785 from rubyforgood/3669-outstanding-requests
Browse files Browse the repository at this point in the history
3669 outstanding requests
  • Loading branch information
awwaiid authored Jul 29, 2023
2 parents a7e46c6 + c302248 commit 5c77138
Show file tree
Hide file tree
Showing 5 changed files with 163 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>
26 changes: 26 additions & 0 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@
</div>
<% 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",
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
91 changes: 91 additions & 0 deletions spec/system/dashboard_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5c77138

Please sign in to comment.