Browse Source

Merge pull request #280 from communitiesuk/feature/CLDC-835-add-radio-hint

CLDC-835: support hint on radio/checkbox questions
pull/293/head
Kidd Hustle 3 years ago committed by GitHub
parent
commit
e47dab322b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/models/form/question.rb
  2. 5
      app/views/form/_checkbox_question.html.erb
  3. 8
      app/views/form/_radio_question.html.erb
  4. 2364
      config/forms/2021_2022.json
  5. 2
      spec/features/form/check_answers_page_spec.rb
  6. 292
      spec/fixtures/forms/2021_2022.json
  7. 4
      spec/models/form/question_spec.rb

3
app/models/form/question.rb

@ -40,7 +40,6 @@ class Form::Question
answer = case_log[id].to_s if case_log[id].present? answer = case_log[id].to_s if case_log[id].present?
answer_label = [prefix, format_value(answer), suffix_label(case_log)].join("") if answer answer_label = [prefix, format_value(answer), suffix_label(case_log)].join("") if answer
return answer_label if answer_label return answer_label if answer_label
has_inferred_check_answers_value?(case_log) ? inferred_check_answers_value["value"] : "" has_inferred_check_answers_value?(case_log) ? inferred_check_answers_value["value"] : ""
@ -95,7 +94,7 @@ private
def checkbox_answer_label(case_log) def checkbox_answer_label(case_log)
answer = [] answer = []
answer_options.each { |key, value| case_log[key] == "Yes" ? answer << value : nil } answer_options.each { |key, options| case_log[key] == "Yes" ? answer << options["value"] : nil }
answer.join(", ") answer.join(", ")
end end

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

@ -6,13 +6,14 @@
hint: { text: question.hint_text&.html_safe } do %> hint: { text: question.hint_text&.html_safe } do %>
<% after_divider = false %> <% after_divider = false %>
<% question.answer_options.map do |key, val| %> <% question.answer_options.map do |key, options| %>
<% if key.starts_with?("divider") %> <% if key.starts_with?("divider") %>
<% after_divider = true %> <% after_divider = true %>
<%= f.govuk_check_box_divider %> <%= f.govuk_check_box_divider %>
<% else %> <% else %>
<%= f.govuk_check_box question.id, key, <%= f.govuk_check_box question.id, key,
label: { text: val }, label: { text: options['value'] },
hint: { text: options['hint'] },
checked: @case_log[key] == "Yes", checked: @case_log[key] == "Yes",
exclusive: after_divider, exclusive: after_divider,
**stimulus_html_attributes(question) **stimulus_html_attributes(question)

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

@ -5,15 +5,15 @@
legend: legend(question, page_header, conditional), legend: legend(question, page_header, conditional),
hint: { text: question.hint_text&.html_safe } do %> hint: { text: question.hint_text&.html_safe } do %>
<% question.answer_options.map do |key, val| %> <% question.answer_options.map do |key, options| %>
<% if key.starts_with?("divider") %> <% if key.starts_with?("divider") %>
<%= f.govuk_radio_divider %> <%= f.govuk_radio_divider %>
<% else %> <% else %>
<% conditional_question = find_conditional_question(@page, question, val) %> <% conditional_question = find_conditional_question(@page, question, options['value']) %>
<% if conditional_question.nil? %> <% if conditional_question.nil? %>
<%= f.govuk_radio_button question.id, val, label: { text: val }, **stimulus_html_attributes(question) %> <%= f.govuk_radio_button question.id, options['value'], label: { text: options['value'] }, hint: { text: options['hint'] }, **stimulus_html_attributes(question) %>
<% else %> <% else %>
<%= f.govuk_radio_button question.id, val, label: { text: val }, **stimulus_html_attributes(question) do %> <%= f.govuk_radio_button question.id, options['value'], label: { text: options['value'] }, hint: { text: options['hint'] }, **stimulus_html_attributes(question) do %>
<%= render partial: "#{conditional_question.type}_question", locals: { <%= render partial: "#{conditional_question.type}_question", locals: {
question: conditional_question, question: conditional_question,
caption_text: caption_text, caption_text: caption_text,

2364
config/forms/2021_2022.json

File diff suppressed because it is too large Load Diff

2
spec/features/form/check_answers_page_spec.rb

@ -110,7 +110,7 @@ RSpec.describe "Form Check Answers Page" do
it "displays conditional question that were visited" do it "displays conditional question that were visited" do
visit("/logs/#{id}/conditional-question") visit("/logs/#{id}/conditional-question")
choose("case-log-preg-occ-no-field") choose("case-log-preg-occ-no-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
visit("/logs/#{id}/#{conditional_subsection}/check-answers") visit("/logs/#{id}/#{conditional_subsection}/check-answers")
question_labels = ["Has the condition been met?", "Has the condition not been met?"] question_labels = ["Has the condition been met?", "Has the condition not been met?"]

292
spec/fixtures/forms/2021_2022.json vendored

@ -39,10 +39,18 @@
"header": "Which of these best describes the tenant’s gender identity?", "header": "Which of these best describes the tenant’s gender identity?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Female", "0": {
"1": "Male", "value": "Female"
"2": "Non-binary", },
"3": "Prefer not to say" "1": {
"value": "Male"
},
"2": {
"value": "Non-binary"
},
"3": {
"value": "Prefer not to say"
}
} }
} }
} }
@ -70,8 +78,12 @@
"header": "What’s person 2’s relationship to lead tenant", "header": "What’s person 2’s relationship to lead tenant",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Other", "0": {
"1": "Prefer not to say" "value": "Other"
},
"1": {
"value": "Prefer not to say"
}
} }
}, },
"age2": { "age2": {
@ -88,10 +100,18 @@
"header": "Which of these best describes person 2’s gender identity?", "header": "Which of these best describes person 2’s gender identity?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Female", "0": {
"1": "Male", "value": "Female"
"2": "Non-binary", },
"3": "Prefer not to say" "1": {
"value": "Male"
},
"2": {
"value": "Non-binary"
},
"3": {
"value": "Prefer not to say"
}
} }
}, },
"ecstat2": { "ecstat2": {
@ -99,8 +119,12 @@
"header": "Which of these best describes person 2’s working situation?", "header": "Which of these best describes person 2’s working situation?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Other", "0": {
"1": "Prefer not to say" "value": "Other"
},
"1": {
"value": "Prefer not to say"
}
} }
} }
} }
@ -128,11 +152,21 @@
"type": "radio", "type": "radio",
"check_answer_label": "Armed Forces", "check_answer_label": "Armed Forces",
"answer_options": { "answer_options": {
"0":"A current or former regular in the UK Armed Forces (excluding National Service)", "0":{
"1":"A current or former reserve in the UK Armed Forces (excluding National Service)", "value": "A current or former regular in the UK Armed Forces (excluding National Service)"
"2": "A spouse / civil partner of a UK Armed Forces member who has separated or been bereaved within the last 2 years", },
"3": "No", "1": {
"4": "Tenant prefers not to say" "value": "A current or former reserve in the UK Armed Forces (excluding National Service)"
},
"2": {
"value": "A spouse / civil partner of a UK Armed Forces member who has separated or been bereaved within the last 2 years"
},
"3": {
"value": "No"
},
"4": {
"value": "Tenant prefers not to say"
}
}, },
"conditional_for": { "conditional_for": {
"leftreg": ["A current or former regular in the UK Armed Forces (excluding National Service)"] "leftreg": ["A current or former regular in the UK Armed Forces (excluding National Service)"]
@ -153,11 +187,21 @@
"type": "radio", "type": "radio",
"check_answer_label": "Physical, mental health or illness in the household", "check_answer_label": "Physical, mental health or illness in the household",
"answer_options": { "answer_options": {
"0": "Yes", "0": {
"1": "No", "value": "Yes"
"divider": true, },
"2": "Don’t know", "1": {
"3": "Prefer not to say" "value": "No"
},
"divider": {
"value": true
},
"2": {
"value": "Don’t know"
},
"3": {
"value": "Prefer not to say"
}
} }
} }
} }
@ -170,11 +214,21 @@
"type": "checkbox", "type": "checkbox",
"check_answer_label": "Disability requirements", "check_answer_label": "Disability requirements",
"answer_options": { "answer_options": {
"housingneeds_a": "Fully wheelchair accessible housing", "housingneeds_a": {
"housingneeds_b": "Wheelchair access to essential rooms", "value": "Fully wheelchair accessible housing"
"housingneeds_c": "Level access housing", },
"divider": true, "housingneeds_b": {
"housingneeds_h": "Don’t know" "value": "Wheelchair access to essential rooms"
},
"housingneeds_c": {
"value": "Level access housing"
},
"divider": {
"value": true
},
"housingneeds_h": {
"value": "Don’t know"
}
} }
} }
} }
@ -205,8 +259,12 @@
"type": "checkbox", "type": "checkbox",
"check_answer_label": "Conditions or illnesses", "check_answer_label": "Conditions or illnesses",
"answer_options": { "answer_options": {
"illness_type_1": "Vision - such as blindness or partial sight", "illness_type_1": {
"illness_type_2": "Hearing - such as deafness or partial hearing" "value": "Vision - such as blindness or partial sight"
},
"illness_type_2": {
"value": "Hearing - such as deafness or partial hearing"
}
} }
} }
} }
@ -264,8 +322,12 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "No", "0": {
"1": "Yes" "value": "No"
},
"1": {
"value": "Yes"
}
} }
} }
}, },
@ -278,8 +340,12 @@
"header": "Is the property built or adapted to wheelchair-user standards?", "header": "Is the property built or adapted to wheelchair-user standards?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Yes", "0": {
"1": "No" "value": "Yes"
},
"1": {
"value": "No"
}
} }
} }
} }
@ -296,8 +362,12 @@
"header": "Has the condition been met?", "header": "Has the condition been met?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Yes", "0": {
"1": "No" "value": "Yes"
},
"1": {
"value": "No"
}
} }
} }
} }
@ -309,8 +379,12 @@
"header": "Has the next condition been met?", "header": "Has the next condition been met?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Yes", "0": {
"1": "No" "value": "Yes"
},
"1": {
"value": "No"
}
} }
} }
}, },
@ -323,8 +397,12 @@
"header": "Has the next condition not been met?", "header": "Has the next condition not been met?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Yes", "0": {
"1": "No" "value": "Yes"
},
"1": {
"value": "No"
}
} }
} }
}, },
@ -337,8 +415,12 @@
"header": "Has the next condition not been met again?", "header": "Has the next condition not been met again?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Yes", "0": {
"1": "No" "value": "Yes"
},
"1": {
"value": "No"
}
} }
} }
}, },
@ -378,9 +460,15 @@
"header": "How often do they receive this income?", "header": "How often do they receive this income?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Weekly", "0": {
"1": "Monthly", "value": "Weekly"
"2": "Yearly" },
"1": {
"value": "Monthly"
},
"2": {
"value": "Yearly"
}
} }
} }
}, },
@ -401,8 +489,12 @@
"header": "How much of the tenant’s income is from Universal Credit, state pensions or benefits?", "header": "How much of the tenant’s income is from Universal Credit, state pensions or benefits?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "All", "0": {
"1": "Some" "value":"All"
},
"1": {
"value":"Some"
}
} }
} }
} }
@ -414,8 +506,12 @@
"header": "Is the tenant likely to be in receipt of any of these housing-related benefits?", "header": "Is the tenant likely to be in receipt of any of these housing-related benefits?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Housing benefit", "0": {
"1": "Tenant prefers not to say" "value": "Housing benefit"
},
"1": {
"value": "Tenant prefers not to say"
}
}, },
"conditional_for": { "conditional_for": {
"conditional_question": ["Housing benefit"] "conditional_question": ["Housing benefit"]
@ -426,8 +522,12 @@
"header": "Question to test page conditions", "header": "Question to test page conditions",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Option A", "0": {
"1": "Option B" "value": "Option A"
},
"1": {
"value": "Option B"
}
} }
} }
} }
@ -440,8 +540,12 @@
"header": "Question to test page routing", "header": "Question to test page routing",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Option A", "0": {
"1": "Option B" "value": "Option A"
},
"1": {
"value": "Option B"
}
} }
} }
} }
@ -458,8 +562,12 @@
"header": "Which period are rent and other charges due?", "header": "Which period are rent and other charges due?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Weekly for 52 weeks", "0": {
"1": "Every 2 weeks" "value": "Weekly for 52 weeks"
},
"1": {
"value": "Every 2 weeks"
}
} }
}, },
"brent": { "brent": {
@ -573,15 +681,33 @@
"header": "How long has the household continuously lived in the local authority area where the new letting is located?", "header": "How long has the household continuously lived in the local authority area where the new letting is located?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Just moved to local authority area", "0": {
"1": "Less than 1 year", "value": "Just moved to local authority area"
"2": "1 to 2 years", },
"3": "2 to 3 years", "1": {
"4": "3 to 4 years", "value": "Less than 1 year"
"5": "4 to 5 years", },
"6": "5 years or more", "2": {
"divider": true, "value": "1 to 2 years"
"7": "Don’t know" },
"3": {
"value": "2 to 3 years"
},
"4": {
"value": "3 to 4 years"
},
"5": {
"value": "4 to 5 years"
},
"6": {
"value": "5 years or more"
},
"divider": {
"value": true
},
"7": {
"value": "Don’t know"
}
} }
} }
} }
@ -593,15 +719,33 @@
"header": "How long has the household been on the local authority waiting list where the new letting is located?", "header": "How long has the household been on the local authority waiting list where the new letting is located?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"0": "Just moved to local authority area", "0": {
"1": "Less than 1 year", "value": "Just moved to local authority area"
"2": "1 to 2 years", },
"3": "2 to 3 years", "1": {
"4": "3 to 4 years", "value": "Less than 1 year"
"5": "4 to 5 years", },
"6": "5 years or more", "2": {
"divider": true, "value": "1 to 2 years"
"7": "Don’t know" },
"3": {
"value": "2 to 3 years"
},
"4": {
"value": "3 to 4 years"
},
"5": {
"value": "4 to 5 years"
},
"6": {
"value": "5 years or more"
},
"divider": {
"value": true
},
"7": {
"value": "Don’t know"
}
} }
} }
} }
@ -658,7 +802,9 @@
"header": "Submit your lettings log ", "header": "Submit your lettings log ",
"type": "checkbox", "type": "checkbox",
"answer_options": { "answer_options": {
"declaration": "The tenant has seen the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice" "declaration": {
"value": "The tenant has seen the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice"
}
} }
} }
} }

4
spec/models/form/question_spec.rb

@ -59,7 +59,7 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "incfreq" } let(:question_id) { "incfreq" }
it "has answer options" do it "has answer options" do
expected_answer_options = { "0" => "Weekly", "1" => "Monthly", "2" => "Yearly" } expected_answer_options = { "0" => { "value" => "Weekly" }, "1" => { "value" => "Monthly" }, "2" => { "value" => "Yearly" } }
expect(question.answer_options).to eq(expected_answer_options) expect(question.answer_options).to eq(expected_answer_options)
end end
end end
@ -69,7 +69,7 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "dependent_question" } let(:question_id) { "dependent_question" }
it "has answer options" do it "has answer options" do
expected_answer_options = { "0" => "Option A", "1" => "Option B" } expected_answer_options = { "0" => { "value" => "Option A" }, "1" => { "value" => "Option B" } }
expect(question.answer_options).to eq(expected_answer_options) expect(question.answer_options).to eq(expected_answer_options)
end end
end end

Loading…
Cancel
Save