From 26cca734fac70cc5d532156589113b38a76226d2 Mon Sep 17 00:00:00 2001 From: MadeTech Dushan Date: Fri, 1 Oct 2021 12:07:31 +0100 Subject: [PATCH] Use questions instead of pages in check answers --- app/helpers/check_answers_helper.rb | 6 +++--- app/views/form/_check_answers_table.html.erb | 6 +++--- app/views/form/check_answers.html.erb | 4 +++- config/forms/2021_2022.json | 14 +++++++------- spec/helpers/check_answers_helper_spec.rb | 4 ++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 605d6c9e7..5941800aa 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -1,9 +1,9 @@ module CheckAnswersHelper def get_answered_questions_total(subsection_pages, case_log) - questions = subsection_pages.values.map do |page| - page["questions"].keys + questions = subsection_pages.values.flat_map do |page| + page["questions"].keys end - return questions.count {|questions_for_page| questions_for_page.none? { |question| case_log[question].blank?}} + questions.count { |question| case_log[question].present? } end diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb index b4551f622..fb3d47d0f 100644 --- a/app/views/form/_check_answers_table.html.erb +++ b/app/views/form/_check_answers_table.html.erb @@ -1,13 +1,13 @@
- <%= page_info["check_answer_label"].to_s %> + <%= question_info["check_answer_label"].to_s %>
- <%= case_log[page] %> + <%= case_log[question_title] %>
- <%= create_update_answer_link(case_log[page], case_log["id"], page)%> + <%= create_update_answer_link(case_log[question_title], case_log["id"], question_title)%>
diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index 872f7ae92..a4404472f 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -3,7 +3,9 @@

You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= subsection_pages.count %> questions

<%= create_next_missing_question_link(case_log["id"], subsection_pages, case_log) %> <% subsection_pages.each do |page, page_info| %> - <%= render partial: 'form/check_answers_table', locals: { page: page, page_info: page_info, case_log: case_log } %> + <% page_info["questions"].each do |question_title, question_info| %> + <%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: case_log } %> + <%end %> <% end %> <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> <%= f.govuk_submit "Save and continue" %> diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 0966a9bdc..51da24d30 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -10,11 +10,11 @@ "label": "Household characteristics", "pages": { "tenant_code":{ - "check_answer_label": "Tenant code", "header": "", "description": "", "questions":{ "tenant_code": { + "check_answer_label": "Tenant code", "header": "What is the tenant code?", "hint_text": "", "type": "text" @@ -22,11 +22,11 @@ } }, "tenant_age":{ - "check_answer_label": "Tenant's age", "header": "", "description": "", "questions":{ "tenant_age": { + "check_answer_label": "Tenant's age", "header": "What is the tenant's age?", "hint_text": "", "type": "numeric", @@ -37,11 +37,11 @@ } }, "tenant_gender":{ - "check_answer_label": "Tenant's gender", "header": "", "description": "", "questions":{ "tenant_gender": { + "check_answer_label": "Tenant's gender", "header": "Which of these best describes the tenant's gender identity?", "hint_text": "", "type": "radio", @@ -55,11 +55,11 @@ } }, "tenant_ethnic_group":{ - "check_answer_label": "Ethnicity", "header": "", "description": "", "questions":{ "tenant_ethnic_group": { + "check_answer_label": "Ethnicity", "header": "What is the tenant's ethnic group?", "hint_text": "", "type": "radio", @@ -88,11 +88,11 @@ } }, "tenant_nationality":{ - "check_answer_label": "Nationality", "header": "", "description": "", "questions":{ "tenant_nationality": { + "check_answer_label": "Nationality", "header": "What is the tenant's nationality?", "hint_text": "", "type": "radio", @@ -118,11 +118,11 @@ } }, "tenant_economic_status":{ - "check_answer_label": "Work", "header": "", "description": "", "questions":{ "tenant_economic_status": { + "check_answer_label": "Work", "header": "Which of these best describes the tenant's working situation?", "hint_text": "", "type": "radio", @@ -143,11 +143,11 @@ } }, "household_number_of_other_members":{ - "check_answer_label": "Number of Other Household Members", "header": "", "description": "", "questions":{ "household_number_of_other_members": { + "check_answer_label": "Number of Other Household Members", "header": "How many other people are there in the household?", "hint_text": "The maximum number of others is 7", "type": "numeric", diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 78cc23b25..598fc9564 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -10,9 +10,9 @@ RSpec.describe CheckAnswersHelper do expect(get_answered_questions_total(subsection_pages, case_log)).to equal(0) end - it "returns 0 if only 1 question on a page gets answered" do + it "returns 1 if 1 question gets answered" do case_log["net_income"] = "123" - expect(get_answered_questions_total(subsection_pages, case_log)).to equal(0) + expect(get_answered_questions_total(subsection_pages, case_log)).to equal(1) end end end