From cce102ae2546ea6814d583a6a9a3286e8f40eed3 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 1 Feb 2023 15:39:36 +0000 Subject: [PATCH] CYA summary list tweaks for bulk upload - When checking answers for a bulk upload related log the copy is tweaked and made red as per designs --- ...swers_summary_list_card_component.html.erb | 6 ++++ ...eck_answers_summary_list_card_component.rb | 16 +++++++++-- app/frontend/styles/application.scss | 4 +++ ...nswers_summary_list_card_component_spec.rb | 28 +++++++++++++------ 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb index 0005ed790..e5b5388ab 100644 --- a/app/components/check_answers_summary_list_card_component.html.erb +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -5,6 +5,7 @@

<%= check_answers_card_title(applicable_questions.first) %>

<% end %> +
<%= govuk_summary_list do |summary_list| %> <% applicable_questions.each do |question| %> @@ -12,15 +13,20 @@ <% 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(log) %> + <% if extra_value %> <%= extra_value %> <% end %> +
+ <% question.get_inferred_answers(log).each do |inferred_answer| %> <%= inferred_answer %> <% end %> <% end %> + <% if @log.collection_period_open? %> <% row.action( text: question.action_text(log), diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index 113303ba0..ad22d9e92 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -1,10 +1,12 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base - attr_reader :questions, :log, :user + attr_reader :questions, :log, :user, :bulk_upload - def initialize(questions:, log:, user:) + def initialize(questions:, log:, user:, bulk_upload: nil) @questions = questions @log = log @user = user + @bulk_upload = bulk_upload + super end @@ -13,7 +15,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base end def get_answer_label(question) - question.answer_label(log, user).presence || "You didn’t answer this question".html_safe + question.answer_label(log, user).presence || unanswered_value end def check_answers_card_title(question) @@ -36,6 +38,14 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base private + def unanswered_value + if bulk_upload + "You still need to answer this question".html_safe + else + "You didn’t answer this question".html_safe + end + end + def number_of_buyers log[:jointpur] == 1 ? 2 : 1 end diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 93d6dd99a..03a6ab6f2 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -51,6 +51,10 @@ $govuk-breakpoints: ( color: $govuk-secondary-text-colour !important; } +.app-\!-colour-red { + color: govuk-colour("red"); +} + .app-\!-font-tabular { @include govuk-font($size: false, $tabular: true); } diff --git a/spec/components/check_answers_summary_list_card_component_spec.rb b/spec/components/check_answers_summary_list_card_component_spec.rb index 6e63c90cd..ece39360a 100644 --- a/spec/components/check_answers_summary_list_card_component_spec.rb +++ b/spec/components/check_answers_summary_list_card_component_spec.rb @@ -1,27 +1,39 @@ require "rails_helper" RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do + subject(:component) { described_class.new(questions:, log:, user:) } + + let(:rendered) { render_inline(component) } + context "when given a set of questions" do - let(:user) { FactoryBot.build(:user) } - let(:log) { FactoryBot.build(:lettings_log, :completed, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } + let(:user) { build(:user) } + let(:log) { build(:lettings_log, :completed, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } let(:subsection_id) { "household_characteristics" } let(:subsection) { log.form.get_subsection(subsection_id) } let(:questions) { subsection.applicable_questions(log) } it "renders a summary list card for the answers to those questions" do - result = render_inline(described_class.new(questions:, log:, user:)) - expect(result).to have_content(questions.first.answer_label(log)) + expect(rendered).to have_content(questions.first.answer_label(log)) end it "applicable questions doesn't return questions that are hidden in check answers" do - summary_list = described_class.new(questions:, log:, user:) - expect(summary_list.applicable_questions.map(&:id).include?("retirement_value_check")).to eq(false) + expect(component.applicable_questions.map(&:id).include?("retirement_value_check")).to eq(false) end it "has the correct answer label for a question" do - summary_list = described_class.new(questions:, log:, user:) sex1_question = questions[2] - expect(summary_list.get_answer_label(sex1_question)).to eq("Female") + expect(component.get_answer_label(sex1_question)).to eq("Female") + end + + context "when filtered by bulk upload with unanswered question" do + subject(:component) { described_class.new(questions:, log:, user:, bulk_upload:) } + + let(:bulk_upload) { build(:bulk_upload, :lettings) } + let(:log) { build(:lettings_log, :in_progress, bulk_upload:, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } + + it "is displayed with tweaked copy in red" do + expect(rendered).to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question") + end end end end