From 9662b14bdefb2a112e096a9ef1e38d110781e0af Mon Sep 17 00:00:00 2001 From: Aaron Spencer <62190777+Airk0n@users.noreply.github.com> Date: Thu, 29 Jun 2023 16:57:46 +0100 Subject: [PATCH] CLDC 2439: apply 22/23 rent range soft validation to 23/24 (#1718) * CLDC-2439: min and max rent value check questions created * CLDC-2439: Informative removed, check pages fixed. * CLDC-2439: removed informative info tests and rent value check * CLDC-2439: fixed informative missing test failure * CLDC-2439: Text moved to en.yml * CLDC-2439: tests added, copy moved to en.yml * CLDC-2439: tests added, copy moved to en.yml * CLDC-2439: content change for bulk upload errors WIP * CLDC-2439: informative rendering change, content change, test updated * CLDC-2439: failing test fix. * CLDC-2439: display_informative_text test added for strings * CLDC-2439: string as var in test --- app/helpers/interruption_screen_helper.rb | 1 + .../lettings/pages/max_rent_value_check.rb | 25 +++-------- .../lettings/pages/min_rent_value_check.rb | 11 +---- .../questions/max_rent_value_check.rb | 15 +++++++ ...value_check.rb => min_rent_value_check.rb} | 3 +- config/locales/en.yml | 4 +- .../interruption_screen_helper_spec.rb | 7 +++ .../pages/max_rent_value_check_spec.rb | 4 -- .../pages/min_rent_value_check_spec.rb | 13 ------ .../questions/max_rent_value_check_spec.rb | 44 +++++++++++++++++++ .../questions/min_rent_value_check_spec.rb | 44 +++++++++++++++++++ .../lettings/year2023/row_parser_spec.rb | 2 +- 12 files changed, 125 insertions(+), 48 deletions(-) create mode 100644 app/models/form/lettings/questions/max_rent_value_check.rb rename app/models/form/lettings/questions/{rent_value_check.rb => min_rent_value_check.rb} (77%) create mode 100644 spec/models/form/lettings/questions/max_rent_value_check_spec.rb create mode 100644 spec/models/form/lettings/questions/min_rent_value_check_spec.rb diff --git a/app/helpers/interruption_screen_helper.rb b/app/helpers/interruption_screen_helper.rb index fc75f6f59..b28c7eaa9 100644 --- a/app/helpers/interruption_screen_helper.rb +++ b/app/helpers/interruption_screen_helper.rb @@ -1,5 +1,6 @@ module InterruptionScreenHelper def display_informative_text(informative_text, log) + return informative_text if informative_text.is_a? String return "" unless informative_text["arguments"] translation_params = {} diff --git a/app/models/form/lettings/pages/max_rent_value_check.rb b/app/models/form/lettings/pages/max_rent_value_check.rb index ffb90f035..82aff8481 100644 --- a/app/models/form/lettings/pages/max_rent_value_check.rb +++ b/app/models/form/lettings/pages/max_rent_value_check.rb @@ -4,29 +4,18 @@ class Form::Lettings::Pages::MaxRentValueCheck < ::Form::Page @depends_on = [{ "rent_in_soft_max_range?" => true }] @title_text = { "translation" => "soft_validations.rent.outside_range_title", - "arguments" => [ - { - "key" => "brent", - "label" => true, - "i18n_template" => "brent", - }, - ], - } - @informative_text = { - "translation" => "soft_validations.rent.max_hint_text", - "arguments" => [ - { - "key" => "field_formatted_as_currency", - "arguments_for_key" => "soft_max_for_period", - "i18n_template" => "soft_max_for_period", - }, - ], + "arguments" => [{ + "key" => "brent", + "label" => true, + "i18n_template" => "brent", + }], } + @informative_text = I18n.t("soft_validations.rent.informative_text", higher_or_lower: "higher") @check_answers_card_number = check_answers_card_number end def questions - @questions ||= [Form::Lettings::Questions::RentValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number)] + @questions ||= [Form::Lettings::Questions::MaxRentValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number)] end def interruption_screen_question_ids diff --git a/app/models/form/lettings/pages/min_rent_value_check.rb b/app/models/form/lettings/pages/min_rent_value_check.rb index f66bc5a7b..b2bae4e8e 100644 --- a/app/models/form/lettings/pages/min_rent_value_check.rb +++ b/app/models/form/lettings/pages/min_rent_value_check.rb @@ -10,19 +10,12 @@ class Form::Lettings::Pages::MinRentValueCheck < ::Form::Page "i18n_template" => "brent", }], } - @informative_text = { - "translation" => "soft_validations.rent.min_hint_text", - "arguments" => [{ - "key" => "field_formatted_as_currency", - "arguments_for_key" => "soft_min_for_period", - "i18n_template" => "soft_min_for_period", - }], - } + @informative_text = I18n.t("soft_validations.rent.informative_text", higher_or_lower: "lower") @check_answers_card_number = check_answers_card_number end def questions - @questions ||= [Form::Lettings::Questions::RentValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number)] + @questions ||= [Form::Lettings::Questions::MinRentValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number)] end def interruption_screen_question_ids diff --git a/app/models/form/lettings/questions/max_rent_value_check.rb b/app/models/form/lettings/questions/max_rent_value_check.rb new file mode 100644 index 000000000..6936e9e36 --- /dev/null +++ b/app/models/form/lettings/questions/max_rent_value_check.rb @@ -0,0 +1,15 @@ +class Form::Lettings::Questions::MaxRentValueCheck < ::Form::Question + def initialize(id, hsh, page, check_answers_card_number:) + super(id, hsh, page) + @id = "rent_value_check" + @check_answer_label = "Total rent confirmation" + @header = "Are you sure this is correct?" + @type = "interruption_screen" + @hint_text = I18n.t("soft_validations.rent.hint_text", higher_or_lower: "higher") + @check_answers_card_number = check_answers_card_number + @answer_options = ANSWER_OPTIONS + @hidden_in_check_answers = { "depends_on" => [{ "rent_value_check" => 0 }, { "rent_value_check" => 1 }] } + end + + ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze +end diff --git a/app/models/form/lettings/questions/rent_value_check.rb b/app/models/form/lettings/questions/min_rent_value_check.rb similarity index 77% rename from app/models/form/lettings/questions/rent_value_check.rb rename to app/models/form/lettings/questions/min_rent_value_check.rb index 6bca43e30..ad4111c61 100644 --- a/app/models/form/lettings/questions/rent_value_check.rb +++ b/app/models/form/lettings/questions/min_rent_value_check.rb @@ -1,10 +1,11 @@ -class Form::Lettings::Questions::RentValueCheck < ::Form::Question +class Form::Lettings::Questions::MinRentValueCheck < ::Form::Question def initialize(id, hsh, page, check_answers_card_number:) super(id, hsh, page) @id = "rent_value_check" @check_answer_label = "Total rent confirmation" @header = "Are you sure this is correct?" @type = "interruption_screen" + @hint_text = I18n.t("soft_validations.rent.hint_text", higher_or_lower: "lower") @check_answers_card_number = check_answers_card_number @answer_options = ANSWER_OPTIONS @hidden_in_check_answers = { "depends_on" => [{ "rent_value_check" => 0 }, { "rent_value_check" => 1 }] } diff --git a/config/locales/en.yml b/config/locales/en.yml index 49aa2d6f1..1365fda3d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -595,8 +595,8 @@ en: over_soft_max_for_la_combined: "You told us the combined income of this household is %{combined_income}. This seems high. Are you sure this is correct?" rent: outside_range_title: "You told us the rent is %{brent}" - min_hint_text: "The minimum rent expected for this type of property in this local authority is %{soft_min_for_period}." - max_hint_text: "The maximum rent expected for this type of property in this local authority is %{soft_max_for_period}." + informative_text: "This is %{higher_or_lower} than we would expect." + hint_text: "Check the following:" purchase_price: title_text: "You told us the purchase price is %{value}" hint_text: "This is %{higher_or_lower} than we would expect" diff --git a/spec/helpers/interruption_screen_helper_spec.rb b/spec/helpers/interruption_screen_helper_spec.rb index 6d9122f27..a100cf3ad 100644 --- a/spec/helpers/interruption_screen_helper_spec.rb +++ b/spec/helpers/interruption_screen_helper_spec.rb @@ -163,6 +163,13 @@ RSpec.describe InterruptionScreenHelper do expect(display_informative_text(informative_text_hash, lettings_log)).to eq("You said this: £12,345.00") end end + + context "when a string given" do + it "returns the string" do + test_string = "some words" + expect(display_informative_text(test_string, lettings_log)).to eq(test_string) + end + end end describe "display_title_text" do diff --git a/spec/models/form/lettings/pages/max_rent_value_check_spec.rb b/spec/models/form/lettings/pages/max_rent_value_check_spec.rb index 7bcc87913..4bbe3d18f 100644 --- a/spec/models/form/lettings/pages/max_rent_value_check_spec.rb +++ b/spec/models/form/lettings/pages/max_rent_value_check_spec.rb @@ -31,10 +31,6 @@ RSpec.describe Form::Lettings::Pages::MaxRentValueCheck, type: :model do expect(page.title_text).to eq({ "arguments" => [{ "i18n_template" => "brent", "key" => "brent", "label" => true }], "translation" => "soft_validations.rent.outside_range_title" }) end - it "has the correct informative_text" do - expect(page.informative_text).to eq({ "arguments" => [{ "arguments_for_key" => "soft_max_for_period", "i18n_template" => "soft_max_for_period", "key" => "field_formatted_as_currency" }], "translation" => "soft_validations.rent.max_hint_text" }) - end - it "has the correct interruption_screen_question_ids" do expect(page.interruption_screen_question_ids).to eq(%w[brent startdate uprn postcode_full la beds rent_type needstype]) end diff --git a/spec/models/form/lettings/pages/min_rent_value_check_spec.rb b/spec/models/form/lettings/pages/min_rent_value_check_spec.rb index bc3c6a081..613c907e9 100644 --- a/spec/models/form/lettings/pages/min_rent_value_check_spec.rb +++ b/spec/models/form/lettings/pages/min_rent_value_check_spec.rb @@ -40,19 +40,6 @@ RSpec.describe Form::Lettings::Pages::MinRentValueCheck, type: :model do }) end - it "has the correct informative_text" do - expect(page.informative_text).to eq({ - "translation" => "soft_validations.rent.min_hint_text", - "arguments" => [ - { - "key" => "field_formatted_as_currency", - "arguments_for_key" => "soft_min_for_period", - "i18n_template" => "soft_min_for_period", - }, - ], - }) - end - it "has the correct interruption_screen_question_ids" do expect(page.interruption_screen_question_ids).to eq(%w[brent startdate uprn postcode_full la beds rent_type needstype]) end diff --git a/spec/models/form/lettings/questions/max_rent_value_check_spec.rb b/spec/models/form/lettings/questions/max_rent_value_check_spec.rb new file mode 100644 index 000000000..0fea335c4 --- /dev/null +++ b/spec/models/form/lettings/questions/max_rent_value_check_spec.rb @@ -0,0 +1,44 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::MaxRentValueCheck, type: :model do + subject(:question) { described_class.new(nil, question_definition, page, check_answers_card_number:) } + + let(:question_definition) { nil } + let(:check_answers_card_number) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("rent_value_check") + end + + it "has the correct header" do + expect(question.header).to eq("Are you sure this is correct?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Total rent confirmation") + end + + it "has the correct type" do + expect(question.type).to eq("interruption_screen") + end + + it "has the correct hint" do + expect(question.hint_text).to eq("Check the following:") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "rent_value_check" => 0 }, { "rent_value_check" => 1 }] }) + end +end diff --git a/spec/models/form/lettings/questions/min_rent_value_check_spec.rb b/spec/models/form/lettings/questions/min_rent_value_check_spec.rb new file mode 100644 index 000000000..fec1e7d97 --- /dev/null +++ b/spec/models/form/lettings/questions/min_rent_value_check_spec.rb @@ -0,0 +1,44 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::MinRentValueCheck, type: :model do + subject(:question) { described_class.new(nil, question_definition, page, check_answers_card_number:) } + + let(:question_definition) { nil } + let(:check_answers_card_number) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("rent_value_check") + end + + it "has the correct header" do + expect(question.header).to eq("Are you sure this is correct?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Total rent confirmation") + end + + it "has the correct type" do + expect(question.type).to eq("interruption_screen") + end + + it "has the correct hint" do + expect(question.hint_text).to eq("Check the following:") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "rent_value_check" => 0 }, { "rent_value_check" => 1 }] }) + end +end diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 4df2757cd..f3a17ac44 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -1098,7 +1098,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do it "populates with correct error message" do expect(parser.errors.where(:field_128, category: :soft_validation).count).to be(1) - expect(parser.errors.where(:field_128, category: :soft_validation).first.message).to eql("You told us the rent is £120.00 every week. The maximum rent expected for this type of property in this local authority is ££118.85 every week.") + expect(parser.errors.where(:field_128, category: :soft_validation).first.message).to eql("You told us the rent is £120.00 every week. This is higher than we would expect.") end end end