Browse Source

CLDC-3354 Show user input on address selection page (#2374)

* Display input playback on the page

* Add input playback to uprn selection pages
pull/2411/head
kosiakkatrina 8 months ago committed by GitHub
parent
commit
7e638657fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      app/models/form/lettings/questions/uprn_selection.rb
  2. 2
      app/models/form/question.rb
  3. 8
      app/models/form/sales/questions/uprn_selection.rb
  4. 4
      app/views/form/_radio_question.html.erb
  5. 38
      spec/models/form/lettings/questions/uprn_selection_spec.rb
  6. 38
      spec/models/form/sales/questions/uprn_selection_spec.rb
  7. 17
      spec/views/form/page_view_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

2
app/models/form/question.rb

@ -60,6 +60,8 @@ class Form::Question
def notification_banner(_log = nil); end
def input_playback(_log = nil); end
def get_inferred_answers(log)
return [] unless inferred_answers

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

4
app/views/form/_radio_question.html.erb

@ -8,6 +8,10 @@
simple_format(banner[:heading])
end %>
<% end %>
<% input_playback = question.input_playback(@log) %>
<% if input_playback %>
<p class="govuk-body"><%= input_playback %></p>
<% end %>
<%= f.govuk_radio_buttons_fieldset question.id.to_sym,
caption: caption(caption_text, page_header, conditional),

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

17
spec/views/form/page_view_spec.rb

@ -150,4 +150,21 @@ RSpec.describe "form/page" do
end
end
end
context "with a question containing input playback" do
let(:expected_playback) { /This is input playback/ }
context "with radio type" do
let(:question_attributes) { { type: "radio", answer_options: { "1": "A", "2": "B" } } }
before do
allow(question).to receive(:input_playback).and_return("This is input playback")
render
end
it "renders the input playback for radio questions" do
expect(rendered).to match(expected_playback)
end
end
end
end

Loading…
Cancel
Save