Browse Source

hide blank bulk upload error meta labels (#1526)

pull/1527/head
Phil Lee 2 years ago committed by GitHub
parent
commit
98060176d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/components/bulk_upload_error_row_component.html.erb
  2. 24
      app/components/bulk_upload_error_row_component.rb
  3. 29
      spec/components/bulk_upload_error_row_component_spec.rb

4
app/components/bulk_upload_error_row_component.html.erb

@ -1,9 +1,9 @@
<div class="x-govuk-summary-card govuk-!-margin-bottom-6"> <div class="x-govuk-summary-card govuk-!-margin-bottom-6">
<div class="x-govuk-summary-card__header"> <div class="x-govuk-summary-card__header">
<% if lettings? %> <% if lettings? %>
<h3 class="x-govuk-summary-card__title"><strong>Row <%= row %></strong> <span class="govuk-!-margin-left-3">Tenant code: <%= tenant_code %></span> <span class="govuk-!-margin-left-3">Property reference: <%= property_ref %></span></h3> <h3 class="x-govuk-summary-card__title"><strong>Row <%= row %></strong> <%= tenant_code_html %> <%= property_ref_html %></h3>
<% else %> <% else %>
<h3 class="x-govuk-summary-card__title"><strong>Row <%= row %></strong> <span class="govuk-!-margin-left-3">Purchaser code: <%= purchaser_code %></span></h3> <h3 class="x-govuk-summary-card__title"><strong>Row <%= row %></strong> <%= purchaser_code_html %></h3>
<% end %> <% end %>
</div> </div>

24
app/components/bulk_upload_error_row_component.rb

@ -15,14 +15,38 @@ class BulkUploadErrorRowComponent < ViewComponent::Base
bulk_upload_errors.first.tenant_code bulk_upload_errors.first.tenant_code
end end
def tenant_code_html
return if tenant_code.blank?
content_tag :span, class: "govuk-!-margin-left-3" do
"Tenant code: #{tenant_code}"
end
end
def purchaser_code def purchaser_code
bulk_upload_errors.first.purchaser_code bulk_upload_errors.first.purchaser_code
end end
def purchaser_code_html
return if purchaser_code.blank?
content_tag :span, class: "govuk-!-margin-left-3" do
"Purchaser code: #{purchaser_code}"
end
end
def property_ref def property_ref
bulk_upload_errors.first.property_ref bulk_upload_errors.first.property_ref
end end
def property_ref_html
return if property_ref.blank?
content_tag :span, class: "govuk-!-margin-left-3" do
"Property reference: #{property_ref}"
end
end
def question_for_field(field) def question_for_field(field)
bulk_upload.prefix_namespace::RowParser.question_for_field(field.to_sym) bulk_upload.prefix_namespace::RowParser.question_for_field(field.to_sym)
end end

29
spec/components/bulk_upload_error_row_component_spec.rb

@ -5,6 +5,7 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do
let(:row) { rand(9_999) } let(:row) { rand(9_999) }
let(:tenant_code) { SecureRandom.hex(4) } let(:tenant_code) { SecureRandom.hex(4) }
let(:property_ref) { SecureRandom.hex(4) } let(:property_ref) { SecureRandom.hex(4) }
let(:purchaser_code) { nil }
let(:field) { :field_134 } let(:field) { :field_134 }
let(:error) { "some error" } let(:error) { "some error" }
let(:bulk_upload) { create(:bulk_upload, :lettings) } let(:bulk_upload) { create(:bulk_upload, :lettings) }
@ -16,6 +17,7 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do
row:, row:,
tenant_code:, tenant_code:,
property_ref:, property_ref:,
purchaser_code:,
field:, field:,
error:, error:,
), ),
@ -49,6 +51,33 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do
expect(result).to have_content(expected) expect(result).to have_content(expected)
end end
context "when tenant_code not present" do
let(:tenant_code) { nil }
it "does not render tenant code label" do
result = render_inline(described_class.new(bulk_upload_errors:))
expect(result).not_to have_content("Tenant code")
end
end
context "when property_ref not present" do
let(:property_ref) { nil }
it "does not render the property_ref label" do
result = render_inline(described_class.new(bulk_upload_errors:))
expect(result).not_to have_content("Property reference")
end
end
context "when purchaser_code not present" do
let(:bulk_upload) { create(:bulk_upload, :sales) }
it "does not render the purchaser_code label" do
result = render_inline(described_class.new(bulk_upload_errors:))
expect(result).not_to have_content("Purchaser code")
end
end
context "when multiple errors for a row" do context "when multiple errors for a row" do
subject(:component) { described_class.new(bulk_upload_errors:) } subject(:component) { described_class.new(bulk_upload_errors:) }

Loading…
Cancel
Save