From 87131a63c3ee407966a66408ad81d26312e5cffd Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 24 Feb 2023 16:19:06 +0000 Subject: [PATCH] bulk upload error summary min limit - the errors summary table only show errors for column where there at least 16 errors for that column - if there are fewer than 16 errors that can see detailed report to pin point and fix those specific issues --- ...bulk_upload_error_summary_table_component.rb | 9 +++++++++ ...upload_error_summary_table_component_spec.rb | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/components/bulk_upload_error_summary_table_component.rb b/app/components/bulk_upload_error_summary_table_component.rb index ac236af4d..510e8e7da 100644 --- a/app/components/bulk_upload_error_summary_table_component.rb +++ b/app/components/bulk_upload_error_summary_table_component.rb @@ -1,4 +1,6 @@ class BulkUploadErrorSummaryTableComponent < ViewComponent::Base + DISPLAY_THRESHOLD = 16 + attr_reader :bulk_upload def initialize(bulk_upload:) @@ -11,7 +13,14 @@ class BulkUploadErrorSummaryTableComponent < ViewComponent::Base @sorted_errors ||= bulk_upload .bulk_upload_errors .group(:col, :field, :error) + .having("count(*) > ?", display_threshold) .count .sort_by { |el| el[0][0].rjust(3, "0") } end + +private + + def display_threshold + DISPLAY_THRESHOLD + end end diff --git a/spec/components/bulk_upload_error_summary_table_component_spec.rb b/spec/components/bulk_upload_error_summary_table_component_spec.rb index cdb0b58bf..a1b3c7247 100644 --- a/spec/components/bulk_upload_error_summary_table_component_spec.rb +++ b/spec/components/bulk_upload_error_summary_table_component_spec.rb @@ -5,6 +5,10 @@ RSpec.describe BulkUploadErrorSummaryTableComponent, type: :component do let(:bulk_upload) { create(:bulk_upload) } + before do + stub_const("BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD", 0) + end + context "when no errors" do it "does not renders any rows" do result = render_inline(component) @@ -12,6 +16,19 @@ RSpec.describe BulkUploadErrorSummaryTableComponent, type: :component do end end + context "when below threshold" do + before do + stub_const("BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD", 16) + + create(:bulk_upload_error, bulk_upload:, col: "A", row: 1) + end + + it "does not render rows" do + result = render_inline(component) + expect(result).to have_selector("tbody tr", count: 0) + end + end + context "when there are 2 independent errors" do let!(:error_2) { create(:bulk_upload_error, bulk_upload:, col: "B", row: 2) } let!(:error_1) { create(:bulk_upload_error, bulk_upload:, col: "A", row: 1) }