From 8095b65497a8f0d4c62d25ceff9d670ddfddce7f Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Fri, 3 Dec 2021 11:22:03 +0000 Subject: [PATCH 1/3] Titles prefixed with error --- app/views/layouts/application.html.erb | 6 +++++- db/schema.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3273c8ca3..257ee4cc9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,7 +1,11 @@ - <%= browser_title(yield(:title)) %> + <% if @case_log.errors.present? %> + <%= browser_title("Error: #{yield(:title)}") %> + <% elsif %> + <%= browser_title(yield(:title)) %> + <% end %> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= tag :meta, name: 'viewport', content: 'width=device-width, initial-scale=1' %> diff --git a/db/schema.rb b/db/schema.rb index fe6ed0955..255b55aa4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -163,9 +163,9 @@ ActiveRecord::Schema.define(version: 2021_12_02_124802) do t.string "why_dont_you_know_la" t.integer "unitletas" t.integer "builtype" + t.datetime "property_void_date" t.bigint "owning_organisation_id" t.bigint "managing_organisation_id" - t.datetime "property_void_date" t.integer "renttype" t.integer "needstype" t.integer "lettype" From 04b4ca6e69f10cdb337b594bee44d5353f40f1a5 Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Fri, 3 Dec 2021 12:03:53 +0000 Subject: [PATCH 2/3] Spex for error title added --- app/views/layouts/application.html.erb | 8 ++++++-- spec/features/form/validations_spec.rb | 2 ++ spec/features/user_spec.rb | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 257ee4cc9..2a0a0bec3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,9 +1,13 @@ - <% if @case_log.errors.present? %> + <% if @resource.present? && @resource.errors.present? %> <%= browser_title("Error: #{yield(:title)}") %> - <% elsif %> + <% elsif @user.present? && @user.errors.present? %> + <%= browser_title("Error: #{yield(:title)}") %> + <% elsif @case_log.present? && @case_log.errors.present?%> + <%= browser_title("Error: #{yield(:title)}") %> + <% else %> <%= browser_title(yield(:title)) %> <% end %> <%= csrf_meta_tags %> 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 From 84d8d6ee95e98693568318145f4d5ad64713ba0f Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Mon, 6 Dec 2021 11:56:15 +0000 Subject: [PATCH 3/3] Error prefix code review changes --- app/helpers/application_helper.rb | 18 +++++++++++++++++- app/views/layouts/application.html.erb | 10 +--------- 2 files changed, 18 insertions(+), 10 deletions(-) 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/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2a0a0bec3..3273c8ca3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,15 +1,7 @@ - <% if @resource.present? && @resource.errors.present? %> - <%= browser_title("Error: #{yield(:title)}") %> - <% elsif @user.present? && @user.errors.present? %> - <%= browser_title("Error: #{yield(:title)}") %> - <% elsif @case_log.present? && @case_log.errors.present?%> - <%= browser_title("Error: #{yield(:title)}") %> - <% else %> - <%= browser_title(yield(:title)) %> - <% end %> + <%= browser_title(yield(:title)) %> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= tag :meta, name: 'viewport', content: 'width=device-width, initial-scale=1' %>