From 5385126694149d3e5e668179545a4e11bfb90aef Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 13 Mar 2023 14:24:53 +0000 Subject: [PATCH] Add carehome charges soft validation to 23/24 forms --- .../pages/care_home_charges_value_check.rb | 15 +++++ .../care_home_charges_value_check.rb | 14 +++++ .../subsections/income_and_benefits.rb | 1 + app/models/lettings_log.rb | 4 ++ config/locales/en.yml | 2 + .../care_home_charges_value_check_spec.rb | 44 +++++++++++++++ .../care_home_charges_value_check_spec.rb | 56 +++++++++++++++++++ .../subsections/income_and_benefits_spec.rb | 1 + 8 files changed, 137 insertions(+) create mode 100644 app/models/form/lettings/pages/care_home_charges_value_check.rb create mode 100644 app/models/form/lettings/questions/care_home_charges_value_check.rb create mode 100644 spec/models/form/lettings/pages/care_home_charges_value_check_spec.rb create mode 100644 spec/models/form/lettings/questions/care_home_charges_value_check_spec.rb diff --git a/app/models/form/lettings/pages/care_home_charges_value_check.rb b/app/models/form/lettings/pages/care_home_charges_value_check.rb new file mode 100644 index 000000000..32468e364 --- /dev/null +++ b/app/models/form/lettings/pages/care_home_charges_value_check.rb @@ -0,0 +1,15 @@ +class Form::Lettings::Pages::CareHomeChargesValueCheck < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "care_home_charges_value_check" + @depends_on = [{ "care_home_charge_expected_not_provided?" => true }] + @title_text = { + "translation" => "soft_validations.care_home_charges.title_text", + } + @informative_text = "" + end + + def questions + @questions ||= [Form::Lettings::Questions::CareHomeChargesValueCheck.new(nil, nil, self)] + end +end diff --git a/app/models/form/lettings/questions/care_home_charges_value_check.rb b/app/models/form/lettings/questions/care_home_charges_value_check.rb new file mode 100644 index 000000000..fdb5aabbd --- /dev/null +++ b/app/models/form/lettings/questions/care_home_charges_value_check.rb @@ -0,0 +1,14 @@ +class Form::Lettings::Questions::CareHomeChargesValueCheck < ::Form::Question + def initialize(id, hsh, page) + super + @id = "carehome_charges_value_check" + @check_answer_label = "Care home charges confirmation" + @header = "Are you sure there are no care home charges?" + @type = "interruption_screen" + @check_answers_card_number = 0 + @answer_options = ANSWER_OPTIONS + @hidden_in_check_answers = { "depends_on" => [{ "carehome_charges_value_check" => 0 }, { "carehome_charges_value_check" => 1 }] } + end + + ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze +end diff --git a/app/models/form/lettings/subsections/income_and_benefits.rb b/app/models/form/lettings/subsections/income_and_benefits.rb index 92adf3c5e..30ba3a7e0 100644 --- a/app/models/form/lettings/subsections/income_and_benefits.rb +++ b/app/models/form/lettings/subsections/income_and_benefits.rb @@ -19,6 +19,7 @@ class Form::Lettings::Subsections::IncomeAndBenefits < ::Form::Subsection Form::Lettings::Pages::CareHomeBiWeekly.new(nil, nil, self), Form::Lettings::Pages::CareHome4Weekly.new(nil, nil, self), Form::Lettings::Pages::CareHomeMonthly.new(nil, nil, self), + Form::Lettings::Pages::CareHomeChargesValueCheck.new(nil, nil, self), Form::Lettings::Pages::RentWeekly.new(nil, nil, self), Form::Lettings::Pages::RentBiWeekly.new(nil, nil, self), Form::Lettings::Pages::Rent4Weekly.new(nil, nil, self), diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 4524ead12..c8aa65546 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -501,6 +501,10 @@ class LettingsLog < Log update!(created_by: nil) end + def care_home_charge_expected_not_provided? + true + end + private def reset_derived_questions diff --git a/config/locales/en.yml b/config/locales/en.yml index 053929f46..36d8b93f8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -528,6 +528,8 @@ en: discounted_sale_value: title_text: "Mortgage, deposit, and grant total must equal £%{value_with_discount}" informative_text: "Your given mortgage, deposit and grant total is £%{mortgage_deposit_and_grant_total}" + care_home_charges: + title_text: "Care home charges should be provided if this is a care home accommodation" devise: two_factor_authentication: diff --git a/spec/models/form/lettings/pages/care_home_charges_value_check_spec.rb b/spec/models/form/lettings/pages/care_home_charges_value_check_spec.rb new file mode 100644 index 000000000..c81538146 --- /dev/null +++ b/spec/models/form/lettings/pages/care_home_charges_value_check_spec.rb @@ -0,0 +1,44 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::CareHomeChargesValueCheck, type: :model do + subject(:page) { described_class.new(nil, page_definition, subsection) } + + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has the correct header" do + expect(page.header).to be nil + end + + it "has the correct description" do + expect(page.description).to be nil + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[carehome_charges_value_check]) + end + + it "has the correct id" do + expect(page.id).to eq("care_home_charges_value_check") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "care_home_charge_expected_not_provided?" => true }], + ) + end + + it "has the correct title_text" do + expect(page.title_text).to eq({ + "translation" => "soft_validations.care_home_charges.title_text", + }) + end + + it "has the correct informative_text" do + expect(page.informative_text).to eq("") + end +end diff --git a/spec/models/form/lettings/questions/care_home_charges_value_check_spec.rb b/spec/models/form/lettings/questions/care_home_charges_value_check_spec.rb new file mode 100644 index 000000000..d31891c5d --- /dev/null +++ b/spec/models/form/lettings/questions/care_home_charges_value_check_spec.rb @@ -0,0 +1,56 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::CareHomeChargesValueCheck, type: :model do + subject(:question) { described_class.new(nil, question_definition, page) } + + let(:question_definition) { 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("carehome_charges_value_check") + end + + it "has the correct header" do + expect(question.header).to eq("Are you sure there are no care home charges?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Care home charges confirmation") + end + + it "has the correct type" do + expect(question.type).to eq("interruption_screen") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + 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" => [ + { + "carehome_charges_value_check" => 0, + }, + { + "carehome_charges_value_check" => 1, + }, + ], + }) + end +end diff --git a/spec/models/form/lettings/subsections/income_and_benefits_spec.rb b/spec/models/form/lettings/subsections/income_and_benefits_spec.rb index 2c4310d5b..8dd4f88a3 100644 --- a/spec/models/form/lettings/subsections/income_and_benefits_spec.rb +++ b/spec/models/form/lettings/subsections/income_and_benefits_spec.rb @@ -25,6 +25,7 @@ RSpec.describe Form::Lettings::Subsections::IncomeAndBenefits, type: :model do care_home_bi_weekly care_home_4_weekly care_home_monthly + care_home_charges_value_check rent_weekly rent_bi_weekly rent_4_weekly