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