Browse Source

Use questions instead of pages in check answers

pull/25/head
MadeTech Dushan 3 years ago
parent
commit
26cca734fa
  1. 4
      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

4
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|
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

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

@ -1,13 +1,13 @@
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= page_info["check_answer_label"].to_s %>
<%= question_info["check_answer_label"].to_s %>
<dt>
<dd class="govuk-summary-list__value">
<%= case_log[page] %>
<%= case_log[question_title] %>
</dd>
<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>
</div>
</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>
<%= 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" %>

14
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",

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)
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

Loading…
Cancel
Save