Browse Source

Do not highlight unanswered optional questions in red (#2110)

pull/2109/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
516fa44a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/components/check_answers_summary_list_card_component.rb
  2. 6
      app/helpers/check_answers_helper.rb
  3. 13
      spec/components/check_answers_summary_list_card_component_spec.rb

6
app/components/check_answers_summary_list_card_component.rb

@ -14,7 +14,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
end end
def get_answer_label(question) def get_answer_label(question)
question.answer_label(log, user).presence || unanswered_value question.answer_label(log, user).presence || unanswered_value(question)
end end
def get_question_label(question) def get_question_label(question)
@ -34,8 +34,8 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
private private
def unanswered_value def unanswered_value(question)
if log.creation_method_bulk_upload? && log.bulk_upload.present? if log.creation_method_bulk_upload? && log.bulk_upload.present? && !log.optional_fields.include?(question.id)
"<span class=\"app-!-colour-red\">You still need to answer this question</span>".html_safe "<span class=\"app-!-colour-red\">You still need to answer this question</span>".html_safe
else else
"<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe

6
app/helpers/check_answers_helper.rb

@ -47,15 +47,15 @@ private
end end
def get_answer_label(question, lettings_log) 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 end
def get_question_label(question) def get_question_label(question)
[question.question_number_string, question.check_answer_label.to_s.presence || question.header.to_s].compact.join(" - ") [question.question_number_string, question.check_answer_label.to_s.presence || question.header.to_s].compact.join(" - ")
end end
def unanswered_value(log:) def unanswered_value(log:, question:)
if log.creation_method_bulk_upload? && log.bulk_upload.present? if log.creation_method_bulk_upload? && log.bulk_upload.present? && !log.optional_fields.include?(question.id)
"<span class=\"app-!-colour-red\">You still need to answer this question</span>".html_safe "<span class=\"app-!-colour-red\">You still need to answer this question</span>".html_safe
else else
"<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe

13
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") expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question")
end end
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
end end

Loading…
Cancel
Save