From 09be3340cf9d0318caf4f042dfee2cc29b4a35e8 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 13 Feb 2023 16:30:12 +0000 Subject: [PATCH] Display the correct hint text depending on joint purchase --- .../pages/number_of_others_in_property.rb | 4 +- ...er_of_others_in_property_joint_purchase.rb | 22 ++++++++++ .../questions/number_of_others_in_property.rb | 6 +-- .../subsections/household_characteristics.rb | 1 + ..._others_in_property_joint_purchase_spec.rb | 42 +++++++++++++++++++ .../number_of_others_in_property_spec.rb | 13 ++++++ .../number_of_others_in_property_spec.rb | 11 ++++- .../household_characteristics_spec.rb | 6 +++ 8 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 app/models/form/sales/pages/number_of_others_in_property_joint_purchase.rb create mode 100644 spec/models/form/sales/pages/number_of_others_in_property_joint_purchase_spec.rb diff --git a/app/models/form/sales/pages/number_of_others_in_property.rb b/app/models/form/sales/pages/number_of_others_in_property.rb index c090422fd..edcaf22fa 100644 --- a/app/models/form/sales/pages/number_of_others_in_property.rb +++ b/app/models/form/sales/pages/number_of_others_in_property.rb @@ -5,16 +5,18 @@ class Form::Sales::Pages::NumberOfOthersInProperty < ::Form::Page @depends_on = [ { "privacynotice" => 1, + "jointpur" => 2, }, { "noint" => 1, + "jointpur" => 2, }, ] end def questions @questions ||= [ - Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self), + Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self, joint_purchase: false), ] end end diff --git a/app/models/form/sales/pages/number_of_others_in_property_joint_purchase.rb b/app/models/form/sales/pages/number_of_others_in_property_joint_purchase.rb new file mode 100644 index 000000000..2810a3a7e --- /dev/null +++ b/app/models/form/sales/pages/number_of_others_in_property_joint_purchase.rb @@ -0,0 +1,22 @@ +class Form::Sales::Pages::NumberOfOthersInPropertyJointPurchase < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "number_of_others_in_property_joint_purchase" + @depends_on = [ + { + "privacynotice" => 1, + "jointpur" => 1, + }, + { + "noint" => 1, + "jointpur" => 1, + }, + ] + end + + def questions + @questions ||= [ + Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self, joint_purchase: true), + ] + end +end diff --git a/app/models/form/sales/questions/number_of_others_in_property.rb b/app/models/form/sales/questions/number_of_others_in_property.rb index cf590291b..c168e7633 100644 --- a/app/models/form/sales/questions/number_of_others_in_property.rb +++ b/app/models/form/sales/questions/number_of_others_in_property.rb @@ -1,11 +1,11 @@ class Form::Sales::Questions::NumberOfOthersInProperty < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "hholdcount" @check_answer_label = "Number of other people living in the property" @header = "Besides the buyer(s), how many other people live or will live in the property?" @type = "numeric" - @hint_text = "You can provide details for a maximum of 4 other people." + @hint_text = "You can provide details for a maximum of #{joint_purchase ? '4' : '5'} other people." @width = 2 @min = 0 @max = 4 diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 181460ae1..cfcb44e12 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -38,6 +38,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Buyer2IncomeValueCheck.new("working_situation_buyer_2_income_value_check", nil, self), Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::NumberOfOthersInProperty.new(nil, nil, self), + Form::Sales::Pages::NumberOfOthersInPropertyJointPurchase.new(nil, nil, self), Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 2), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1", nil, self, person_index: 2), Form::Sales::Pages::PersonAge.new("person_2_age", nil, self, person_index: 2), diff --git a/spec/models/form/sales/pages/number_of_others_in_property_joint_purchase_spec.rb b/spec/models/form/sales/pages/number_of_others_in_property_joint_purchase_spec.rb new file mode 100644 index 000000000..f798ec0ae --- /dev/null +++ b/spec/models/form/sales/pages/number_of_others_in_property_joint_purchase_spec.rb @@ -0,0 +1,42 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::NumberOfOthersInPropertyJointPurchase, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[hholdcount]) + end + + it "has the correct id" do + expect(page.id).to eq("number_of_others_in_property_joint_purchase") + 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 the correct depends_on" do + expect(page.depends_on).to eq([ + { + "privacynotice" => 1, + "jointpur" => 1, + }, + { + "noint" => 1, + "jointpur" => 1, + }, + ]) + end +end diff --git a/spec/models/form/sales/pages/number_of_others_in_property_spec.rb b/spec/models/form/sales/pages/number_of_others_in_property_spec.rb index c2efdcb21..e7f245f83 100644 --- a/spec/models/form/sales/pages/number_of_others_in_property_spec.rb +++ b/spec/models/form/sales/pages/number_of_others_in_property_spec.rb @@ -26,4 +26,17 @@ RSpec.describe Form::Sales::Pages::NumberOfOthersInProperty, type: :model do it "has the correct description" do expect(page.description).to be_nil end + + it "has the correct depends_on" do + expect(page.depends_on).to eq([ + { + "privacynotice" => 1, + "jointpur" => 2, + }, + { + "noint" => 1, + "jointpur" => 2, + }, + ]) + end end diff --git a/spec/models/form/sales/questions/number_of_others_in_property_spec.rb b/spec/models/form/sales/questions/number_of_others_in_property_spec.rb index 81c49770a..af3963c6e 100644 --- a/spec/models/form/sales/questions/number_of_others_in_property_spec.rb +++ b/spec/models/form/sales/questions/number_of_others_in_property_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::NumberOfOthersInProperty, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase:) } let(:question_id) { nil } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:joint_purchase) { true } it "has correct page" do expect(question.page).to eq(page) @@ -34,4 +35,12 @@ RSpec.describe Form::Sales::Questions::NumberOfOthersInProperty, type: :model do it "has the correct hint" do expect(question.hint_text).to eq("You can provide details for a maximum of 4 other people.") end + + context "with non joint purchase" do + let(:joint_purchase) { false } + + it "has the correct hint" do + expect(question.hint_text).to eq("You can provide details for a maximum of 5 other people.") + end + end end diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 33e9a1409..ac7dc671e 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -45,6 +45,12 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model age_2_buyer_retirement_value_check buyer_2_gender_identity gender_2_buyer_retirement_value_check + buyer_2_ethnic_group + buyer_2_ethnic_background_black + buyer_2_ethnic_background_asian + buyer_2_ethnic_background_arab + buyer_2_ethnic_background_mixed + buyer_2_ethnic_background_white buyer_2_working_situation working_situation_2_retirement_value_check_joint_purchase working_situation_buyer_2_income_value_check