Skip to content

Commit

Permalink
Fix: The first part of the new Casa Case form does not save certain i…
Browse files Browse the repository at this point in the history
…nput on error (#5785)

* fixed clearing of contact_types when from has error

* fixed clearing of empty_court_date when form has error

* added helper for empty_cout_case variable

* added contact_type case to ensure it doesn't clear on form error

* added empty_court_date checked box  case to ensure it doesn't clear on form error

* changed single quoted to double-quoted

* fixed date picker when empty_court_date selected
  • Loading branch information
iamronakgupta authored May 28, 2024
1 parent 3ca7d14 commit 08868ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/controllers/casa_cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def create
format.json { render json: @casa_case, status: :created }
end
else
set_contact_types
@empty_court_date = court_date_unknown?
respond_to do |format|
format.html { render :new }
format.json { render json: @casa_case.errors.full_messages, status: :unprocessable_entity }
Expand Down
4 changes: 2 additions & 2 deletions app/views/casa_cases/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
<%= cdf.label :date, "Next Court Date" %>
<br>
<div class="input-style-1">
<%= cdf.date_field :date, class: "form-control" %>
<%= cdf.date_field :date, class: "form-control", hidden: @empty_court_date %>
</div>
</div>
<% end %>
<%= form.check_box :empty_court_date, class: "toggle-court-date-input" %>
<%= form.check_box :empty_court_date, checked: @empty_court_date, class: "toggle-court-date-input" %>
<%= form.label :empty_court_date, "I don't know the court date yet" %>
<% end %>
<div class="select-style-1">
Expand Down
12 changes: 11 additions & 1 deletion spec/system/casa_cases/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@

sign_in admin
visit new_casa_case_path
check "casa_case_empty_court_date"

within ".actions-cc" do
click_on "Create CASA Case"
end

expect(find("#casa_case_empty_court_date")).to be_checked
expect(page).to have_current_path(casa_cases_path, ignore_query: true)
expect(page).to have_content("Case number can't be blank")
end
Expand Down Expand Up @@ -127,9 +129,11 @@
end

context "when empty court date checkbox is not checked" do
it "does not create a new case" do
it "does not create a new case", js: true do
casa_org = build(:casa_org)
admin = create(:casa_admin, casa_org: casa_org)
contact_type_group = create(:contact_type_group, casa_org: casa_org)
contact_type = create(:contact_type, contact_type_group: contact_type_group)
case_number = "12345"

sign_in admin
Expand All @@ -140,10 +144,16 @@
select "March", from: "casa_case_birth_month_year_youth_2i"
select five_years, from: "casa_case_birth_month_year_youth_1i"

find(".ts-control").click
find("span", text: contact_type.name).click

within ".actions-cc" do
click_on "Create CASA Case"
end

selected_contact_type = find(".ts-control .item").text

expect(selected_contact_type).to eq(contact_type.name)
expect(page).to have_current_path(casa_cases_path, ignore_query: true)
expect(page).to have_content("Court dates date can't be blank")
end
Expand Down

0 comments on commit 08868ee

Please sign in to comment.