Skip to content

Commit

Permalink
Merge pull request rubyforgood#4253 from rubyforgood/issue4223-add_ba…
Browse files Browse the repository at this point in the history
…nner_after_case_contact_creation
  • Loading branch information
compwron authored Dec 6, 2022
2 parents 897dbf5 + 76dcc04 commit e3cb876
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/helpers/court_dates_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

# Helper methods for court_dates
module CourtDatesHelper
def when_do_we_have_court_dates(casa_case)
return if casa_case.blank?

court_dates = casa_case.court_dates.ordered_ascending
date_now = Date.current

return if court_dates.blank?

if court_dates.last.date < date_now
"past"
elsif court_dates.first.date > date_now
"future"
end
end
end
12 changes: 11 additions & 1 deletion app/views/casa_cases/_thank_you_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
<div class="modal fade" id="thank_you" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-body">
<div class="modal-header">
<%= "Case contact was successfully created. #{thank_you_message}" %>
</div>
<% when_do_we_have_court_dates = when_do_we_have_court_dates(@casa_case) %>
<% if when_do_we_have_court_dates == "future" %>
<div id="prompt-update-user" class="modal-body">
Please enter the previous court date if you know it so that court reports can be generated with the correct case contacts.
</div>
<% elsif when_do_we_have_court_dates == "past" %>
<div id="prompt-update-user" class="modal-body">
Please enter the next court date if you know it so that court reports can be generated with the correct case contacts.
</div>
<% end %>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/casa_cases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@
create(:court_date, casa_case: casa_case, date: Date.tomorrow)
end
end

trait :with_past_court_date do
after(:create) do |casa_case|
create(:court_date, casa_case: casa_case, date: Date.yesterday)
end
end
end
25 changes: 25 additions & 0 deletions spec/helpers/court_dates_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "rails_helper"

RSpec.describe CourtDatesHelper do
describe "#when_do_we_have_court_dates" do
subject { helper.when_do_we_have_court_dates(casa_case) }

describe "when casa case has only dates in the past" do
let(:casa_case) { create(:casa_case, :with_past_court_date) }

it { expect(subject).to eq("past") }
end

describe "when casa case only has dates in the future" do
let(:casa_case) { create(:casa_case, :with_upcoming_court_date) }

it { expect(subject).to eq("future") }
end

describe "when casa case has dates both in the past and future" do
let(:casa_case) { create(:casa_case, :with_upcoming_court_date, :with_past_court_date) }

it { expect(subject).to be_nil }
end
end
end

0 comments on commit e3cb876

Please sign in to comment.