diff options
Diffstat (limited to 'spec/features/profiles/user_edit_profile_spec.rb')
-rw-r--r-- | spec/features/profiles/user_edit_profile_spec.rb | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/spec/features/profiles/user_edit_profile_spec.rb b/spec/features/profiles/user_edit_profile_spec.rb index af085b63155..026da5814e3 100644 --- a/spec/features/profiles/user_edit_profile_spec.rb +++ b/spec/features/profiles/user_edit_profile_spec.rb @@ -19,6 +19,17 @@ RSpec.describe 'User edit profile' do wait_for_requests if respond_to?(:wait_for_requests) end + def update_user_email + fill_in 'user_email', with: 'new-email@example.com' + click_button 'Update profile settings' + end + + def confirm_password(password) + fill_in 'password-confirmation', with: password + click_button 'Confirm password' + wait_for_requests if respond_to?(:wait_for_requests) + end + def visit_user visit user_path(user) wait_for_requests @@ -88,16 +99,42 @@ RSpec.describe 'User edit profile' do expect(page).to have_content('Website url is not a valid URL') end - describe 'when I change my email' do + describe 'when I change my email', :js do before do user.send_reset_password_instructions end + it 'will prompt to confirm my password' do + expect(user.reset_password_token?).to be true + + update_user_email + + expect(page).to have_selector('[data-testid="password-prompt-modal"]') + end + + context 'when prompted to confirm password' do + before do + update_user_email + end + + it 'with the correct password successfully updates' do + confirm_password(user.password) + + expect(page).to have_text("Profile was successfully updated") + end + + it 'with the incorrect password fails to update' do + confirm_password("Fake password") + + expect(page).to have_text("Invalid password") + end + end + it 'clears the reset password token' do expect(user.reset_password_token?).to be true - fill_in 'user_email', with: 'new-email@example.com' - submit_settings + update_user_email + confirm_password(user.password) user.reload expect(user.confirmation_token).not_to be_nil @@ -524,14 +561,11 @@ RSpec.describe 'User edit profile' do page.find("a", text: "Nuku'alofa").click - tz = page.find('.user-time-preferences #user_timezone', visible: false) - - expect(tz.value).to eq('Pacific/Tongatapu') + expect(page).to have_field(:user_timezone, with: 'Pacific/Tongatapu', type: :hidden) end - it 'timezone defaults to servers default' do - timezone_name = Time.zone.tzinfo.name - expect(page.find('.user-time-preferences #user_timezone', visible: false).value).to eq(timezone_name) + it 'timezone defaults to empty' do + expect(page).to have_field(:user_timezone, with: '', type: :hidden) end end end |