Skip to content

Commit

Permalink
Update the button text on place finders
Browse files Browse the repository at this point in the history
This an accessibility fix required by the DAC audit:
Update the button text from "Find" to "Find results near you"

For one place page, the Find a register office, the new button text
is "Find a register office".

The code uses the content of the publication title to determine that this is
the find a register service, rather than checking the base_path or content id, which would be
the usual way of doing it. This is intentional, because the button text only makes
sense on this page if the title matches. If in the future the title of this publication
changes, the button text will revert to the more generic "Find results near you". If we
were checking basepath and the page title changed, the button text would drift out of sync.
  • Loading branch information
hannako committed Oct 16, 2024
1 parent 84afd56 commit 4f39d23
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
8 changes: 7 additions & 1 deletion app/helpers/location_form_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
module LocationFormHelper
def button_text(publication_format = nil)
def button_text(publication_format = nil, publication_title = nil)
case publication_format
when "local_transaction", "licence"
I18n.t("formats.local_transaction.find_council")
when "place"
places_button_text(publication_title)
else
I18n.t("find")
end
end

def places_button_text(publication_title)
publication_title == "Find a register office" ? publication_title : I18n.t("formats.place.find_results")
end
end
3 changes: 2 additions & 1 deletion app/views/application/_location_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
form_method ||= "post"
margin_top ||= nil
publication_format ||= nil
publication_title ||= nil

css_classes = %w[postcode-search-form]
css_classes << "govuk-!-margin-top-#{margin_top}" if margin_top
Expand Down Expand Up @@ -73,7 +74,7 @@
} %>
<%= render "govuk_publishing_components/components/button",
text: button_text(publication_format),
text: button_text(publication_format, publication_title),
margin_bottom: true
%>
Expand Down
1 change: 1 addition & 0 deletions config/locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ cy:
change: Newid
postcode: Cod post
select_address: Dewiswch gyfeiriad
find_results:
simple_smart_answer:
change: Newid
next_step: Cam nesaf
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ en:
change: Change
postcode: Postcode
select_address: Select an address
find_results: Find results near you
simple_smart_answer:
change: Change
next_step: Next step
Expand Down
33 changes: 24 additions & 9 deletions spec/system/place_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.describe "Places" do
include GdsApi::TestHelpers::PlacesManager
include ContentStoreHelpers

before do
@payload = {
Expand Down Expand Up @@ -82,7 +83,7 @@

expect(page).to have_content("Enter your postcode to find a passport interview office near you.")
expect(page).to have_field("Enter a postcode")
expect(page).to have_css("button", text: "Find")
expect(page).to have_css("button", text: "Find results near you")
expect(page).not_to have_content("Please enter a valid full UK postcode.")

within(".further-information") do
Expand Down Expand Up @@ -112,7 +113,7 @@
stub_places_manager_has_places_for_postcode(@places, "find-passport-offices", "SW1A 1AA", Frontend::PLACES_MANAGER_QUERY_LIMIT, nil)
visit "/passport-interview-office"
fill_in("Enter a postcode", with: "SW1A 1AA")
click_on("Find")
click_on("Find results near you")
end

it "redirects to same page and not put postcode as URL query parameter" do
Expand Down Expand Up @@ -184,7 +185,7 @@
stub_places_manager_has_places_for_postcode(@places, "find-passport-offices", "SW1A 1AA", Frontend::PLACES_MANAGER_QUERY_LIMIT, nil)
visit "/passport-interview-office"
fill_in("Enter a postcode", with: "SW1A 1AA")
click_on("Find")
click_on("Find results near you")
end

it "does not error on a bad postcode" do
Expand All @@ -199,7 +200,7 @@
context "given an empty postcode" do
before do
visit "/passport-interview-office"
click_on("Find")
click_on("Find results near you")
end

it "displays error message" do
Expand Down Expand Up @@ -232,7 +233,7 @@
stub_places_manager_places_request("find-passport-offices", query_hash, return_data, 400)
visit "/passport-interview-office"
fill_in("Enter a postcode", with: "BAD POSTCODE")
click_on("Find")
click_on("Find results near you")
end

it "displays error message" do
Expand All @@ -247,7 +248,7 @@
within(".location-form") do
expect(page).to have_field("Enter a postcode")
expect(page).to have_field("postcode", with: "BAD POSTCODE")
expect(page).to have_css("button", text: "Find")
expect(page).to have_css("button", text: "Find results near you")
end
end
end
Expand All @@ -259,7 +260,7 @@
stub_places_manager_places_request("find-passport-offices", query_hash, return_data, 400)
visit "/passport-interview-office"
fill_in("Enter a postcode", with: "JE4 5TP")
click_on("Find")
click_on("Find results near you")
end

it "displays the 'no locations found' message" do
Expand All @@ -285,7 +286,7 @@
stub_places_manager_has_multiple_authorities_for_postcode(addresses, "find-passport-offices", "CH25 9BJ", Frontend::PLACES_MANAGER_QUERY_LIMIT)
visit "/passport-interview-office"
fill_in("Enter a postcode", with: "CH25 9BJ")
click_on("Find")
click_on("Find results near you")
end

it "displays the address chooser" do
Expand All @@ -299,11 +300,25 @@
stub_places_manager_places_request("find-passport-offices", query_hash, {}, 500)
visit "/passport-interview-office"
fill_in("Enter a postcode", with: "JE4 5TP")
click_on("Find")
click_on("Find results near you")
end

it "reraises as a 503" do
expect(page.status_code).to eq(503)
end
end

context "Find a register office page" do
before do
content_item = GovukSchemas::Example.find("place", example_name: "find-regional-passport-office")
content_item["title"] = "Find a register office"
content_item["base_path"] = "/register-offices"
stub_content_store_has_item("/register-offices", content_item)
end

it "uses the page title as the button text" do
visit "/register-offices"
expect(page).to have_css("button", text: "Find a register office")
end
end
end

0 comments on commit 4f39d23

Please sign in to comment.