2 changed files with 141 additions and 0 deletions
@ -0,0 +1,47 @@
|
||||
class Form::Sales::Subsections::SharedOwnershipInitialPurchase < ::Form::Subsection |
||||
def initialize(id, hsh, section) |
||||
super |
||||
@id = "shared_ownership_initial_purchase" |
||||
@label = "Shared ownership - initial purchase" |
||||
@depends_on = [{ "ownershipsch" => 1, "setup_completed?" => true, "staircase" => 2 }] |
||||
end |
||||
|
||||
def pages |
||||
@pages ||= [ |
||||
Form::Sales::Pages::Resale.new(nil, nil, self), |
||||
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership_joint_purchase", nil, self, ownershipsch: 1, joint_purchase: true), |
||||
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership", nil, self, ownershipsch: 1, joint_purchase: false), |
||||
Form::Sales::Pages::HandoverDate.new(nil, nil, self), |
||||
Form::Sales::Pages::HandoverDateCheck.new(nil, nil, self), |
||||
Form::Sales::Pages::BuyerPrevious.new("buyer_previous_joint_purchase", nil, self, joint_purchase: true), |
||||
Form::Sales::Pages::BuyerPrevious.new("buyer_previous_not_joint_purchase", nil, self, joint_purchase: false), |
||||
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), |
||||
Form::Sales::Pages::PreviousPropertyType.new(nil, nil, self), |
||||
Form::Sales::Pages::PreviousTenure.new(nil, nil, self), |
||||
Form::Sales::Pages::ValueSharedOwnership.new(nil, nil, self), |
||||
Form::Sales::Pages::AboutPriceValueCheck.new("about_price_shared_ownership_value_check", nil, self), |
||||
Form::Sales::Pages::Equity.new(nil, nil, self), |
||||
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_equity_value_check", nil, self), |
||||
Form::Sales::Pages::Mortgageused.new("mortgage_used_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::MortgageValueCheck.new("mortgage_used_mortgage_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_mortgage_amount_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageValueCheck.new("mortgage_amount_mortgage_value_check", nil, self), |
||||
Form::Sales::Pages::MortgageLength.new("mortgage_length_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::Deposit.new("deposit_shared_ownership", nil, self, ownershipsch: 1, optional: false), |
||||
Form::Sales::Pages::Deposit.new("deposit_shared_ownership_optional", nil, self, ownershipsch: 1, optional: true), |
||||
Form::Sales::Pages::DepositValueCheck.new("deposit_joint_purchase_value_check", nil, self, joint_purchase: true), |
||||
Form::Sales::Pages::DepositValueCheck.new("deposit_value_check", nil, self, joint_purchase: false), |
||||
Form::Sales::Pages::DepositDiscount.new("deposit_discount", nil, self, optional: false), |
||||
Form::Sales::Pages::DepositDiscount.new("deposit_discount_optional", nil, self, optional: true), |
||||
Form::Sales::Pages::SharedOwnershipDepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), |
||||
Form::Sales::Pages::MonthlyRent.new(nil, nil, self), |
||||
Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self, ownershipsch: 1), |
||||
Form::Sales::Pages::MonthlyChargesValueCheck.new("monthly_charges_shared_ownership_value_check", nil, self), |
||||
].compact |
||||
end |
||||
|
||||
def displayed_in_tasklist?(log) |
||||
log.staircase == 2 && (log.ownershipsch.nil? || log.ownershipsch == 1) |
||||
end |
||||
end |
@ -0,0 +1,94 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Subsections::SharedOwnershipInitialPurchase, type: :model do |
||||
subject(:shared_ownership_initial_purchase) { described_class.new(subsection_id, subsection_definition, section) } |
||||
|
||||
let(:subsection_id) { nil } |
||||
let(:subsection_definition) { nil } |
||||
let(:section) { instance_double(Form::Sales::Sections::SaleInformation) } |
||||
|
||||
before do |
||||
allow(section).to receive(:form).and_return(instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) |
||||
end |
||||
|
||||
it "has correct section" do |
||||
expect(shared_ownership_initial_purchase.section).to eq(section) |
||||
end |
||||
|
||||
it "has correct pages" do |
||||
expect(shared_ownership_initial_purchase.pages.map(&:id)).to eq( |
||||
%w[ |
||||
resale |
||||
living_before_purchase_shared_ownership_joint_purchase |
||||
living_before_purchase_shared_ownership |
||||
handover_date |
||||
handover_date_check |
||||
buyer_previous_joint_purchase |
||||
buyer_previous_not_joint_purchase |
||||
previous_bedrooms |
||||
previous_property_type |
||||
shared_ownership_previous_tenure |
||||
value_shared_ownership |
||||
about_price_shared_ownership_value_check |
||||
equity |
||||
shared_ownership_equity_value_check |
||||
mortgage_used_shared_ownership |
||||
mortgage_used_mortgage_value_check |
||||
mortgage_amount_shared_ownership |
||||
shared_ownership_mortgage_amount_value_check |
||||
mortgage_amount_mortgage_value_check |
||||
mortgage_length_shared_ownership |
||||
deposit_shared_ownership |
||||
deposit_shared_ownership_optional |
||||
deposit_joint_purchase_value_check |
||||
deposit_value_check |
||||
deposit_discount |
||||
deposit_discount_optional |
||||
shared_ownership_deposit_value_check |
||||
monthly_rent |
||||
leasehold_charges_shared_ownership |
||||
monthly_charges_shared_ownership_value_check |
||||
], |
||||
) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(shared_ownership_initial_purchase.id).to eq("shared_ownership_initial_purchase") |
||||
end |
||||
|
||||
it "has the correct label" do |
||||
expect(shared_ownership_initial_purchase.label).to eq("Shared ownership - initial purchase") |
||||
end |
||||
|
||||
it "has the correct depends_on" do |
||||
expect(shared_ownership_initial_purchase.depends_on).to eq([ |
||||
{ |
||||
"ownershipsch" => 1, "setup_completed?" => true, "staircase" => 2 |
||||
}, |
||||
]) |
||||
end |
||||
|
||||
context "when it is a shared ownership scheme and not staircase" do |
||||
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 1, staircase: 2) } |
||||
|
||||
it "is displayed in tasklist" do |
||||
expect(shared_ownership_initial_purchase.displayed_in_tasklist?(log)).to eq(true) |
||||
end |
||||
end |
||||
|
||||
context "when it is not a shared ownership scheme" do |
||||
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 2, staircase: 2) } |
||||
|
||||
it "is displayed in tasklist" do |
||||
expect(shared_ownership_initial_purchase.displayed_in_tasklist?(log)).to eq(false) |
||||
end |
||||
end |
||||
|
||||
context "when it is staircase" do |
||||
let(:log) { FactoryBot.build(:sales_log, ownershipsch: 1, staircase: 1) } |
||||
|
||||
it "is displayed in tasklist" do |
||||
expect(shared_ownership_initial_purchase.displayed_in_tasklist?(log)).to eq(false) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue