Browse Source

feat: update answer options and hint text, add new period tenancy length question and test

pull/2214/head
natdeanlewissoftwire 2 years ago
parent
commit
4c32e7e669
  1. 11
      app/models/form/lettings/pages/tenancy_length_periodic.rb
  2. 16
      app/models/form/lettings/questions/tenancy_length_periodic.rb
  3. 1
      app/models/form/lettings/subsections/tenancy_information.rb
  4. 4
      app/models/lettings_log.rb
  5. 6
      spec/models/form/lettings/pages/starter_tenancy_type_spec.rb
  6. 96
      spec/models/form/lettings/questions/starter_tenancy_type_spec.rb
  7. 94
      spec/models/form/lettings/questions/tenancy_type_spec.rb
  8. 2
      spec/models/form/lettings/subsections/tenancy_information_spec.rb

11
app/models/form/lettings/pages/tenancy_length_periodic.rb

@ -0,0 +1,11 @@
class Form::Lettings::Pages::TenancyLengthPeriodic < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "tenancy_length_periodic"
@depends_on = [{ "tenancy_type_periodic?" => true }]
end
def questions
@questions ||= [Form::Lettings::Questions::TenancyLengthPeriodic.new(nil, nil, self)]
end
end

16
app/models/form/lettings/questions/tenancy_length_periodic.rb

@ -0,0 +1,16 @@
class Form::Lettings::Questions::TenancyLengthPeriodic < ::Form::Question
def initialize(id, hsh, page)
super
@id = "tenancylength"
@check_answer_label = "Length of periodic tenancy"
@header = "What is the length of the periodic tenancy to the nearest year?"
@type = "numeric"
@width = 2
@check_answers_card_number = 0
@max = 150
@min = 0
@step = 1
@question_number = 28
@hint_text = "As this is a periodic tenancy, this question is optional. If you do not have the information available click save and continue"
end
end

1
app/models/form/lettings/subsections/tenancy_information.rb

@ -15,6 +15,7 @@ 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::ShelteredAccommodation.new(nil, nil, self),
].compact
end

4
app/models/lettings_log.rb

@ -286,6 +286,10 @@ class LettingsLog < Log
[4, 6].include? tenancy
end
def tenancy_type_periodic?
tenancy == 8
end
def is_general_needs?
# 1: General Needs
needstype == 1

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

@ -4,6 +4,12 @@ RSpec.describe Form::Lettings::Pages::StarterTenancyType, type: :model do
subject(:page) { described_class.new(nil, nil, subsection) }
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)

96
spec/models/form/lettings/questions/starter_tenancy_type_spec.rb

@ -0,0 +1,96 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::StarterTenancyType, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form) }
before do
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form)
end
context "with collection year before 2024" do
before do
allow(form).to receive(:start_year_after_2024?).and_return(false)
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("This is also known as an ‘introductory period’.")
end
it "has the correct answer options" do
expect(question.answer_options).to eq(
{
"4" => {
"value" => "Assured Shorthold Tenancy (AST) – Fixed term",
"hint" => "Mostly housing associations provide these. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"6" => {
"value" => "Secure – fixed term",
"hint" => "Mostly local authorities provide these. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"2" => {
"value" => "Assured – lifetime",
},
"7" => {
"value" => "Secure – lifetime",
},
"5" => {
"value" => "Licence agreement",
"hint" => "Licence agreements are mostly used for Supported Housing and work on a rolling basis.",
},
"3" => {
"value" => "Other",
},
},
)
end
end
context "with collection year >= 2024" do
before do
allow(form).to receive(:start_year_after_2024?).and_return(true)
end
it "has the correct updated hint_text" do
expect(question.hint_text).to eq("")
end
it "has the correct answer options" do
expect(question.answer_options).to eq(
{
"4" => {
"value" => "Assured Shorthold Tenancy (AST) – Fixed term",
"hint" => "These are mostly provided by housing associations. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"6" => {
"value" => "Secure – fixed term",
"hint" => "These are mostly provided by local authorities. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"2" => {
"value" => "Assured – lifetime",
},
"7" => {
"value" => "Secure – lifetime",
},
"8" => {
"value" => "Periodic",
"hint" => "These are rolling tenancies with no fixed end date. They may have an initial fixed term and then become rolling.",
},
"5" => {
"value" => "Licence agreement",
"hint" => "These are mostly used for Supported Housing and work on a rolling basis.",
},
"3" => {
"value" => "Other",
},
},
)
end
end
end

94
spec/models/form/lettings/questions/tenancy_type_spec.rb

@ -4,6 +4,14 @@ RSpec.describe Form::Lettings::Questions::TenancyType, type: :model do
subject(:question) { described_class.new(nil, nil, page) }
let(:page) { instance_double(Form::Page) }
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(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(form)
end
it "has correct page" do
expect(question.page).to eq(page)
@ -33,30 +41,68 @@ RSpec.describe Form::Lettings::Questions::TenancyType, type: :model do
expect(question.conditional_for).to eq({ "tenancyother" => [3] })
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"4" => {
"value" => "Assured Shorthold Tenancy (AST) – Fixed term",
"hint" => "Mostly housing associations provide these. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"6" => {
"value" => "Secure – fixed term",
"hint" => "Mostly local authorities provide these. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"2" => {
"value" => "Assured – lifetime",
},
"7" => {
"value" => "Secure – lifetime",
},
"5" => {
"value" => "Licence agreement",
"hint" => "Licence agreements are mostly used for Supported Housing and work on a rolling basis.",
},
"3" => {
"value" => "Other",
},
})
context "with 2023/24 form" do
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"4" => {
"value" => "Assured Shorthold Tenancy (AST) – Fixed term",
"hint" => "Mostly housing associations provide these. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"6" => {
"value" => "Secure – fixed term",
"hint" => "Mostly local authorities provide these. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"2" => {
"value" => "Assured – lifetime",
},
"7" => {
"value" => "Secure – lifetime",
},
"5" => {
"value" => "Licence agreement",
"hint" => "Licence agreements are mostly used for Supported Housing and work on a rolling basis.",
},
"3" => {
"value" => "Other",
},
})
end
end
context "with 2024/25 form" do
before do
allow(form).to receive(:start_year_after_2024?).and_return(true)
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"4" => {
"value" => "Assured Shorthold Tenancy (AST) – Fixed term",
"hint" => "These are mostly provided by housing associations. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"6" => {
"value" => "Secure – fixed term",
"hint" => "These are mostly provided by local authorities. Fixed term tenancies are intended to be for a set amount of time up to 20 years.",
},
"2" => {
"value" => "Assured – lifetime",
},
"7" => {
"value" => "Secure – lifetime",
},
"8" => {
"value" => "Periodic",
"hint" => "These are rolling tenancies with no fixed end date. They may have an initial fixed term and then become rolling.",
},
"5" => {
"value" => "Licence agreement",
"hint" => "These are mostly used for Supported Housing and work on a rolling basis.",
},
"3" => {
"value" => "Other",
},
})
end
end
it "is not marked as derived" do

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

@ -13,7 +13,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do
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],
%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

Loading…
Cancel
Save