Browse Source

Display the answers in the answer check page

Save radio button and checkbox string values instead of the key/number in
the db. ADR will be added to explain why we are saving values directly to
the db instead of using enums with active record to convert the key/numbers
to the appropriate strings.
pull/25/head
MadeTech Dushan 3 years ago
parent
commit
fe43a1e999
  1. 2
      app/controllers/case_logs_controller.rb
  2. 2
      app/views/form/_checkbox_question.html.erb
  3. 4
      app/views/form/_radio_question.html.erb
  4. 3
      app/views/form/check_answers.html.erb
  5. 23
      spec/features/case_log_spec.rb

2
app/controllers/case_logs_controller.rb

@ -44,7 +44,7 @@ class CaseLogsController < ApplicationController
current_url = request.env['PATH_INFO']
subsection = current_url.split('/')[-2]
subsection_pages = form.pages_for_subsection(subsection)
render "form/check_answers", locals: { case_log_id: @case_log.id, subsection_pages: subsection_pages }
render "form/check_answers", locals: { case_log_id: @case_log.id, case_log: @case_log, subsection_pages: subsection_pages }
end
form = Form.new(2021, 2022)

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

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

4
app/views/form/_radio_question.html.erb

@ -6,8 +6,8 @@
<% question["answer_options"].map do |key, val| %>
<% if key.starts_with?("divider") %>
<%= f.govuk_radio_divider %>
<% else %>
<%= f.govuk_radio_button question_key, key, label: { text: val } %>
<% else %>
<%= f.govuk_radio_button question_key, val, label: { text: val } %>
<% end %>
<% end %>
<% end %>

3
app/views/form/check_answers.html.erb

@ -6,6 +6,9 @@
<dt class="govuk-summary-list__key">
<%= page_info["check_answer_label"].to_s %>
<dt>
<dd class="govuk-summary-list__value">
<%= case_log[page] %>
</dd>
</div>
</dl>
<% end %>

23
spec/features/case_log_spec.rb

@ -7,10 +7,10 @@ RSpec.describe "Test Features" do
question_answers = {
tenant_code: { type: "text", answer: "BZ737" },
tenant_age: { type: "numeric", answer: 25 },
tenant_gender: { type: "radio", answer: "1" },
tenant_ethnic_group: { type: "radio", answer: "2" },
tenant_nationality: { type: "radio", answer: "0" },
tenant_economic_status: { type: "radio", answer: "4" },
tenant_gender: { type: "radio", answer: "Female" },
tenant_ethnic_group: { type: "radio", answer: "Prefer not to say" },
tenant_nationality: { type: "radio", answer: "Lithuania" },
tenant_economic_status: { type: "radio", answer: "Jobseeker" },
household_number_of_other_members: { type: "numeric", answer: 2 },
}
@ -37,7 +37,7 @@ RSpec.describe "Test Features" do
click_button("Save and continue")
expect(page).to have_field("tenant-age-field")
click_button("Save and continue")
expect(page).to have_field("tenant-gender-0-field")
expect(page).to have_field("tenant-gender-male-field")
visit page.driver.request.env["HTTP_REFERER"]
expect(page).to have_field("tenant-age-field")
end
@ -58,7 +58,7 @@ RSpec.describe "Test Features" do
when "text"
fill_in(question.to_s, with: answer)
when "radio"
choose("#{question.to_s.tr('_', '-')}-#{answer}-field")
choose("#{question.to_s.tr('_', '-')}-#{answer.parameterize}-field")
else
fill_in(question.to_s, with: answer)
end
@ -123,6 +123,17 @@ RSpec.describe "Test Features" do
expect(page).to have_content("Nationality")
expect(page).to have_content("Work")
expect(page).to have_content("Number of Other Household Members")
end
it "should display answers given by the user for the question in the subsection" do
visit("/case_logs/#{id}/tenant_age")
fill_in("tenant_age", with: 28)
click_button("Save and continue")
choose("tenant-gender-non-binary-field")
click_button("Save and continue")
visit("/case_logs/#{id}/#{subsection}/check_answers")
expect(page).to have_content("28")
expect(page).to have_content("Non-binary")
end
end
end

Loading…
Cancel
Save