From 4f39d235aff610fa26088c489a2979f77d1ec904 Mon Sep 17 00:00:00 2001 From: Jessica Jones Date: Wed, 16 Oct 2024 12:02:45 +0100 Subject: [PATCH] Update the button text on place finders 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. --- app/helpers/location_form_helper.rb | 8 ++++- app/views/application/_location_form.html.erb | 3 +- config/locales/cy.yml | 1 + config/locales/en.yml | 1 + spec/system/place_spec.rb | 33 ++++++++++++++----- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/helpers/location_form_helper.rb b/app/helpers/location_form_helper.rb index ee8cef3304..a1ae3a13bb 100644 --- a/app/helpers/location_form_helper.rb +++ b/app/helpers/location_form_helper.rb @@ -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 diff --git a/app/views/application/_location_form.html.erb b/app/views/application/_location_form.html.erb index d67689f547..3b2516047f 100644 --- a/app/views/application/_location_form.html.erb +++ b/app/views/application/_location_form.html.erb @@ -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 @@ -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 %> diff --git a/config/locales/cy.yml b/config/locales/cy.yml index 21cf44fa70..57f4f92ef3 100644 --- a/config/locales/cy.yml +++ b/config/locales/cy.yml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 4def9e9ece..625558750d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/spec/system/place_spec.rb b/spec/system/place_spec.rb index 282a7e2eac..1649e9db24 100644 --- a/spec/system/place_spec.rb +++ b/spec/system/place_spec.rb @@ -2,6 +2,7 @@ RSpec.describe "Places" do include GdsApi::TestHelpers::PlacesManager + include ContentStoreHelpers before do @payload = { @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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