Browse Source

CLDC-1847 Add person 6 for non joint purchases (#1297)

* Display the correct hint text depending on joint purchase

* update validation for non joint purchase

* Add person 6 questions and refactor check_answers_card_title

* update hint text

* Reuse join purchase page
pull/1361/head v0.3.1
kosiakkatrina 2 years ago committed by GitHub
parent
commit
567f2b5ce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      app/components/check_answers_summary_list_card_component.rb
  2. 10
      app/models/form/sales/pages/number_of_others_in_property.rb
  3. 18
      app/models/form/sales/questions/number_of_others_in_property.rb
  4. 11
      app/models/form/sales/subsections/household_characteristics.rb
  5. 1
      app/views/form/headers/_person_6_known_page.erb
  6. 40
      spec/models/form/sales/pages/number_of_others_in_property_spec.rb
  7. 25
      spec/models/form/sales/questions/number_of_others_in_property_spec.rb
  8. 18
      spec/models/form/sales/subsections/household_characteristics_spec.rb

19
app/components/check_answers_summary_list_card_component.rb

@ -18,21 +18,10 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
end end
def check_answers_card_title(question) def check_answers_card_title(question)
if question.form.type == "lettings" return "Lead tenant" if question.form.type == "lettings" && question.check_answers_card_number == 1
case question.check_answers_card_number return "Buyer #{question.check_answers_card_number}" if question.check_answers_card_number <= number_of_buyers
when 1
"Lead tenant" "Person #{question.check_answers_card_number}"
when 2..8
"Person #{question.check_answers_card_number}"
end
else
case question.check_answers_card_number
when 1..number_of_buyers
"Buyer #{question.check_answers_card_number}"
when (number_of_buyers + 1)..(number_of_buyers + 4)
"Person #{question.check_answers_card_number}"
end
end
end end
private private

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

@ -1,20 +1,22 @@
class Form::Sales::Pages::NumberOfOthersInProperty < ::Form::Page class Form::Sales::Pages::NumberOfOthersInProperty < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection, joint_purchase:)
super super(id, hsh, subsection)
@id = "number_of_others_in_property"
@depends_on = [ @depends_on = [
{ {
"privacynotice" => 1, "privacynotice" => 1,
"jointpur" => joint_purchase ? 1 : 2,
}, },
{ {
"noint" => 1, "noint" => 1,
"jointpur" => joint_purchase ? 1 : 2,
}, },
] ]
@joint_purchase = joint_purchase
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: @joint_purchase),
] ]
end end
end end

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

@ -1,13 +1,23 @@
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 = hint(joint_purchase)
@width = 2 @width = 2
@min = 0 @min = 0
@max = 4 @max = joint_purchase ? 4 : 5
end
private
def hint(joint_purchase)
if joint_purchase
"You can provide details for a maximum of 4 other people for a joint purchase."
else
"You can provide details for a maximum of 5 other people if there is only one buyer."
end
end end
end end

11
app/models/form/sales/subsections/household_characteristics.rb

@ -37,7 +37,8 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::RetirementValueCheck.new("working_situation_2_retirement_value_check_joint_purchase", nil, self, person_index: 2), Form::Sales::Pages::RetirementValueCheck.new("working_situation_2_retirement_value_check_joint_purchase", nil, self, person_index: 2),
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("number_of_others_in_property", nil, self, joint_purchase: false),
Form::Sales::Pages::NumberOfOthersInProperty.new("number_of_others_in_property_joint_purchase", nil, self, joint_purchase: true),
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),
@ -70,6 +71,14 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::RetirementValueCheck.new("gender_5_retirement_value_check", nil, self, person_index: 5), Form::Sales::Pages::RetirementValueCheck.new("gender_5_retirement_value_check", nil, self, person_index: 5),
Form::Sales::Pages::PersonWorkingSituation.new("person_5_working_situation", nil, self, person_index: 5), Form::Sales::Pages::PersonWorkingSituation.new("person_5_working_situation", nil, self, person_index: 5),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_5_retirement_value_check", nil, self, person_index: 5), Form::Sales::Pages::RetirementValueCheck.new("working_situation_5_retirement_value_check", nil, self, person_index: 5),
Form::Sales::Pages::PersonKnown.new("person_6_known", nil, self, person_index: 6),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_6_relationship_to_buyer_1", nil, self, person_index: 6),
Form::Sales::Pages::PersonAge.new("person_6_age", nil, self, person_index: 6),
Form::Sales::Pages::RetirementValueCheck.new("age_6_retirement_value_check", nil, self, person_index: 6),
Form::Sales::Pages::PersonGenderIdentity.new("person_6_gender_identity", nil, self, person_index: 6),
Form::Sales::Pages::RetirementValueCheck.new("gender_6_retirement_value_check", nil, self, person_index: 6),
Form::Sales::Pages::PersonWorkingSituation.new("person_6_working_situation", nil, self, person_index: 6),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_6_retirement_value_check", nil, self, person_index: 6),
].flatten.compact ].flatten.compact
end end

1
app/views/form/headers/_person_6_known_page.erb

@ -0,0 +1 @@
You have given us the details for <%= log.joint_purchase? ? 3 : 4 %> of the <%= log.hholdcount %> other people in the household

40
spec/models/form/sales/pages/number_of_others_in_property_spec.rb

@ -1,10 +1,11 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Pages::NumberOfOthersInProperty, type: :model do RSpec.describe Form::Sales::Pages::NumberOfOthersInProperty, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase:) }
let(:page_id) { nil } let(:page_id) { "number_of_others_in_property" }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:joint_purchase) { false }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do it "has correct subsection" do
@ -26,4 +27,39 @@ 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
context "with joint purchase" do
let(:page_id) { "number_of_others_in_property_joint_purchase" }
let(:joint_purchase) { true }
it "has the correct id" do
expect(page.id).to eq("number_of_others_in_property_joint_purchase")
end
it "has the correct depends_on" do
expect(page.depends_on).to eq([
{
"privacynotice" => 1,
"jointpur" => 1,
},
{
"noint" => 1,
"jointpur" => 1,
},
])
end
end
end end

25
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)
@ -32,6 +33,26 @@ RSpec.describe Form::Sales::Questions::NumberOfOthersInProperty, type: :model do
end end
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 for a joint purchase.")
end
it "has the correct min" do
expect(question.min).to eq(0)
end
it "has the correct max" do
expect(question.max).to eq(4)
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 if there is only one buyer.")
end
it "has the correct max" do
expect(question.max).to eq(5)
end
end end
end end

18
spec/models/form/sales/subsections/household_characteristics_spec.rb

@ -50,6 +50,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
working_situation_buyer_2_income_value_check working_situation_buyer_2_income_value_check
buyer_2_live_in_property buyer_2_live_in_property
number_of_others_in_property number_of_others_in_property
number_of_others_in_property_joint_purchase
person_2_known person_2_known
person_2_relationship_to_buyer_1 person_2_relationship_to_buyer_1
person_2_age person_2_age
@ -82,6 +83,14 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
gender_5_retirement_value_check gender_5_retirement_value_check
person_5_working_situation person_5_working_situation
working_situation_5_retirement_value_check working_situation_5_retirement_value_check
person_6_known
person_6_relationship_to_buyer_1
person_6_age
age_6_retirement_value_check
person_6_gender_identity
gender_6_retirement_value_check
person_6_working_situation
working_situation_6_retirement_value_check
], ],
) )
end end
@ -131,6 +140,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
working_situation_buyer_2_income_value_check working_situation_buyer_2_income_value_check
buyer_2_live_in_property buyer_2_live_in_property
number_of_others_in_property number_of_others_in_property
number_of_others_in_property_joint_purchase
person_2_known person_2_known
person_2_relationship_to_buyer_1 person_2_relationship_to_buyer_1
person_2_age person_2_age
@ -163,6 +173,14 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
gender_5_retirement_value_check gender_5_retirement_value_check
person_5_working_situation person_5_working_situation
working_situation_5_retirement_value_check working_situation_5_retirement_value_check
person_6_known
person_6_relationship_to_buyer_1
person_6_age
age_6_retirement_value_check
person_6_gender_identity
gender_6_retirement_value_check
person_6_working_situation
working_situation_6_retirement_value_check
], ],
) )
end end

Loading…
Cancel
Save