Browse Source

CLDC-3595 Remove duplicate errors for check errors page (#2560)

* Remove duplicate errors for check errors page

* Remove unused line

* Format some missed errors correctly
pull/2603/head
kosiakkatrina 4 months ago committed by GitHub
parent
commit
4690fb446e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/helpers/form_page_error_helper.rb
  2. 4
      app/models/validations/sales/sale_information_validations.rb
  3. 1
      app/views/form/check_errors.html.erb
  4. 18
      spec/helpers/form_page_error_helper_spec.rb

9
app/helpers/form_page_error_helper.rb

@ -4,6 +4,15 @@ module FormPageErrorHelper
other_page_error_ids.each { |id| lettings_log.errors.delete(id) } other_page_error_ids.each { |id| lettings_log.errors.delete(id) }
end end
def remove_duplicate_page_errors(lettings_log)
lettings_log.errors.group_by(&:message).each do |_, errors|
next if errors.size == 1
errors.shift
errors.each { |error| lettings_log.errors.delete(error.attribute) }
end
end
def all_questions_affected_by_errors(log) def all_questions_affected_by_errors(log)
log.errors.map(&:attribute) - [:base] log.errors.map(&:attribute) - [:base]
end end

4
app/models/validations/sales/sale_information_validations.rb

@ -222,7 +222,7 @@ module Validations::Sales::SaleInformationValidations
value: record.field_formatted_as_currency("value"), value: record.field_formatted_as_currency("value"),
equity: "#{record.equity}%", equity: "#{record.equity}%",
mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"),
expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")).html_safe
end end
record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used", record.errors.add :type, :skip_bu_error, message: I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used",
mortgage: record.field_formatted_as_currency("mortgage"), mortgage: record.field_formatted_as_currency("mortgage"),
@ -230,7 +230,7 @@ module Validations::Sales::SaleInformationValidations
value: record.field_formatted_as_currency("value"), value: record.field_formatted_as_currency("value"),
equity: "#{record.equity}%", equity: "#{record.equity}%",
mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"),
expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")).html_safe
end end
elsif record.mortgage_not_used? elsif record.mortgage_not_used?
if over_tolerance?(record.deposit, record.expected_shared_ownership_deposit_value, 1) if over_tolerance?(record.deposit, record.expected_shared_ownership_deposit_value, 1)

1
app/views/form/check_errors.html.erb

@ -2,6 +2,7 @@
<div class="govuk-grid-column-three-quarters-from-desktop"> <div class="govuk-grid-column-three-quarters-from-desktop">
<%= form_with model: @log, url: send("#{@log.model_name.param_key}_confirm_clear_answer_path", @log), method: "post", local: true do |f| %> <%= form_with model: @log, url: send("#{@log.model_name.param_key}_confirm_clear_answer_path", @log), method: "post", local: true do |f| %>
<% remove_duplicate_page_errors(@log) %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<%= f.hidden_field :page_id, value: @page.id %> <%= f.hidden_field :page_id, value: @page.id %>

18
spec/helpers/form_page_error_helper_spec.rb

@ -21,4 +21,22 @@ RSpec.describe FormPageErrorHelper do
end end
end end
end end
describe "#remove_duplicate_page_errors" do
context "when non base other questions are removed" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :in_progress) }
before do
lettings_log.errors.add :layear, "error"
lettings_log.errors.add :period, "error_one"
lettings_log.errors.add :base, "error_one"
end
it "returns details and user tabs" do
remove_duplicate_page_errors(lettings_log)
expect(lettings_log.errors.count).to eq(2)
expect(lettings_log.errors.map(&:message)).to match_array(%w[error_one error])
end
end
end
end end

Loading…
Cancel
Save