From c15fc54f8dbe23e71f0bddd64726221ecf8fcac1 Mon Sep 17 00:00:00 2001 From: Ted-U Date: Fri, 12 Aug 2022 15:39:48 +0100 Subject: [PATCH] fix pushing to wrong branch --- ...swers_summary_list_card_component.html.erb | 25 +++++++++++++++++++ ...eck_answers_summary_list_card_component.rb | 18 +++++++++++++ app/helpers/check_answers_helper.rb | 4 --- app/models/form/question.rb | 3 ++- app/views/form/check_answers.html.erb | 10 +++++--- app/views/form/review.html.erb | 5 +--- config/forms/2021_2022.json | 10 ++++++++ ...nswers_summary_list_card_component_spec.rb | 16 ++++++++++++ 8 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 app/components/check_answers_summary_list_card_component.html.erb create mode 100644 app/components/check_answers_summary_list_card_component.rb create mode 100644 spec/components/check_answers_summary_list_card_component_spec.rb diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb new file mode 100644 index 000000000..c93f28b60 --- /dev/null +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -0,0 +1,25 @@ +
+<%= govuk_summary_list do |summary_list| %> + <% 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) %> + <% 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| %> + <%= inferred_answer %> + <% end %> + <% end %> + <% row.action( + 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 760c08ab0..f412c5464 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -41,8 +41,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/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index 8db15d81e..abd0ed914 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -17,10 +17,12 @@ <% end %> <%= display_answered_questions_summary(subsection, @case_log, current_user) %> - <%= render partial: "form/check_answers_summary_list", locals: { - subsection:, - case_log: @case_log, - } %> + <% subsection.applicable_questions(@case_log).group_by(&:check_answers_card_number).values.each do |question_group| %> + <%= render CheckAnswersSummaryListCardComponent.new(questions: question_group, case_log: @case_log, user: current_user) %> +
+
+
+ <% end %> <%= 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 3c8777359..ec1db6f2a 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 ffbdc0887..10d0e93e3 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1063,6 +1063,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": { @@ -1077,6 +1078,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.", @@ -1176,6 +1178,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", @@ -1307,6 +1310,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", @@ -1419,6 +1423,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", @@ -1652,6 +1657,7 @@ "ecstat1": { "check_answer_label": "Lead tenant’s working situation", "header": "Which of these best describes the lead tenant’s working situation?", + "check_answers_card_number": 0, "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", "answer_options": { @@ -1789,6 +1795,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", @@ -1832,6 +1839,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", @@ -2005,6 +2013,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": { @@ -2126,6 +2135,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