From 567f2b5ce0fa425db3f90ebb8b2ce106ec12b0b0 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 2 Mar 2023 09:37:50 +0000 Subject: [PATCH] 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 --- ...eck_answers_summary_list_card_component.rb | 19 ++------- .../pages/number_of_others_in_property.rb | 10 +++-- .../questions/number_of_others_in_property.rb | 18 +++++++-- .../subsections/household_characteristics.rb | 11 ++++- .../form/headers/_person_6_known_page.erb | 1 + .../number_of_others_in_property_spec.rb | 40 ++++++++++++++++++- .../number_of_others_in_property_spec.rb | 25 +++++++++++- .../household_characteristics_spec.rb | 18 +++++++++ 8 files changed, 114 insertions(+), 28 deletions(-) create mode 100644 app/views/form/headers/_person_6_known_page.erb diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index af8ebd36a..e8ed971bc 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -18,21 +18,10 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base end def check_answers_card_title(question) - if question.form.type == "lettings" - case question.check_answers_card_number - when 1 - "Lead tenant" - 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 + return "Lead tenant" if question.form.type == "lettings" && question.check_answers_card_number == 1 + return "Buyer #{question.check_answers_card_number}" if question.check_answers_card_number <= number_of_buyers + + "Person #{question.check_answers_card_number}" end private 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..ebf9817bd 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 @@ -1,20 +1,22 @@ class Form::Sales::Pages::NumberOfOthersInProperty < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "number_of_others_in_property" + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) @depends_on = [ { "privacynotice" => 1, + "jointpur" => joint_purchase ? 1 : 2, }, { "noint" => 1, + "jointpur" => joint_purchase ? 1 : 2, }, ] + @joint_purchase = joint_purchase end def questions @questions ||= [ - Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self), + Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self, joint_purchase: @joint_purchase), ] 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..97a873430 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,13 +1,23 @@ 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 = hint(joint_purchase) @width = 2 @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 diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 181460ae1..571968c8f 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/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::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::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::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), @@ -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::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::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 end diff --git a/app/views/form/headers/_person_6_known_page.erb b/app/views/form/headers/_person_6_known_page.erb new file mode 100644 index 000000000..96cc94fd3 --- /dev/null +++ b/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 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..3503a1b9f 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 @@ -1,10 +1,11 @@ require "rails_helper" 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(:joint_purchase) { false } let(:subsection) { instance_double(Form::Subsection) } it "has correct subsection" do @@ -26,4 +27,39 @@ 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 + + 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 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..2bb50f80b 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) @@ -32,6 +33,26 @@ RSpec.describe Form::Sales::Questions::NumberOfOthersInProperty, type: :model do end 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 diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 33e9a1409..4645b7231 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/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 buyer_2_live_in_property number_of_others_in_property + number_of_others_in_property_joint_purchase person_2_known person_2_relationship_to_buyer_1 person_2_age @@ -82,6 +83,14 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model gender_5_retirement_value_check person_5_working_situation 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 @@ -131,6 +140,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model working_situation_buyer_2_income_value_check buyer_2_live_in_property number_of_others_in_property + number_of_others_in_property_joint_purchase person_2_known person_2_relationship_to_buyer_1 person_2_age @@ -163,6 +173,14 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model gender_5_retirement_value_check person_5_working_situation 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