From 516fa44a8c0c7aa8928184966178a05d7ff619b5 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Tue, 2 Jan 2024 10:12:09 +0000
Subject: [PATCH] Do not highlight unanswered optional questions in red (#2110)
---
.../check_answers_summary_list_card_component.rb | 6 +++---
app/helpers/check_answers_helper.rb | 6 +++---
...heck_answers_summary_list_card_component_spec.rb | 13 +++++++++++++
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb
index 650a7d8a3..8f18b1ffc 100644
--- a/app/components/check_answers_summary_list_card_component.rb
+++ b/app/components/check_answers_summary_list_card_component.rb
@@ -14,7 +14,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
end
def get_answer_label(question)
- question.answer_label(log, user).presence || unanswered_value
+ question.answer_label(log, user).presence || unanswered_value(question)
end
def get_question_label(question)
@@ -34,8 +34,8 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
private
- def unanswered_value
- if log.creation_method_bulk_upload? && log.bulk_upload.present?
+ def unanswered_value(question)
+ if log.creation_method_bulk_upload? && log.bulk_upload.present? && !log.optional_fields.include?(question.id)
"You still need to answer this question".html_safe
else
"You didn’t answer this question".html_safe
diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb
index 761a7ac44..0209d8e14 100644
--- a/app/helpers/check_answers_helper.rb
+++ b/app/helpers/check_answers_helper.rb
@@ -47,15 +47,15 @@ private
end
def get_answer_label(question, lettings_log)
- question.answer_label(lettings_log, current_user).presence || unanswered_value(log: lettings_log)
+ question.answer_label(lettings_log, current_user).presence || unanswered_value(log: lettings_log, question:)
end
def get_question_label(question)
[question.question_number_string, question.check_answer_label.to_s.presence || question.header.to_s].compact.join(" - ")
end
- def unanswered_value(log:)
- if log.creation_method_bulk_upload? && log.bulk_upload.present?
+ def unanswered_value(log:, question:)
+ if log.creation_method_bulk_upload? && log.bulk_upload.present? && !log.optional_fields.include?(question.id)
"You still need to answer this question".html_safe
else
"You didn’t answer this question".html_safe
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 63af2cf84..f2b300d57 100644
--- a/spec/components/check_answers_summary_list_card_component_spec.rb
+++ b/spec/components/check_answers_summary_list_card_component_spec.rb
@@ -67,6 +67,19 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question")
end
end
+
+ context "when log was created via a bulk upload and has an unanswered optional question" do
+ subject(:component) { described_class.new(questions:, log:, user:) }
+
+ let(:subsection_id) { "setup" }
+ let(:bulk_upload) { create(:bulk_upload) }
+ let(:log) { build(:lettings_log, :completed, creation_method: "bulk upload", tenancycode: nil, startdate: Time.zone.local(2021, 5, 1), bulk_upload:) }
+
+ it "displays tweaked copy in red" do
+ expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question")
+ expect(rendered).not_to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question")
+ end
+ end
end
end