Browse Source

Merge pull request #118 from communitiesuk/formbuilder-fixes

Formbuilder fixes
pull/121/head
Paul Robert Lloyd 3 years ago committed by GitHub
parent
commit
3804aad4ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/application_controller.rb
  2. 2
      app/views/case_logs/bulk_upload.html.erb
  3. 13
      app/views/devise/confirmations/new.html.erb
  4. 4
      app/views/devise/confirmations/reset.html.erb
  5. 15
      app/views/devise/passwords/edit.html.erb
  6. 10
      app/views/devise/passwords/new.html.erb
  7. 20
      app/views/devise/registrations/edit.html.erb
  8. 30
      app/views/devise/registrations/new.html.erb
  9. 19
      app/views/devise/sessions/new.html.erb
  10. 12
      app/views/devise/unlocks/new.html.erb
  11. 2
      app/views/form/check_answers.html.erb
  12. 2
      app/views/form/page.html.erb
  13. 94
      app/views/users/account/index.html.erb
  14. 17
      app/views/users/account/personal_details.html.erb
  15. 4
      spec/features/form/helpers.rb
  16. 32
      spec/features/user_spec.rb

2
app/controllers/application_controller.rb

@ -1,4 +1,6 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
default_form_builder GOVUKDesignSystemFormBuilder::FormBuilder
def render_not_found_html def render_not_found_html
render file: Rails.root.join("public/404.html"), status: :not_found render file: Rails.root.join("public/404.html"), status: :not_found
end end

2
app/views/case_logs/bulk_upload.html.erb

@ -1,5 +1,5 @@
<div class="govuk-form-group"> <div class="govuk-form-group">
<%= 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_error_summary %>
<%= f.govuk_file_field :case_log_bulk_upload, <%= f.govuk_file_field :case_log_bulk_upload,
label: { text: "Bulk Upload", size: "l" }, label: { text: "Bulk Upload", size: "l" },

13
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| %> <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %> <%= render "devise/shared/error_messages", resource: resource %>
<div class="field"> <%= f.govuk_email_field :email,
<%= f.label :email %><br /> label: { text: "Email address" },
<%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> autocomplete: "email",
</div> value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email)
%>
<div class="actions"> <%= f.govuk_submit "Resend confirmation instructions" %>
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %> <% end %>
<%= render "devise/shared/links" %> <%= render "devise/shared/links" %>

4
app/views/devise/confirmations/reset.html.erb

@ -1,8 +1,8 @@
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"> Check your email</h1> <h1 class="govuk-heading-l">Check your email</h1>
<p class="govuk-body">We’ve sent a link to reset your password to <strong><%= @email %></strong>.</p> <p class="govuk-body">We’ve sent a link to reset your password to <strong><%= @email %></strong>.</p>
<p class="govuk-body">You’ll only this receive this link if your email address already exists in our system.</p> <p class="govuk-body">You’ll only this receive this link if your email address already exists in our system.</p>
<p class="govuk-body">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.</p> <p class="govuk-body">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.</p>
</div> </div>
</div> </div>

15
app/views/devise/passwords/edit.html.erb

@ -3,17 +3,16 @@
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Reset your password</h1> <h1 class="govuk-heading-l">Reset your password</h1>
<%= render "devise/shared/error_messages", resource: resource %> <%= render "devise/shared/error_messages", resource: resource %>
<%= f.hidden_field :reset_password_token %> <%= f.hidden_field :reset_password_token %>
<div class="govuk-form-group"> <%= f.govuk_password_field :password,
<%= f.label :password, "New password", class: "govuk-label" %> label: { text: "New password" },
<% if @minimum_password_length %> hint: @minimum_password_length ? { text: "Your password must be at least #{@minimum_password_length} characters and hard to guess." } : nil,
<div class="govuk-hint">Your password must be at least 8 characters and hard to guess.</div> autocomplete: "new-password"
<% end %> %>
<%= f.password_field :password, autofocus: true, autocomplete: "new-password", class: "govuk-input" %>
</div>
<%= f.submit "Reset password", class: "govuk-button" %> <%= f.govuk_submit "Reset password" %>
</div> </div>
</div> </div>
<% end %> <% end %>

10
app/views/devise/passwords/new.html.erb

@ -14,12 +14,12 @@
<p class="govuk-body">Enter the email address you used to create your account.</p> <p class="govuk-body">Enter the email address you used to create your account.</p>
<p class="govuk-body">We’ll email you a link to reset your password. This link will expire in 3 hours.</p> <p class="govuk-body">We’ll email you a link to reset your password. This link will expire in 3 hours.</p>
<div class="govuk-form-group"> <%= f.govuk_email_field :email,
<%= f.label :email, "Email address", class: "govuk-label" %> label: { text: "Email address" },
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: "govuk-input" %> autocomplete: "email"
</div> %>
<%= f.submit "Send email", class: "govuk-button" %> <%= f.govuk_submit "Send email" %>
</div> </div>
</div> </div>
<% end %> <% end %>

20
app/views/devise/registrations/edit.html.erb

@ -10,20 +10,16 @@
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Change your password</h1> <h1 class="govuk-heading-l">Change your password</h1>
<div class="govuk-form-group"> <%= f.govuk_password_field :current_password,
<%= f.label :current_password, class: "govuk-label" %> autocomplete: "current-password"
<%= f.password_field :current_password, autocomplete: "current-password", class: "govuk-input" %> %>
</div>
<div class="govuk-form-group"> <%= f.govuk_password_field :password,
<%= f.label :password, class: "govuk-label" %> hint: @minimum_password_length ? { text: "Your password must be at least #{@minimum_password_length} characters and hard to guess." } : nil,
<div id="undefined-hint" class="govuk-hint"> autocomplete: "new-password"
Your password must be at least 8 characters and hard to guess. %>
</div>
<%= f.password_field :password, autocomplete: "new-password", class: "govuk-input" %>
</div>
<%= f.submit "Update", class: "govuk-button" %> <%= f.govuk_submit "Update" %>
</div> </div>
</div> </div>
<% end %> <% end %>

30
app/views/devise/registrations/new.html.erb

@ -3,27 +3,21 @@
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %> <%= render "devise/shared/error_messages", resource: resource %>
<div class="field"> <%= f.govuk_email_field :email,
<%= f.label :email %><br /> label: { text: "Email address" },
<%= f.email_field :email, autofocus: true, autocomplete: "email" %> autocomplete: "email"
</div> %>
<div class="field"> <%= f.govuk_password_field :password,
<%= f.label :password %> hint: @minimum_password_length ? { text: "#{@minimum_password_length} characters minimum" } : nil,
<% if @minimum_password_length %> autocomplete: "new-password"
<em>(<%= @minimum_password_length %> characters minimum)</em> %>
<% end %><br />
<%= f.password_field :password, autocomplete: "new-password" %>
</div>
<div class="field"> <%= f.govuk_password_field :password_confirmation,
<%= f.label :password_confirmation %><br /> autocomplete: "new-password"
<%= f.password_field :password_confirmation, autocomplete: "new-password" %> %>
</div>
<div class="actions"> <%= f.govuk_submit "Sign up" %>
<%= f.submit "Sign up" %>
</div>
<% end %> <% end %>
<%= render "devise/shared/links" %> <%= render "devise/shared/links" %>

19
app/views/devise/sessions/new.html.erb

@ -2,18 +2,17 @@
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Sign in to your account to submit CORE data</h1> <h1 class="govuk-heading-l">Sign in to your account to submit CORE data</h1>
<div class="govuk-form-group">
<%= f.label :email, "Email address", class: "govuk-label" %>
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: "govuk-input" %>
</div>
<div class="govuk-form-group"> <%= f.govuk_email_field :email,
<%= f.label :password, class: "govuk-label" %> label: { text: "Email address" },
<%= f.password_field :password, autocomplete: "current-password", class: "govuk-input" %> autocomplete: "email"
</div> %>
<%= f.submit "Sign in", class: "govuk-button" %> <%= f.govuk_password_field :password,
autocomplete: "current-password"
%>
<%= f.govuk_submit "Sign in" %>
</div> </div>
</div> </div>
<% end %> <% end %>

12
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| %> <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %> <%= render "devise/shared/error_messages", resource: resource %>
<div class="field"> <%= f.govuk_email_field :email,
<%= f.label :email %><br /> label: { text: "Email address" },
<%= f.email_field :email, autofocus: true, autocomplete: "email" %> autocomplete: "email"
</div> %>
<div class="actions"> <%= f.govuk_submit "Resend unlock instructions" %>
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %> <% end %>
<%= render "devise/shared/links" %> <%= render "devise/shared/links" %>

2
app/views/form/check_answers.html.erb

@ -8,7 +8,7 @@
<%= render partial: 'form/check_answers_table', locals: { question: question, case_log: @case_log } %> <%= render partial: 'form/check_answers_table', locals: { question: question, case_log: @case_log } %>
<% end %> <% end %>
</dl> </dl>
<%= 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" %> <%= f.govuk_submit "Save and continue" %>
<% end %> <% end %>
</div> </div>

2
app/views/form/page.html.erb

@ -16,7 +16,7 @@
<%= page.header %> <%= page.header %>
</h1> </h1>
<% end %> <% 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 %> <%= f.govuk_error_summary %>
<% page.questions.map do |question| %> <% page.questions.map do |question| %>
<div id=<%= question.id + "_div " %><%= display_question_key_div(page, question) %> > <div id=<%= question.id + "_div " %><%= display_question_key_div(page, question) %> >

94
app/views/users/account/index.html.erb

@ -6,68 +6,36 @@
<h2 class="govuk-heading-m"> <h2 class="govuk-heading-m">
Personal details Personal details
</h2> </h2>
<dl class="govuk-summary-list"> <%= govuk_summary_list do |summary_list| %>
<div class="govuk-summary-list__row"> <%= summary_list.row do |row|
<dt class="govuk-summary-list__key"> row.key { 'Name' }
Name row.value { current_user.name }
</dt> row.action(visually_hidden_text: 'name', href: '/users/account/personal_details', html_attributes: { 'data-qa': 'change-name' })
<dd class="govuk-summary-list__value"> end %>
<%= current_user.name %>
</dd> <%= summary_list.row() do |row|
<dd class="govuk-summary-list__actions"> row.key { 'Email address' }
<a class="govuk-link" href="/users/account/personal_details" id="change-name"> row.value { current_user.email }
Change<span class="govuk-visually-hidden"> row.action(visually_hidden_text: 'email address', href: '/users/account/personal_details', html_attributes: { 'data-qa': 'change-email' })
name</span> end %>
</a>
</dd> <%= summary_list.row do |row|
</div> row.key { 'Password' }
<div class="govuk-summary-list__row"> row.value { '••••••••' }
<dt class="govuk-summary-list__key"> row.action(visually_hidden_text: 'password', href: edit_user_registration_path, html_attributes: { 'data-qa': 'change-password' })
Email address end %>
</dt>
<dd class="govuk-summary-list__value"> <%= summary_list.row do |row|
<%= current_user.email %> row.key { 'Organisation' }
</dd> row.value { current_user.organisation }
<dd class="govuk-summary-list__actions"> row.action()
<a class="govuk-link" href="/users/account/personal_details" id="change-email"> end %>
Change<span class="govuk-visually-hidden">
email address</span> <%= summary_list.row do |row|
</a> row.key { 'Role' }
</dd> row.value { current_user.role }
</div> row.action()
<div class="govuk-summary-list__row"> end %>
<dt class="govuk-summary-list__key"> <% end %>
Password
</dt>
<dd class="govuk-summary-list__value">
••••••••
</dd>
<dd class="govuk-summary-list__actions">
<%= govuk_link_to "Change", edit_user_registration_path, id: "change-password" %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Organisation
</dt>
<dd class="govuk-summary-list__value">
<%= current_user.organisation %>
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href=""></a>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Role
</dt>
<dd class="govuk-summary-list__value">
<%= current_user.role %>
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href=""></a>
</dd>
</div>
</dl>
</div> </div>
</div> </div>

17
app/views/users/account/personal_details.html.erb

@ -10,17 +10,16 @@
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Change your personal details</h1> <h1 class="govuk-heading-l">Change your personal details</h1>
<div class="govuk-form-group"> <%= f.govuk_text_field :name,
<%= f.label :name, class: "govuk-label" %> autocomplete: "name"
<%= f.text_field :name, autocomplete: "name", class: "govuk-input" %> %>
</div>
<div class="govuk-form-group"> <%= f.govuk_email_field :email,
<%= f.label :email, class: "govuk-label" %> label: { text: "Email address" },
<%= f.email_field :email, autocomplete: "email", class: "govuk-input" %> autocomplete: "email"
</div> %>
<%= f.submit "Save changes", class: "govuk-button" %> <%= f.govuk_submit "Save changes" %>
</div> </div>
</div> </div>
<% end %> <% end %>

4
spec/features/form/helpers.rb

@ -18,8 +18,8 @@ module Helpers
def sign_in(user) def sign_in(user)
visit("/case_logs") visit("/case_logs")
fill_in("user_email", with: user.email) fill_in("user[email]", with: user.email)
fill_in("user_password", with: user.password) fill_in("user[password]", with: user.password)
click_button("Sign in") click_button("Sign in")
end end
end end

32
spec/features/user_spec.rb

@ -9,8 +9,8 @@ RSpec.describe "User Features" do
it " is redirected to case logs after signing in" do it " is redirected to case logs after signing in" do
visit("/case_logs") visit("/case_logs")
fill_in("user_email", with: user.email) fill_in("user[email]", with: user.email)
fill_in("user_password", with: "pAssword1") fill_in("user[password]", with: "pAssword1")
click_button("Sign in") click_button("Sign in")
expect(page).to have_current_path("/case_logs") expect(page).to have_current_path("/case_logs")
end 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 it " is redirected to check your email page after submitting an email on the reset password page" do
visit("/users/password/new") visit("/users/password/new")
fill_in("user_email", with: user.email) fill_in("user[email]", with: user.email)
click_button("Send email") click_button("Send email")
expect(page).to have_content("Check your email") expect(page).to have_content("Check your email")
end end
it " is shown their email on the password reset confirmation page" do it " is shown their email on the password reset confirmation page" do
visit("/users/password/new") visit("/users/password/new")
fill_in("user_email", with: user.email) fill_in("user[email]", with: user.email)
click_button("Send email") click_button("Send email")
expect(page).to have_content(user.email) expect(page).to have_content(user.email)
end end
it " is shown the reset password confirmation page even if their email doesn't exist in the system" do it " is shown the reset password confirmation page even if their email doesn't exist in the system" do
visit("/users/password/new") visit("/users/password/new")
fill_in("user_email", with: "idontexist@example.com") fill_in("user[email]", with: "idontexist@example.com")
click_button("Send email") click_button("Send email")
expect(page).to have_current_path("/confirmations/reset?email=idontexist%40example.com") expect(page).to have_current_path("/confirmations/reset?email=idontexist%40example.com")
end end
it " is sent a reset password email" do it " is sent a reset password email" do
visit("/users/password/new") 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) expect { click_button("Send email") }.to change { ActionMailer::Base.deliveries.count }.by(1)
end end
it " is shown the password reset confirmation page and successful flash message shows" do it " is shown the password reset confirmation page and successful flash message shows" do
visit("/users/password/new") visit("/users/password/new")
fill_in("user_email", with: user.email) fill_in("user[email]", with: user.email)
click_button("Send email") click_button("Send email")
expect(page).to have_css ".govuk-notification-banner.govuk-notification-banner--success" expect(page).to have_css ".govuk-notification-banner.govuk-notification-banner--success"
end end
@ -68,8 +68,8 @@ RSpec.describe "User Features" do
visit("/") visit("/")
expect(page).to have_link("Case logs") expect(page).to have_link("Case logs")
click_link("Case logs") click_link("Case logs")
fill_in("user_email", with: user.email) fill_in("user[email]", with: user.email)
fill_in("user_password", with: "pAssword1") fill_in("user[password]", with: "pAssword1")
click_button("Sign in") click_button("Sign in")
expect(page).to have_current_path("/case_logs") expect(page).to have_current_path("/case_logs")
end end
@ -83,8 +83,8 @@ RSpec.describe "User Features" do
context "Your Account " do context "Your Account " do
before(:each) do before(:each) do
visit("/case_logs") visit("/case_logs")
fill_in("user_email", with: user.email) fill_in("user[email]", with: user.email)
fill_in("user_password", with: "pAssword1") fill_in("user[password]", with: "pAssword1")
click_button("Sign in") click_button("Sign in")
end end
@ -112,19 +112,19 @@ RSpec.describe "User Features" do
it "can navigate to change your password page from main account page" do it "can navigate to change your password page from main account page" do
visit("/users/account") visit("/users/account")
click_link("change-password") find('[data-qa="change-password"]').click
expect(page).to have_content("Change your password") expect(page).to have_content("Change your password")
fill_in("user_current_password", with: "pAssword1") fill_in("user[current_password]", with: "pAssword1")
fill_in("user_password", with: "Password123!") fill_in("user[password]", with: "Password123!")
click_button("Update") click_button("Update")
expect(page).to have_current_path("/users/account") expect(page).to have_current_path("/users/account")
end end
it "allow user to change name" do it "allow user to change name" do
visit("/users/account") visit("/users/account")
click_link("change-name") find('[data-qa="change-name"]').click
expect(page).to have_content("Change your personal details") 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") click_button("Save changes")
expect(page).to have_current_path("/users/account") expect(page).to have_current_path("/users/account")
expect(page).to have_content("Test New") expect(page).to have_content("Test New")

Loading…
Cancel
Save