Browse Source

Check that bulk upload is present (#1802)

* Check that bulk upload is present

* test
pull/1803/head v0.3.43
kosiakkatrina 1 year ago committed by GitHub
parent
commit
1f400c8223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/components/check_answers_summary_list_card_component.rb
  2. 2
      app/helpers/check_answers_helper.rb
  3. 2
      app/helpers/log_actions_helper.rb
  4. 13
      spec/components/check_answers_summary_list_card_component_spec.rb
  5. 3
      spec/helpers/check_answers_helper_spec.rb
  6. 12
      spec/views/logs/edit.html.erb_spec.rb

2
app/components/check_answers_summary_list_card_component.rb

@ -35,7 +35,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
private private
def unanswered_value def unanswered_value
if log.creation_method_bulk_upload? if log.creation_method_bulk_upload? && log.bulk_upload.present?
"<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

2
app/helpers/check_answers_helper.rb

@ -54,7 +54,7 @@ private
end end
def unanswered_value(log:) def unanswered_value(log:)
if log.creation_method_bulk_upload? if log.creation_method_bulk_upload? && log.bulk_upload.present?
"<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

2
app/helpers/log_actions_helper.rb

@ -16,7 +16,7 @@ private
def back_button_for(log) def back_button_for(log)
if log.completed? if log.completed?
if log.creation_method_bulk_upload? if log.creation_method_bulk_upload? && log.bulk_upload.present?
if log.lettings? if log.lettings?
govuk_button_link_to "Back to uploaded logs", resume_bulk_upload_lettings_result_path(log.bulk_upload) govuk_button_link_to "Back to uploaded logs", resume_bulk_upload_lettings_result_path(log.bulk_upload)
else else

13
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 context "when log was created via a bulk upload and has an unanswered question" do
subject(:component) { described_class.new(questions:, log:, user:) } 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 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") expect(rendered).to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question")
end end
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 context "when log was not created via a bulk upload and has an unanswered question" do
subject(:component) { described_class.new(questions:, log:, user:) } subject(:component) { described_class.new(questions:, log:, user:) }

3
spec/helpers/check_answers_helper_spec.rb

@ -39,7 +39,8 @@ RSpec.describe CheckAnswersHelper do
describe "#get_answer_label" do describe "#get_answer_label" do
context "when unanswered and bulk upload" do context "when unanswered and bulk upload" do
let(:question) { log.form.questions.sample } 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 it "is red" do
expect(get_answer_label(question, log)).to include("red") expect(get_answer_label(question, log)).to include("red")

12
spec/views/logs/edit.html.erb_spec.rb

@ -88,6 +88,18 @@ RSpec.describe "logs/edit.html.erb" do
end end
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 context "when sales log is bulk uploaded" do
let(:bulk_upload) { create(:bulk_upload, :sales) } let(:bulk_upload) { create(:bulk_upload, :sales) }
let(:log) { create(:sales_log, :completed, bulk_upload:, creation_method: "bulk upload") } let(:log) { create(:sales_log, :completed, bulk_upload:, creation_method: "bulk upload") }

Loading…
Cancel
Save