Browse Source

Make checkboxes checked if we have already saved an answer for them

pull/39/head^2
baarkerlounger 3 years ago
parent
commit
c4ae32a053
  1. 6
      app/views/form/_checkbox_question.html.erb
  2. 29
      spec/features/case_log_spec.rb

6
app/views/form/_checkbox_question.html.erb

@ -6,7 +6,11 @@
<% if key.starts_with?("divider") %> <% if key.starts_with?("divider") %>
<%= f.govuk_check_box_divider %> <%= f.govuk_check_box_divider %>
<% else %> <% else %>
<%= f.govuk_check_box question_key, key, label: { text: val }, **stimulus_html_attributes(question) %> <%= f.govuk_check_box question_key, key,
label: { text: val },
checked: f.object.send(key),
**stimulus_html_attributes(question)
%>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

29
spec/features/case_log_spec.rb

@ -96,6 +96,14 @@ RSpec.describe "Test Features" do
end end
describe "form questions" do describe "form questions" do
let(:case_log_with_checkbox_questions_answered) do
FactoryBot.create(
:case_log, :in_progress,
accessibility_requirements_fully_wheelchair_accessible_housing: true,
accessibility_requirements_level_access_housing: true
)
end
it "can be accessed by url" do it "can be accessed by url" do
visit("/case_logs/#{id}/tenant_age") visit("/case_logs/#{id}/tenant_age")
expect(page).to have_field("case-log-tenant-age-field") expect(page).to have_field("case-log-tenant-age-field")
@ -146,6 +154,23 @@ RSpec.describe "Test Features" do
visit("/case_logs/#{id}/tenant_age") visit("/case_logs/#{id}/tenant_age")
expect(page).to have_field("case-log-tenant-age-field", with: "12") expect(page).to have_field("case-log-tenant-age-field", with: "12")
end end
it "displays checkbox answers in inputs if they are already saved" do
visit("/case_logs/#{case_log_with_checkbox_questions_answered.id}/accessibility_requirements")
# Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we pass false here
expect(page).to have_checked_field(
"case-log-accessibility-requirements-accessibility-requirements-fully-wheelchair-accessible-housing-field",
visible: false
)
expect(page).to have_unchecked_field(
"case-log-accessibility-requirements-accessibility-requirements-wheelchair-access-to-essential-rooms-field",
visible: false
)
expect(page).to have_checked_field(
"case-log-accessibility-requirements-accessibility-requirements-level-access-housing-field",
visible: false
)
end
end end
describe "Back link directs correctly" do describe "Back link directs correctly" do
@ -258,11 +283,11 @@ RSpec.describe "Test Features" do
choose("case-log-armed-forces-yes-a-regular-field", allow_label_click: true) choose("case-log-armed-forces-yes-a-regular-field", allow_label_click: true)
expect(page).to have_selector("#armed_forces_injured_div") expect(page).to have_selector("#armed_forces_injured_div")
choose("case-log-armed-forces-injured-no-field", allow_label_click: true) choose("case-log-armed-forces-injured-no-field", allow_label_click: true)
expect(find_field("case-log-armed-forces-injured-no-field", visible: false).checked?).to be_truthy expect(page).to have_checked_field("case-log-armed-forces-injured-no-field", visible: false)
choose("case-log-armed-forces-no-field", allow_label_click: true) choose("case-log-armed-forces-no-field", allow_label_click: true)
expect(page).not_to have_selector("#armed_forces_injured_div") expect(page).not_to have_selector("#armed_forces_injured_div")
choose("case-log-armed-forces-yes-a-regular-field", allow_label_click: true) choose("case-log-armed-forces-yes-a-regular-field", allow_label_click: true)
expect(find_field("case-log-armed-forces-injured-no-field", visible: false).checked?).to be_falsey expect(page).to have_unchecked_field("case-log-armed-forces-injured-no-field", visible: false)
end end
end end
end end

Loading…
Cancel
Save