Browse Source

feat: add min and max conditional text

pull/1225/head
natdeanlewissoftwire 2 years ago
parent
commit
c5bb9c6eaf
  1. 38
      app/models/form/sales/pages/about_price_shared_ownership_max_value_check.rb
  2. 38
      app/models/form/sales/pages/about_price_shared_ownership_min_value_check.rb
  3. 18
      app/models/form/sales/pages/about_price_shared_ownership_value_check.rb
  4. 2
      app/models/form/sales/pages/handover_date_check.rb
  5. 4
      app/models/form/sales/questions/about_price_shared_ownership_value_check.rb
  6. 3
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  7. 8
      app/models/sales_log.rb
  8. 11
      app/models/validations/sales/soft_validations.rb
  9. 11
      config/locales/en.yml
  10. 2
      spec/models/form/sales/pages/handover_date_check_spec.rb

38
app/models/form/sales/pages/about_price_shared_ownership_max_value_check.rb

@ -0,0 +1,38 @@
class Form::Sales::Pages::AboutPriceSharedOwnershipMaxValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_shared_ownership_max_value_check"
@depends_on = [
{
"purchase_price_above_soft_max?" => true,
},
]
@informative_text = {}
@title_text = {
"translation" => "soft_validations.purchase_price.max.title_text",
"arguments" => [
{
"key" => "value",
"label" => true,
"i18n_template" => "value",
},
],
}
@informative_text = {
"translation" => "soft_validations.purchase_price.max.hint_text",
"arguments" => [
{
"key" => "purchase_price_soft_max",
"label" => false,
"i18n_template" => "soft_max",
},
],
}
end
def questions
@questions ||= [
Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self),
]
end
end

38
app/models/form/sales/pages/about_price_shared_ownership_min_value_check.rb

@ -0,0 +1,38 @@
class Form::Sales::Pages::AboutPriceSharedOwnershipMinValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_shared_ownership_min_value_check"
@depends_on = [
{
"purchase_price_below_soft_min?" => true,
},
]
@informative_text = {}
@title_text = {
"translation" => "soft_validations.purchase_price.min.title_text",
"arguments" => [
{
"key" => "value",
"label" => true,
"i18n_template" => "value",
},
],
}
@informative_text = {
"translation" => "soft_validations.purchase_price.min.hint_text",
"arguments" => [
{
"key" => "purchase_price_soft_min",
"label" => false,
"i18n_template" => "soft_min",
},
],
}
end
def questions
@questions ||= [
Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self),
]
end
end

18
app/models/form/sales/pages/about_price_shared_ownership_value_check.rb

@ -1,18 +0,0 @@
class Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_shared_ownership_value_check"
@depends_on = [
{
"purchase_price_out_of_expected_range?" => true,
},
]
@informative_text = {}
end
def questions
@questions ||= [
Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self),
]
end
end

2
app/models/form/sales/pages/handover_date_check.rb

@ -1,7 +1,7 @@
class Form::Sales::Pages::HandoverDateCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@depends_on = [{ "hodate_3_years_or_more_saledate?" => true }]
@depends_on = [{ "hodate_3_years_or_more_exdate?" => true }]
@informative_text = {}
end

4
app/models/form/sales/questions/about_price_shared_ownership_value_check.rb

@ -2,8 +2,8 @@ class Form::Sales::Questions::AboutPriceSharedOwnershipValueCheck < ::Form::Ques
def initialize(id, hsh, page)
super
@id = "value_value_check"
@check_answer_label = "Deposit confirmation"
@header = "Are you sure? This purchase price is outside the expected range for this local authority and number of bedrooms"
@check_answer_label = "Purchase price confirmation"
@header = "Are you sure this is correct?"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },

3
app/models/form/sales/subsections/shared_ownership_scheme.rb

@ -21,7 +21,8 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self),
Form::Sales::Pages::PreviousTenure.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnershipValueCheck.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnershipMinValueCheck.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnershipMaxValueCheck.new(nil, nil, self),
Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self),
Form::Sales::Pages::MortgageLender.new("mortgage_lender_shared_ownership", nil, self),

8
app/models/sales_log.rb

@ -202,4 +202,12 @@ class SalesLog < Log
def old_persons_shared_ownership?
type == 24
end
def purchase_price_soft_min
LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds).soft_min
end
def purchase_price_soft_max
LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds).soft_max
end
end

11
app/models/validations/sales/soft_validations.rb

@ -43,10 +43,17 @@ module Validations::Sales::SoftValidations
((exdate.to_date - hodate.to_date).to_i / 365) >= 3
end
def purchase_price_out_of_expected_range?
def purchase_price_below_soft_min?
return unless value && beds && la
purchase_price_range = LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds)
purchase_price_range.present? && !value.between?(purchase_price_range.soft_min, purchase_price_range.soft_max)
purchase_price_range.present? && value < purchase_price_range.soft_min
end
def purchase_price_above_soft_max?
return unless value && beds && la
purchase_price_range = LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds)
purchase_price_range.present? && value > purchase_price_range.soft_max
end
end

11
config/locales/en.yml

@ -429,10 +429,17 @@ en:
rent:
min:
title_text: "You told us the rent is %{brent}"
hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}."
hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}"
max:
title_text: "You told us the rent is %{brent}"
hint_text: "The maximum rent expected for this type of property in this local authority is £%{soft_max_for_period}."
hint_text: "The maximum rent expected for this type of property in this local authority is £%{soft_max_for_period}"
purchase_price:
min:
title_text: "You told us the purchase price is %{value}"
hint_text: "The minimum purchase price expected for this type of property in this local authority is £%{soft_min}"
max:
title_text: "You told us the purchase price is %{value}"
hint_text: "The maximum purchase price expected for this type of property in this local authority is £%{soft_max}"
retirement:
min:
title: "You told us this person is under %{age} and retired"

2
spec/models/form/sales/pages/handover_date_check_spec.rb

@ -26,7 +26,7 @@ RSpec.describe Form::Sales::Pages::HandoverDateCheck, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq([
{
"hodate_3_years_or_more_saledate?" => true,
"hodate_3_years_or_more_exdate?" => true,
},
])
end

Loading…
Cancel
Save