From 86e57231ef4269ea4c96fc5dcddbb36e84e19191 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 30 Mar 2022 11:18:02 +0100 Subject: [PATCH] Separate max and min error screens --- app/helpers/interuption_screen_helper.rb | 10 ++---- app/models/case_log.rb | 8 +++++ app/models/form.rb | 2 +- config/forms/2021_2022.json | 34 ++++++++++++++++--- config/locales/en.yml | 6 ++-- spec/fixtures/forms/2021_2022.json | 2 +- .../helpers/interuption_screen_helper_spec.rb | 8 ++--- 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/app/helpers/interuption_screen_helper.rb b/app/helpers/interuption_screen_helper.rb index 766668c60..393134f83 100644 --- a/app/helpers/interuption_screen_helper.rb +++ b/app/helpers/interuption_screen_helper.rb @@ -1,14 +1,10 @@ module InteruptionScreenHelper 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 - case translation_questions.count - 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 + 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 diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 94589db0d..d3271083c 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -285,6 +285,14 @@ class CaseLog < ApplicationRecord [30, 31].any?(prevten) 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 PIO = Postcodes::IO.new diff --git a/app/models/form.rb b/app/models/form.rb index cd3c5a972..3f1a83224 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -37,7 +37,7 @@ class Form def next_page(page, case_log) page_ids = subsection_for_page(page).pages.map(&: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) return :check_answers if nxt_page.nil? diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 68438ab41..f14084727 100644 --- a/config/forms/2021_2022.json +++ b/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", "informative_text": { "translation": "soft_validations.net_income.hint_text", - "argument": ["ecstat1", "earnings"] + "argument": {"ecstat1": "question", "earnings": "question"} }, "questions": { "net_income_value_check": { @@ -5568,12 +5568,36 @@ } ] }, - "rent_value_check": { - "depends_on": [{ "rent_in_soft_validation_range?": true }], + "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_max.hint_text", - "argument": ["brent"] + "translation": "soft_validations.rent.min.hint_text", + "argument": {"la": "question", "soft_min": "method", "brent":"question"} + }, + "questions": { + "rent_value_check": { + "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", + "informative_text": { + "translation": "soft_validations.rent.max.hint_text", + "argument": {"la": "question", "soft_max": "method", "brent":"question"} }, "questions": { "rent_value_check": { diff --git a/config/locales/en.yml b/config/locales/en.yml index a5696d1be..ab8c70099 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -225,8 +225,10 @@ en: 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?" rent: - min_max: - hint_text: "You have entered %{brent}" + min: + hint_text: "

The minimum rent for a property in %{la} is £%{soft_min} every week.

You entered %{brent}

" + max: + hint_text: "

The maximum rent for a property in %{la} is £%{soft_max} every week.

You entered %{brent}

" devise: two_factor_authentication: success: "Two factor authentication successful." diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 8bd6c662e..06c471ff2 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -562,7 +562,7 @@ "title_text": "Net income is outside the expected range based on the main tenant’s working situation", "informative_text": { "translation": "soft_validations.net_income.hint_text", - "argument": ["ecstat1", "earnings"] + "argument": {"ecstat1": "question", "earnings": "question"} }, "questions": { "net_income_value_check": { diff --git a/spec/helpers/interuption_screen_helper_spec.rb b/spec/helpers/interuption_screen_helper_spec.rb index 3ad158857..9b050cf14 100644 --- a/spec/helpers/interuption_screen_helper_spec.rb +++ b/spec/helpers/interuption_screen_helper_spec.rb @@ -22,7 +22,7 @@ RSpec.describe InteruptionScreenHelper do it "returns correct informative text" do informative_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)) .to eq("

You told us the main tenant’s working situation is: Full-time – 30 hours or more

The household income you have entered is £750.00 every week

") @@ -33,7 +33,7 @@ RSpec.describe InteruptionScreenHelper do it "returns correct informative text" do informative_text = { "translation" => "test.one_argument", - "argument" => %w[ecstat1], + "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") @@ -45,7 +45,7 @@ RSpec.describe InteruptionScreenHelper do it "returns correct informative text" do informative_text = { "translation" => "test.one_argument", - "argument" => %w[ecstat1 earnings], + "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") @@ -56,7 +56,7 @@ RSpec.describe InteruptionScreenHelper do it "returns an empty string" do informative_text = { "translation" => "soft_validations.net_income.hint_text", - "argument" => %w[ecstat1], + "argument" => { "ecstat1": "question" }, } expect(display_informative_text(informative_text, case_log)) .to eq("")