Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: The first part of the new Casa Case form does not save certain input on error #5785

Merged
merged 7 commits into from
May 28, 2024
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