From fe43a1e99910b23af8286dc5dbc3776f9d2687e4 Mon Sep 17 00:00:00 2001 From: MadeTech Dushan Date: Wed, 29 Sep 2021 15:25:58 +0100 Subject: [PATCH] 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. --- app/controllers/case_logs_controller.rb | 2 +- app/views/form/_checkbox_question.html.erb | 2 +- app/views/form/_radio_question.html.erb | 4 ++-- app/views/form/check_answers.html.erb | 3 +++ spec/features/case_log_spec.rb | 23 ++++++++++++++++------ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 54afdeffe..b34ab0740 100644 --- a/app/controllers/case_logs_controller.rb +++ b/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) diff --git a/app/views/form/_checkbox_question.html.erb b/app/views/form/_checkbox_question.html.erb index e41ab5029..0a958fb0e 100644 --- a/app/views/form/_checkbox_question.html.erb +++ b/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 %> diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb index 3681bb21d..e525cf159 100644 --- a/app/views/form/_radio_question.html.erb +++ b/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 %> diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index f9122a0a2..7efc276b6 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -6,6 +6,9 @@
<%= page_info["check_answer_label"].to_s %>
+
+ <%= case_log[page] %> +
<% end %> diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 2501ed1a4..8aa7aa153 100644 --- a/spec/features/case_log_spec.rb +++ b/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