Browse Source

Reuse join purchase page

pull/1297/head
Kat 3 years ago
parent
commit
5328007fd2
  1. 12
      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. 4
      app/models/form/sales/subsections/household_characteristics.rb
  4. 42
      spec/models/form/sales/pages/number_of_others_in_property_joint_purchase_spec.rb
  5. 27
      spec/models/form/sales/pages/number_of_others_in_property_spec.rb

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

@ -1,22 +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" => 2, "jointpur" => joint_purchase ? 1 : 2,
}, },
{ {
"noint" => 1, "noint" => 1,
"jointpur" => 2, "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, joint_purchase: false), Form::Sales::Questions::NumberOfOthersInProperty.new(nil, nil, self, joint_purchase: @joint_purchase),
] ]
end end
end end

22
app/models/form/sales/pages/number_of_others_in_property_joint_purchase.rb

@ -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

4
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::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::NumberOfOthersInPropertyJointPurchase.new(nil, nil, self), 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),

42
spec/models/form/sales/pages/number_of_others_in_property_joint_purchase_spec.rb

@ -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

27
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
@ -39,4 +40,26 @@ RSpec.describe Form::Sales::Pages::NumberOfOthersInProperty, type: :model do
}, },
]) ])
end 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

Loading…
Cancel
Save