diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9ad342b8a..af51a93e7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,21 @@ module ApplicationHelper def browser_title(title) - [title, t("service_name"), "GOV.UK"].select(&:present?).join(" - ") + if user_log_errors || case_log_errors || resource_errors + ["Error", title, t("service_name"), "GOV.UK"].select(&:present?).join(" - ") + else + [title, t("service_name"), "GOV.UK"].select(&:present?).join(" - ") + end + end + + def user_log_errors + @user.present? && @user.errors.present? + end + + def case_log_errors + @case_log.present? && @case_log.errors.present? + end + + def resource_errors + @resource.present? && @resource.errors.present? end end diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index 5f39d92d7..9f7a1c415 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -33,6 +33,7 @@ RSpec.describe "validations" do expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#case-log-age1-error") expect(page).to have_selector("#case-log-age1-field-error") + expect(page).to have_title('Error') end it " of greater than 120 it shows validation" do @@ -41,6 +42,7 @@ RSpec.describe "validations" do expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#case-log-age1-error") expect(page).to have_selector("#case-log-age1-field-error") + expect(page).to have_title('Error') end end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 9f2eaf9b2..25bfa6d85 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -34,6 +34,7 @@ RSpec.describe "User Features" do click_button("Send email") expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#user-email-field-error") + expect(page).to have_title('Error') end it " is shown an error message if they submit an invalid email address" do @@ -42,6 +43,7 @@ RSpec.describe "User Features" do click_button("Send email") expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#user-email-field-error") + expect(page).to have_title('Error') end it " is redirected to check your email page after submitting an email on the reset password page" do @@ -109,6 +111,7 @@ RSpec.describe "User Features" do click_button("Sign in") expect(page).to have_selector("#error-summary-title") expect(page).to have_no_css(".govuk-notification-banner.govuk-notification-banner--success") + expect(page).to have_title('Error') end it "show specific field error messages if a field was omitted" do @@ -117,6 +120,7 @@ RSpec.describe "User Features" do expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#user-email-field-error") expect(page).to have_selector("#user-password-field-error") + expect(page).to have_title('Error') end it "show specific field error messages if an invalid email address is entered" do @@ -126,6 +130,7 @@ RSpec.describe "User Features" do expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#user-email-field-error") expect(page).to have_content(/Enter an email address in the correct format, like name@example.com/) + expect(page).to have_title('Error') end end @@ -180,6 +185,7 @@ RSpec.describe "User Features" do expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#user-email-field-error") expect(page).to have_content(/Enter an email address/) + expect(page).to have_title('Error') end it "validates email" do @@ -190,6 +196,7 @@ RSpec.describe "User Features" do expect(page).to have_selector("#error-summary-title") expect(page).to have_selector("#user-email-field-error") expect(page).to have_content(/Enter an email address in the correct format, like name@example.com/) + expect(page).to have_title('Error') end end end