From 92fdc0fff1a35e3e6574ee293e7fde10d5dfd2d7 Mon Sep 17 00:00:00 2001 From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com> Date: Mon, 13 Mar 2023 17:36:09 +0000 Subject: [PATCH] CLDC-1816 add hint text to tenancy type options (#1341) * 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 * update some depends on for readability and write test files for page classes * change the condition to avoid conflicts with 2034 and cover that ticket in this one * also add hints to other tenancy question --- .../lettings/pages/starter_tenancy_type.rb | 6 +- .../form/lettings/pages/tenancy_length.rb | 4 +- .../form/lettings/pages/tenancy_type.rb | 6 +- .../lettings/questions/starter_tenancy.rb | 22 ------- .../questions/starter_tenancy_type.rb | 37 +++++++++++ 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 +++++++++++ app/models/lettings_log.rb | 8 +++ .../pages/starter_tenancy_type_spec.rb | 31 +++++++++ .../lettings/pages/tenancy_length_spec.rb | 31 +++++++++ .../form/lettings/pages/tenancy_type_spec.rb | 31 +++++++++ .../lettings/questions/tenancy_length_spec.rb | 44 +++++++++++++ .../lettings/questions/tenancy_other_spec.rb | 35 ++++++++++ .../lettings/questions/tenancy_type_spec.rb | 65 +++++++++++++++++++ 16 files changed, 329 insertions(+), 54 deletions(-) delete mode 100644 app/models/form/lettings/questions/starter_tenancy.rb create mode 100644 app/models/form/lettings/questions/starter_tenancy_type.rb 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/pages/starter_tenancy_type_spec.rb create mode 100644 spec/models/form/lettings/pages/tenancy_length_spec.rb create mode 100644 spec/models/form/lettings/pages/tenancy_type_spec.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..fe147bc77 100644 --- a/app/models/form/lettings/pages/starter_tenancy_type.rb +++ b/app/models/form/lettings/pages/starter_tenancy_type.rb @@ -2,13 +2,13 @@ class Form::Lettings::Pages::StarterTenancyType < ::Form::Page def initialize(id, hsh, subsection) super @id = "starter_tenancy_type" - @depends_on = [{ "startertenancy" => 1 }] + @depends_on = [{ "starter_tenancy?" => true }] end def questions @questions ||= [ - Form::Lettings::Questions::StarterTenancy.new(nil, nil, self), - Form::Lettings::Questions::Tenancyother.new(nil, nil, self), + Form::Lettings::Questions::StarterTenancyType.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..cb533dcf9 100644 --- a/app/models/form/lettings/pages/tenancy_length.rb +++ b/app/models/form/lettings/pages/tenancy_length.rb @@ -2,10 +2,10 @@ class Form::Lettings::Pages::TenancyLength < ::Form::Page def initialize(id, hsh, subsection) super @id = "tenancy_length" - @depends_on = [{ "tenancy" => 4 }, { "tenancy" => 6 }, { "tenancy" => 3 }] + @depends_on = [{ "tenancy_type_fixed_term?" => true }] 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..c15f6f27a 100644 --- a/app/models/form/lettings/pages/tenancy_type.rb +++ b/app/models/form/lettings/pages/tenancy_type.rb @@ -2,13 +2,13 @@ class Form::Lettings::Pages::TenancyType < ::Form::Page def initialize(id, hsh, subsection) super @id = "tenancy_type" - @depends_on = [{ "startertenancy" => 2 }] + @depends_on = [{ "starter_tenancy?" => false }] end 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/starter_tenancy.rb b/app/models/form/lettings/questions/starter_tenancy.rb deleted file mode 100644 index 9e489c129..000000000 --- a/app/models/form/lettings/questions/starter_tenancy.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Form::Lettings::Questions::StarterTenancy < ::Form::Question - def initialize(id, hsh, page) - super - @id = "tenancy" - @check_answer_label = "Type of main tenancy after the starter period has ended?" - @header = "What is the type of tenancy after the starter period has ended?" - @type = "radio" - @check_answers_card_number = 0 - @hint_text = "This is also known as an ‘introductory period’." - @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/starter_tenancy_type.rb b/app/models/form/lettings/questions/starter_tenancy_type.rb new file mode 100644 index 000000000..13fa20ef6 --- /dev/null +++ b/app/models/form/lettings/questions/starter_tenancy_type.rb @@ -0,0 +1,37 @@ +class Form::Lettings::Questions::StarterTenancyType < ::Form::Question + def initialize(id, hsh, page) + super + @id = "tenancy" + @check_answer_label = "Type of main tenancy after the starter period has ended?" + @header = "What is the type of tenancy after the starter period has ended?" + @type = "radio" + @check_answers_card_number = 0 + @hint_text = "This is also known as an ‘introductory period’." + @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/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/app/models/lettings_log.rb b/app/models/lettings_log.rb index 6491c100f..108cb1be1 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -195,6 +195,14 @@ class LettingsLog < Log renewal == 1 end + def starter_tenancy? + startertenancy == 1 + end + + def tenancy_type_fixed_term? + [4, 6].include? tenancy + end + def is_general_needs? # 1: General Needs needstype == 1 diff --git a/spec/models/form/lettings/pages/starter_tenancy_type_spec.rb b/spec/models/form/lettings/pages/starter_tenancy_type_spec.rb new file mode 100644 index 000000000..795dee561 --- /dev/null +++ b/spec/models/form/lettings/pages/starter_tenancy_type_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::StarterTenancyType, 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[tenancy tenancyother]) + end + + it "has the correct id" do + expect(page.id).to eq("starter_tenancy_type") + 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([{ "starter_tenancy?" => true }]) + end +end diff --git a/spec/models/form/lettings/pages/tenancy_length_spec.rb b/spec/models/form/lettings/pages/tenancy_length_spec.rb new file mode 100644 index 000000000..d4ea920ae --- /dev/null +++ b/spec/models/form/lettings/pages/tenancy_length_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::TenancyLength, 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 }] + end +end diff --git a/spec/models/form/lettings/pages/tenancy_type_spec.rb b/spec/models/form/lettings/pages/tenancy_type_spec.rb new file mode 100644 index 000000000..ef772e85e --- /dev/null +++ b/spec/models/form/lettings/pages/tenancy_type_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::TenancyType, 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[tenancy tenancyother] + end + + it "has the correct id" do + expect(page.id).to eq "tenancy_type" + 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 [{ "starter_tenancy?" => false }] + end +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