Browse Source

Use questions instead of pages in check answers

pull/25/head
MadeTech Dushan 3 years ago
parent
commit
26cca734fa
  1. 6
      app/helpers/check_answers_helper.rb
  2. 6
      app/views/form/_check_answers_table.html.erb
  3. 4
      app/views/form/check_answers.html.erb
  4. 14
      config/forms/2021_2022.json
  5. 4
      spec/helpers/check_answers_helper_spec.rb

6
app/helpers/check_answers_helper.rb

@ -1,9 +1,9 @@
module CheckAnswersHelper module CheckAnswersHelper
def get_answered_questions_total(subsection_pages, case_log) def get_answered_questions_total(subsection_pages, case_log)
questions = subsection_pages.values.map do |page| questions = subsection_pages.values.flat_map do |page|
page["questions"].keys page["questions"].keys
end end
return questions.count {|questions_for_page| questions_for_page.none? { |question| case_log[question].blank?}} questions.count { |question| case_log[question].present? }
end end

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

@ -1,13 +1,13 @@
<dl class="govuk-summary-list govuk-!-margin-bottom-9"> <dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row"> <div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key"> <dt class="govuk-summary-list__key">
<%= page_info["check_answer_label"].to_s %> <%= question_info["check_answer_label"].to_s %>
<dt> <dt>
<dd class="govuk-summary-list__value"> <dd class="govuk-summary-list__value">
<%= case_log[page] %> <%= case_log[question_title] %>
</dd> </dd>
<dd class="govuk-summary-list__actions"> <dd class="govuk-summary-list__actions">
<%= create_update_answer_link(case_log[page], case_log["id"], page)%> <%= create_update_answer_link(case_log[question_title], case_log["id"], question_title)%>
</dd> </dd>
</div> </div>
</dl> </dl>

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

@ -3,7 +3,9 @@
<p>You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= subsection_pages.count %> questions</p> <p>You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= subsection_pages.count %> questions</p>
<%= create_next_missing_question_link(case_log["id"], subsection_pages, case_log) %> <%= create_next_missing_question_link(case_log["id"], subsection_pages, case_log) %>
<% subsection_pages.each do |page, page_info| %> <% 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 %> <% end %>
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>

14
config/forms/2021_2022.json

@ -10,11 +10,11 @@
"label": "Household characteristics", "label": "Household characteristics",
"pages": { "pages": {
"tenant_code":{ "tenant_code":{
"check_answer_label": "Tenant code",
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_code": { "tenant_code": {
"check_answer_label": "Tenant code",
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"
@ -22,11 +22,11 @@
} }
}, },
"tenant_age":{ "tenant_age":{
"check_answer_label": "Tenant's age",
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_age": { "tenant_age": {
"check_answer_label": "Tenant's age",
"header": "What is the tenant's age?", "header": "What is the tenant's age?",
"hint_text": "", "hint_text": "",
"type": "numeric", "type": "numeric",
@ -37,11 +37,11 @@
} }
}, },
"tenant_gender":{ "tenant_gender":{
"check_answer_label": "Tenant's gender",
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_gender": { "tenant_gender": {
"check_answer_label": "Tenant's gender",
"header": "Which of these best describes the tenant's gender identity?", "header": "Which of these best describes the tenant's gender identity?",
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
@ -55,11 +55,11 @@
} }
}, },
"tenant_ethnic_group":{ "tenant_ethnic_group":{
"check_answer_label": "Ethnicity",
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_ethnic_group": { "tenant_ethnic_group": {
"check_answer_label": "Ethnicity",
"header": "What is the tenant's ethnic group?", "header": "What is the tenant's ethnic group?",
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
@ -88,11 +88,11 @@
} }
}, },
"tenant_nationality":{ "tenant_nationality":{
"check_answer_label": "Nationality",
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_nationality": { "tenant_nationality": {
"check_answer_label": "Nationality",
"header": "What is the tenant's nationality?", "header": "What is the tenant's nationality?",
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
@ -118,11 +118,11 @@
} }
}, },
"tenant_economic_status":{ "tenant_economic_status":{
"check_answer_label": "Work",
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_economic_status": { "tenant_economic_status": {
"check_answer_label": "Work",
"header": "Which of these best describes the tenant's working situation?", "header": "Which of these best describes the tenant's working situation?",
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
@ -143,11 +143,11 @@
} }
}, },
"household_number_of_other_members":{ "household_number_of_other_members":{
"check_answer_label": "Number of Other Household Members",
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"household_number_of_other_members": { "household_number_of_other_members": {
"check_answer_label": "Number of Other Household Members",
"header": "How many other people are there in the household?", "header": "How many other people are there in the household?",
"hint_text": "The maximum number of others is 7", "hint_text": "The maximum number of others is 7",
"type": "numeric", "type": "numeric",

4
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) expect(get_answered_questions_total(subsection_pages, case_log)).to equal(0)
end 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" 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 end
end end

Loading…
Cancel
Save