From 98060176d21b78b8bf229a48fe797e1a0bc520e7 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Tue, 11 Apr 2023 15:17:09 +0100 Subject: [PATCH 1/3] hide blank bulk upload error meta labels (#1526) --- .../bulk_upload_error_row_component.html.erb | 4 +-- .../bulk_upload_error_row_component.rb | 24 +++++++++++++++ .../bulk_upload_error_row_component_spec.rb | 29 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/app/components/bulk_upload_error_row_component.html.erb b/app/components/bulk_upload_error_row_component.html.erb index 6f8de6919..54a2c6c93 100644 --- a/app/components/bulk_upload_error_row_component.html.erb +++ b/app/components/bulk_upload_error_row_component.html.erb @@ -1,9 +1,9 @@
<% if lettings? %> -

Row <%= row %> Tenant code: <%= tenant_code %> Property reference: <%= property_ref %>

+

Row <%= row %> <%= tenant_code_html %> <%= property_ref_html %>

<% else %> -

Row <%= row %> Purchaser code: <%= purchaser_code %>

+

Row <%= row %> <%= purchaser_code_html %>

<% end %>
diff --git a/app/components/bulk_upload_error_row_component.rb b/app/components/bulk_upload_error_row_component.rb index 13ac326ef..f4f129cbc 100644 --- a/app/components/bulk_upload_error_row_component.rb +++ b/app/components/bulk_upload_error_row_component.rb @@ -15,14 +15,38 @@ class BulkUploadErrorRowComponent < ViewComponent::Base bulk_upload_errors.first.tenant_code 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 bulk_upload_errors.first.purchaser_code 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 bulk_upload_errors.first.property_ref 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) bulk_upload.prefix_namespace::RowParser.question_for_field(field.to_sym) end diff --git a/spec/components/bulk_upload_error_row_component_spec.rb b/spec/components/bulk_upload_error_row_component_spec.rb index 4950817f0..665a630c8 100644 --- a/spec/components/bulk_upload_error_row_component_spec.rb +++ b/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(:tenant_code) { SecureRandom.hex(4) } let(:property_ref) { SecureRandom.hex(4) } + let(:purchaser_code) { nil } let(:field) { :field_134 } let(:error) { "some error" } let(:bulk_upload) { create(:bulk_upload, :lettings) } @@ -16,6 +17,7 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do row:, tenant_code:, property_ref:, + purchaser_code:, field:, error:, ), @@ -49,6 +51,33 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do expect(result).to have_content(expected) 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 subject(:component) { described_class.new(bulk_upload_errors:) } From 8e8362a74b88bbc030a299afe60ccb1435aeaa60 Mon Sep 17 00:00:00 2001 From: Jack <113976590+bibblobcode@users.noreply.github.com> Date: Wed, 12 Apr 2023 09:17:32 +0100 Subject: [PATCH 2/3] CLDC-1856 Add housing question flow validation (#1508) * CLDC-1856 Add housing question flow validation * Update copy and methods --- app/models/validations/household_validations.rb | 8 ++++++++ config/locales/en.yml | 2 ++ .../validations/household_validations_spec.rb | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 8f28bff74..47d094be8 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -121,6 +121,14 @@ module Validations::HouseholdValidations end end + def validate_combination_of_housing_needs_responses(record) + if record.housingneeds == 1 && record.housingneeds_type == 3 && record.housingneeds_other&.zero? + record.errors.add :housingneeds, I18n.t("validations.household.housingneeds.invalid") + record.errors.add :housingneeds_type, I18n.t("validations.household.housingneeds.invalid") + record.errors.add :housingneeds_other, I18n.t("validations.household.housingneeds.invalid") + end + end + private def household_no_illness?(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index 68e1d72fc..e223c7fc9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -389,6 +389,8 @@ en: housingneeds_type: only_one_option_permitted: "Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected" housingneeds: + invalid: + If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs no_disabled_needs_conjunction: "No disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs" dont_know_disabled_needs_conjunction: "Don’t know disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs" no_and_dont_know_disabled_needs_conjunction: "No disabled access needs and don’t know disabled access needs cannot be selected together" diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index a79db2541..b1c01b7a5 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -637,4 +637,20 @@ RSpec.describe Validations::HouseholdValidations do end end end + + describe "housing needs validations" do + it "is invalid when a combination of housingneeds == 1 (yes) && housingneeds_type == 3 (none of listed) && housingneeds_other == 0 (no)" do + record.housingneeds = 1 + record.housingneeds_type = 3 + record.housingneeds_other = 0 + + household_validator.validate_combination_of_housing_needs_responses(record) + + error_message = ["If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs"] + + expect(record.errors["housingneeds"]).to eq(error_message) + expect(record.errors["housingneeds_type"]).to eq(error_message) + expect(record.errors["housingneeds_other"]).to eq(error_message) + end + end end From ca2aa82af6c25961333552d7498ba8bbef7f0a6f Mon Sep 17 00:00:00 2001 From: Jack <113976590+bibblobcode@users.noreply.github.com> Date: Wed, 12 Apr 2023 12:44:00 +0100 Subject: [PATCH 3/3] Bump nokogiri (#1530) --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9083ba67e..78fe1e157 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -233,11 +233,11 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.8) - nokogiri (1.14.2-arm64-darwin) + nokogiri (1.14.3-arm64-darwin) racc (~> 1.4) - nokogiri (1.14.2-x86_64-darwin) + nokogiri (1.14.3-x86_64-darwin) racc (~> 1.4) - nokogiri (1.14.2-x86_64-linux) + nokogiri (1.14.3-x86_64-linux) racc (~> 1.4) notifications-ruby-client (5.4.0) jwt (>= 1.5, < 3)