Browse Source

[CLDC-1484] Add Age1 page and sections

pull/898/head
Jack S 3 years ago
parent
commit
fb9369ce9e
  1. 16
      app/models/form/sales/pages/age1.rb
  2. 10
      app/models/form/sales/sections/household.rb
  3. 14
      app/models/form/sales/subsections/household_characteristics.rb
  4. 1
      app/models/form/sales/subsections/setup.rb
  5. 5
      app/models/form_handler.rb
  6. 2
      spec/factories/sales_log.rb
  7. 33
      spec/models/form/sales/pages/age1_spec.rb
  8. 2
      spec/models/form/sales/subsections/setup_spec.rb
  9. 4
      spec/models/form_handler_spec.rb
  10. 4
      spec/models/form_spec.rb

16
app/models/form/sales/pages/age1.rb

@ -0,0 +1,16 @@
class Form::Sales::Pages::Age1 < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_age"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1AgeKnown.new(nil, nil, self),
Form::Sales::Questions::Age1.new(nil, nil, self),
]
end
end

10
app/models/form/sales/sections/household.rb

@ -0,0 +1,10 @@
class Form::Sales::Sections::Household < ::Form::Section
def initialize(id, hsh, form)
super
@id = "household"
@label = "About the household"
@description = ""
@form = form
@subsections = [Form::Sales::Subsections::HouseholdCharacteristics.new(nil, nil, self)] || []
end
end

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

@ -0,0 +1,14 @@
class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "household_characteristics"
@label = "Household characteristics"
@section = section
end
def pages
@pages ||= [
Form::Sales::Pages::Age1.new(nil, nil, self),
]
end
end

1
app/models/form/sales/subsections/setup.rb

@ -18,6 +18,7 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection
Form::Sales::Pages::OutrightOwnershipType.new(nil, nil, self),
Form::Sales::Pages::JointPurchase.new(nil, nil, self),
Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self),
Form::Sales::Pages::Age1.new(nil, nil, self),
]
end
end

5
app/models/form_handler.rb

@ -19,7 +19,10 @@ class FormHandler
end
def sales_forms
sales_sections = [Form::Sales::Property::Sections::PropertyInformation] # Add section classes here e.g. Form::Sales::Property::Sections::PropertyInformation
sales_sections = [
Form::Sales::Property::Sections::PropertyInformation,
Form::Sales::Sections::Household,
]
current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales")
previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales")
{ "current_sales" => current_form,

2
spec/factories/sales_log.rb

@ -19,6 +19,8 @@ FactoryBot.define do
jointpur { 1 }
beds { 2 }
jointmore { 1 }
age1_known { 0 }
age1 { 30 }
end
end
end

33
spec/models/form/sales/pages/age1_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Age1, 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[age1_known age1])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_age")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

2
spec/models/form/sales/subsections/setup_spec.rb

@ -13,7 +13,7 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do
it "has correct pages" do
expect(setup.pages.map(&:id)).to eq(
%w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type joint_purchase number_joint_buyers],
%w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type joint_purchase number_joint_buyers buyer_1_age],
)
end

4
spec/models/form_handler_spec.rb

@ -61,14 +61,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(11)
expect(form.pages.count).to eq(13)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(11)
expect(form.pages.count).to eq(13)
expect(form.name).to eq("2021_2022_sales")
end
end

4
spec/models/form_spec.rb

@ -218,9 +218,9 @@ RSpec.describe Form, type: :model do
expect(form.sections[0].class).to eq(Form::Sales::Sections::Setup)
expect(form.subsections.count).to eq(1)
expect(form.subsections.first.id).to eq("setup")
expect(form.pages.count).to eq(10)
expect(form.pages.count).to eq(11)
expect(form.pages.first.id).to eq("organisation")
expect(form.questions.count).to eq(11)
expect(form.questions.count).to eq(13)
expect(form.questions.first.id).to eq("owning_organisation_id")
expect(form.start_date).to eq(Time.zone.parse("2022-04-01"))
expect(form.end_date).to eq(Time.zone.parse("2023-07-01"))

Loading…
Cancel
Save