From c41acd442fb0b93ec75c08e74c7917f92ac5058a Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Thu, 2 Feb 2023 14:19:39 +0000 Subject: [PATCH] CLDC-1775 Bulk upload check your answers treatment (#1262) * 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 * different CYA treatment when for bulk upload * bulk upload CYA missing answers always red - whereas previosly this only happened if user was filtering logs via a bulk upload --- ...swers_summary_list_card_component.html.erb | 6 +++ ...eck_answers_summary_list_card_component.rb | 15 +++++++- app/controllers/lettings_logs_controller.rb | 4 +- app/frontend/styles/application.scss | 4 ++ app/services/filter_service.rb | 18 +++++++++ ...nswers_summary_list_card_component_spec.rb | 38 +++++++++++++++---- 6 files changed, 74 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..874ac8c10 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -5,6 +5,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base @questions = questions @log = log @user = user + super end @@ -13,7 +14,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 +37,18 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base private + def unanswered_value + if bulk_uploaded? + "You still need to answer this question".html_safe + else + "You didn’t answer this question".html_safe + end + end + + def bulk_uploaded? + log.bulk_upload + end + def number_of_buyers log[:jointpur] == 1 ? 2 : 1 end diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index a7bc2dc56..5181d21ca 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/app/controllers/lettings_logs_controller.rb @@ -119,8 +119,8 @@ private end def extract_bulk_upload_from_session_filters - id = ((@session_filters["bulk_upload_id"] || []).reject(&:blank?))[0] - @bulk_upload = current_user.bulk_uploads.find_by(id:) + filter_service = FilterService.new(current_user:, session:) + @bulk_upload = filter_service.bulk_upload end def permitted_log_params 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/app/services/filter_service.rb b/app/services/filter_service.rb index 4ef3a582c..affe31f02 100644 --- a/app/services/filter_service.rb +++ b/app/services/filter_service.rb @@ -27,4 +27,22 @@ class FilterService logs end end + + attr_reader :current_user, :session + + def initialize(current_user:, session:) + @current_user = current_user + @session = session + end + + def bulk_upload + id = ((logs_filters["bulk_upload_id"] || []).reject(&:blank?))[0] + @bulk_upload ||= current_user.bulk_uploads.find_by(id:) + end + +private + + def logs_filters + JSON.parse(session[:logs_filters] || "{}") || {} + end end 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..f9b8f6667 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,49 @@ 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 log was created via a bulk upload and has an unanswered question" do + subject(:component) { described_class.new(questions:, log:, user:) } + + 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 "displays 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 + + context "when log was not created via a bulk upload and has an unanswered question" do + subject(:component) { described_class.new(questions:, log:, user:) } + + let(:log) { build(:lettings_log, :in_progress, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } + + it "displays normal copy with muted colour " do + expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question") + end end end end