diff --git a/app/models/form/sales/pages/property_building_type.rb b/app/models/form/sales/pages/property_building_type.rb index 40c8f3738..b9a829a64 100644 --- a/app/models/form/sales/pages/property_building_type.rb +++ b/app/models/form/sales/pages/property_building_type.rb @@ -2,6 +2,10 @@ class Form::Sales::Pages::PropertyBuildingType < ::Form::Page def initialize(id, hsh, subsection) super @id = "property_building_type" + @depends_on = [ + { "form.start_year_2025_or_later?" => false }, + { "is_staircase?" => false }, + ] end def questions diff --git a/app/models/form/sales/pages/property_wheelchair_accessible.rb b/app/models/form/sales/pages/property_wheelchair_accessible.rb index a63964059..358f16d50 100644 --- a/app/models/form/sales/pages/property_wheelchair_accessible.rb +++ b/app/models/form/sales/pages/property_wheelchair_accessible.rb @@ -2,6 +2,10 @@ class Form::Sales::Pages::PropertyWheelchairAccessible < ::Form::Page def initialize(id, hsh, subsection) super @id = "property_wheelchair_accessible" + @depends_on = [ + { "form.start_year_2025_or_later?" => false }, + { "is_staircase?" => false }, + ] end def questions diff --git a/spec/models/form/sales/pages/property_building_type_spec.rb b/spec/models/form/sales/pages/property_building_type_spec.rb index aac8fbf24..b9c6bddca 100644 --- a/spec/models/form/sales/pages/property_building_type_spec.rb +++ b/spec/models/form/sales/pages/property_building_type_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::PropertyBuildingType, type: :model do let(:page_id) { nil } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } + let(:subsection) { instance_double(Form::Subsection, enabled?: true, form:) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -22,4 +23,46 @@ RSpec.describe Form::Sales::Pages::PropertyBuildingType, type: :model do it "has the correct description" do expect(page.description).to be_nil end + + context "with form year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + let(:saledate) { Time.zone.local(2024, 4, 1) } + + context "with a staircasing log" do + let(:log) { build(:sales_log, :shared_ownership_setup_complete, staircase: 1, saledate:) } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + + context "with a non-staircasing log" do + let(:log) { build(:sales_log, staircase: nil, saledate:) } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + end + + context "with form year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + let(:saledate) { Time.zone.local(2025, 4, 1) } + + context "with a staircasing log" do + let(:log) { build(:sales_log, :shared_ownership_setup_complete, staircase: 1, saledate:) } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "with a non-staircasing log" do + let(:log) { build(:sales_log, staircase: nil, saledate:) } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + end end diff --git a/spec/models/form/sales/pages/property_wheelchair_accessible_spec.rb b/spec/models/form/sales/pages/property_wheelchair_accessible_spec.rb index 01dcb7ce7..bf0493a6d 100644 --- a/spec/models/form/sales/pages/property_wheelchair_accessible_spec.rb +++ b/spec/models/form/sales/pages/property_wheelchair_accessible_spec.rb @@ -5,11 +5,8 @@ RSpec.describe Form::Sales::Pages::PropertyWheelchairAccessible, type: :model do let(:page_id) { nil } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection) } - - before do - allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_2024_or_later?: false, start_date: Time.zone.local(2023, 4, 1))) - end + let(:form) { instance_double(Form, start_year_2024_or_later?: false, start_date: Time.zone.local(2023, 4, 1)) } + let(:subsection) { instance_double(Form::Subsection, enabled?: true, form:) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -26,4 +23,46 @@ RSpec.describe Form::Sales::Pages::PropertyWheelchairAccessible, type: :model do it "has the correct description" do expect(page.description).to be_nil end + + context "with form year 2024" do + let(:form) { Form.new(nil, 2024, [], "sales") } + let(:saledate) { Time.zone.local(2024, 4, 1) } + + context "with a staircasing log" do + let(:log) { build(:sales_log, :shared_ownership_setup_complete, staircase: 1, saledate:) } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + + context "with a non-staircasing log" do + let(:log) { build(:sales_log, :shared_ownership_setup_complete, staircase: 2, saledate:) } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + end + + context "with form year 2025" do + let(:form) { Form.new(nil, 2025, [], "sales") } + let(:saledate) { Time.zone.local(2025, 4, 1) } + + context "with a staircasing log" do + let(:log) { build(:sales_log, :shared_ownership_setup_complete, staircase: 1, saledate:) } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "with a non-staircasing log" do + let(:log) { build(:sales_log, :shared_ownership_setup_complete, staircase: 2, saledate:) } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + end end