diff --git a/app/views/form/_check_answers_summary_list.html.erb b/app/components/check_answers_summary_list_card_component.html.erb
similarity index 63%
rename from app/views/form/_check_answers_summary_list.html.erb
rename to app/components/check_answers_summary_list_card_component.html.erb
index d04dfa031..c93f28b60 100644
--- a/app/views/form/_check_answers_summary_list.html.erb
+++ b/app/components/check_answers_summary_list_card_component.html.erb
@@ -1,23 +1,25 @@
+
<%= govuk_summary_list do |summary_list| %>
- <% total_applicable_questions(subsection, @case_log, current_user).each do |question| %>
+ <% applicable_questions.each do |question| %>
<% summary_list.row do |row| %>
<% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %>
<% row.value do %>
- <%= get_answer_label(question, @case_log) %>
- <% extra_value = question.get_extra_check_answer_value(@case_log) %>
+ <%= get_answer_label(question) %>
+ <% extra_value = question.get_extra_check_answer_value(case_log) %>
<% if extra_value %>
<%= extra_value %>
<% end %>
- <% question.get_inferred_answers(@case_log).each do |inferred_answer| %>
+ <% question.get_inferred_answers(case_log).each do |inferred_answer| %>
<%= inferred_answer %>
<% end %>
<% end %>
<% row.action(
- text: question.action_text(@case_log),
- href: question.action_href(@case_log, question.page.id),
+ text: question.action_text(case_log),
+ href: question.action_href(case_log, question.page.id),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% end %>
<% end %>
<% end %>
+
diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb
new file mode 100644
index 000000000..0ae6afcac
--- /dev/null
+++ b/app/components/check_answers_summary_list_card_component.rb
@@ -0,0 +1,18 @@
+class CheckAnswersSummaryListCardComponent < ViewComponent::Base
+ attr_reader :questions, :case_log, :user
+
+ def initialize(questions:, case_log:, user:)
+ @questions = questions
+ @case_log = case_log
+ @user = user
+ super
+ end
+
+ def applicable_questions
+ questions.reject { |q| q.hidden_in_check_answers?(case_log, user) }
+ end
+
+ def get_answer_label(question)
+ question.answer_label(case_log).presence || "You didn’t answer this question".html_safe
+ end
+end
diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb
index 982cab7cc..bd5f15a50 100644
--- a/app/helpers/check_answers_helper.rb
+++ b/app/helpers/check_answers_helper.rb
@@ -28,8 +28,4 @@ private
def total_applicable_questions(subsection, case_log, current_user)
subsection.applicable_questions(case_log).reject { |q| q.hidden_in_check_answers?(case_log, current_user) }
end
-
- def get_answer_label(question, case_log)
- question.answer_label(case_log).presence || "You didn’t answer this question".html_safe
- end
end
diff --git a/app/models/form/question.rb b/app/models/form/question.rb
index c21477bc9..11fa40c0b 100644
--- a/app/models/form/question.rb
+++ b/app/models/form/question.rb
@@ -3,7 +3,7 @@ class Form::Question
:type, :min, :max, :step, :width, :fields_to_add, :result_field,
:conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value,
- :guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived
+ :guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived, :check_answers_card_number
module GuidancePosition
TOP = 1
@@ -37,6 +37,7 @@ class Form::Question
@suffix = hsh["suffix"]
@requires_js = hsh["requires_js"]
@fields_added = hsh["fields_added"]
+ @check_answers_card_number = hsh["check_answers_card_number"]
end
end
diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb
index 80a4db102..81d6a238c 100644
--- a/app/models/form/subsection.rb
+++ b/app/models/form/subsection.rb
@@ -34,6 +34,7 @@ class Form::Subsection
qs = applicable_questions(case_log)
qs_optional_removed = qs.reject { |q| case_log.optional_fields.include?(q.id) }
+ binding.pry if id == "income_and_benefits"
return :not_started if qs.count.positive? && qs.all? { |question| case_log[question.id].blank? || question.read_only? || question.derived? }
return :completed if qs_optional_removed.all? { |question| question.completed?(case_log) }
diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb
index 8db15d81e..a743e3dae 100644
--- a/app/views/form/check_answers.html.erb
+++ b/app/views/form/check_answers.html.erb
@@ -17,10 +17,7 @@
<% end %>
<%= display_answered_questions_summary(subsection, @case_log, current_user) %>
- <%= render partial: "form/check_answers_summary_list", locals: {
- subsection:,
- case_log: @case_log,
- } %>
+ <%= render CheckAnswersSummaryListCardComponent.new(questions: subsection.applicable_questions(@case_log), case_log: @case_log, user: current_user) %>
<%= form_with model: @case_log, method: "get" do |f| %>
<%= f.govuk_submit "Save and return to log" do %>
diff --git a/app/views/form/review.html.erb b/app/views/form/review.html.erb
index e8ff06a1f..b66985483 100644
--- a/app/views/form/review.html.erb
+++ b/app/views/form/review.html.erb
@@ -21,10 +21,7 @@
<%= subsection.label %>
- <%= render partial: "form/check_answers_summary_list", locals: {
- subsection:,
- case_log: @case_log,
- } %>
+ <%= render CheckAnswersSummaryListCardComponent.new(questions: subsection.applicable_questions(@case_log), case_log: @case_log, user: current_user) %>
<% end %>
diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json
index 7765ce9ba..5332cadbc 100644
--- a/config/forms/2021_2022.json
+++ b/config/forms/2021_2022.json
@@ -1056,6 +1056,7 @@
"header": "",
"guidance_partial": "privacy_notice",
"check_answer_label": "Tenant has seen the privacy notice",
+ "check_answers_card_number": 0,
"type": "checkbox",
"answer_options": {
"declaration": {
@@ -1070,6 +1071,7 @@
"description": "",
"questions": {
"hhmemb": {
+ "check_answers_card_number": 0,
"check_answer_label": "Number of household members",
"header": "How many people live in the household for this letting?",
"hint_text": "You can provide details for a maximum of 8 people.",
@@ -1165,6 +1167,7 @@
"description": "",
"questions": {
"age1_known": {
+ "check_answers_card_number": 1,
"header": "Do you know the lead tenant’s age?",
"hint_text": "The ’lead’ or ’main’ tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.",
"type": "radio",
@@ -1292,6 +1295,7 @@
"questions": {
"sex1": {
"check_answer_label": "Lead tenant’s gender identity",
+ "check_answers_card_number": 1,
"header": "Which of these best describes the lead tenant’s gender identity?",
"hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.",
"type": "radio",
@@ -1400,6 +1404,7 @@
"questions": {
"ethnic_group": {
"check_answer_label": "Lead tenant’s ethnic group",
+ "check_answers_card_number": 0,
"header": "What is the lead tenant’s ethnic group?",
"hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.",
"type": "radio",
@@ -1632,6 +1637,7 @@
"questions": {
"ecstat1": {
"check_answer_label": "Lead tenant’s working situation",
+ "check_answers_card_number": 0,
"header": "Which of these best describes the lead tenant’s working situation?",
"hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.",
"type": "radio",
@@ -1770,6 +1776,7 @@
"questions": {
"details_known_2": {
"check_answer_label": "Details known for person 2",
+ "check_answers_card_number": 1,
"header": "Do you know details for person 2?",
"hint_text": "You must provide details for everyone in the household if you know them.",
"type": "radio",
@@ -1813,6 +1820,7 @@
"questions": {
"relat2": {
"check_answer_label": "Person 2’s relationship to the lead tenant",
+ "check_answers_card_number": 1,
"header": "What is person 2’s relationship to the lead tenant?",
"hint_text": "",
"type": "radio",
@@ -1986,6 +1994,7 @@
"sex2": {
"check_answer_label": "Person 2’s gender identity",
"header": "Which of these best describes person 2’s gender identity?",
+ "check_answers_card_number": 1,
"hint_text": "",
"type": "radio",
"answer_options": {
@@ -2107,6 +2116,7 @@
"questions": {
"ecstat2": {
"check_answer_label": "Person 2’s working situation",
+ "check_answers_card_number": 1,
"header": "Which of these best describes person 2’s working situation?",
"hint_text": "",
"type": "radio",
diff --git a/spec/components/check_answers_summary_list_card_component_spec.rb b/spec/components/check_answers_summary_list_card_component_spec.rb
new file mode 100644
index 000000000..f1e8d4ce8
--- /dev/null
+++ b/spec/components/check_answers_summary_list_card_component_spec.rb
@@ -0,0 +1,16 @@
+require "rails_helper"
+
+RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
+ context "when given a set of questions" do
+ let(:user) { FactoryBot.build(:user) }
+ let(:case_log) { FactoryBot.build(:case_log, :completed) }
+ let(:subsection_id) { "household_characteristics" }
+ let(:subsection) { case_log.form.get_subsection(subsection_id) }
+ let(:questions) { subsection.applicable_questions(case_log) }
+
+ it "renders a summary list card for the answers to those questions" do
+ result = render_inline(described_class.new(questions:, case_log:, user:))
+ expect(result).to have_content(questions.first.answer_label(case_log))
+ end
+ end
+end