Browse Source

Separate max and min error screens

pull/434/head
Kat 3 years ago
parent
commit
86e57231ef
  1. 10
      app/helpers/interuption_screen_helper.rb
  2. 8
      app/models/case_log.rb
  3. 2
      app/models/form.rb
  4. 32
      config/forms/2021_2022.json
  5. 6
      config/locales/en.yml
  6. 2
      spec/fixtures/forms/2021_2022.json
  7. 8
      spec/helpers/interuption_screen_helper_spec.rb

10
app/helpers/interuption_screen_helper.rb

@ -1,14 +1,10 @@
module InteruptionScreenHelper module InteruptionScreenHelper
def display_informative_text(informative_text, case_log) def display_informative_text(informative_text, case_log)
translation_questions = informative_text["argument"].map { |x| case_log.form.get_question(x, 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 begin
case translation_questions.count 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])
when 2
translation = I18n.t(informative_text["translation"], informative_text["argument"][0].to_sym => translation_questions[0].answer_label(case_log), informative_text["argument"][1].to_sym => translation_questions[1].answer_label(case_log))
when 1
translation = I18n.t(informative_text["translation"], informative_text["argument"][0].to_sym => translation_questions[0].answer_label(case_log))
end
rescue StandardError rescue StandardError
return "" return ""
end end

8
app/models/case_log.rb

@ -285,6 +285,14 @@ class CaseLog < ApplicationRecord
[30, 31].any?(prevten) [30, 31].any?(prevten)
end end
def soft_min
LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:).soft_min
end
def soft_max
LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:).soft_max
end
private private
PIO = Postcodes::IO.new PIO = Postcodes::IO.new

2
app/models/form.rb

@ -37,7 +37,7 @@ class Form
def next_page(page, case_log) def next_page(page, case_log)
page_ids = subsection_for_page(page).pages.map(&:id) page_ids = subsection_for_page(page).pages.map(&:id)
page_index = page_ids.index(page.id) page_index = page_ids.index(page.id)
page_id = page.id.include?("value_check") && case_log[page.questions[0].id] == 1 ? previous_page(page_ids, page_index, case_log) : page_ids[page_index + 1] page_id = page.id.include?("value_check") && case_log[page.questions[0].id] == 1 && page.routed_to?(case_log) ? previous_page(page_ids, page_index, case_log) : page_ids[page_index + 1]
nxt_page = get_page(page_id) nxt_page = get_page(page_id)
return :check_answers if nxt_page.nil? return :check_answers if nxt_page.nil?

32
config/forms/2021_2022.json

@ -4578,7 +4578,7 @@
"title_text": "Net income is outside the expected range based on the main tenant’s working situation", "title_text": "Net income is outside the expected range based on the main tenant’s working situation",
"informative_text": { "informative_text": {
"translation": "soft_validations.net_income.hint_text", "translation": "soft_validations.net_income.hint_text",
"argument": ["ecstat1", "earnings"] "argument": {"ecstat1": "question", "earnings": "question"}
}, },
"questions": { "questions": {
"net_income_value_check": { "net_income_value_check": {
@ -5568,12 +5568,36 @@
} }
] ]
}, },
"min_rent_value_check": {
"depends_on": [{ "rent_in_soft_min_range?": true }],
"title_text": "Rent value is outside of the expected range",
"informative_text": {
"translation": "soft_validations.rent.min.hint_text",
"argument": {"la": "question", "soft_min": "method", "brent":"question"}
},
"questions": {
"rent_value_check": { "rent_value_check": {
"depends_on": [{ "rent_in_soft_validation_range?": true }], "check_answer_label": "Rent 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"
}
}
}
}
},
"max_rent_value_check": {
"depends_on": [{ "rent_in_soft_max_range?": true }],
"title_text": "Rent value is outside of the expected range", "title_text": "Rent value is outside of the expected range",
"informative_text": { "informative_text": {
"translation": "soft_validations.rent.min_max.hint_text", "translation": "soft_validations.rent.max.hint_text",
"argument": ["brent"] "argument": {"la": "question", "soft_max": "method", "brent":"question"}
}, },
"questions": { "questions": {
"rent_value_check": { "rent_value_check": {

6
config/locales/en.yml

@ -225,8 +225,10 @@ en:
in_soft_max_range: in_soft_max_range:
message: "Net income is higher than expected based on the main tenant’s working situation. Are you sure this is correct?" message: "Net income is higher than expected based on the main tenant’s working situation. Are you sure this is correct?"
rent: rent:
min_max: min:
hint_text: "You have entered %{brent}" hint_text: "<p>The minimum rent for a property in %{la} is £%{soft_min} every week.</p><p>You entered <strong>%{brent}</strong></p>"
max:
hint_text: "<p>The maximum rent for a property in %{la} is £%{soft_max} every week.</p><p>You entered <strong>%{brent}</strong></p>"
devise: devise:
two_factor_authentication: two_factor_authentication:
success: "Two factor authentication successful." success: "Two factor authentication successful."

2
spec/fixtures/forms/2021_2022.json vendored

@ -562,7 +562,7 @@
"title_text": "Net income is outside the expected range based on the main tenant’s working situation", "title_text": "Net income is outside the expected range based on the main tenant’s working situation",
"informative_text": { "informative_text": {
"translation": "soft_validations.net_income.hint_text", "translation": "soft_validations.net_income.hint_text",
"argument": ["ecstat1", "earnings"] "argument": {"ecstat1": "question", "earnings": "question"}
}, },
"questions": { "questions": {
"net_income_value_check": { "net_income_value_check": {

8
spec/helpers/interuption_screen_helper_spec.rb

@ -22,7 +22,7 @@ RSpec.describe InteruptionScreenHelper do
it "returns correct informative text" do it "returns correct informative text" do
informative_text = { informative_text = {
"translation" => "soft_validations.net_income.hint_text", "translation" => "soft_validations.net_income.hint_text",
"argument" => %w[ecstat1 earnings], "argument" => { "ecstat1": "question", "earnings": "question" },
} }
expect(display_informative_text(informative_text, case_log)) expect(display_informative_text(informative_text, case_log))
.to eq("<p>You told us the main 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>") .to eq("<p>You told us the main 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>")
@ -33,7 +33,7 @@ RSpec.describe InteruptionScreenHelper do
it "returns correct informative text" do it "returns correct informative text" do
informative_text = { informative_text = {
"translation" => "test.one_argument", "translation" => "test.one_argument",
"argument" => %w[ecstat1], "argument" => { "ecstat1": "question" },
} }
expect(display_informative_text(informative_text, case_log)) 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") .to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more")
@ -45,7 +45,7 @@ RSpec.describe InteruptionScreenHelper do
it "returns correct informative text" do it "returns correct informative text" do
informative_text = { informative_text = {
"translation" => "test.one_argument", "translation" => "test.one_argument",
"argument" => %w[ecstat1 earnings], "argument" => { "ecstat1": "question", "earnings": "question" },
} }
expect(display_informative_text(informative_text, case_log)) 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") .to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more")
@ -56,7 +56,7 @@ RSpec.describe InteruptionScreenHelper do
it "returns an empty string" do it "returns an empty string" do
informative_text = { informative_text = {
"translation" => "soft_validations.net_income.hint_text", "translation" => "soft_validations.net_income.hint_text",
"argument" => %w[ecstat1], "argument" => { "ecstat1": "question" },
} }
expect(display_informative_text(informative_text, case_log)) expect(display_informative_text(informative_text, case_log))
.to eq("") .to eq("")

Loading…
Cancel
Save