Skip to content

Commit

Permalink
feat: use most recent court date in modal
Browse files Browse the repository at this point in the history
On the case show page it should autofill the start date of
the date range with the most recent court date.

This most closely mirrors existing behavior.
  • Loading branch information
elasticspoon committed Apr 8, 2024
1 parent 985f1a3 commit b449a47
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/models/casa_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def most_recent_past_court_date
court_dates.where("date < ?", Date.today).order(:date).last
end

def formatted_latest_court_date
most_recent = most_recent_past_court_date&.date&.in_time_zone || Time.zone.now

most_recent.strftime(::DateHelper::RUBY_MONTH_DAY_YEAR_FORMAT)
end

def has_judge_name?
judge_name
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/casa_cases/_generate_report_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="field form-group mb-20">
<h6><label class="form-label" for="start_date">Starting From</label></h6>
<%= form.text_field :start_date,
value: Time.zone.now.strftime(::DateHelper::RUBY_MONTH_DAY_YEAR_FORMAT),
value: @casa_case.formatted_latest_court_date,
data: { provide: "datepicker",
date_format: ::DateHelper::JQUERY_MONTH_DAY_YEAR_FORMAT },
class: "form-control" %>
Expand Down
28 changes: 28 additions & 0 deletions spec/models/casa_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,34 @@
end
end

describe "#formatted_latest_court_date" do
let(:casa_case) { create(:casa_case) }

before do
travel_to Date.new(2021, 1, 1)
end

context "with a past court date" do
it "returns the latest past court date as a formatted string" do
most_recent_past_court_date = create(:court_date, date: 3.months.ago)

casa_case.court_dates << create(:court_date, date: 9.months.ago)
casa_case.court_dates << most_recent_past_court_date
casa_case.court_dates << create(:court_date, date: 15.months.ago)

expect(casa_case.formatted_latest_court_date).to eq("October 01, 2020") # 3 months before 1/1/21
end
end

context "without a past court date" do
it "returns the current day as a formatted string" do
allow(casa_case).to receive(:most_recent_past_court_date).and_return(nil)

expect(casa_case.formatted_latest_court_date).to eq("January 01, 2021")
end
end
end

context "#remove_emancipation_category" do
let(:casa_case) { create(:casa_case) }
let(:emancipation_category) { build(:emancipation_category) }
Expand Down

0 comments on commit b449a47

Please sign in to comment.