Browse Source

order bulk upload errors by cell (#1193)

pull/1173/head
Phil Lee 2 years ago committed by GitHub
parent
commit
24b8232874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/components/bulk_upload_error_row_component.rb
  2. 16
      spec/components/bulk_upload_error_row_component_spec.rb

8
app/components/bulk_upload_error_row_component.rb

@ -2,7 +2,7 @@ class BulkUploadErrorRowComponent < ViewComponent::Base
attr_reader :bulk_upload_errors
def initialize(bulk_upload_errors:)
@bulk_upload_errors = bulk_upload_errors
@bulk_upload_errors = sorted_errors(bulk_upload_errors)
super
end
@ -45,4 +45,10 @@ class BulkUploadErrorRowComponent < ViewComponent::Base
def sales?
bulk_upload.log_type == "sales"
end
private
def sorted_errors(errors)
errors.sort_by { |e| e.cell.rjust(3, "0") }
end
end

16
spec/components/bulk_upload_error_row_component_spec.rb

@ -49,6 +49,22 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do
expect(result).to have_content(expected)
end
context "when multiple errors for a row" do
subject(:component) { described_class.new(bulk_upload_errors:) }
let(:bulk_upload_errors) do
[
build(:bulk_upload_error, cell: "Z1"),
build(:bulk_upload_error, cell: "AB1"),
build(:bulk_upload_error, cell: "A1"),
]
end
it "is sorted by cell" do
expect(component.bulk_upload_errors.map(&:cell)).to eql(%w[A1 Z1 AB1])
end
end
context "when a sales bulk upload" do
let(:bulk_upload) { create(:bulk_upload, :sales) }
let(:field) { :field_87 }

Loading…
Cancel
Save