From b07de948593556e71380ee223762b005d739e0c9 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Mon, 29 Nov 2021 17:59:20 +0000 Subject: [PATCH 1/3] Make GOVUKDesignSystemFormBuilder the default form builder --- app/controllers/application_controller.rb | 2 ++ app/views/case_logs/bulk_upload.html.erb | 2 +- app/views/form/check_answers.html.erb | 2 +- app/views/form/page.html.erb | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bac7edc5a..c125850fc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,6 @@ class ApplicationController < ActionController::Base + default_form_builder GOVUKDesignSystemFormBuilder::FormBuilder + def render_not_found_html render file: Rails.root.join("public/404.html"), status: :not_found end diff --git a/app/views/case_logs/bulk_upload.html.erb b/app/views/case_logs/bulk_upload.html.erb index 02cb109df..86416b4d1 100644 --- a/app/views/case_logs/bulk_upload.html.erb +++ b/app/views/case_logs/bulk_upload.html.erb @@ -1,5 +1,5 @@
- <%= form_for @bulk_upload, url: bulk_upload_case_logs_path, method: "post", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= form_for @bulk_upload, url: bulk_upload_case_logs_path, method: "post" do |f| %> <%= f.govuk_error_summary %> <%= f.govuk_file_field :case_log_bulk_upload, label: { text: "Bulk Upload", size: "l" }, diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index 447732748..d2a2551d4 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -8,7 +8,7 @@ <%= render partial: 'form/check_answers_table', locals: { question: question, case_log: @case_log } %> <% end %> - <%= form_with model: @case_log, method: "get", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= form_with model: @case_log, method: "get" do |f| %> <%= f.govuk_submit "Save and continue" %> <% end %>
diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index 744dfa503..d3c4dbc29 100644 --- a/app/views/form/page.html.erb +++ b/app/views/form/page.html.erb @@ -16,7 +16,7 @@ <%= page.header %> <% end %> - <%= form_with model: @case_log, url: form_case_log_path(@case_log), method: "post", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= form_with model: @case_log, url: form_case_log_path(@case_log), method: "post" do |f| %> <%= f.govuk_error_summary %> <% page.questions.map do |question| %>
<%= display_question_key_div(page, question) %> > From ccbb942e2389535d7c52b4de8f5163557dca7425 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Mon, 29 Nov 2021 19:42:17 +0000 Subject: [PATCH 2/3] Use GOVUKDesignSystemFormBuilder components for Devise forms --- app/views/devise/confirmations/new.html.erb | 13 ++++---- app/views/devise/confirmations/reset.html.erb | 4 +-- app/views/devise/passwords/edit.html.erb | 15 +++++----- app/views/devise/passwords/new.html.erb | 10 +++---- app/views/devise/registrations/edit.html.erb | 20 +++++-------- app/views/devise/registrations/new.html.erb | 30 ++++++++----------- app/views/devise/sessions/new.html.erb | 19 ++++++------ app/views/devise/unlocks/new.html.erb | 12 ++++---- .../users/account/personal_details.html.erb | 17 +++++------ spec/features/form/helpers.rb | 4 +-- spec/features/user_spec.rb | 28 ++++++++--------- 11 files changed, 78 insertions(+), 94 deletions(-) diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index b12dd0cbe..8fec1b4ff 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -3,14 +3,13 @@ <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> -
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> -
+ <%= f.govuk_email_field :email, + label: { text: "Email address" }, + autocomplete: "email", + value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) + %> -
- <%= f.submit "Resend confirmation instructions" %> -
+ <%= f.govuk_submit "Resend confirmation instructions" %> <% end %> <%= render "devise/shared/links" %> diff --git a/app/views/devise/confirmations/reset.html.erb b/app/views/devise/confirmations/reset.html.erb index 2932d21bd..6ad58fa3c 100644 --- a/app/views/devise/confirmations/reset.html.erb +++ b/app/views/devise/confirmations/reset.html.erb @@ -1,8 +1,8 @@
-

Check your email

+

Check your email

We’ve sent a link to reset your password to <%= @email %>.

You’ll only this receive this link if your email address already exists in our system.

If you don’t receive the email within 5 minutes, check your spam or junk folders. Try again if you still haven’t received the email.

-
\ No newline at end of file +
diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index 0b2bc2067..be85834c2 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -3,17 +3,16 @@

Reset your password

<%= render "devise/shared/error_messages", resource: resource %> + <%= f.hidden_field :reset_password_token %> -
- <%= f.label :password, "New password", class: "govuk-label" %> - <% if @minimum_password_length %> -
Your password must be at least 8 characters and hard to guess.
- <% end %> - <%= f.password_field :password, autofocus: true, autocomplete: "new-password", class: "govuk-input" %> -
+ <%= f.govuk_password_field :password, + label: { text: "New password" }, + hint: @minimum_password_length ? { text: "Your password must be at least #{@minimum_password_length} characters and hard to guess." } : nil, + autocomplete: "new-password" + %> - <%= f.submit "Reset password", class: "govuk-button" %> + <%= f.govuk_submit "Reset password" %>
<% end %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index 8422e3349..197c05574 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -14,12 +14,12 @@

Enter the email address you used to create your account.

We’ll email you a link to reset your password. This link will expire in 3 hours.

-
- <%= f.label :email, "Email address", class: "govuk-label" %> - <%= f.email_field :email, autofocus: true, autocomplete: "email", class: "govuk-input" %> -
+ <%= f.govuk_email_field :email, + label: { text: "Email address" }, + autocomplete: "email" + %> - <%= f.submit "Send email", class: "govuk-button" %> + <%= f.govuk_submit "Send email" %> <% end %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 48654e239..3aff3f6ea 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -10,20 +10,16 @@

Change your password

-
- <%= f.label :current_password, class: "govuk-label" %> - <%= f.password_field :current_password, autocomplete: "current-password", class: "govuk-input" %> -
+ <%= f.govuk_password_field :current_password, + autocomplete: "current-password" + %> -
- <%= f.label :password, class: "govuk-label" %> -
- Your password must be at least 8 characters and hard to guess. -
- <%= f.password_field :password, autocomplete: "new-password", class: "govuk-input" %> -
+ <%= f.govuk_password_field :password, + hint: @minimum_password_length ? { text: "Your password must be at least #{@minimum_password_length} characters and hard to guess." } : nil, + autocomplete: "new-password" + %> - <%= f.submit "Update", class: "govuk-button" %> + <%= f.govuk_submit "Update" %>
<% end %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index d655b66f6..ec331e9df 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -3,27 +3,21 @@ <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> -
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true, autocomplete: "email" %> -
+ <%= f.govuk_email_field :email, + label: { text: "Email address" }, + autocomplete: "email" + %> -
- <%= f.label :password %> - <% if @minimum_password_length %> - (<%= @minimum_password_length %> characters minimum) - <% end %>
- <%= f.password_field :password, autocomplete: "new-password" %> -
+ <%= f.govuk_password_field :password, + hint: @minimum_password_length ? { text: "#{@minimum_password_length} characters minimum" } : nil, + autocomplete: "new-password" + %> -
- <%= f.label :password_confirmation %>
- <%= f.password_field :password_confirmation, autocomplete: "new-password" %> -
+ <%= f.govuk_password_field :password_confirmation, + autocomplete: "new-password" + %> -
- <%= f.submit "Sign up" %> -
+ <%= f.govuk_submit "Sign up" %> <% end %> <%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 940ccf9d1..5ad69b2fe 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -2,18 +2,17 @@

Sign in to your account to submit CORE data

- -
- <%= f.label :email, "Email address", class: "govuk-label" %> - <%= f.email_field :email, autofocus: true, autocomplete: "email", class: "govuk-input" %> -
-
- <%= f.label :password, class: "govuk-label" %> - <%= f.password_field :password, autocomplete: "current-password", class: "govuk-input" %> -
+ <%= f.govuk_email_field :email, + label: { text: "Email address" }, + autocomplete: "email" + %> - <%= f.submit "Sign in", class: "govuk-button" %> + <%= f.govuk_password_field :password, + autocomplete: "current-password" + %> + + <%= f.govuk_submit "Sign in" %>
<% end %> diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb index ffc34de8d..2454c692a 100644 --- a/app/views/devise/unlocks/new.html.erb +++ b/app/views/devise/unlocks/new.html.erb @@ -3,14 +3,12 @@ <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> -
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true, autocomplete: "email" %> -
+ <%= f.govuk_email_field :email, + label: { text: "Email address" }, + autocomplete: "email" + %> -
- <%= f.submit "Resend unlock instructions" %> -
+ <%= f.govuk_submit "Resend unlock instructions" %> <% end %> <%= render "devise/shared/links" %> diff --git a/app/views/users/account/personal_details.html.erb b/app/views/users/account/personal_details.html.erb index 801575821..0db97f6b7 100644 --- a/app/views/users/account/personal_details.html.erb +++ b/app/views/users/account/personal_details.html.erb @@ -10,17 +10,16 @@

Change your personal details

-
- <%= f.label :name, class: "govuk-label" %> - <%= f.text_field :name, autocomplete: "name", class: "govuk-input" %> -
+ <%= f.govuk_text_field :name, + autocomplete: "name" + %> -
- <%= f.label :email, class: "govuk-label" %> - <%= f.email_field :email, autocomplete: "email", class: "govuk-input" %> -
+ <%= f.govuk_email_field :email, + label: { text: "Email address" }, + autocomplete: "email" + %> - <%= f.submit "Save changes", class: "govuk-button" %> + <%= f.govuk_submit "Save changes" %>
<% end %> diff --git a/spec/features/form/helpers.rb b/spec/features/form/helpers.rb index e0c1631b4..bec302881 100644 --- a/spec/features/form/helpers.rb +++ b/spec/features/form/helpers.rb @@ -18,8 +18,8 @@ module Helpers def sign_in(user) visit("/case_logs") - fill_in("user_email", with: user.email) - fill_in("user_password", with: user.password) + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: user.password) click_button("Sign in") end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 8aa6e25c4..5dcabcf7d 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -9,8 +9,8 @@ RSpec.describe "User Features" do it " is redirected to case logs after signing in" do visit("/case_logs") - fill_in("user_email", with: user.email) - fill_in("user_password", with: "pAssword1") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: "pAssword1") click_button("Sign in") expect(page).to have_current_path("/case_logs") end @@ -25,34 +25,34 @@ RSpec.describe "User Features" do it " is redirected to check your email page after submitting an email on the reset password page" do visit("/users/password/new") - fill_in("user_email", with: user.email) + fill_in("user[email]", with: user.email) click_button("Send email") expect(page).to have_content("Check your email") end it " is shown their email on the password reset confirmation page" do visit("/users/password/new") - fill_in("user_email", with: user.email) + fill_in("user[email]", with: user.email) click_button("Send email") expect(page).to have_content(user.email) end it " is shown the reset password confirmation page even if their email doesn't exist in the system" do visit("/users/password/new") - fill_in("user_email", with: "idontexist@example.com") + fill_in("user[email]", with: "idontexist@example.com") click_button("Send email") expect(page).to have_current_path("/confirmations/reset?email=idontexist%40example.com") end it " is sent a reset password email" do visit("/users/password/new") - fill_in("user_email", with: user.email) + fill_in("user[email]", with: user.email) expect { click_button("Send email") }.to change { ActionMailer::Base.deliveries.count }.by(1) end it " is shown the password reset confirmation page and successful flash message shows" do visit("/users/password/new") - fill_in("user_email", with: user.email) + fill_in("user[email]", with: user.email) click_button("Send email") expect(page).to have_css ".govuk-notification-banner.govuk-notification-banner--success" end @@ -68,8 +68,8 @@ RSpec.describe "User Features" do visit("/") expect(page).to have_link("Case logs") click_link("Case logs") - fill_in("user_email", with: user.email) - fill_in("user_password", with: "pAssword1") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: "pAssword1") click_button("Sign in") expect(page).to have_current_path("/case_logs") end @@ -83,8 +83,8 @@ RSpec.describe "User Features" do context "Your Account " do before(:each) do visit("/case_logs") - fill_in("user_email", with: user.email) - fill_in("user_password", with: "pAssword1") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: "pAssword1") click_button("Sign in") end @@ -114,8 +114,8 @@ RSpec.describe "User Features" do visit("/users/account") click_link("change-password") expect(page).to have_content("Change your password") - fill_in("user_current_password", with: "pAssword1") - fill_in("user_password", with: "Password123!") + fill_in("user[current_password]", with: "pAssword1") + fill_in("user[password]", with: "Password123!") click_button("Update") expect(page).to have_current_path("/users/account") end @@ -124,7 +124,7 @@ RSpec.describe "User Features" do visit("/users/account") click_link("change-name") expect(page).to have_content("Change your personal details") - fill_in("user_name", with: "Test New") + fill_in("user[name]", with: "Test New") click_button("Save changes") expect(page).to have_current_path("/users/account") expect(page).to have_content("Test New") From 6f3cc781ef675e905f7e53ab1d1df3b613da0276 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Tue, 30 Nov 2021 11:18:27 +0000 Subject: [PATCH 3/3] Use govuk_summary_list helper for personal details summary --- app/views/users/account/index.html.erb | 94 +++++++++----------------- spec/features/user_spec.rb | 4 +- 2 files changed, 33 insertions(+), 65 deletions(-) diff --git a/app/views/users/account/index.html.erb b/app/views/users/account/index.html.erb index 83b5d76fd..3dde070eb 100644 --- a/app/views/users/account/index.html.erb +++ b/app/views/users/account/index.html.erb @@ -6,68 +6,36 @@

Personal details

-
-
-
- Name -
-
- <%= current_user.name %> -
-
- - Change - name - -
-
-
-
- Email address -
-
- <%= current_user.email %> -
-
- - Change - email address - -
-
-
-
- Password -
-
- •••••••• -
-
- <%= govuk_link_to "Change", edit_user_registration_path, id: "change-password" %> -
-
-
-
- Organisation -
-
- <%= current_user.organisation %> -
-
- -
-
-
-
- Role -
-
- <%= current_user.role %> -
-
- -
-
-
+ <%= govuk_summary_list do |summary_list| %> + <%= summary_list.row do |row| + row.key { 'Name' } + row.value { current_user.name } + row.action(visually_hidden_text: 'name', href: '/users/account/personal_details', html_attributes: { 'data-qa': 'change-name' }) + end %> + + <%= summary_list.row() do |row| + row.key { 'Email address' } + row.value { current_user.email } + row.action(visually_hidden_text: 'email address', href: '/users/account/personal_details', html_attributes: { 'data-qa': 'change-email' }) + end %> + + <%= summary_list.row do |row| + row.key { 'Password' } + row.value { '••••••••' } + row.action(visually_hidden_text: 'password', href: edit_user_registration_path, html_attributes: { 'data-qa': 'change-password' }) + end %> + + <%= summary_list.row do |row| + row.key { 'Organisation' } + row.value { current_user.organisation } + row.action() + end %> + + <%= summary_list.row do |row| + row.key { 'Role' } + row.value { current_user.role } + row.action() + end %> + <% end %> diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 5dcabcf7d..e41551845 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -112,7 +112,7 @@ RSpec.describe "User Features" do it "can navigate to change your password page from main account page" do visit("/users/account") - click_link("change-password") + find('[data-qa="change-password"]').click expect(page).to have_content("Change your password") fill_in("user[current_password]", with: "pAssword1") fill_in("user[password]", with: "Password123!") @@ -122,7 +122,7 @@ RSpec.describe "User Features" do it "allow user to change name" do visit("/users/account") - click_link("change-name") + find('[data-qa="change-name"]').click expect(page).to have_content("Change your personal details") fill_in("user[name]", with: "Test New") click_button("Save changes")