From 5328007fd2b697c32a404549bfadcfdb4db0ef0e Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 15 Feb 2023 09:39:19 +0000 Subject: [PATCH] Reuse join purchase page --- .../pages/number_of_others_in_property.rb | 12 +++--- ...er_of_others_in_property_joint_purchase.rb | 22 ---------- .../subsections/household_characteristics.rb | 4 +- ..._others_in_property_joint_purchase_spec.rb | 42 ------------------- .../number_of_others_in_property_spec.rb | 27 +++++++++++- 5 files changed, 33 insertions(+), 74 deletions(-) delete mode 100644 app/models/form/sales/pages/number_of_others_in_property_joint_purchase.rb delete 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 edcaf22fa..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,22 +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" => 2, + "jointpur" => joint_purchase ? 1 : 2, }, { "noint" => 1, - "jointpur" => 2, + "jointpur" => joint_purchase ? 1 : 2, }, ] + @joint_purchase = joint_purchase end def questions @questions ||= [ - Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self, joint_purchase: false), + Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self, joint_purchase: @joint_purchase), ] 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 deleted file mode 100644 index 2810a3a7e..000000000 --- a/app/models/form/sales/pages/number_of_others_in_property_joint_purchase.rb +++ /dev/null @@ -1,22 +0,0 @@ -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/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 1ce9a8baa..571968c8f 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -37,8 +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::NumberOfOthersInPropertyJointPurchase.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), 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 deleted file mode 100644 index f798ec0ae..000000000 --- a/spec/models/form/sales/pages/number_of_others_in_property_joint_purchase_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -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 e7f245f83..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 @@ -39,4 +40,26 @@ RSpec.describe Form::Sales::Pages::NumberOfOthersInProperty, type: :model do }, ]) 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