Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/decorators/case_contact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ def miles_traveled
object.miles_driven.zero? ? nil : "#{object.miles_driven} miles driven"
end

def reimbursement
object.want_driving_reimbursement ? "Reimbursement" : nil
# Text for the reimbursement status badge shown on the case contact card so
# volunteers can see at a glance whether their reimbursement is still pending
# or has been completed, without having to ask their supervisor.
def reimbursement_status_text
object.reimbursement_complete? ? "Reimbursement Complete" : "Reimbursement Pending"
end

# Bootstrap badge color for the reimbursement status.
def reimbursement_status_badge_type
object.reimbursement_complete? ? :success : :warning
end

def contact_made
Expand All @@ -40,8 +48,7 @@ def subheading
I18n.l(object.occurred_at, format: :full, default: nil),
duration_minutes,
contact_made,
miles_traveled,
reimbursement
miles_traveled
].compact.join(" | ")
end

Expand Down
11 changes: 11 additions & 0 deletions app/views/case_contacts/_case_contact.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
<% if !contact.active? %>
<span class="badge badge-pill light-bg text-black">Draft</span>
<% end %>
<% if contact.want_driving_reimbursement? %>
<% decorated_contact = contact.decorate %>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caching contact.decorate in a local variable here is actually a nice improvement over how the rest of this partial handles it, worth considering decorating once at the top of this partial and reusing it everywhere, rather than just in this new block. From what I see, right now contact.decorate gets called fresh four separate times above this (medium_icon_classes, contact_groups, contact_types, subheading), each one allocating a new decorator instance, and this renders once per case contact on the page, so it adds up across however many rows are showing. Not a blocker, but would be nice for anyone touching this file again, pulling the decoration to the top and reusing your variable throughout would clean up an existing inefficiency.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could totally be done in a separate PR dedicated exclusively to improvements, and then testing the corresponding pieces that were touched.

<span class="ms-auto">
<%= render BadgeComponent.new(
text: decorated_contact.reimbursement_status_text,
type: decorated_contact.reimbursement_status_badge_type,
rounded: true,
margin: false
) %>
</span>
<% end %>
<%= link_to("undelete", restore_case_contact_path(contact.id), method: :post, data: { turbo: false },
class: "btn btn-info") if policy(contact).restore? && contact.deleted? %>
</h5>
Expand Down
40 changes: 38 additions & 2 deletions spec/decorators/case_contact_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
case_contact.contact_types = [contact_type]

expect(case_contact.decorate.subheading).to eq(
"December 1, 2020 | 1 hour 39 minutes | No Contact Made | 100 miles driven | Reimbursement"
"December 1, 2020 | 1 hour 39 minutes | No Contact Made | 100 miles driven"
)
end
end
Expand All @@ -166,9 +166,45 @@
case_contact.contact_types = [contact_type]

expect(case_contact.decorate.subheading).to eq(
"December 1, 2020 | 1 hour 39 minutes | 100 miles driven | Reimbursement"
"December 1, 2020 | 1 hour 39 minutes | 100 miles driven"
)
end
end
end

describe "#reimbursement_status_text" do
context "when the reimbursement has not been completed" do
let(:case_contact) { build(:case_contact, reimbursement_complete: false) }

it "returns pending text" do
expect(case_contact.decorate.reimbursement_status_text).to eq("Reimbursement Pending")
end
end

context "when the reimbursement has been completed" do
let(:case_contact) { build(:case_contact, reimbursement_complete: true) }

it "returns complete text" do
expect(case_contact.decorate.reimbursement_status_text).to eq("Reimbursement Complete")
end
end
end

describe "#reimbursement_status_badge_type" do
context "when the reimbursement has not been completed" do
let(:case_contact) { build(:case_contact, reimbursement_complete: false) }

it "returns the warning badge type" do
expect(case_contact.decorate.reimbursement_status_badge_type).to eq(:warning)
end
end

context "when the reimbursement has been completed" do
let(:case_contact) { build(:case_contact, reimbursement_complete: true) }

it "returns the success badge type" do
expect(case_contact.decorate.reimbursement_status_badge_type).to eq(:success)
end
end
end
end
38 changes: 38 additions & 0 deletions spec/system/case_contacts/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,44 @@
end
end

describe "reimbursement status" do
it "shows a pending badge when the reimbursement has not been completed" do
create(:case_contact, :wants_reimbursement, creator: volunteer, casa_case: casa_case,
occurred_at: 2.days.ago, reimbursement_complete: false)

subject

within(".full-card", match: :first) do
expect(page).to have_text("Reimbursement Pending")
expect(page).to have_no_text("Reimbursement Complete")
end
end

it "shows a complete badge when the reimbursement has been completed" do
create(:case_contact, :wants_reimbursement, creator: volunteer, casa_case: casa_case,
occurred_at: 2.days.ago, reimbursement_complete: true)

subject

within(".full-card", match: :first) do
expect(page).to have_text("Reimbursement Complete")
expect(page).to have_no_text("Reimbursement Pending")
end
end

it "shows no reimbursement badge when reimbursement was not requested" do
create(:case_contact, creator: volunteer, casa_case: casa_case, occurred_at: 2.days.ago,
want_driving_reimbursement: false)

subject

within(".full-card", match: :first) do
expect(page).to have_no_text("Reimbursement Pending")
expect(page).to have_no_text("Reimbursement Complete")
end
end
end

describe "automated filtering case contacts" do
describe "by date of contact" do
it "only shows the contacts with the correct date", :js do
Expand Down
Loading