Browse Source

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
pull/1264/head
Phil Lee 2 years ago committed by GitHub
parent
commit
c41acd442f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/components/check_answers_summary_list_card_component.html.erb
  2. 15
      app/components/check_answers_summary_list_card_component.rb
  3. 4
      app/controllers/lettings_logs_controller.rb
  4. 4
      app/frontend/styles/application.scss
  5. 18
      app/services/filter_service.rb
  6. 38
      spec/components/check_answers_summary_list_card_component_spec.rb

6
app/components/check_answers_summary_list_card_component.html.erb

@ -5,6 +5,7 @@
<h3 class="x-govuk-summary-card__title"><%= check_answers_card_title(applicable_questions.first) %></h3>
</div>
<% end %>
<div class="x-govuk-summary-card__body">
<%= 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 %>
<span class="govuk-!-margin-right-4"><%= get_answer_label(question) %></span>
<% extra_value = question.get_extra_check_answer_value(log) %>
<% if extra_value %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= extra_value %></span>
<% end %>
<br>
<% question.get_inferred_answers(log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %>
<% end %>
<% if @log.collection_period_open? %>
<% row.action(
text: question.action_text(log),

15
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 || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".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?
"<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.bulk_upload
end
def number_of_buyers
log[:jointpur] == 1 ? 2 : 1
end

4
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

4
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);
}

18
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

38
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

Loading…
Cancel
Save