Browse Source

feat: update tests

pull/2214/head
natdeanlewissoftwire 2 years ago
parent
commit
187c756811
  1. 4
      app/models/form/lettings/subsections/tenancy_information.rb
  2. 31
      spec/models/form/lettings/pages/tenancy_length_periodic_spec.rb
  3. 33
      spec/models/form/lettings/questions/tenancy_length_periodic_spec.rb
  4. 27
      spec/models/form/lettings/subsections/tenancy_information_spec.rb

4
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

31
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

33
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

27
spec/models/form/lettings/subsections/tenancy_information_spec.rb

@ -11,11 +11,38 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
expect(tenancy_information.section).to eq(section)
end
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
expect(tenancy_information.id).to eq("tenancy_information")

Loading…
Cancel
Save