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. 25
      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 class Form::Sales::Pages::HandoverDateCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@depends_on = [{ "hodate_3_years_or_more_saledate?" => true }] @depends_on = [{ "hodate_3_years_or_more_exdate?" => true }]
@informative_text = {} @informative_text = {}
end 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) def initialize(id, hsh, page)
super super
@id = "value_value_check" @id = "value_value_check"
@check_answer_label = "Deposit confirmation" @check_answer_label = "Purchase price confirmation"
@header = "Are you sure? This purchase price is outside the expected range for this local authority and number of bedrooms" @header = "Are you sure this is correct?"
@type = "interruption_screen" @type = "interruption_screen"
@answer_options = { @answer_options = {
"0" => { "value" => "Yes" }, "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::PreviousPropertyType.new(nil, nil, self),
Form::Sales::Pages::PreviousTenure.new(nil, nil, self), Form::Sales::Pages::PreviousTenure.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnership.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::Mortgageused.new("mortgage_used_shared_ownership", nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_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), 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? def old_persons_shared_ownership?
type == 24 type == 24
end 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 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 ((exdate.to_date - hodate.to_date).to_i / 365) >= 3
end end
def purchase_price_out_of_expected_range? def purchase_price_below_soft_min?
return unless value && beds && la return unless value && beds && la
purchase_price_range = LaPurchasePriceRange.find_by(start_year: collection_start_year, la:, bedrooms: beds) 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
end end

25
config/locales/en.yml

@ -301,7 +301,7 @@ en:
child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’" child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’"
not_student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student" not_student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student"
student_16_19: student_16_19:
cannot_be_16_19: cannot_be_16_19:
student_not_child: "Person cannot be aged 16-19 if they are a student but don't have relationship ‘child’" student_not_child: "Person cannot be aged 16-19 if they are a student but don't have relationship ‘child’"
child_not_student: "Person cannot be aged 16-19 if they have relationship ‘child’ but are not a student" child_not_student: "Person cannot be aged 16-19 if they have relationship ‘child’ but are not a student"
must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’" must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’"
@ -313,8 +313,8 @@ en:
child_under_16: "Person’s %{person_num} working situation must be ’child under 16‘ as you told us they’re under 16" child_under_16: "Person’s %{person_num} working situation must be ’child under 16‘ as you told us they’re under 16"
child_over_16: "Answer cannot be ‘child under 16’ as you told us the person %{person_num} is older than 16" child_over_16: "Answer cannot be ‘child under 16’ as you told us the person %{person_num} is older than 16"
not_student_16_19: "Person’s %{person_num} working situation must be full-time student or prefers not to say as you told us they’re between 16 and 19." not_student_16_19: "Person’s %{person_num} working situation must be full-time student or prefers not to say as you told us they’re between 16 and 19."
student_16_19: student_16_19:
cannot_be_student: cannot_be_student:
child_not_16_19: "Person cannot be a student if they are not aged 16-19 but have relationship ‘child’" child_not_16_19: "Person cannot be a student if they are not aged 16-19 but have relationship ‘child’"
16_19_not_child: "Person cannot be a student if they are aged 16-19 but don‘t have relationship ‘child’" 16_19_not_child: "Person cannot be a student if they are aged 16-19 but don‘t have relationship ‘child’"
must_be_student: "Person must be a student if they are aged 16-19 and have relationship ‘child’" must_be_student: "Person must be a student if they are aged 16-19 and have relationship ‘child’"
@ -326,8 +326,8 @@ en:
child_over_20: "Answer cannot be ‘child’ if the person's age is 20 or over" child_over_20: "Answer cannot be ‘child’ if the person's age is 20 or over"
one_partner: "Number of partners cannot be greater than 1" one_partner: "Number of partners cannot be greater than 1"
not_student_16_19: "Answer cannot be ‘child’ as you told us the person %{person_num} is between 16 and 19 and is not a full-time student" not_student_16_19: "Answer cannot be ‘child’ as you told us the person %{person_num} is between 16 and 19 and is not a full-time student"
student_16_19: student_16_19:
cannot_be_child: cannot_be_child:
student_not_16_19: "Answer cannot be ‘child’ if the person is a student but not aged 16-19" student_not_16_19: "Answer cannot be ‘child’ if the person is a student but not aged 16-19"
16_19_not_student: "Answer cannot be ‘child’ if the person is aged 16-19 but not a student" 16_19_not_student: "Answer cannot be ‘child’ if the person is aged 16-19 but not a student"
must_be_child: "Answer must be ‘child’ if the person is aged 16-19 and a student" must_be_child: "Answer must be ‘child’ if the person is aged 16-19 and a student"
@ -413,9 +413,9 @@ en:
deactivation: deactivation:
during_deactivated_period: "The location is already deactivated during this date, please enter a different date" during_deactivated_period: "The location is already deactivated during this date, please enter a different date"
sale_information: sale_information:
previous_property_beds: previous_property_beds:
property_type_bedsit: "Bedsit bedroom maximum 1" property_type_bedsit: "Bedsit bedroom maximum 1"
previous_property_type: previous_property_type:
property_type_bedsit: "A bedsit can not have more than 1 bedroom" property_type_bedsit: "A bedsit can not have more than 1 bedroom"
soft_validations: soft_validations:
@ -429,10 +429,17 @@ en:
rent: rent:
min: min:
title_text: "You told us the rent is %{brent}" 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: max:
title_text: "You told us the rent is %{brent}" 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: retirement:
min: min:
title: "You told us this person is under %{age} and retired" 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 it "has correct depends_on" do
expect(page.depends_on).to eq([ expect(page.depends_on).to eq([
{ {
"hodate_3_years_or_more_saledate?" => true, "hodate_3_years_or_more_exdate?" => true,
}, },
]) ])
end end

Loading…
Cancel
Save