From a7c99604b76d4f02b330078990b037cac7570c1c Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Thu, 23 Feb 2023 17:04:25 +0000 Subject: [PATCH] add hint text to several options on tenancy type, rename question class and a few others to make them pascal case and write test files for all changed questions --- .../lettings/pages/starter_tenancy_type.rb | 2 +- .../form/lettings/pages/tenancy_length.rb | 2 +- .../form/lettings/pages/tenancy_type.rb | 4 +- app/models/form/lettings/questions/tenancy.rb | 22 ------- .../{tenancylength.rb => tenancy_length.rb} | 2 +- .../{tenancyother.rb => tenancy_other.rb} | 2 +- .../form/lettings/questions/tenancy_type.rb | 37 +++++++++++ .../lettings/questions/tenancy_length_spec.rb | 44 +++++++++++++ .../lettings/questions/tenancy_other_spec.rb | 35 ++++++++++ .../lettings/questions/tenancy_type_spec.rb | 65 +++++++++++++++++++ 10 files changed, 187 insertions(+), 28 deletions(-) delete mode 100644 app/models/form/lettings/questions/tenancy.rb rename app/models/form/lettings/questions/{tenancylength.rb => tenancy_length.rb} (86%) rename app/models/form/lettings/questions/{tenancyother.rb => tenancy_other.rb} (78%) create mode 100644 app/models/form/lettings/questions/tenancy_type.rb create mode 100644 spec/models/form/lettings/questions/tenancy_length_spec.rb create mode 100644 spec/models/form/lettings/questions/tenancy_other_spec.rb create mode 100644 spec/models/form/lettings/questions/tenancy_type_spec.rb diff --git a/app/models/form/lettings/pages/starter_tenancy_type.rb b/app/models/form/lettings/pages/starter_tenancy_type.rb index c488b7b17..4b6ac64c6 100644 --- a/app/models/form/lettings/pages/starter_tenancy_type.rb +++ b/app/models/form/lettings/pages/starter_tenancy_type.rb @@ -8,7 +8,7 @@ class Form::Lettings::Pages::StarterTenancyType < ::Form::Page def questions @questions ||= [ Form::Lettings::Questions::StarterTenancy.new(nil, nil, self), - Form::Lettings::Questions::Tenancyother.new(nil, nil, self), + Form::Lettings::Questions::TenancyOther.new(nil, nil, self), ] end end diff --git a/app/models/form/lettings/pages/tenancy_length.rb b/app/models/form/lettings/pages/tenancy_length.rb index 943ea2bc9..17d2e825b 100644 --- a/app/models/form/lettings/pages/tenancy_length.rb +++ b/app/models/form/lettings/pages/tenancy_length.rb @@ -6,6 +6,6 @@ class Form::Lettings::Pages::TenancyLength < ::Form::Page end def questions - @questions ||= [Form::Lettings::Questions::Tenancylength.new(nil, nil, self)] + @questions ||= [Form::Lettings::Questions::TenancyLength.new(nil, nil, self)] end end diff --git a/app/models/form/lettings/pages/tenancy_type.rb b/app/models/form/lettings/pages/tenancy_type.rb index 8ee6c3bbc..b681b7553 100644 --- a/app/models/form/lettings/pages/tenancy_type.rb +++ b/app/models/form/lettings/pages/tenancy_type.rb @@ -7,8 +7,8 @@ class Form::Lettings::Pages::TenancyType < ::Form::Page def questions @questions ||= [ - Form::Lettings::Questions::Tenancy.new(nil, nil, self), - Form::Lettings::Questions::Tenancyother.new(nil, nil, self), + Form::Lettings::Questions::TenancyType.new(nil, nil, self), + Form::Lettings::Questions::TenancyOther.new(nil, nil, self), ] end end diff --git a/app/models/form/lettings/questions/tenancy.rb b/app/models/form/lettings/questions/tenancy.rb deleted file mode 100644 index 06a8d4fce..000000000 --- a/app/models/form/lettings/questions/tenancy.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Form::Lettings::Questions::Tenancy < ::Form::Question - def initialize(id, hsh, page) - super - @id = "tenancy" - @check_answer_label = "Type of main tenancy" - @header = "What is the type of tenancy?" - @type = "radio" - @check_answers_card_number = 0 - @hint_text = "" - @answer_options = ANSWER_OPTIONS - @conditional_for = { "tenancyother" => [3] } - end - - ANSWER_OPTIONS = { - "4" => { "value" => "Assured Shorthold Tenancy (AST) – Fixed term" }, - "6" => { "value" => "Secure – fixed term" }, - "2" => { "value" => "Assured – lifetime" }, - "7" => { "value" => "Secure – lifetime" }, - "5" => { "value" => "Licence agreement" }, - "3" => { "value" => "Other" }, - }.freeze -end diff --git a/app/models/form/lettings/questions/tenancylength.rb b/app/models/form/lettings/questions/tenancy_length.rb similarity index 86% rename from app/models/form/lettings/questions/tenancylength.rb rename to app/models/form/lettings/questions/tenancy_length.rb index 426a95669..0a8088c51 100644 --- a/app/models/form/lettings/questions/tenancylength.rb +++ b/app/models/form/lettings/questions/tenancy_length.rb @@ -1,4 +1,4 @@ -class Form::Lettings::Questions::Tenancylength < ::Form::Question +class Form::Lettings::Questions::TenancyLength < ::Form::Question def initialize(id, hsh, page) super @id = "tenancylength" diff --git a/app/models/form/lettings/questions/tenancyother.rb b/app/models/form/lettings/questions/tenancy_other.rb similarity index 78% rename from app/models/form/lettings/questions/tenancyother.rb rename to app/models/form/lettings/questions/tenancy_other.rb index 468d592aa..6eea47ac8 100644 --- a/app/models/form/lettings/questions/tenancyother.rb +++ b/app/models/form/lettings/questions/tenancy_other.rb @@ -1,4 +1,4 @@ -class Form::Lettings::Questions::Tenancyother < ::Form::Question +class Form::Lettings::Questions::TenancyOther < ::Form::Question def initialize(id, hsh, page) super @id = "tenancyother" diff --git a/app/models/form/lettings/questions/tenancy_type.rb b/app/models/form/lettings/questions/tenancy_type.rb new file mode 100644 index 000000000..c05b4349d --- /dev/null +++ b/app/models/form/lettings/questions/tenancy_type.rb @@ -0,0 +1,37 @@ +class Form::Lettings::Questions::TenancyType < ::Form::Question + def initialize(id, hsh, page) + super + @id = "tenancy" + @check_answer_label = "Type of main tenancy" + @header = "What is the type of tenancy?" + @type = "radio" + @check_answers_card_number = 0 + @hint_text = "" + @answer_options = ANSWER_OPTIONS + @conditional_for = { "tenancyother" => [3] } + end + + ANSWER_OPTIONS = { + "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", + }, + }.freeze +end diff --git a/spec/models/form/lettings/questions/tenancy_length_spec.rb b/spec/models/form/lettings/questions/tenancy_length_spec.rb new file mode 100644 index 000000000..8eea52a81 --- /dev/null +++ b/spec/models/form/lettings/questions/tenancy_length_spec.rb @@ -0,0 +1,44 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::TenancyLength, type: :model do + subject(:question) { described_class.new(nil, nil, page) } + + 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 fixed-term tenancy to the nearest year?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Length of fixed-term 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("Don’t include the starter or introductory period.") + end + + it "has the correct minimum and maximum" do + expect(question.min).to eq 0 + expect(question.max).to eq 150 + end + + it "has the correct step" do + expect(question.step).to eq 1 + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end +end diff --git a/spec/models/form/lettings/questions/tenancy_other_spec.rb b/spec/models/form/lettings/questions/tenancy_other_spec.rb new file mode 100644 index 000000000..58a656e57 --- /dev/null +++ b/spec/models/form/lettings/questions/tenancy_other_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::TenancyOther, type: :model do + subject(:question) { described_class.new(nil, nil, page) } + + 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("tenancyother") + end + + it "has the correct header" do + expect(question.header).to eq("Please state the tenancy type") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("") + end + + it "has the correct type" do + expect(question.type).to eq("text") + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq("") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end +end diff --git a/spec/models/form/lettings/questions/tenancy_type_spec.rb b/spec/models/form/lettings/questions/tenancy_type_spec.rb new file mode 100644 index 000000000..8fd8a50f0 --- /dev/null +++ b/spec/models/form/lettings/questions/tenancy_type_spec.rb @@ -0,0 +1,65 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::TenancyType, type: :model do + subject(:question) { described_class.new(nil, nil, page) } + + 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("tenancy") + end + + it "has the correct header" do + expect(question.header).to eq("What is the type of tenancy?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Type of main tenancy") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "has the correct hint_text" do + expect(question.hint_text).to eq("") + end + + it "has the correct conditional_for" 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", + }, + }) + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end +end