diff --git a/app/models/form/sales/pages/shared_ownership_type.rb b/app/models/form/sales/pages/shared_ownership_type.rb index a3566b914..ae0f15eab 100644 --- a/app/models/form/sales/pages/shared_ownership_type.rb +++ b/app/models/form/sales/pages/shared_ownership_type.rb @@ -8,13 +8,13 @@ class Form::Sales::Pages::SharedOwnershipType < ::Form::Page }] end - def header - "Shared ownership type" if form.start_date.year >= 2023 - end - def questions @questions ||= [ - Form::Sales::Questions::SharedOwnershipType.new(nil, nil, self), + Form::Sales::Questions::SharedOwnershipType.new(nil, nil, self), ] end + + def header + "Shared ownership type" if form.start_date.year >= 2023 + end end diff --git a/spec/models/form/sales/pages/discounted_ownership_type_spec.rb b/spec/models/form/sales/pages/discounted_ownership_type_spec.rb index 054f2288f..17796adf9 100644 --- a/spec/models/form/sales/pages/discounted_ownership_type_spec.rb +++ b/spec/models/form/sales/pages/discounted_ownership_type_spec.rb @@ -5,7 +5,26 @@ RSpec.describe Form::Sales::Pages::DiscountedOwnershipType, type: :model do let(:page_id) { nil } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + let(:start_date) { Time.zone.today } + + describe "headers" do + context "when form year is for 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has the correct header" do + expect(page.header).to eq("Discounted ownership type") + end + end + + context "when form year is for before 2023" do + let(:start_date) { Time.utc(2022, 2, 8) } + + it "does not have a page header" do + expect(page.header).to eq(nil) + end + end + end it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -19,10 +38,6 @@ RSpec.describe Form::Sales::Pages::DiscountedOwnershipType, type: :model do expect(page.id).to eq("discounted_ownership_type") end - it "has the correct header" do - expect(page.header).to eq("Discounted ownership type") - end - it "has the correct description" do expect(page.description).to be_nil end diff --git a/spec/models/form/sales/pages/outright_ownership_type_spec.rb b/spec/models/form/sales/pages/outright_ownership_type_spec.rb index 249496d00..428011692 100644 --- a/spec/models/form/sales/pages/outright_ownership_type_spec.rb +++ b/spec/models/form/sales/pages/outright_ownership_type_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Pages::OutrightOwnershipType, type: :model do let(:page_id) { nil } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + let(:start_date) { Time.zone.today } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -19,10 +20,6 @@ RSpec.describe Form::Sales::Pages::OutrightOwnershipType, type: :model do expect(page.id).to eq("outright_ownership_type") end - it "has the correct header" do - expect(page.header).to eq("Outright ownership type") - end - it "has the correct description" do expect(page.description).to be_nil end @@ -32,4 +29,22 @@ RSpec.describe Form::Sales::Pages::OutrightOwnershipType, type: :model do "ownershipsch" => 3, }]) end + + describe "headers" do + context "when the form year is 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has the correct header" do + expect(page.header).to eq("Outright ownership type") + end + end + + context "when the form is before the year 2023" do + let(:start_date) { Time.utc(2022, 2, 8) } + + it "does not have a page header" do + expect(page.header).to eq(nil) + end + end + end end diff --git a/spec/models/form/sales/pages/shared_ownership_type_spec.rb b/spec/models/form/sales/pages/shared_ownership_type_spec.rb index c648cea8c..db0ef4538 100644 --- a/spec/models/form/sales/pages/shared_ownership_type_spec.rb +++ b/spec/models/form/sales/pages/shared_ownership_type_spec.rb @@ -1,14 +1,30 @@ -require "rails_helper" +require "rails_hel\per" RSpec.describe Form::Sales::Pages::SharedOwnershipType, 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, form: instance_double(Form, start_date:)) } let(:start_date) { Time.utc(2022, 4, 1) } - let(:form) { instance_double(Form, start_date:) } - let(:subsection) { instance_double(Form::Subsection, form:) } + describe "headers" do + context "when 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has the correct header" do + expect(page.header).to eq("Shared ownership type") + end + end + + context "when before 2023" do + let(:start_date) { Time.utc(2022, 2, 8) } + + it "has the correct header" do + expect(page.header).to eq(nil) + end + end + end it "has correct subsection" do expect(page.subsection).to eq(subsection) end @@ -21,10 +37,6 @@ RSpec.describe Form::Sales::Pages::SharedOwnershipType, type: :model do expect(page.id).to eq("shared_ownership_type") end - it "has the correct header" do - expect(page.header).to eq("Shared Ownership") - end - it "has the correct description" do expect(page.description).to be_nil end diff --git a/spec/models/form/sales/questions/discounted_ownership_type_spec.rb b/spec/models/form/sales/questions/discounted_ownership_type_spec.rb index d1c074023..02e7c1eed 100644 --- a/spec/models/form/sales/questions/discounted_ownership_type_spec.rb +++ b/spec/models/form/sales/questions/discounted_ownership_type_spec.rb @@ -5,7 +5,9 @@ RSpec.describe Form::Sales::Questions::DiscountedOwnershipType, type: :model do let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page) } + let(:page) { instance_double(Form::Page, subsection:) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + let(:start_date) { Time.zone.today } it "has correct page" do expect(question.page).to eq(page) @@ -42,4 +44,27 @@ RSpec.describe Form::Sales::Questions::DiscountedOwnershipType, type: :model do "22" => { "value" => "Any other equity loan scheme" }, }) end + + describe "partial guidance" do + context "when the form is for 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "shows shows correct guidance_partial" do + expect(question.guidance_partial).to eq("discounted_ownership_type_definitions") + end + + it "is at the top" do + expect(question.top_guidance?).to eq(true) + expect(question.bottom_guidance?).to eq(false) + end + end + + context "when the form is for before 2023" do + let(:start_date) { Time.utc(2022, 2, 8) } + + it "does not show a guidance_partial" do + expect(question.guidance_partial).to eq(nil) + end + end + end end diff --git a/spec/models/form/sales/questions/outright_ownership_type_spec.rb b/spec/models/form/sales/questions/outright_ownership_type_spec.rb index 69b499e52..f743261e5 100644 --- a/spec/models/form/sales/questions/outright_ownership_type_spec.rb +++ b/spec/models/form/sales/questions/outright_ownership_type_spec.rb @@ -5,7 +5,9 @@ RSpec.describe Form::Sales::Questions::OutrightOwnershipType, type: :model do let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page) } + let(:page) { instance_double(Form::Page, subsection:) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) } + let(:start_date) { Time.zone.today } it "has correct page" do expect(question.page).to eq(page) @@ -15,10 +17,6 @@ RSpec.describe Form::Sales::Questions::OutrightOwnershipType, type: :model do expect(question.id).to eq("type") end - it "has the correct header" do - expect(question.header).to eq("What is the type of outright sale?") - end - it "has the correct check_answer_label" do expect(question.check_answer_label).to eq("Type of outright sale") end @@ -43,4 +41,33 @@ RSpec.describe Form::Sales::Questions::OutrightOwnershipType, type: :model do "othtype" => [12], }) end + + it "has the correct header" do + expect(question.header).to eq("What is the type of outright sale?") + end + + describe "partial guidance" do + context "when the form is for year 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has the correct guidance_partial" do + expect(question.guidance_partial).to eq("outright_sale_type_definitions") + end + + it "is at the top" do + expect(question.top_guidance?).to eq(true) + expect(question.bottom_guidance?).to eq(false) + end + end + + context "when the form is for before year 2023" do + let(:start_date) { Time.utc(2022, 2, 8) } + + it "does not display a guidance partial" do + expect(question.guidance_partial).to eq(nil); + end + end + end + + end diff --git a/spec/models/form/sales/questions/shared_ownership_type_spec.rb b/spec/models/form/sales/questions/shared_ownership_type_spec.rb index 3f60155bf..a00c552f7 100644 --- a/spec/models/form/sales/questions/shared_ownership_type_spec.rb +++ b/spec/models/form/sales/questions/shared_ownership_type_spec.rb @@ -50,6 +50,10 @@ RSpec.describe Form::Sales::Questions::SharedOwnershipType, type: :model do "30" => { "value" => "Shared Ownership - 2021 model lease" }, }) end + + it "does not show a guidance_partial" do + expect(question.guidance_partial).to eq(nil) + end end context "when form start date is 2023" do @@ -67,5 +71,9 @@ RSpec.describe Form::Sales::Questions::SharedOwnershipType, type: :model do "32" => { "value" => "London Living Rent — Shared Ownership" }, }) end + + it "shows shows correct guidance_partial" do + expect(question.guidance_partial).to eq("shared_ownership_type_definitions") + end end end