From 1f400c82231d23cab5504bf31174ea804775e835 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 25 Jul 2023 16:11:15 +0100 Subject: [PATCH] Check that bulk upload is present (#1802) * Check that bulk upload is present * test --- .../check_answers_summary_list_card_component.rb | 2 +- app/helpers/check_answers_helper.rb | 2 +- app/helpers/log_actions_helper.rb | 2 +- ...heck_answers_summary_list_card_component_spec.rb | 13 ++++++++++++- spec/helpers/check_answers_helper_spec.rb | 3 ++- spec/views/logs/edit.html.erb_spec.rb | 12 ++++++++++++ 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index d4e7650de..650a7d8a3 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -35,7 +35,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base private def unanswered_value - if log.creation_method_bulk_upload? + if log.creation_method_bulk_upload? && log.bulk_upload.present? "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 d235dbc6f..ed07f3b56 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -54,7 +54,7 @@ private end def unanswered_value(log:) - if log.creation_method_bulk_upload? + if log.creation_method_bulk_upload? && log.bulk_upload.present? "You still need to answer this question".html_safe else "You didn’t answer this question".html_safe diff --git a/app/helpers/log_actions_helper.rb b/app/helpers/log_actions_helper.rb index d6949e0cb..b0f950a5e 100644 --- a/app/helpers/log_actions_helper.rb +++ b/app/helpers/log_actions_helper.rb @@ -16,7 +16,7 @@ private def back_button_for(log) if log.completed? - if log.creation_method_bulk_upload? + if log.creation_method_bulk_upload? && log.bulk_upload.present? if log.lettings? govuk_button_link_to "Back to uploaded logs", resume_bulk_upload_lettings_result_path(log.bulk_upload) else 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 3dcafe104..63af2cf84 100644 --- a/spec/components/check_answers_summary_list_card_component_spec.rb +++ b/spec/components/check_answers_summary_list_card_component_spec.rb @@ -40,13 +40,24 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do context "when log was 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, creation_method: "bulk upload", age2: 99, startdate: Time.zone.local(2021, 5, 1)) } + let(:bulk_upload) { create(:bulk_upload) } + let(:log) { build(:lettings_log, :in_progress, creation_method: "bulk upload", age2: 99, 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-red", text: "You still need to answer this question") end end + context "when log was imported with a bulk upload creation method, without bulk upload id and has an unanswered question" do + subject(:component) { described_class.new(questions:, log:, user:) } + + let(:log) { build(:lettings_log, :in_progress, creation_method: "bulk upload", age2: 99, startdate: Time.zone.local(2021, 5, 1), bulk_upload_id: nil) } + + it "displays tweaked copy in red" do + expect(rendered).not_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:) } diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index f633801cb..bc9382127 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -39,7 +39,8 @@ RSpec.describe CheckAnswersHelper do describe "#get_answer_label" do context "when unanswered and bulk upload" do let(:question) { log.form.questions.sample } - let(:log) { build(:sales_log, creation_method: "bulk upload") } + let(:bulk_upload) { create(:bulk_upload) } + let(:log) { build(:sales_log, creation_method: "bulk upload", bulk_upload:) } it "is red" do expect(get_answer_label(question, log)).to include("red") diff --git a/spec/views/logs/edit.html.erb_spec.rb b/spec/views/logs/edit.html.erb_spec.rb index e28e0bc4b..9a511c32f 100644 --- a/spec/views/logs/edit.html.erb_spec.rb +++ b/spec/views/logs/edit.html.erb_spec.rb @@ -88,6 +88,18 @@ RSpec.describe "logs/edit.html.erb" do end end + context "when lettings log is bulk uploaded without a bulk upload id" do + let(:log) { create(:lettings_log, :completed, bulk_upload: nil, creation_method: "bulk upload") } + + it "does not have link 'Back to uploaded logs'" do + render + + fragment = Capybara::Node::Simple.new(rendered) + + expect(fragment).not_to have_link(text: "Back to uploaded logs") + end + end + context "when sales log is bulk uploaded" do let(:bulk_upload) { create(:bulk_upload, :sales) } let(:log) { create(:sales_log, :completed, bulk_upload:, creation_method: "bulk upload") }