diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..9ad342b8a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def browser_title(title) + [title, t("service_name"), "GOV.UK"].select(&:present?).join(" - ") + end end diff --git a/app/views/case_logs/edit.html.erb b/app/views/case_logs/edit.html.erb index 19b274488..d387aecea 100644 --- a/app/views/case_logs/edit.html.erb +++ b/app/views/case_logs/edit.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "Case log #{@case_log.id} – #{t('service_name')} - GOV.UK" %> +<% content_for :title, "Case log #{@case_log.id}" %> <%= turbo_frame_tag "case_log_form", target: "_top" do %>
diff --git a/app/views/case_logs/index.html.erb b/app/views/case_logs/index.html.erb index 639b5cc38..07855d687 100644 --- a/app/views/case_logs/index.html.erb +++ b/app/views/case_logs/index.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "Case logs – #{t('service_name')} - GOV.UK" %> +<% content_for :title, "Case logs" %>

Your logs

diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 74bd0bcbd..6e2630b8e 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "Sign in – #{t('service_name')} - GOV.UK" %> +<% content_for :title, "Sign in" %> <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index 2516a73d1..942184dd6 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "Check answers – #{t('service_name')} - GOV.UK" %> +<% content_for :title, "Check answers" %> <%= turbo_frame_tag "case_log_form", target: "_top" do %>
diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index e7fe0c7e2..72a825957 100644 --- a/app/views/form/page.html.erb +++ b/app/views/form/page.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "#{subsection} – #{t('service_name')} - GOV.UK" %> +<% content_for :title, subsection %> <% content_for :before_content do %> <%= govuk_back_link( diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ce2ec84db..384d9cf0b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,7 +1,7 @@ - <%= yield(:title).present? ? yield(:title) : t('service_name') %> + <%= browser_title(yield(:title)) %> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= tag :meta, name: 'viewport', content: 'width=device-width, initial-scale=1' %> diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index d9cac8d2a..d554e6596 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "Your organisation (Details) – #{t('service_name')} - GOV.UK" %> +<% content_for :title, "Your organisation (Details)" %> <% content_for :tab_title do %> <%= "Details" %> <% end %> diff --git a/app/views/organisations/users.html.erb b/app/views/organisations/users.html.erb index dbf53b484..d088445d1 100644 --- a/app/views/organisations/users.html.erb +++ b/app/views/organisations/users.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "Your organisation (Users) – #{t('service_name')} - GOV.UK" %> +<% content_for :title, "Your organisation (Users)" %> <% content_for :tab_title do %> <%= "Users" %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index e90d35cdc..7b2dae5c2 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "Your account – #{t('service_name')} - GOV.UK" %> +<% content_for :title, "Your account" %>

diff --git a/spec/helpers/application_helper.rb b/spec/helpers/application_helper.rb new file mode 100644 index 000000000..3815474ad --- /dev/null +++ b/spec/helpers/application_helper.rb @@ -0,0 +1,20 @@ +require "rails_helper" + +RSpec.describe ApplicationHelper do + form_handler = FormHandler.instance + let(:form) { form_handler.get_form("test_form") } + let(:subsection) { form.get_subsection("household_characteristics") } + let(:case_log) { FactoryBot.build(:case_log, :in_progress) } + + describe "browser_title" do + it "returns correct browser title when title is given" do + expect(browser_title("title")) + .to eq("title - #{t('service_name')} - GOV.UK") + end + + it "returns correct browser title when title is not given" do + expect(browser_title(nil)) + .to eq("#{t('service_name')} - GOV.UK") + end + end +end