From 187c756811e39549ffa655ee38082cbf93a4e9f8 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 5 Feb 2024 15:57:14 +0000 Subject: [PATCH] feat: update tests --- .../subsections/tenancy_information.rb | 4 +-- .../pages/tenancy_length_periodic_spec.rb | 31 ++++++++++++++++ .../questions/tenancy_length_periodic_spec.rb | 33 +++++++++++++++++ .../subsections/tenancy_information_spec.rb | 35 ++++++++++++++++--- 4 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 spec/models/form/lettings/pages/tenancy_length_periodic_spec.rb create mode 100644 spec/models/form/lettings/questions/tenancy_length_periodic_spec.rb diff --git a/app/models/form/lettings/subsections/tenancy_information.rb b/app/models/form/lettings/subsections/tenancy_information.rb index 99c701058..5525c182f 100644 --- a/app/models/form/lettings/subsections/tenancy_information.rb +++ b/app/models/form/lettings/subsections/tenancy_information.rb @@ -15,8 +15,8 @@ class Form::Lettings::Subsections::TenancyInformation < ::Form::Subsection Form::Lettings::Pages::TenancyLength.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self), - Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self), + (Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self) if form.start_year_after_2024?), Form::Lettings::Pages::ShelteredAccommodation.new(nil, nil, self), - ].compact + ].flatten.compact end end diff --git a/spec/models/form/lettings/pages/tenancy_length_periodic_spec.rb b/spec/models/form/lettings/pages/tenancy_length_periodic_spec.rb new file mode 100644 index 000000000..f3860d1cb --- /dev/null +++ b/spec/models/form/lettings/pages/tenancy_length_periodic_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::TenancyLengthPeriodic, type: :model do + subject(:page) { described_class.new(nil, nil, subsection) } + + 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[tenancylength] + end + + it "has the correct id" do + expect(page.id).to eq "tenancy_length" + 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 [{ "tenancy_type_fixed_term?" => true, "needstype" => 2 }] + end +end diff --git a/spec/models/form/lettings/questions/tenancy_length_periodic_spec.rb b/spec/models/form/lettings/questions/tenancy_length_periodic_spec.rb new file mode 100644 index 000000000..7708ee9d8 --- /dev/null +++ b/spec/models/form/lettings/questions/tenancy_length_periodic_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::TenancyLengthPeriodic, type: :model do + subject(:question) { described_class.new(nil, nil, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("tenancylength") + end + + it "has the correct header" do + expect(question.header).to eq("What is the length of the periodic tenancy to the nearest year?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Length of periodic tenancy") + end + + it "has the correct type" do + expect(question.type).to eq("numeric") + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq("As this is a periodic tenancy, this question is optional. If you do not have the information available click save and continue") + end +end diff --git a/spec/models/form/lettings/subsections/tenancy_information_spec.rb b/spec/models/form/lettings/subsections/tenancy_information_spec.rb index bca0e096f..96770ea78 100644 --- a/spec/models/form/lettings/subsections/tenancy_information_spec.rb +++ b/spec/models/form/lettings/subsections/tenancy_information_spec.rb @@ -11,10 +11,37 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do expect(tenancy_information.section).to eq(section) end - it "has correct pages" do - expect(tenancy_information.pages.map(&:id)).to eq( - %w[joint starter_tenancy tenancy_type starter_tenancy_type tenancy_length tenancy_length_affordable_rent tenancy_length_intermediate_rent tenancy_length_periodic sheltered_accommodation], - ) + describe "pages" do + let(:section) { instance_double(Form::Sales::Sections::Household, form:) } + let(:form) { instance_double(Form, start_date:) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(false) + end + + context "when 2023" do + let(:start_date) { Time.utc(2023, 2, 8) } + + it "has correct pages" do + expect(tenancy_information.pages.map(&:id)).to eq( + %w[joint starter_tenancy tenancy_type starter_tenancy_type tenancy_length tenancy_length_affordable_rent tenancy_length_intermediate_rent sheltered_accommodation], + ) + end + end + + context "when 2024" do + let(:start_date) { Time.utc(2024, 2, 8) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(true) + end + + it "has correct pages" do + expect(tenancy_information.pages.map(&:id)).to eq( + %w[joint starter_tenancy tenancy_type starter_tenancy_type tenancy_length tenancy_length_affordable_rent tenancy_length_intermediate_rent tenancy_length_periodic sheltered_accommodation], + ) + end + end end it "has the correct id" do