44 changed files with 1086 additions and 44 deletions
			
			
		| @ -0,0 +1,21 @@ | ||||
| class Form::Sales::Pages::Address < ::Form::Page | ||||
|   def initialize(id, hsh, subsection) | ||||
|     super | ||||
|     @id = "address" | ||||
|     @header = "What is the property's address?" | ||||
|   end | ||||
| 
 | ||||
|   def questions | ||||
|     @questions ||= [ | ||||
|       Form::Sales::Questions::AddressLine1.new(nil, nil, self), | ||||
|       Form::Sales::Questions::AddressLine2.new(nil, nil, self), | ||||
|       Form::Sales::Questions::TownOrCity.new(nil, nil, self), | ||||
|       Form::Sales::Questions::County.new(nil, nil, self), | ||||
|       Form::Sales::Questions::PostcodeForFullAddress.new(nil, nil, self), | ||||
|     ] | ||||
|   end | ||||
| 
 | ||||
|   def routed_to?(log, _current_user) | ||||
|     log.uprn_confirmed != 1 || log.uprn_known&.zero? | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,26 @@ | ||||
| class Form::Sales::Pages::Uprn < ::Form::Page | ||||
|   def initialize(id, hsh, subsection) | ||||
|     super | ||||
|     @id = "uprn" | ||||
|   end | ||||
| 
 | ||||
|   def questions | ||||
|     @questions ||= [ | ||||
|       Form::Sales::Questions::Uprn.new(nil, nil, self), | ||||
|     ] | ||||
|   end | ||||
| 
 | ||||
|   def routed_to?(log, _current_user) | ||||
|     log.uprn_known == 1 | ||||
|   end | ||||
| 
 | ||||
|   def skip_text | ||||
|     "Enter address instead" | ||||
|   end | ||||
| 
 | ||||
|   def skip_href(log = nil) | ||||
|     return unless log | ||||
| 
 | ||||
|     "/#{log.model_name.param_key.dasherize}s/#{log.id}/address" | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,17 @@ | ||||
| class Form::Sales::Pages::UprnConfirmation < ::Form::Page | ||||
|   def initialize(id, hsh, subsection) | ||||
|     super | ||||
|     @id = "uprn_confirmation" | ||||
|     @header = "We found an address that might be this property" | ||||
|   end | ||||
| 
 | ||||
|   def questions | ||||
|     @questions ||= [ | ||||
|       Form::Sales::Questions::UprnConfirmation.new(nil, nil, self), | ||||
|     ] | ||||
|   end | ||||
| 
 | ||||
|   def routed_to?(log, _current_user) | ||||
|     log.uprn.present? && log.uprn_known == 1 | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,12 @@ | ||||
| class Form::Sales::Pages::UprnKnown < ::Form::Page | ||||
|   def initialize(id, hsh, subsection) | ||||
|     super | ||||
|     @id = "uprn_known" | ||||
|   end | ||||
| 
 | ||||
|   def questions | ||||
|     @questions ||= [ | ||||
|       Form::Sales::Questions::UprnKnown.new(nil, nil, self), | ||||
|     ] | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,35 @@ | ||||
| class Form::Sales::Questions::AddressLine1 < ::Form::Question | ||||
|   def initialize(id, hsh, page) | ||||
|     super | ||||
|     @id = "address_line1" | ||||
|     @check_answer_label = "Address" | ||||
|     @header = "Address line 1" | ||||
|     @type = "text" | ||||
|     @plain_label = true | ||||
|   end | ||||
| 
 | ||||
|   def hidden_in_check_answers?(log, _current_user = nil) | ||||
|     return true if log.uprn_known.nil? | ||||
|     return false if log.uprn_known&.zero? | ||||
|     return true if log.uprn_confirmed.nil? && log.uprn.present? | ||||
|     return true if log.uprn_known == 1 && log.uprn.blank? | ||||
| 
 | ||||
|     log.uprn_confirmed == 1 | ||||
|   end | ||||
| 
 | ||||
|   def answer_label(log, _current_user = nil) | ||||
|     [ | ||||
|       log.address_line1, | ||||
|       log.address_line2, | ||||
|       log.postcode_full, | ||||
|       log.town_or_city, | ||||
|       log.county, | ||||
|     ].select(&:present?).join("\n") | ||||
|   end | ||||
| 
 | ||||
|   def get_extra_check_answer_value(log) | ||||
|     la = LocalAuthority.find_by(code: log.la)&.name | ||||
| 
 | ||||
|     la.presence | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,13 @@ | ||||
| class Form::Sales::Questions::AddressLine2 < ::Form::Question | ||||
|   def initialize(id, hsh, page) | ||||
|     super | ||||
|     @id = "address_line2" | ||||
|     @header = "Address line 2 (optional)" | ||||
|     @type = "text" | ||||
|     @plain_label = true | ||||
|   end | ||||
| 
 | ||||
|   def hidden_in_check_answers?(_log = nil, _current_user = nil) | ||||
|     true | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,13 @@ | ||||
| class Form::Sales::Questions::County < ::Form::Question | ||||
|   def initialize(id, hsh, page) | ||||
|     super | ||||
|     @id = "county" | ||||
|     @header = "County (optional)" | ||||
|     @type = "text" | ||||
|     @plain_label = true | ||||
|   end | ||||
| 
 | ||||
|   def hidden_in_check_answers?(_log = nil, _current_user = nil) | ||||
|     true | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,25 @@ | ||||
| class Form::Sales::Questions::PostcodeForFullAddress < ::Form::Question | ||||
|   def initialize(id, hsh, page) | ||||
|     super | ||||
|     @id = "postcode_full" | ||||
|     @header = "Postcode" | ||||
|     @type = "text" | ||||
|     @width = 5 | ||||
|     @inferred_check_answers_value = [{ | ||||
|       "condition" => { | ||||
|         "pcodenk" => 1, | ||||
|       }, | ||||
|       "value" => "Not known", | ||||
|     }] | ||||
|     @inferred_answers = { | ||||
|       "la" => { | ||||
|         "is_la_inferred" => true, | ||||
|       }, | ||||
|     } | ||||
|     @plain_label = true | ||||
|   end | ||||
| 
 | ||||
|   def hidden_in_check_answers?(_log = nil, _current_user = nil) | ||||
|     true | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,13 @@ | ||||
| class Form::Sales::Questions::TownOrCity < ::Form::Question | ||||
|   def initialize(id, hsh, page) | ||||
|     super | ||||
|     @id = "town_or_city" | ||||
|     @header = "Town or city" | ||||
|     @type = "text" | ||||
|     @plain_label = true | ||||
|   end | ||||
| 
 | ||||
|   def hidden_in_check_answers?(_log = nil, _current_user = nil) | ||||
|     true | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,34 @@ | ||||
| class Form::Sales::Questions::Uprn < ::Form::Question | ||||
|   def initialize(id, hsh, page) | ||||
|     super | ||||
|     @id = "uprn" | ||||
|     @check_answer_label = "UPRN" | ||||
|     @header = "What is the property's UPRN" | ||||
|     @type = "text" | ||||
|     @hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355." | ||||
|     @width = 10 | ||||
|   end | ||||
| 
 | ||||
|   def unanswered_error_message | ||||
|     I18n.t("validations.property.uprn.invalid") | ||||
|   end | ||||
| 
 | ||||
|   def get_extra_check_answer_value(log) | ||||
|     value = [ | ||||
|       log.address_line1, | ||||
|       log.address_line2, | ||||
|       log.town_or_city, | ||||
|       log.county, | ||||
|       log.postcode_full, | ||||
|       (LocalAuthority.find_by(code: log.uprn)&.name if log.uprn.present?), | ||||
|     ].select(&:present?) | ||||
| 
 | ||||
|     return unless value.any? | ||||
| 
 | ||||
|     "\n\n#{value.join("\n")}" | ||||
|   end | ||||
| 
 | ||||
|   def hidden_in_check_answers?(log, _current_user = nil) | ||||
|     log.uprn_known != 1 | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,34 @@ | ||||
| class Form::Sales::Questions::UprnConfirmation < ::Form::Question | ||||
|   def initialize(id, hsh, page) | ||||
|     super | ||||
|     @id = "uprn_confirmed" | ||||
|     @header = "Is this the property address?" | ||||
|     @type = "radio" | ||||
|     @answer_options = ANSWER_OPTIONS | ||||
|     @check_answer_label = "Is this the right address?" | ||||
|   end | ||||
| 
 | ||||
|   ANSWER_OPTIONS = { | ||||
|     "1" => { "value" => "Yes" }, | ||||
|     "0" => { "value" => "No, I want to enter the address manually" }, | ||||
|   }.freeze | ||||
| 
 | ||||
|   def notification_banner(log = nil) | ||||
|     return unless log&.uprn | ||||
| 
 | ||||
|     { | ||||
|       title: "UPRN: #{log.uprn}", | ||||
|       heading: [ | ||||
|         log.address_line1, | ||||
|         log.address_line2, | ||||
|         log.postcode_full, | ||||
|         log.town_or_city, | ||||
|         log.county, | ||||
|       ].select(&:present?).join("\n"), | ||||
|     } | ||||
|   end | ||||
| 
 | ||||
|   def hidden_in_check_answers?(log, _current_user = nil) | ||||
|     log.uprn_known != 1 || log.uprn_confirmed.present? | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,21 @@ | ||||
| class Form::Sales::Questions::UprnKnown < ::Form::Question | ||||
|   def initialize(id, hsh, page) | ||||
|     super | ||||
|     @id = "uprn_known" | ||||
|     @check_answer_label = "UPRN known?" | ||||
|     @header = "Do you know the sale UPRN?" | ||||
|     @type = "radio" | ||||
|     @answer_options = ANSWER_OPTIONS | ||||
|     @hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.<br><br> | ||||
|     You can continue without the UPRN, but it means we will need you to enter the address of the property." | ||||
|   end | ||||
| 
 | ||||
|   ANSWER_OPTIONS = { | ||||
|     "1" => { "value" => "Yes" }, | ||||
|     "0" => { "value" => "No" }, | ||||
|   }.freeze | ||||
| 
 | ||||
|   def unanswered_error_message | ||||
|     I18n.t("validations.property.uprn_known.invalid") | ||||
|   end | ||||
| end | ||||
| 
 | 
| 
 | 
| 
 | 
| @ -0,0 +1,37 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Pages::Address, type: :model do | ||||
|   subject(:page) { described_class.new(page_id, page_definition, subsection) } | ||||
| 
 | ||||
|   let(:page_id) { nil } | ||||
|   let(:page_definition) { nil } | ||||
|   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[address_line1 address_line2 town_or_city county postcode_full]) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(page.id).to eq("address") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(page.header).to eq("What is the property's address?") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct description" do | ||||
|     expect(page.description).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has correct depends_on" do | ||||
|     expect(page.depends_on).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   xit "has correct routed_to" do | ||||
|     expect(page.routed_to?).to be_nil | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,37 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Pages::UprnConfirmation, type: :model do | ||||
|   subject(:page) { described_class.new(page_id, page_definition, subsection) } | ||||
| 
 | ||||
|   let(:page_id) { nil } | ||||
|   let(:page_definition) { nil } | ||||
|   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[uprn_confirmed]) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(page.id).to eq("uprn_confirmation") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(page.header).to eq("We found an address that might be this property") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct description" do | ||||
|     expect(page.description).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has correct depends_on" do | ||||
|     expect(page.depends_on).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   xit "has correct routed_to" do | ||||
|     expect(page.routed_to?).to be_nil | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,33 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Pages::UprnKnown, type: :model do | ||||
|   subject(:page) { described_class.new(page_id, page_definition, subsection) } | ||||
| 
 | ||||
|   let(:page_id) { nil } | ||||
|   let(:page_definition) { nil } | ||||
|   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[uprn_known]) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(page.id).to eq("uprn_known") | ||||
|   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 correct depends_on" do | ||||
|     expect(page.depends_on).to be_nil | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,45 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Pages::Uprn, type: :model do | ||||
|   subject(:page) { described_class.new(page_id, page_definition, subsection) } | ||||
| 
 | ||||
|   let(:page_id) { nil } | ||||
|   let(:page_definition) { nil } | ||||
|   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[uprn]) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(page.id).to eq("uprn") | ||||
|   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 correct depends_on" do | ||||
|     expect(page.depends_on).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has correct skip_text" do | ||||
|     expect(page.skip_text).to eq("Enter address instead") | ||||
|   end | ||||
| 
 | ||||
|   xit "has correct routed_to?" do | ||||
|     expect(page.routed_to?).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   xit "has correct skip_href" do | ||||
|     expect(page.skip_href).to be_nil | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,45 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::AddressLine1, 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) } | ||||
| 
 | ||||
|   it "has correct page" do | ||||
|     expect(question.page).to eq(page) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(question.id).to eq("address_line1") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(question.header).to eq("Address line 1") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answer_label" do | ||||
|     expect(question.check_answer_label).to eq("Address") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct type" do | ||||
|     expect(question.type).to eq("text") | ||||
|   end | ||||
| 
 | ||||
|   it "is not marked as derived" do | ||||
|     expect(question.derived?).to be false | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hint" do | ||||
|     expect(question.hint_text).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct inferred check answers value" do | ||||
|     expect(question.inferred_check_answers_value).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answers_card_number" do | ||||
|     expect(question.check_answers_card_number).to be_nil | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,49 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::AddressLine2, 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) } | ||||
| 
 | ||||
|   it "has correct page" do | ||||
|     expect(question.page).to eq(page) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(question.id).to eq("address_line2") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(question.header).to eq("Address line 2 (optional)") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answer_label" do | ||||
|     expect(question.check_answer_label).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct type" do | ||||
|     expect(question.type).to eq("text") | ||||
|   end | ||||
| 
 | ||||
|   it "is not marked as derived" do | ||||
|     expect(question.derived?).to be false | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hint" do | ||||
|     expect(question.hint_text).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct inferred check answers value" do | ||||
|     expect(question.inferred_check_answers_value).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answers_card_number" do | ||||
|     expect(question.check_answers_card_number).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hidden_in_check_answers" do | ||||
|     expect(question.hidden_in_check_answers?).to eq(true) | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,49 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::County, 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) } | ||||
| 
 | ||||
|   it "has correct page" do | ||||
|     expect(question.page).to eq(page) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(question.id).to eq("county") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(question.header).to eq("County (optional)") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answer_label" do | ||||
|     expect(question.check_answer_label).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct type" do | ||||
|     expect(question.type).to eq("text") | ||||
|   end | ||||
| 
 | ||||
|   it "is not marked as derived" do | ||||
|     expect(question.derived?).to be false | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hint" do | ||||
|     expect(question.hint_text).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct inferred check answers value" do | ||||
|     expect(question.inferred_check_answers_value).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answers_card_number" do | ||||
|     expect(question.check_answers_card_number).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hidden_in_check_answers" do | ||||
|     expect(question.hidden_in_check_answers?).to eq(true) | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,62 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::PostcodeForFullAddress, 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) } | ||||
| 
 | ||||
|   it "has correct page" do | ||||
|     expect(question.page).to eq(page) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(question.id).to eq("postcode_full") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(question.header).to eq("Postcode") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answer_label" do | ||||
|     expect(question.check_answer_label).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct type" do | ||||
|     expect(question.type).to eq("text") | ||||
|   end | ||||
| 
 | ||||
|   it "is not marked as derived" do | ||||
|     expect(question.derived?).to be false | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hint" do | ||||
|     expect(question.hint_text).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct width" do | ||||
|     expect(question.width).to eq(5) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct inferred_answers" do | ||||
|     expect(question.inferred_answers).to eq({ | ||||
|       "la" => { | ||||
|         "is_la_inferred" => true, | ||||
|       }, | ||||
|     }) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct inferred_check_answers_value" do | ||||
|     expect(question.inferred_check_answers_value).to eq([{ | ||||
|       "condition" => { | ||||
|         "pcodenk" => 1, | ||||
|       }, | ||||
|       "value" => "Not known", | ||||
|     }]) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hidden_in_check_answers" do | ||||
|     expect(question.hidden_in_check_answers?).to eq(true) | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,49 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::TownOrCity, 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) } | ||||
| 
 | ||||
|   it "has correct page" do | ||||
|     expect(question.page).to eq(page) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(question.id).to eq("town_or_city") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(question.header).to eq("Town or city") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answer_label" do | ||||
|     expect(question.check_answer_label).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct type" do | ||||
|     expect(question.type).to eq("text") | ||||
|   end | ||||
| 
 | ||||
|   it "is not marked as derived" do | ||||
|     expect(question.derived?).to be false | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hint" do | ||||
|     expect(question.hint_text).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct inferred check answers value" do | ||||
|     expect(question.inferred_check_answers_value).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answers_card_number" do | ||||
|     expect(question.check_answers_card_number).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hidden_in_check_answers" do | ||||
|     expect(question.hidden_in_check_answers?).to eq(true) | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,68 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::UprnConfirmation, 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) } | ||||
| 
 | ||||
|   it "has correct page" do | ||||
|     expect(question.page).to eq(page) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(question.id).to eq("uprn_confirmed") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(question.header).to eq("Is this the property address?") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answer_label" do | ||||
|     expect(question.check_answer_label).to eq("Is this the right address?") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct type" do | ||||
|     expect(question.type).to eq("radio") | ||||
|   end | ||||
| 
 | ||||
|   it "is not marked as derived" do | ||||
|     expect(question.derived?).to be false | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hint" do | ||||
|     expect(question.hint_text).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct unanswered_error_message" do | ||||
|     expect(question.unanswered_error_message).to eq("You must answer is this the right address?") | ||||
|   end | ||||
| 
 | ||||
|   describe "notification_banner" do | ||||
|     context "when address is not present" do | ||||
|       it "returns nil" do | ||||
|         log = create(:sales_log) | ||||
| 
 | ||||
|         expect(question.notification_banner(log)).to be_nil | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|     context "when address is present" do | ||||
|       it "returns formatted value" do | ||||
|         log = create(:sales_log, address_line1: "1, Test Street", town_or_city: "Test Town", county: "Test County", postcode_full: "AA1 1AA", uprn: "1234") | ||||
| 
 | ||||
|         expect(question.notification_banner(log)).to eq( | ||||
|           { | ||||
|             heading: "1, Test Street\nAA1 1AA\nTest Town\nTest County", | ||||
|             title: "UPRN: 1234", | ||||
|           }, | ||||
|         ) | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   xit "has the correct hidden_in_check_answers" do | ||||
|     expect(question.hidden_in_check_answers).to eq("UPRN must be 12 digits or less") | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,59 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::UprnKnown, 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) } | ||||
| 
 | ||||
|   it "has correct page" do | ||||
|     expect(question.page).to eq(page) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(question.id).to eq("uprn_known") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(question.header).to eq("Do you know the sale UPRN?") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answer_label" do | ||||
|     expect(question.check_answer_label).to eq("UPRN known?") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct type" do | ||||
|     expect(question.type).to eq("radio") | ||||
|   end | ||||
| 
 | ||||
|   it "is not marked as derived" do | ||||
|     expect(question.derived?).to be false | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct answer_options" do | ||||
|     expect(question.answer_options).to eq({ | ||||
|       "0" => { "value" => "No" }, | ||||
|       "1" => { "value" => "Yes" }, | ||||
|     }) | ||||
|   end | ||||
| 
 | ||||
|   it "has correct conditional for" do | ||||
|     expect(question.conditional_for).to be_nil | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct unanswered_error_message" do | ||||
|     expect(question.unanswered_error_message).to eq("You must answer UPRN known?") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hint" do | ||||
|     expect(question.hint_text).to eq( | ||||
|       "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.<br><br> | ||||
|     You can continue without the UPRN, but it means we will need you to enter the address of the property.", | ||||
|     ) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hidden_in_check_answers" do | ||||
|     expect(question.hidden_in_check_answers).to be_nil | ||||
|   end | ||||
| end | ||||
| @ -0,0 +1,65 @@ | ||||
| require "rails_helper" | ||||
| 
 | ||||
| RSpec.describe Form::Sales::Questions::Uprn, 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) } | ||||
| 
 | ||||
|   it "has correct page" do | ||||
|     expect(question.page).to eq(page) | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct id" do | ||||
|     expect(question.id).to eq("uprn") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct header" do | ||||
|     expect(question.header).to eq("What is the property's UPRN") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct check_answer_label" do | ||||
|     expect(question.check_answer_label).to eq("UPRN") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct type" do | ||||
|     expect(question.type).to eq("text") | ||||
|   end | ||||
| 
 | ||||
|   it "is not marked as derived" do | ||||
|     expect(question.derived?).to be false | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct hint" do | ||||
|     expect(question.hint_text).to eq("The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.") | ||||
|   end | ||||
| 
 | ||||
|   it "has the correct unanswered_error_message" do | ||||
|     expect(question.unanswered_error_message).to eq("UPRN must be 12 digits or less") | ||||
|   end | ||||
| 
 | ||||
|   describe "get_extra_check_answer_value" do | ||||
|     context "when address is not present" do | ||||
|       it "returns nil" do | ||||
|         log = create(:sales_log) | ||||
| 
 | ||||
|         expect(question.get_extra_check_answer_value(log)).to be_nil | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|     context "when address is present" do | ||||
|       it "returns formatted value" do | ||||
|         log = create(:sales_log, address_line1: "1, Test Street", town_or_city: "Test Town", county: "Test County", postcode_full: "AA1 1AA") | ||||
| 
 | ||||
|         expect(question.get_extra_check_answer_value(log)).to eq( | ||||
|           "\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA", | ||||
|         ) | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   xit "has the correct hidden_in_check_answers" do | ||||
|     expect(question.hidden_in_check_answers).to eq("UPRN must be 12 digits or less") | ||||
|   end | ||||
| end | ||||
					Loading…
					
					
				
		Reference in new issue