Browse Source

Add input playback to uprn selection pages

pull/2374/head
Kat 2 years ago
parent
commit
af972eaf9d
  1. 8
      app/models/form/lettings/questions/uprn_selection.rb
  2. 8
      app/models/form/sales/questions/uprn_selection.rb
  3. 38
      spec/models/form/lettings/questions/uprn_selection_spec.rb
  4. 38
      spec/models/form/sales/questions/uprn_selection_spec.rb

8
app/models/form/lettings/questions/uprn_selection.rb

@ -31,4 +31,12 @@ class Form::Lettings::Questions::UprnSelection < ::Form::Question
def hidden_in_check_answers?(log, _current_user = nil)
(log.uprn_known == 1 || log.uprn_confirmed == 1) || !(1..10).cover?(log.address_options&.count)
end
def input_playback(log = nil)
return unless log&.address_line1_input || log&.postcode_full_input
address_options_count = answer_options(log).count > 1 ? answer_options(log).count - 2 : 0
searched_address = [log.address_line1_input, log.postcode_full_input].select(&:present?).map { |x| "<strong>#{x}</strong>" }.join(" and ")
"#{address_options_count} #{'address'.pluralize(address_options_count)} found for #{searched_address}. <a href=\"#{page.skip_href(log)}\">Search again</a>".html_safe
end
end

8
app/models/form/sales/questions/uprn_selection.rb

@ -31,4 +31,12 @@ class Form::Sales::Questions::UprnSelection < ::Form::Question
def hidden_in_check_answers?(log, _current_user = nil)
(log.uprn_known == 1 || log.uprn_confirmed == 1) || !(1..10).cover?(log.address_options&.count)
end
def input_playback(log = nil)
return unless log&.address_line1_input || log&.postcode_full_input
address_options_count = answer_options(log).count > 1 ? answer_options(log).count - 2 : 0
searched_address = [log.address_line1_input, log.postcode_full_input].select(&:present?).map { |x| "<strong>#{x}</strong>" }.join(" and ")
"#{address_options_count} #{'address'.pluralize(address_options_count)} found for #{searched_address}. <a href=\"#{page.skip_href(log)}\">Search again</a>".html_safe
end
end

38
spec/models/form/lettings/questions/uprn_selection_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Form::Lettings::Questions::UprnSelection, type: :model do
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
let(:page) { instance_double(Form::Page, skip_href: "skip_href") }
let(:log) { create(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") }
let(:address_client_instance) { AddressClient.new(log.address_string) }
@ -99,4 +99,40 @@ RSpec.describe Form::Lettings::Questions::UprnSelection, type: :model do
expect(question.hidden_in_check_answers?(log)).to eq(true)
end
end
context "when the log has address line 1 input only" do
before do
log.address_line1_input = "Address line 1"
log.postcode_full_input = nil
log.save!(valudate: false)
end
it "has the correct input_playback" do
expect(question.input_playback(log)).to eq("0 addresses found for <strong>Address line 1</strong>. <a href=\"skip_href\">Search again</a>")
end
end
context "when the log has postcode input only" do
before do
log.address_line1_input = nil
log.postcode_full_input = "A1 1AA"
log.save!(valudate: false)
end
it "has the correct input_playback" do
expect(question.input_playback(log)).to eq("0 addresses found for <strong>A1 1AA</strong>. <a href=\"skip_href\">Search again</a>")
end
end
context "when the log has address line 1 and postcode inputs" do
before do
log.address_line1_input = "Address line 1"
log.postcode_full_input = "A1 1AA"
log.save!(valudate: false)
end
it "has the correct input_playback" do
expect(question.input_playback(log)).to eq("1 address found for <strong>Address line 1</strong> and <strong>A1 1AA</strong>. <a href=\"skip_href\">Search again</a>")
end
end
end

38
spec/models/form/sales/questions/uprn_selection_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Questions::UprnSelection, type: :model do
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
let(:page) { instance_double(Form::Page, skip_href: "skip_href") }
let(:log) { create(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") }
let(:address_client_instance) { AddressClient.new(log.address_string) }
@ -99,4 +99,40 @@ RSpec.describe Form::Sales::Questions::UprnSelection, type: :model do
expect(question.hidden_in_check_answers?(log)).to eq(true)
end
end
context "when the log has address line 1 input only" do
before do
log.address_line1_input = "Address line 1"
log.postcode_full_input = nil
log.save!(valudate: false)
end
it "has the correct input_playback" do
expect(question.input_playback(log)).to eq("0 addresses found for <strong>Address line 1</strong>. <a href=\"skip_href\">Search again</a>")
end
end
context "when the log has postcode input only" do
before do
log.address_line1_input = nil
log.postcode_full_input = "A1 1AA"
log.save!(valudate: false)
end
it "has the correct input_playback" do
expect(question.input_playback(log)).to eq("0 addresses found for <strong>A1 1AA</strong>. <a href=\"skip_href\">Search again</a>")
end
end
context "when the log has address line 1 and postcode inputs" do
before do
log.address_line1_input = "Address line 1"
log.postcode_full_input = "A1 1AA"
log.save!(valudate: false)
end
it "has the correct input_playback" do
expect(question.input_playback(log)).to eq("1 address found for <strong>Address line 1</strong> and <strong>A1 1AA</strong>. <a href=\"skip_href\">Search again</a>")
end
end
end

Loading…
Cancel
Save