diff --git a/app/models/form/sales/pages/living_before_purchase.rb b/app/models/form/sales/pages/living_before_purchase.rb index 5fa695bbc..ac61ab1de 100644 --- a/app/models/form/sales/pages/living_before_purchase.rb +++ b/app/models/form/sales/pages/living_before_purchase.rb @@ -1,7 +1,14 @@ class Form::Sales::Pages::LivingBeforePurchase < ::Form::Page def questions @questions ||= [ - Form::Sales::Questions::LivingBeforePurchase.new(nil, nil, self), - ] + living_before_purchase, + Form::Sales::Questions::LivingBeforePurchaseYears.new(nil, nil, self), + ].compact + end + + def living_before_purchase + if form.start_date.year >= 2023 + Form::Sales::Questions::LivingBeforePurchase.new(nil, nil, self) + end end end diff --git a/app/models/form/sales/questions/living_before_purchase.rb b/app/models/form/sales/questions/living_before_purchase.rb index feedaac63..d1b21252a 100644 --- a/app/models/form/sales/questions/living_before_purchase.rb +++ b/app/models/form/sales/questions/living_before_purchase.rb @@ -1,15 +1,29 @@ class Form::Sales::Questions::LivingBeforePurchase < ::Form::Question def initialize(id, hsh, page) super - @id = "proplen" - @check_answer_label = "Number of years living in the property before purchase" - @header = "How long did the buyer(s) live in the property before purchase?" - @hint_text = "You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'" - @type = "numeric" - @min = 0 - @max = 80 - @step = 1 - @width = 5 - @suffix = " years" + @id = "proplen_asked" + @check_answer_label = "Did the buyer live in the property before purchasing it?" + @header = "Did the buyer live in the property before purchasing it?" + @hint_text = nil + @type = "radio" + @answer_options = ANSWER_OPTIONS + @conditional_for = { + "proplen" => [0], + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "proplen_asked" => 0, + }, + { + "proplen_asked" => 1, + }, + ], + } end + + ANSWER_OPTIONS = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }.freeze end diff --git a/app/models/form/sales/questions/living_before_purchase_years.rb b/app/models/form/sales/questions/living_before_purchase_years.rb new file mode 100644 index 000000000..f3f1e58a7 --- /dev/null +++ b/app/models/form/sales/questions/living_before_purchase_years.rb @@ -0,0 +1,31 @@ +class Form::Sales::Questions::LivingBeforePurchaseYears < ::Form::Question + def initialize(id, hsh, page) + super + @id = "proplen" + @check_answer_label = "Number of years living in the property before purchase" + @header = header_text + @hint_text = hint_text + @type = "numeric" + @min = 0 + @max = 80 + @step = 1 + @width = 5 + @suffix = " years" + end + + def header_text + if form.start_date.year >= 2023 + "How long did they live there?" + else + "How long did the buyer(s) live in the property before purchase?" + end + end + + def hint_text + if form.start_date.year >= 2023 + "You should round up to the nearest year" + else + "You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'" + end + end +end diff --git a/spec/models/form/sales/questions/living_before_purchase_spec.rb b/spec/models/form/sales/questions/living_before_purchase_years_spec.rb similarity index 94% rename from spec/models/form/sales/questions/living_before_purchase_spec.rb rename to spec/models/form/sales/questions/living_before_purchase_years_spec.rb index 29f785c06..0176eb96c 100644 --- a/spec/models/form/sales/questions/living_before_purchase_spec.rb +++ b/spec/models/form/sales/questions/living_before_purchase_years_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe Form::Sales::Questions::LivingBeforePurchase, type: :model do +RSpec.describe Form::Sales::Questions::LivingBeforePurchaseYears, type: :model do subject(:question) { described_class.new(question_id, question_definition, page) } let(:question_id) { nil }