Browse Source

refactor and fix page tests

pull/2147/head
Kat 2 years ago
parent
commit
c6d4e3cfd3
  1. 4
      app/models/form.rb
  2. 4
      app/models/form/lettings/questions/renewal.rb
  3. 6
      spec/models/form/lettings/pages/renewal_spec.rb
  4. 4
      spec/models/form/lettings/questions/renewal_spec.rb

4
app/models/form.rb

@ -323,4 +323,8 @@ class Form
def sales_or_start_year_after_2022?(type, start_year)
type == "sales" || (start_year && start_year.to_i > 2022)
end
def start_year_after_2024?
start_date && start_date.year >= 2024
end
end

4
app/models/form/lettings/questions/renewal.rb

@ -17,7 +17,7 @@ class Form::Lettings::Questions::Renewal < ::Form::Question
.freeze
def header_text
if form.start_date && form.start_date.year >= 2024
if form.start_year_after_2024?
"Is this letting a renewal of social housing to the same tenant in the same property?"
else
"Is this letting a renewal?"
@ -25,7 +25,7 @@ class Form::Lettings::Questions::Renewal < ::Form::Question
end
def hint_text
if form.start_date && form.start_date.year >= 2024
if form.start_year_after_2024?
"If the property was previously being used as temporary accommodation, then answer 'no'"
else
"A renewal is a letting to the same tenant in the same property. If the property was previously being used as temporary accommodation, then answer 'no'"

6
spec/models/form/lettings/pages/renewal_spec.rb

@ -6,6 +6,12 @@ RSpec.describe Form::Lettings::Pages::Renewal, type: :model do
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form) }
before do
allow(form).to receive(:start_year_after_2024?).and_return(false)
allow(subsection).to receive(:form).and_return(form)
end
it "has correct subsection" do
expect(page.subsection).to eq(subsection)

4
spec/models/form/lettings/questions/renewal_spec.rb

@ -10,7 +10,7 @@ RSpec.describe Form::Lettings::Questions::Renewal, type: :model do
let(:form) { instance_double(Form) }
before do
allow(form).to receive(:start_date).and_return(Time.zone.local(2023, 4, 1))
allow(form).to receive(:start_year_after_2024?).and_return(false)
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form)
end
@ -52,7 +52,7 @@ RSpec.describe Form::Lettings::Questions::Renewal, type: :model do
context "with collection year on or after 2024" do
before do
allow(form).to receive(:start_date).and_return(Time.zone.local(2024, 4, 1))
allow(form).to receive(:start_year_after_2024?).and_return(true)
end
it "has the correct header" do

Loading…
Cancel
Save