Browse Source

Interruption screen refactor

pull/570/head
Stéphane Meny 3 years ago committed by Dushan Despotovic
parent
commit
e151b1393b
  1. 23
      app/helpers/interruption_screen_helper.rb
  2. 13
      app/helpers/interuption_screen_helper.rb
  3. 13
      app/models/case_log.rb
  4. 48
      app/models/validations/household_validations.rb
  5. 34
      app/models/validations/soft_validations.rb
  6. 4
      app/views/form/_interruption_screen_question.html.erb
  7. 579
      config/forms/2021_2022.json
  8. 11
      config/locales/en.yml
  9. 5
      db/migrate/20220509110842_add_retirement_value_check.rb
  10. 1
      db/schema.rb
  11. 99
      spec/helpers/interruption_screen_helper_spec.rb
  12. 65
      spec/helpers/interuption_screen_helper_spec.rb

23
app/helpers/interruption_screen_helper.rb

@ -0,0 +1,23 @@
module InterruptionScreenHelper
def display_informative_text(informative_text, case_log)
return "" unless informative_text["arguments"]
translation_params = {}
informative_text["arguments"].each do |argument|
value = if argument["label"]
case_log.form.get_question(argument["key"], case_log).answer_label(case_log).downcase
else
case_log.public_send(argument["key"])
end
translation_params[argument["i18n_template"].to_sym] = value
end
begin
translation = I18n.t(informative_text["translation"], **translation_params)
translation.to_s.html_safe
rescue I18n::MissingInterpolationArgument => e
Rails.logger.error(e.message)
""
end
end
end

13
app/helpers/interuption_screen_helper.rb

@ -1,13 +0,0 @@
module InteruptionScreenHelper
def display_informative_text(informative_text, case_log)
arguments = informative_text["argument"].map { |x, type| type == "question" ? case_log.form.get_question(x, case_log).answer_label(case_log) : case_log.public_send(x) }
keys = informative_text["argument"].keys
begin
translation = I18n.t(informative_text["translation"], keys[0].present? ? keys[0].to_sym : "" => arguments[0], keys[1].present? ? keys[1].to_sym : "" => arguments[1], keys[2].present? ? keys[2].to_sym : "" => arguments[2])
rescue StandardError
return ""
end
translation.to_s.html_safe
end
end

13
app/models/case_log.rb

@ -58,6 +58,7 @@ class CaseLog < ApplicationRecord
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze
SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze
enum status: STATUS enum status: STATUS
def form def form
@ -375,6 +376,18 @@ class CaseLog < ApplicationRecord
OPTIONAL_FIELDS + dynamically_not_required OPTIONAL_FIELDS + dynamically_not_required
end end
(1..8).each do |person_num|
define_method("retirement_age_for_person_#{person_num}") do
retirement_age_for_person(person_num)
end
end
def retirement_age_for_person(person_num)
gender = public_send("sex#{person_num}".to_sym)
return unless gender
RETIREMENT_AGES[gender]
end
private private
PIO = Postcodes::IO.new PIO = Postcodes::IO.new

48
app/models/validations/household_validations.rb

@ -45,7 +45,7 @@ module Validations::HouseholdValidations
(2..8).each do |n| (2..8).each do |n|
validate_person_age_matches_economic_status(record, n) validate_person_age_matches_economic_status(record, n)
validate_person_age_matches_relationship(record, n) validate_person_age_matches_relationship(record, n)
validate_person_age_and_gender_match_economic_status(record, n) # validate_person_age_and_gender_match_economic_status(record, n)
validate_person_age_and_relationship_matches_economic_status(record, n) validate_person_age_and_relationship_matches_economic_status(record, n)
end end
validate_partner_count(record) validate_partner_count(record)
@ -146,10 +146,10 @@ private
economic_status = record.public_send("ecstat#{person_num}") economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status return unless age && economic_status
if age > 70 && !tenant_is_retired?(economic_status) # if age > 70 && !tenant_is_retired?(economic_status)
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_over_70", person_num:) # record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_over_70", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_over_70", person_num:) # record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_over_70", person_num:)
end # end
if age < 16 && !tenant_is_economic_child?(economic_status) if age < 16 && !tenant_is_economic_child?(economic_status)
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:)
@ -184,23 +184,23 @@ private
end end
end end
def validate_person_age_and_gender_match_economic_status(record, person_num) # def validate_person_age_and_gender_match_economic_status(record, person_num)
age = record.public_send("age#{person_num}") # age = record.public_send("age#{person_num}")
gender = record.public_send("sex#{person_num}") # gender = record.public_send("sex#{person_num}")
economic_status = record.public_send("ecstat#{person_num}") # economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status && gender # return unless age && economic_status && gender
#
if gender == "M" && tenant_is_retired?(economic_status) && age < 65 # if gender == "M" && tenant_is_retired?(economic_status) && age < 65
record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_male") # record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_male")
record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_male") # record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_male")
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_male") # record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_male")
end # end
if gender == "F" && tenant_is_retired?(economic_status) && age < 60 # if gender == "F" && tenant_is_retired?(economic_status) && age < 60
record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_female") # record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_female")
record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_female") # record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_female")
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_female") # record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_female")
end # end
end # end
def validate_partner_count(record) def validate_partner_count(record)
partner_count = (2..8).count { |n| tenant_is_partner?(record["relat#{n}"]) } partner_count = (2..8).count { |n| tenant_is_partner?(record["relat#{n}"]) }
@ -209,10 +209,6 @@ private
end end
end end
def tenant_is_retired?(economic_status)
economic_status == 5
end
def tenant_is_economic_child?(economic_status) def tenant_is_economic_child?(economic_status)
economic_status == 9 economic_status == 9
end end

34
app/models/validations/soft_validations.rb

@ -38,4 +38,38 @@ module Validations::SoftValidations
rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:) rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:)
rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max) rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max)
end end
(1..8).each do |person_num|
define_method("person_#{person_num}_retired_under_soft_min_age?") do
retired_under_soft_min_age?(person_num)
end
define_method("person_#{person_num}_not_retired_over_soft_max_age?") do
not_retired_over_soft_max_age?(person_num)
end
end
private
def tenant_is_retired?(economic_status)
economic_status == 5
end
def retired_under_soft_min_age?(person_num)
age = public_send("age#{person_num}")
economic_status = public_send("ecstat#{person_num}")
gender = public_send("sex#{person_num}")
return unless age && economic_status && gender
%w[M X].include?(gender) && tenant_is_retired?(economic_status) && age < 67 ||
gender == "F" && tenant_is_retired?(economic_status) && age < 60
end
def not_retired_over_soft_max_age?(person_num)
age = public_send("age#{person_num}")
economic_status = public_send("ecstat#{person_num}")
gender = public_send("sex#{person_num}")
return unless age && economic_status && gender
%w[M X].include?(gender) && !tenant_is_retired?(economic_status) && age > 67 ||
gender == "F" && !tenant_is_retired?(economic_status) && age > 60
end
end end

4
app/views/form/_interruption_screen_question.html.erb

@ -1,8 +1,8 @@
<%= govuk_panel( <%= govuk_panel(
title_text:, title_text: I18n.t(title_text),
classes: "app-panel--interruption", classes: "app-panel--interruption",
) do %> ) do %>
<%= display_informative_text(informative_text, case_log) %> <p class="govuk-panel__body"><%= display_informative_text(informative_text, case_log) %></p>
<%= f.govuk_radio_buttons_fieldset question.id.to_sym, <%= f.govuk_radio_buttons_fieldset question.id.to_sym,
legend: { text: question.header }, legend: { text: question.header },
hint: { text: question.hint_text&.html_safe } do %> hint: { text: question.hint_text&.html_safe } do %>

579
config/forms/2021_2022.json

@ -1529,6 +1529,72 @@
} }
} }
}, },
"lead_tenant_under_retirement_value_check": {
"depends_on": [{ "person_1_retired_under_soft_min_age?": true }],
"title_text": "soft_validations.retirement.min.title",
"informative_text": {
"translation": "soft_validations.retirement.min.hint_text",
"arguments": [{
"key": "sex1",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_1",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"lead_tenant_over_retirement_value_check": {
"depends_on": [{ "person_1_not_retired_over_soft_max_age?": true }],
"title_text": "soft_validations.retirement.max.title",
"informative_text": {
"translation": "soft_validations.retirement.max.hint_text",
"arguments": [{
"key": "sex1",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_1",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_2_known": { "person_2_known": {
"header": "You’ve given us the details for 1 person in the household", "header": "You’ve given us the details for 1 person in the household",
"description": "", "description": "",
@ -1754,6 +1820,72 @@
} }
] ]
}, },
"person_2_under_retirement_value_check": {
"depends_on": [{ "person_2_retired_under_soft_min_age?": true }],
"title_text": "soft_validations.retirement.min.title",
"informative_text": {
"translation": "soft_validations.retirement.min.hint_text",
"arguments": [{
"key": "sex2",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_2",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_2_over_retirement_value_check": {
"depends_on": [{ "person_2_not_retired_over_soft_max_age?": true }],
"title_text": "soft_validations.retirement.max.title",
"informative_text": {
"translation": "soft_validations.retirement.max.hint_text",
"arguments": [{
"key": "sex2",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_2",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_3_known": { "person_3_known": {
"header": "You’ve given us the details for 2 people in the household", "header": "You’ve given us the details for 2 people in the household",
"description": "", "description": "",
@ -1965,6 +2097,7 @@
} }
} }
}, },
"depends_on": [ "depends_on": [
{ {
"details_known_3": 0, "details_known_3": 0,
@ -1976,6 +2109,72 @@
} }
] ]
}, },
"person_3_under_retirement_value_check": {
"depends_on": [{ "person_3_retired_under_soft_min_age?": true }],
"title_text": "soft_validations.retirement.min.title",
"informative_text": {
"translation": "soft_validations.retirement.min.hint_text",
"arguments": [{
"key": "sex3",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_3",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_3_over_retirement_value_check": {
"depends_on": [{ "person_3_not_retired_over_soft_max_age?": true }],
"title_text": "soft_validations.retirement.max.title",
"informative_text": {
"translation": "soft_validations.retirement.max.hint_text",
"arguments": [{
"key": "sex3",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_3",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_4_known": { "person_4_known": {
"header": "You’ve given us the details for 3 people in the household", "header": "You’ve given us the details for 3 people in the household",
"description": "", "description": "",
@ -2011,7 +2210,7 @@
"hhmemb": 8 "hhmemb": 8
} }
] ]
}, },
"person_4_relationship_to_lead": { "person_4_relationship_to_lead": {
"header": "", "header": "",
"description": "", "description": "",
@ -2195,6 +2394,72 @@
} }
] ]
}, },
"person_4_under_retirement_value_check": {
"depends_on": [{ "person_4_retired_under_soft_min_age?": true }],
"title_text": "soft_validations.retirement.min.title",
"informative_text": {
"translation": "soft_validations.retirement.min.hint_text",
"arguments": [{
"key": "sex4",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_4",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_4_over_retirement_value_check": {
"depends_on": [{ "person_4_not_retired_over_soft_max_age?": true }],
"title_text": "soft_validations.retirement.max.title",
"informative_text": {
"translation": "soft_validations.retirement.max.hint_text",
"arguments": [{
"key": "sex4",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_4",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_5_known": { "person_5_known": {
"header": "You’ve given us the details for 4 people in the household", "header": "You’ve given us the details for 4 people in the household",
"description": "", "description": "",
@ -2411,6 +2676,72 @@
} }
] ]
}, },
"person_5_under_retirement_value_check": {
"depends_on": [{ "person_5_retired_under_soft_min_age?": true }],
"title_text": "soft_validations.retirement.min.title",
"informative_text": {
"translation": "soft_validations.retirement.min.hint_text",
"arguments": [{
"key": "sex5",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_5",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_5_over_retirement_value_check": {
"depends_on": [{ "person_5_not_retired_over_soft_max_age?": true }],
"title_text": "soft_validations.retirement.max.title",
"informative_text": {
"translation": "soft_validations.retirement.max.hint_text",
"arguments": [{
"key": "sex5",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_5",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_6_known": { "person_6_known": {
"header": "You’ve given us the details for 5 people in the household", "header": "You’ve given us the details for 5 people in the household",
"description": "", "description": "",
@ -2624,6 +2955,72 @@
} }
] ]
}, },
"person_6_under_retirement_value_check": {
"depends_on": [{ "person_6_retired_under_soft_min_age?": true }],
"title_text": "soft_validations.retirement.min.title",
"informative_text": {
"translation": "soft_validations.retirement.min.hint_text",
"arguments": [{
"key": "sex6",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_6",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_6_over_retirement_value_check": {
"depends_on": [{ "person_6_not_retired_over_soft_max_age?": true }],
"title_text": "soft_validations.retirement.max.title",
"informative_text": {
"translation": "soft_validations.retirement.max.hint_text",
"arguments": [{
"key": "sex6",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_6",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_7_known": { "person_7_known": {
"header": "You’ve given us the details for 7 people in the household", "header": "You’ve given us the details for 7 people in the household",
"description": "", "description": "",
@ -2834,6 +3231,72 @@
} }
] ]
}, },
"person_7_under_retirement_value_check": {
"depends_on": [{ "person_7_retired_under_soft_min_age?": true }],
"title_text": "soft_validations.retirement.min.title",
"informative_text": {
"translation": "soft_validations.retirement.min.hint_text",
"arguments": [{
"key": "sex7",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_7",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_7_over_retirement_value_check": {
"depends_on": [{ "person_7_not_retired_over_soft_max_age?": true }],
"title_text": "soft_validations.retirement.max.title",
"informative_text": {
"translation": "soft_validations.retirement.max.hint_text",
"arguments": [{
"key": "sex7",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_7",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_8_known": { "person_8_known": {
"header": "You’ve given us the details for 7 people in the household", "header": "You’ve given us the details for 7 people in the household",
"description": "", "description": "",
@ -3040,6 +3503,72 @@
"age8": null "age8": null
} }
] ]
},
"person_8_under_retirement_value_check": {
"depends_on": [{ "person_8_retired_under_soft_min_age?": true }],
"title_text": "soft_validations.retirement.min.title",
"informative_text": {
"translation": "soft_validations.retirement.min.hint_text",
"arguments": [{
"key": "sex8",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_8",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
},
"person_8_over_retirement_value_check": {
"depends_on": [{ "person_8_not_retired_over_soft_max_age?": true }],
"title_text": "soft_validations.retirement.max.title",
"informative_text": {
"translation": "soft_validations.retirement.max.hint_text",
"arguments": [{
"key": "sex8",
"label": true,
"i18n_template": "gender"
},
{
"key": "retirement_age_for_person_8",
"label": false,
"i18n_template": "age"
}]
},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this is correct?",
"type": "interruption_screen",
"answer_options": {
"0": {
"value":"Yes"
},
"1": {
"value":"No"
}
}
}
}
} }
} }
}, },
@ -4634,10 +5163,18 @@
}, },
"net_income_value_check": { "net_income_value_check": {
"depends_on": [{ "net_income_soft_validation_triggered?": true }], "depends_on": [{ "net_income_soft_validation_triggered?": true }],
"title_text": "Net income is outside the expected range based on the lead tenant’s working situation", "title_text": "soft_validations.net_income.title_text",
"informative_text": { "informative_text": {
"translation": "soft_validations.net_income.hint_text", "translation": "soft_validations.net_income.hint_text",
"argument": {"ecstat1": "question", "earnings": "question"} "arguments": [{
"key": "ecstat1",
"label": true,
"i18n_template": "ecstat1"
},
{"key": "earnings",
"label": true,
"i18n_template": "earnings"
}]
}, },
"questions": { "questions": {
"net_income_value_check": { "net_income_value_check": {
@ -5628,7 +6165,23 @@
"depends_on": [{ "rent_in_soft_min_range?": true }], "depends_on": [{ "rent_in_soft_min_range?": true }],
"informative_text": { "informative_text": {
"translation": "soft_validations.rent.min.hint_text", "translation": "soft_validations.rent.min.hint_text",
"argument": {"la": "question", "soft_min_for_period": "method", "brent":"question"} "arguments": [
{
"key": "la",
"label": true,
"i18n_template": "la"
},
{
"key": "soft_min_for_period",
"label": false,
"i18n_template": "soft_min_for_period"
},
{
"key":"brent",
"label": true,
"i18n_template": "brent"
}
]
}, },
"questions": { "questions": {
"rent_value_check": { "rent_value_check": {
@ -5651,7 +6204,23 @@
"depends_on": [{ "rent_in_soft_max_range?": true }], "depends_on": [{ "rent_in_soft_max_range?": true }],
"informative_text": { "informative_text": {
"translation": "soft_validations.rent.max.hint_text", "translation": "soft_validations.rent.max.hint_text",
"argument": {"la": "question", "soft_max_for_period": "method", "brent":"question"} "arguments": [
{
"key": "la",
"label": true,
"i18n_template": "la"
},
{
"key": "soft_max_for_period",
"label": false,
"i18n_template": "soft_max_for_period"
},
{
"key":"brent",
"label": true,
"i18n_template": "brent"
}
]
}, },
"questions": { "questions": {
"rent_value_check": { "rent_value_check": {

11
config/locales/en.yml

@ -223,13 +223,14 @@ en:
cannot_be_internal_transfer: "Answer cannot be internal transfer as you already told us this is not a secure tenancy" cannot_be_internal_transfer: "Answer cannot be internal transfer as you already told us this is not a secure tenancy"
not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household" not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household"
joint_more_than_one_member: "There must be more than one person in the household as you've told us this is a joint tenancy" joint_more_than_one_member: "There must be more than one person in the household as you've told us this is a joint tenancy"
declaration: declaration:
missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log." missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log."
soft_validations: soft_validations:
net_income: net_income:
title_text: "Net income is outside the expected range based on the lead tenant’s working situation"
hint_text: "<p>You told us the lead tenant’s working situation is: <strong>%{ecstat1}</strong>.</p><p>The household income you have entered is <strong>%{earnings}</strong>.</p>" hint_text: "<p>You told us the lead tenant’s working situation is: <strong>%{ecstat1}</strong>.</p><p>The household income you have entered is <strong>%{earnings}</strong>.</p>"
in_soft_min_range: in_soft_min_range:
message: "Net income is lower than expected based on the lead tenant’s working situation. Are you sure this is correct?" message: "Net income is lower than expected based on the lead tenant’s working situation. Are you sure this is correct?"
@ -240,6 +241,14 @@ en:
hint_text: "<h1 class=\"govuk-heading-l app-panel--interruption\">You told us the rent is %{brent}</h1><p>The minimum rent for this type of property in %{la} is £%{soft_min_for_period}.</p>" hint_text: "<h1 class=\"govuk-heading-l app-panel--interruption\">You told us the rent is %{brent}</h1><p>The minimum rent for this type of property in %{la} is £%{soft_min_for_period}.</p>"
max: max:
hint_text: "<h1 class=\"govuk-heading-l app-panel--interruption\">You told us the rent is %{brent}</h1><p>The maximum rent for this type of property in %{la} is £%{soft_max_for_period}.</p>" hint_text: "<h1 class=\"govuk-heading-l app-panel--interruption\">You told us the rent is %{brent}</h1><p>The maximum rent for this type of property in %{la} is £%{soft_max_for_period}.</p>"
retirement:
min:
title: "Age is below the expected range based on the person being retired"
hint_text: "This person cannot be retired as you told us they're %{gender} and under %{age}"
max:
title: "Age is above the expected range based on the person not being retired"
hint_text: "This person must be retired as you told us they're %{gender} and over %{age}"
devise: devise:
two_factor_authentication: two_factor_authentication:
success: "Two-factor authentication successful" success: "Two-factor authentication successful"

5
db/migrate/20220509110842_add_retirement_value_check.rb

@ -0,0 +1,5 @@
class AddRetirementValueCheck < ActiveRecord::Migration[7.0]
def change
add_column :case_logs, :retirement_value_check, :integer
end
end

1
db/schema.rb

@ -224,6 +224,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_05_11_114334) do
t.integer "illness_type_0" t.integer "illness_type_0"
t.integer "tshortfall_known" t.integer "tshortfall_known"
t.integer "shelteredaccom" t.integer "shelteredaccom"
t.integer "retirement_value_check"
t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true

99
spec/helpers/interruption_screen_helper_spec.rb

@ -0,0 +1,99 @@
require "rails_helper"
RSpec.describe InterruptionScreenHelper do
form_handler = FormHandler.instance
let(:form) { form_handler.get_form("test_form") }
let(:subsection) { form.get_subsection("household_characteristics") }
let(:user) { FactoryBot.create(:user) }
let(:case_log) do
FactoryBot.create(
:case_log,
:in_progress,
ecstat1: 1,
earnings: 750,
incfreq: 1,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
)
end
describe "display_informative_text" do
context "when 2 out of 2 arguments are given" do
it "returns correct informative text" do
informative_text = {
"translation" => "soft_validations.net_income.hint_text",
"arguments" => [
{
"key" => "ecstat1",
"label" => true,
"i18n_template" => "ecstat1",
},
{
"key" => "earnings",
"label" => true,
"i18n_template" => "earnings",
},
],
}
expect(display_informative_text(informative_text, case_log))
.to eq("<p>You told us the lead tenant’s working situation is: <strong>Full-time – 30 hours or more</strong>.</p><p>The household income you have entered is <strong>£750.00 every week</strong>.</p>")
end
end
context "when 1 out of 1 arguments is given" do
it "returns correct informative text" do
informative_text = {
"translation" => "test.one_argument",
"arguments" => [
{
"key" => "ecstat1",
"label" => true,
"i18n_template" => "ecstat1",
},
],
}
expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more")
end
end
context "when 2 out of 1 arguments are given" do
it "returns correct informative text" do
informative_text = {
"translation" => "test.one_argument",
"arguments" => [
{
"key" => "ecstat1",
"label" => true,
"i18n_template" => "ecstat1",
},
{
"key" => "earnings",
"label" => true,
"i18n_template" => "earnings",
},
],
}
expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more")
end
end
context "when 1 out of 2 arguments are given" do
it "returns an empty string" do
informative_text = {
"translation" => "soft_validations.net_income.hint_text",
"arguments" => [
{
"key" => "ecstat1",
"label" => true,
"i18n_template" => "ecstat1",
},
],
}
expect(display_informative_text(informative_text, case_log))
.to eq("")
end
end
end
end

65
spec/helpers/interuption_screen_helper_spec.rb

@ -1,65 +0,0 @@
require "rails_helper"
RSpec.describe InteruptionScreenHelper do
form_handler = FormHandler.instance
let(:form) { form_handler.get_form("test_form") }
let(:subsection) { form.get_subsection("household_characteristics") }
let(:user) { FactoryBot.create(:user) }
let(:case_log) do
FactoryBot.create(
:case_log,
:in_progress,
ecstat1: 1,
earnings: 750,
incfreq: 1,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
)
end
describe "display_informative_text" do
context "when 2 out of 2 arguments are given" do
it "returns correct informative text" do
informative_text = {
"translation" => "soft_validations.net_income.hint_text",
"argument" => { "ecstat1": "question", "earnings": "question" },
}
expect(display_informative_text(informative_text, case_log))
.to eq("<p>You told us the lead tenant’s working situation is: <strong>Full-time – 30 hours or more</strong>.</p><p>The household income you have entered is <strong>£750.00 every week</strong>.</p>")
end
end
context "when 1 out of 1 arguments is given" do
it "returns correct informative text" do
informative_text = {
"translation" => "test.one_argument",
"argument" => { "ecstat1": "question" },
}
expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more")
end
end
end
context "when 2 out of 1 arguments are given" do
it "returns correct informative text" do
informative_text = {
"translation" => "test.one_argument",
"argument" => { "ecstat1": "question", "earnings": "question" },
}
expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more")
end
end
context "when 1 out of 2 arguments are given" do
it "returns an empty string" do
informative_text = {
"translation" => "soft_validations.net_income.hint_text",
"argument" => { "ecstat1": "question" },
}
expect(display_informative_text(informative_text, case_log))
.to eq("")
end
end
end
Loading…
Cancel
Save