Refactor account form to use bootstrap

There's further refactoring that could be done, but this is sufficient for now.
This commit is contained in:
Andy Allan 2021-01-27 15:36:59 +00:00
parent f737d2d34a
commit a7d959e588
3 changed files with 97 additions and 175 deletions

View file

@ -958,9 +958,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
get user_account_path(user)
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.standard-form-row > div#user_description_container > div#user_description_content > textarea#user_description", user.description
assert_select "form#accountForm > div.form-group > div#user_description_container > div#user_description_content > textarea#user_description", user.description
# Changing to a invalid editor should fail
user.preferred_editor = "unknown"
@ -968,8 +967,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_template :account
assert_select ".notice", false
assert_select "div#errorExplanation"
assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected]", false
assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false
# Changing to a valid editor should work
user.preferred_editor = "id"
@ -979,9 +977,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
get user_account_path(user)
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected][value=?]", "id"
assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected][value=?]", "id"
# Changing to the default editor should work
user.preferred_editor = "default"
@ -991,9 +988,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
get user_account_path(user)
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected]", false
assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false
# Changing to an uploaded image should work
image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
@ -1003,9 +999,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
get user_account_path(user)
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked][value=?]", "keep"
assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
# Changing to a gravatar image should work
post user_account_path(user), :params => { :avatar_action => "gravatar", :user => user.attributes }
@ -1014,9 +1009,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
get user_account_path(user)
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked][value=?]", "gravatar"
assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
# Removing the image should work
post user_account_path(user), :params => { :avatar_action => "delete", :user => user.attributes }
@ -1025,9 +1019,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
get user_account_path(user)
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked]", false
assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked]", false
assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked]", false
# Adding external authentication should redirect to the auth provider
post user_account_path(user), :params => { :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }
@ -1040,8 +1034,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_template :account
assert_select ".notice", false
assert_select "div#errorExplanation"
assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name"
# Changing name to one that exists should fail, regardless of case
new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name.upcase)
@ -1049,8 +1042,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_template :account
assert_select ".notice", false
assert_select "div#errorExplanation"
assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name"
# Changing name to one that doesn't exist should work
new_attributes = user.attributes.dup.merge(:display_name => "new tester")
@ -1060,9 +1052,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
get user_account_path(:display_name => "new tester")
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.standard-form-row > input#user_display_name[value=?]", "new tester"
assert_select "form#accountForm > div.form-group > input#user_display_name[value=?]", "new tester"
# Record the change of name
user.display_name = "new tester"
@ -1077,8 +1068,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_template :account
assert_select ".notice", false
assert_select "div#errorExplanation"
assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_new_email"
assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email"
# Changing email to one that exists should fail, regardless of case
user.new_email = create(:user).email.upcase
@ -1090,8 +1080,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_template :account
assert_select ".notice", false
assert_select "div#errorExplanation"
assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_new_email"
assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email"
# Changing email to one that doesn't exist should work
user.new_email = "new_tester@example.com"
@ -1105,9 +1094,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
get user_account_path(user)
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.standard-form-row > input#user_new_email[value=?]", user.new_email
assert_select "form#accountForm > div.form-group > input#user_new_email[value=?]", user.new_email
email = ActionMailer::Base.deliveries.first
assert_equal 1, email.to.count
assert_equal user.new_email, email.to.first