Browse Source

CLDC-3334 Improve address search flow (#2339)

* Refactor page buttons

* Immediately show address search results
pull/2342/head^2
kosiakkatrina 10 months ago committed by GitHub
parent
commit
a38d6a265f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/controllers/form_controller.rb
  2. 28
      app/helpers/form_page_helper.rb
  3. 4
      app/models/form/lettings/pages/address_matcher.rb
  4. 3
      app/models/form/page.rb
  5. 4
      app/models/form/sales/pages/address_matcher.rb
  6. 15
      app/views/form/page.html.erb
  7. 83
      spec/features/form/form_navigation_spec.rb

2
app/controllers/form_controller.rb

@ -249,7 +249,7 @@ private
redirect_to lettings_log_path(@log) unless @log.collection_period_open_for_editing?
end
CONFIRMATION_PAGE_IDS = %w[uprn_confirmation].freeze
CONFIRMATION_PAGE_IDS = %w[uprn_confirmation uprn_selection].freeze
def correcting_duplicate_logs_redirect_path
class_name = @log.class.name.underscore

28
app/helpers/form_page_helper.rb

@ -18,4 +18,32 @@ module FormPageHelper
def relevant_check_answers_path(log, subsection)
send("#{log.class.name.underscore}_#{subsection.id}_check_answers_path", log)
end
def submit_button_text(page, referrer)
return page.submit_text if page.submit_text.present?
if accessed_from_duplicate_logs?(referrer) || returning_to_question_page?(page, referrer)
"Save changes"
else
"Save and continue"
end
end
def cancel_button_text(page, referrer)
if accessed_from_duplicate_logs?(referrer) || returning_to_question_page?(page, referrer)
"Cancel"
else
page.skip_text || "Skip for now"
end
end
def cancel_button_link(page, referrer, original_log_id, log)
if accessed_from_duplicate_logs?(referrer)
duplicate_log_set_path(log, original_log_id)
elsif returning_to_question_page?(page, referrer)
send(log.form.cancel_path(page, log), log)
else
page.skip_href(log) || send(log.form.next_page_redirect_path(page, log, current_user), log)
end
end
end

4
app/models/form/lettings/pages/address_matcher.rb

@ -16,4 +16,8 @@ class Form::Lettings::Pages::AddressMatcher < ::Form::Page
Form::Lettings::Questions::PostcodeForAddressMatcher.new(nil, nil, self),
]
end
def submit_text
"Search"
end
end

3
app/models/form/page.rb

@ -1,7 +1,7 @@
class Form::Page
attr_accessor :id, :header, :header_partial, :description, :questions, :depends_on, :title_text,
:informative_text, :subsection, :hide_subsection_label, :next_unresolved_page_id,
:skip_text, :interruption_screen_question_ids
:skip_text, :interruption_screen_question_ids, :submit_text
def initialize(id, hsh, subsection)
@id = id
@ -17,6 +17,7 @@ class Form::Page
@hide_subsection_label = hsh["hide_subsection_label"]
@next_unresolved_page_id = hsh["next_unresolved_page_id"]
@skip_text = hsh["skip_text"]
@submit_text = hsh["submit_text"]
@interruption_screen_question_ids = hsh["interruption_screen_question_ids"] || []
end
end

4
app/models/form/sales/pages/address_matcher.rb

@ -16,4 +16,8 @@ class Form::Sales::Pages::AddressMatcher < ::Form::Page
Form::Sales::Questions::PostcodeForAddressMatcher.new(nil, nil, self),
]
end
def submit_text
"Search"
end
end

15
app/views/form/page.html.erb

@ -72,19 +72,8 @@
<div class="govuk-button-group">
<% if !@page.interruption_screen? %>
<% if accessed_from_duplicate_logs?(request.query_parameters["referrer"]) %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", duplicate_log_set_path(@log, request.query_parameters["original_log_id"]) %>
<% elsif returning_to_question_page?(@page, request.query_parameters["referrer"]) %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", send(@log.form.cancel_path(@page, @log), @log) %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to(
(@page.skip_text || "Skip for now"),
(@page.skip_href(@log) || send(@log.form.next_page_redirect_path(@page, @log, current_user), @log)),
) %>
<% end %>
<%= f.govuk_submit submit_button_text(@page, request.query_parameters["referrer"]) %>
<%= govuk_link_to cancel_button_text(@page, request.query_parameters["referrer"]), cancel_button_link(@page, request.query_parameters["referrer"], request.query_parameters["original_log_id"], @log) %>
<% end %>
</div>
</div>

83
spec/features/form/form_navigation_spec.rb

@ -2,16 +2,7 @@ require "rails_helper"
require_relative "helpers"
RSpec.describe "Form Navigation" do
around do |example|
Timecop.travel(Time.zone.local(2022, 1, 1)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
include Helpers
let(:now) { Time.zone.local(2022, 1, 1) }
let(:user) { FactoryBot.create(:user) }
let(:lettings_log) do
FactoryBot.create(
@ -30,7 +21,6 @@ RSpec.describe "Form Navigation" do
created_by: user,
)
end
let(:id) { lettings_log.id }
let(:question_answers) do
{
@ -43,6 +33,17 @@ RSpec.describe "Form Navigation" do
end
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
around do |example|
Timecop.travel(now) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
include Helpers
before do
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
@ -185,4 +186,64 @@ RSpec.describe "Form Navigation" do
expect(page).to have_current_path("/lettings-logs/#{id}/duplicate-logs?original_log_id=#{id}")
end
end
describe "searching for an address" do
let(:now) { Time.zone.local(2024, 5, 1) }
context "with a lettings log" do
let(:lettings_log) { create(:lettings_log, :completed, startdate: Time.zone.local(2024, 5, 5), created_by: user) }
before do
stub_request(:get, /api\.os\.uk/)
.to_return(status: 200, body: { results: [{ DPA: { MATCH: 0.9, BUILDING_NAME: "result address line 1", POST_TOWN: "result town or city", POSTCODE: "AA1 1AA", UPRN: "12345" } }] }.to_json, headers: {})
end
it "allows searching for an address" do
visit("lettings-logs/#{id}/address-matcher")
fill_in("lettings-log-address-line1-input-field", with: "address")
fill_in("lettings-log-postcode-full-input-field", with: "A1 1AA")
click_button(text: "Search")
expect(page).to have_current_path("/lettings-logs/#{id}/uprn-selection")
end
it "allows searching for an address from check your answers page" do
visit("lettings-logs/#{id}/address-matcher?referrer=check_answers")
fill_in("lettings-log-address-line1-input-field", with: "address")
fill_in("lettings-log-postcode-full-input-field", with: "A1 1AA")
click_button(text: "Search")
expect(page).to have_current_path("/lettings-logs/#{id}/uprn-selection?referrer=check_answers")
choose("lettings-log-uprn-selection-12345-field", allow_label_click: true)
click_button(text: "Save changes")
expect(page).to have_current_path("/lettings-logs/#{id}/property-information/check-answers")
end
end
context "with a sales log" do
let(:sales_log) { create(:sales_log, :completed, saledate: Time.zone.local(2024, 5, 5), created_by: user) }
before do
stub_request(:get, /api\.os\.uk/)
.to_return(status: 200, body: { results: [{ DPA: { MATCH: 0.9, BUILDING_NAME: "result address line 1", POST_TOWN: "result town or city", POSTCODE: "AA1 1AA", UPRN: "12345" } }] }.to_json, headers: {})
end
it "allows searching for an address" do
visit("sales-logs/#{sales_log.id}/address-matcher")
fill_in("sales-log-address-line1-input-field", with: "address")
fill_in("sales-log-postcode-full-input-field", with: "A1 1AA")
click_button(text: "Search")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/uprn-selection")
end
it "allows searching for an address from check your answers page" do
visit("sales-logs/#{sales_log.id}/address-matcher?referrer=check_answers")
fill_in("sales-log-address-line1-input-field", with: "address")
fill_in("sales-log-postcode-full-input-field", with: "A1 1AA")
click_button(text: "Search")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/uprn-selection?referrer=check_answers")
choose("sales-log-uprn-selection-12345-field", allow_label_click: true)
click_button(text: "Save changes")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/property-information/check-answers")
end
end
end
end

Loading…
Cancel
Save