From 90cfedb0e12eb10719c03a142f023c501ce4a6f0 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:21:06 +0000 Subject: [PATCH] Deletion report sales bug fix (#2235) * feat: don't display error row components for rows with no errors * feat: add failing test for bug * feat: remove redundant condition --- .../deletion_report.html.erb | 4 +++- .../deletion_report.html.erb | 4 +++- ...lk_upload_lettings_resume_controller_spec.rb | 17 +++++++++++++++++ .../bulk_upload_sales_resume_controller_spec.rb | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/views/bulk_upload_lettings_resume/deletion_report.html.erb b/app/views/bulk_upload_lettings_resume/deletion_report.html.erb index 2624012d4..881f9026c 100644 --- a/app/views/bulk_upload_lettings_resume/deletion_report.html.erb +++ b/app/views/bulk_upload_lettings_resume/deletion_report.html.erb @@ -18,7 +18,9 @@
<% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> - <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: all_answers_to_be_cleared(errors_for_row)) %> + <% if all_answers_to_be_cleared(errors_for_row).present? %> + <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: all_answers_to_be_cleared(errors_for_row)) %> + <% end %> <% end %>
diff --git a/app/views/bulk_upload_sales_resume/deletion_report.html.erb b/app/views/bulk_upload_sales_resume/deletion_report.html.erb index 3b6088c3c..299cff4f4 100644 --- a/app/views/bulk_upload_sales_resume/deletion_report.html.erb +++ b/app/views/bulk_upload_sales_resume/deletion_report.html.erb @@ -18,7 +18,9 @@
<% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> - <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: all_answers_to_be_cleared(errors_for_row)) %> + <% if all_answers_to_be_cleared(errors_for_row).present? %> + <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: all_answers_to_be_cleared(errors_for_row)) %> + <% end %> <% end %>
diff --git a/spec/requests/bulk_upload_lettings_resume_controller_spec.rb b/spec/requests/bulk_upload_lettings_resume_controller_spec.rb index ce2c3b7c6..c91211d5a 100644 --- a/spec/requests/bulk_upload_lettings_resume_controller_spec.rb +++ b/spec/requests/bulk_upload_lettings_resume_controller_spec.rb @@ -211,5 +211,22 @@ RSpec.describe BulkUploadLettingsResumeController, type: :request do expect(response).to redirect_to("/lettings-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") end end + + context "and has a row with all non-cleared errors" do + let(:bulk_upload_errors) { [create(:bulk_upload_error, row: 1), create(:bulk_upload_error, row: 2, category: :not_answered), create(:bulk_upload_error, row: 3, category: :soft_validation), create(:bulk_upload_error, row: 4)] } + let(:bulk_upload) { create(:bulk_upload, :lettings, user:, bulk_upload_errors:) } + + it "renders the page correctly" do + get "/lettings-logs/bulk-upload-resume/#{bulk_upload.id}/deletion-report" + + expect(response).to be_successful + + expect(response.body).to include("Bulk upload for lettings") + expect(response.body).to include("2023/24") + expect(response.body).to include("These 2 answers will be deleted if you upload the log") + expect(response.body).to include(bulk_upload.filename) + expect(response.body).to include("Clear this data and upload the logs") + end + end end end diff --git a/spec/requests/bulk_upload_sales_resume_controller_spec.rb b/spec/requests/bulk_upload_sales_resume_controller_spec.rb index 36c853097..47acc1ae6 100644 --- a/spec/requests/bulk_upload_sales_resume_controller_spec.rb +++ b/spec/requests/bulk_upload_sales_resume_controller_spec.rb @@ -211,5 +211,22 @@ RSpec.describe BulkUploadSalesResumeController, type: :request do expect(response).to redirect_to("/sales-logs/bulk-upload-soft-validations-check/#{bulk_upload.id}/chosen") end end + + context "and has a row with all non-cleared errors" do + let(:bulk_upload_errors) { [create(:bulk_upload_error, row: 1), create(:bulk_upload_error, row: 2, category: :not_answered), create(:bulk_upload_error, row: 3, category: :soft_validation), create(:bulk_upload_error, row: 4)] } + let(:bulk_upload) { create(:bulk_upload, :sales, user:, bulk_upload_errors:) } + + it "renders the page correctly" do + get "/sales-logs/bulk-upload-resume/#{bulk_upload.id}/deletion-report" + + expect(response).to be_successful + + expect(response.body).to include("Bulk upload for sales") + expect(response.body).to include("2023/24") + expect(response.body).to include("These 2 answers will be deleted if you upload the log") + expect(response.body).to include(bulk_upload.filename) + expect(response.body).to include("Clear this data and upload the logs") + end + end end end