From 41d038035a3b817c2ce5886da7e24163207ac263 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 5 Feb 2024 10:06:37 +0000 Subject: [PATCH] Update optional hint text for deposit in 24/25 --- .../pages/about_deposit_with_discount.rb | 17 ++++--- .../pages/about_deposit_without_discount.rb | 20 ++++++--- .../form/sales/questions/deposit_amount.rb | 12 ++++- .../discounted_ownership_scheme.rb | 2 +- .../form/sales/subsections/outright_sale.rb | 2 +- .../subsections/shared_ownership_scheme.rb | 8 ++-- app/models/sales_log.rb | 4 ++ .../pages/about_deposit_with_discount_spec.rb | 40 ++++++++++++++++- .../about_deposit_without_discount_spec.rb | 44 ++++++++++++++++++- .../sales/questions/deposit_amount_spec.rb | 10 ++++- .../shared_ownership_scheme_spec.rb | 4 ++ 11 files changed, 142 insertions(+), 21 deletions(-) diff --git a/app/models/form/sales/pages/about_deposit_with_discount.rb b/app/models/form/sales/pages/about_deposit_with_discount.rb index 1c684b0bc..5d1e41a95 100644 --- a/app/models/form/sales/pages/about_deposit_with_discount.rb +++ b/app/models/form/sales/pages/about_deposit_with_discount.rb @@ -1,15 +1,22 @@ class Form::Sales::Pages::AboutDepositWithDiscount < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "about_deposit_with_discount" + def initialize(id, hsh, subsection, optional:) + super(id, hsh, subsection) @header = "About the deposit" - @depends_on = [{ "is_type_discount?" => true }] + @optional = optional end def questions @questions ||= [ - Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: 1), + Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: 1, optional: @optional), Form::Sales::Questions::DepositDiscount.new(nil, nil, self), ] end + + def depends_on + if form.start_year_after_2024? + [{ "is_type_discount?" => true, "stairowned_100?" => @optional }] + else + [{ "is_type_discount?" => true }] + end + end end diff --git a/app/models/form/sales/pages/about_deposit_without_discount.rb b/app/models/form/sales/pages/about_deposit_without_discount.rb index 1114b8f84..fdd74cf31 100644 --- a/app/models/form/sales/pages/about_deposit_without_discount.rb +++ b/app/models/form/sales/pages/about_deposit_without_discount.rb @@ -1,16 +1,26 @@ class Form::Sales::Pages::AboutDepositWithoutDiscount < ::Form::Page - def initialize(id, hsh, subsection, ownershipsch:) + def initialize(id, hsh, subsection, ownershipsch:, optional:) super(id, hsh, subsection) @header = "About the deposit" - @depends_on = [{ "is_type_discount?" => false, "ownershipsch" => 1 }, - { "ownershipsch" => 2 }, - { "ownershipsch" => 3, "mortgageused" => 1 }] @ownershipsch = ownershipsch + @optional = optional end def questions @questions ||= [ - Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: @ownershipsch), + Form::Sales::Questions::DepositAmount.new(nil, nil, self, ownershipsch: @ownershipsch, optional: @optional), ] end + + def depends_on + if form.start_year_after_2024? + [{ "is_type_discount?" => false, "ownershipsch" => 1, "stairowned_100?" => @optional }, + { "ownershipsch" => 2 }, + { "ownershipsch" => 3, "mortgageused" => 1 }] + else + [{ "is_type_discount?" => false, "ownershipsch" => 1 }, + { "ownershipsch" => 2 }, + { "ownershipsch" => 3, "mortgageused" => 1 }] + end + end end diff --git a/app/models/form/sales/questions/deposit_amount.rb b/app/models/form/sales/questions/deposit_amount.rb index 784bb56a1..689299e56 100644 --- a/app/models/form/sales/questions/deposit_amount.rb +++ b/app/models/form/sales/questions/deposit_amount.rb @@ -1,5 +1,5 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question - def initialize(id, hsh, subsection, ownershipsch:) + def initialize(id, hsh, subsection, ownershipsch:, optional:) super(id, hsh, subsection) @id = "deposit" @check_answer_label = "Cash deposit" @@ -10,10 +10,10 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question @step = 1 @width = 5 @prefix = "£" - @hint_text = "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage" @derived = true @ownershipsch = ownershipsch @question_number = question_number + @optional = optional end def selected_answer_option_is_derived?(_log) @@ -30,4 +30,12 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question 116 end end + + def hint_text + if @optional + "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. As this is a fully staircased sale this question is optional. If you do not have the information available click save and continue" + else + "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage" + end + end end diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index 52ee9e95c..200565ab6 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -31,7 +31,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::MortgageLength.new("mortgage_length_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_discounted_ownership", nil, self, ownershipsch: 2), Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_value_check", nil, self), - Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self, ownershipsch: 2), + Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self, ownershipsch: 2, optional: false), Form::Sales::Pages::ExtraBorrowingValueCheck.new("extra_borrowing_deposit_value_check", nil, self), Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self), Form::Sales::Pages::DepositAndMortgageValueCheck.new("discounted_ownership_deposit_and_mortgage_value_check_after_deposit", nil, self), diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index 245cbcb10..39275d7b2 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/app/models/form/sales/subsections/outright_sale.rb @@ -18,7 +18,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection (Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_outright_sale", nil, self, ownershipsch: 3) unless form.start_year_after_2024?), Form::Sales::Pages::MortgageLength.new("mortgage_length_outright_sale", nil, self, ownershipsch: 3), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_outright_sale", nil, self, ownershipsch: 3), - Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self, ownershipsch: 3), + Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self, ownershipsch: 3, optional: false), Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self), leasehold_charge_pages, Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_outright_sale_value_check", nil, self), diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 66a711dcd..9688702f9 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -37,14 +37,16 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::MortgageLenderOther.new("mortgage_lender_other_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::ExtraBorrowing.new("extra_borrowing_shared_ownership", nil, self, ownershipsch: 1), - Form::Sales::Pages::AboutDepositWithDiscount.new(nil, nil, self), - Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self, ownershipsch: 1), + Form::Sales::Pages::AboutDepositWithDiscount.new("about_deposit_with_discount", nil, self, optional: false), + form.start_year_after_2024? ? Form::Sales::Pages::AboutDepositWithDiscount.new("about_deposit_with_discount_optional", nil, self, optional: true) : nil, + Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false), + form.start_year_after_2024? ? Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true) : nil, Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self), Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), Form::Sales::Pages::MonthlyRent.new(nil, nil, self), Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self, ownershipsch: 1), Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self), - ] + ].compact end def displayed_in_tasklist?(log) diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 76c43b09e..11d373903 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -495,4 +495,8 @@ class SalesLog < Log def is_not_staircasing? staircase == 2 || staircase == 3 end + + def stairowned_100? + stairowned == 100 + end end diff --git a/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb b/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb index cc33a9641..89db397f1 100644 --- a/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb +++ b/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb @@ -1,12 +1,16 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::AboutDepositWithDiscount, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, optional: false) } - let(:page_id) { nil } + let(:page_id) { "about_deposit_with_discount" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + before do + allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: false)) + end + it "has correct subsection" do expect(page.subsection).to eq(subsection) end @@ -32,4 +36,36 @@ RSpec.describe Form::Sales::Pages::AboutDepositWithDiscount, type: :model do [{ "is_type_discount?" => true }], ) end + + context "when optional" do + subject(:page) { described_class.new(page_id, page_definition, subsection, optional: true) } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "is_type_discount?" => true }], + ) + end + end + + context "when it's a 2024 form" do + before do + allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: true)) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "is_type_discount?" => true, "stairowned_100?" => false }], + ) + end + + context "and optional" do + subject(:page) { described_class.new(page_id, page_definition, subsection, optional: true) } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "is_type_discount?" => true, "stairowned_100?" => true }], + ) + end + end + end end diff --git a/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb b/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb index 1a0b5ef4d..1a4e420c6 100644 --- a/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb +++ b/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb @@ -1,12 +1,16 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::AboutDepositWithoutDiscount, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1) } + subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: false) } let(:page_id) { nil } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + before do + allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: false)) + end + it "has correct subsection" do expect(page.subsection).to eq(subsection) end @@ -34,4 +38,42 @@ RSpec.describe Form::Sales::Pages::AboutDepositWithoutDiscount, type: :model do { "ownershipsch" => 3, "mortgageused" => 1 }], ) end + + context "when optional is true" do + subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: true) } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "is_type_discount?" => false, "ownershipsch" => 1 }, + { "ownershipsch" => 2 }, + { "ownershipsch" => 3, "mortgageused" => 1 }], + ) + end + end + + context "when it's a 2024 form" do + before do + allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: true)) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "is_type_discount?" => false, "ownershipsch" => 1, "stairowned_100?" => false }, + { "ownershipsch" => 2 }, + { "ownershipsch" => 3, "mortgageused" => 1 }], + ) + end + + context "and optional is true" do + subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional: true) } + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "is_type_discount?" => false, "ownershipsch" => 1, "stairowned_100?" => true }, + { "ownershipsch" => 2 }, + { "ownershipsch" => 3, "mortgageused" => 1 }], + ) + end + end + end end diff --git a/spec/models/form/sales/questions/deposit_amount_spec.rb b/spec/models/form/sales/questions/deposit_amount_spec.rb index e0a77b7fc..80429b5af 100644 --- a/spec/models/form/sales/questions/deposit_amount_spec.rb +++ b/spec/models/form/sales/questions/deposit_amount_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1) } + subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1, optional: false) } let(:question_id) { nil } let(:question_definition) { nil } @@ -50,4 +50,12 @@ RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do it "has correct max" do expect(question.max).to eq(999_999) end + + context "when optional iis true" do + subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1, optional: true) } + + it "has a correct hint_text" do + expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. As this is a fully staircased sale this question is optional. If you do not have the information available click save and continue") + end + end end diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb index 192f7cbda..3746768d0 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -7,6 +7,10 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do let(:subsection_definition) { nil } let(:section) { instance_double(Form::Sales::Sections::SaleInformation) } + before do + allow(section).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: false)) + end + it "has correct section" do expect(shared_ownership_scheme.section).to eq(section) end