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. 2
      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'] current_url = request.env['PATH_INFO']
subsection = current_url.split('/')[-2] subsection = current_url.split('/')[-2]
subsection_pages = form.pages_for_subsection(subsection) 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 end
form = Form.new(2021, 2022) form = Form.new(2021, 2022)

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

@ -6,7 +6,7 @@
<% 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 } %> <%= f.govuk_check_box question_key, val, label: { text: val } %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

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

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

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

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

23
spec/features/case_log_spec.rb

@ -7,10 +7,10 @@ RSpec.describe "Test Features" do
question_answers = { question_answers = {
tenant_code: { type: "text", answer: "BZ737" }, tenant_code: { type: "text", answer: "BZ737" },
tenant_age: { type: "numeric", answer: 25 }, tenant_age: { type: "numeric", answer: 25 },
tenant_gender: { type: "radio", answer: "1" }, tenant_gender: { type: "radio", answer: "Female" },
tenant_ethnic_group: { type: "radio", answer: "2" }, tenant_ethnic_group: { type: "radio", answer: "Prefer not to say" },
tenant_nationality: { type: "radio", answer: "0" }, tenant_nationality: { type: "radio", answer: "Lithuania" },
tenant_economic_status: { type: "radio", answer: "4" }, tenant_economic_status: { type: "radio", answer: "Jobseeker" },
household_number_of_other_members: { type: "numeric", answer: 2 }, household_number_of_other_members: { type: "numeric", answer: 2 },
} }
@ -37,7 +37,7 @@ RSpec.describe "Test Features" do
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_field("tenant-age-field") expect(page).to have_field("tenant-age-field")
click_button("Save and continue") 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"] visit page.driver.request.env["HTTP_REFERER"]
expect(page).to have_field("tenant-age-field") expect(page).to have_field("tenant-age-field")
end end
@ -58,7 +58,7 @@ RSpec.describe "Test Features" do
when "text" when "text"
fill_in(question.to_s, with: answer) fill_in(question.to_s, with: answer)
when "radio" when "radio"
choose("#{question.to_s.tr('_', '-')}-#{answer}-field") choose("#{question.to_s.tr('_', '-')}-#{answer.parameterize}-field")
else else
fill_in(question.to_s, with: answer) fill_in(question.to_s, with: answer)
end end
@ -124,6 +124,17 @@ RSpec.describe "Test Features" do
expect(page).to have_content("Work") expect(page).to have_content("Work")
expect(page).to have_content("Number of Other Household Members") expect(page).to have_content("Number of Other Household Members")
end 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
end end
end end

Loading…
Cancel
Save