Browse Source

Display the correct hint text depending on joint purchase

pull/1297/head
Kat 3 years ago
parent
commit
09be3340cf
  1. 4
      app/models/form/sales/pages/number_of_others_in_property.rb
  2. 22
      app/models/form/sales/pages/number_of_others_in_property_joint_purchase.rb
  3. 6
      app/models/form/sales/questions/number_of_others_in_property.rb
  4. 1
      app/models/form/sales/subsections/household_characteristics.rb
  5. 42
      spec/models/form/sales/pages/number_of_others_in_property_joint_purchase_spec.rb
  6. 13
      spec/models/form/sales/pages/number_of_others_in_property_spec.rb
  7. 11
      spec/models/form/sales/questions/number_of_others_in_property_spec.rb
  8. 6
      spec/models/form/sales/subsections/household_characteristics_spec.rb

4
app/models/form/sales/pages/number_of_others_in_property.rb

@ -5,16 +5,18 @@ class Form::Sales::Pages::NumberOfOthersInProperty < ::Form::Page
@depends_on = [ @depends_on = [
{ {
"privacynotice" => 1, "privacynotice" => 1,
"jointpur" => 2,
}, },
{ {
"noint" => 1, "noint" => 1,
"jointpur" => 2,
}, },
] ]
end end
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self), Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self, joint_purchase: false),
] ]
end end
end end

22
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

6
app/models/form/sales/questions/number_of_others_in_property.rb

@ -1,11 +1,11 @@
class Form::Sales::Questions::NumberOfOthersInProperty < ::Form::Question class Form::Sales::Questions::NumberOfOthersInProperty < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page, joint_purchase:)
super super(id, hsh, page)
@id = "hholdcount" @id = "hholdcount"
@check_answer_label = "Number of other people living in the property" @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?" @header = "Besides the buyer(s), how many other people live or will live in the property?"
@type = "numeric" @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 @width = 2
@min = 0 @min = 0
@max = 4 @max = 4

1
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::Buyer2IncomeValueCheck.new("working_situation_buyer_2_income_value_check", nil, self),
Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::NumberOfOthersInProperty.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::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::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), Form::Sales::Pages::PersonAge.new("person_2_age", nil, self, person_index: 2),

42
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

13
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 it "has the correct description" do
expect(page.description).to be_nil expect(page.description).to be_nil
end end
it "has the correct depends_on" do
expect(page.depends_on).to eq([
{
"privacynotice" => 1,
"jointpur" => 2,
},
{
"noint" => 1,
"jointpur" => 2,
},
])
end
end end

11
spec/models/form/sales/questions/number_of_others_in_property_spec.rb

@ -1,11 +1,12 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::NumberOfOthersInProperty, type: :model do 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_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:joint_purchase) { true }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) 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 it "has the correct hint" do
expect(question.hint_text).to eq("You can provide details for a maximum of 4 other people.") expect(question.hint_text).to eq("You can provide details for a maximum of 4 other people.")
end 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 end

6
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 age_2_buyer_retirement_value_check
buyer_2_gender_identity buyer_2_gender_identity
gender_2_buyer_retirement_value_check 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 buyer_2_working_situation
working_situation_2_retirement_value_check_joint_purchase working_situation_2_retirement_value_check_joint_purchase
working_situation_buyer_2_income_value_check working_situation_buyer_2_income_value_check

Loading…
Cancel
Save