Browse Source

ensure bulk upload answers are red (#1664)

pull/1688/head
Phil Lee 2 years ago committed by GitHub
parent
commit
3ced8390b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/helpers/check_answers_helper.rb
  2. 5
      app/views/form/_check_answers_summary_list.html.erb
  3. 14
      spec/helpers/check_answers_helper_spec.rb

14
app/helpers/check_answers_helper.rb

@ -46,10 +46,22 @@ 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 || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe question.answer_label(lettings_log, current_user).presence || unanswered_value(log: lettings_log)
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:)
if bulk_uploaded?(log:)
"<span class=\"app-!-colour-red\">You still need to answer this question</span>".html_safe
else
"<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end
end
def bulk_uploaded?(log:)
log.bulk_upload
end
end end

5
app/views/form/_check_answers_summary_list.html.erb

@ -2,13 +2,16 @@
<% questions.each do |question| %> <% questions.each do |question| %>
<% summary_list.row do |row| %> <% summary_list.row do |row| %>
<% row.key { get_question_label(question) } %> <% row.key { get_question_label(question) } %>
<% row.value do %> <% row.value do %>
<%= simple_format( <%= simple_format(
get_answer_label(question, @log), get_answer_label(question, @log),
wrapper_tag: "span", wrapper_tag: "span",
class: "govuk-!-margin-right-4", class: "govuk-!-margin-right-4",
) %> ) %>
<% extra_value = question.get_extra_check_answer_value(@log) %> <% extra_value = question.get_extra_check_answer_value(@log) %>
<% if extra_value && question.answer_label(@log, current_user).present? %> <% if extra_value && question.answer_label(@log, current_user).present? %>
<%= simple_format( <%= simple_format(
extra_value, extra_value,
@ -16,10 +19,12 @@
class: "govuk-!-font-weight-regular app-!-colour-muted", class: "govuk-!-font-weight-regular app-!-colour-muted",
) %> ) %>
<% end %> <% end %>
<% question.get_inferred_answers(@log).each do |inferred_answer| %> <% question.get_inferred_answers(@log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span> <span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %> <% end %>
<% end %> <% end %>
<% if @log.collection_period_open? %> <% if @log.collection_period_open? %>
<% row.action( <% row.action(
text: question.action_text(@log), text: question.action_text(@log),

14
spec/helpers/check_answers_helper_spec.rb

@ -11,8 +11,6 @@ RSpec.describe CheckAnswersHelper do
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
example.run example.run
end end
Timecop.return
Singleton.__init__(FormHandler)
end end
describe "display_answered_questions_summary" do describe "display_answered_questions_summary" do
@ -37,4 +35,16 @@ RSpec.describe CheckAnswersHelper do
end end
end end
end end
describe "#get_answer_label" do
context "when unanswered and bulk upload" do
let(:question) { log.form.questions.sample }
let(:bulk_upload) { build(:bulk_upload, :sales) }
let(:log) { build(:sales_log, bulk_upload:) }
it "is red" do
expect(get_answer_label(question, log)).to include("red")
end
end
end
end end

Loading…
Cancel
Save