diff options
Diffstat (limited to 'spec/features/users/signup_spec.rb')
-rw-r--r-- | spec/features/users/signup_spec.rb | 214 |
1 files changed, 33 insertions, 181 deletions
diff --git a/spec/features/users/signup_spec.rb b/spec/features/users/signup_spec.rb index 5fd0e677cd0..c59121626f0 100644 --- a/spec/features/users/signup_spec.rb +++ b/spec/features/users/signup_spec.rb @@ -7,6 +7,14 @@ RSpec.shared_examples 'Signup' do let(:new_user) { build_stubbed(:user) } + def fill_in_signup_form + fill_in 'new_user_username', with: new_user.username + fill_in 'new_user_email', with: new_user.email + fill_in 'new_user_first_name', with: new_user.first_name + fill_in 'new_user_last_name', with: new_user.last_name + fill_in 'new_user_password', with: new_user.password + end + describe 'username validation', :js do before do visit new_user_registration_path @@ -144,20 +152,9 @@ RSpec.shared_examples 'Signup' do it 'creates the user account and sends a confirmation email' do visit new_user_registration_path - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password + fill_in_signup_form expect { click_button 'Register' }.to change { User.count }.by(1) - expect(current_path).to eq users_almost_there_path expect(page).to have_content('Please check your email to confirm your account') end @@ -171,46 +168,14 @@ RSpec.shared_examples 'Signup' do it 'creates the user account and sends a confirmation email' do visit new_user_registration_path - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password + fill_in_signup_form expect { click_button 'Register' }.to change { User.count }.by(1) - expect(current_path).to eq users_sign_up_welcome_path end end end - context "when sigining up with different cased emails" do - it "creates the user successfully" do - visit new_user_registration_path - - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password - click_button "Register" - - expect(current_path).to eq users_sign_up_welcome_path - end - end - context "when not sending confirmation email" do before do stub_application_setting(send_user_confirmation_email: false) @@ -219,17 +184,7 @@ RSpec.shared_examples 'Signup' do it 'creates the user account and goes to dashboard' do visit new_user_registration_path - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password + fill_in_signup_form click_button "Register" expect(current_path).to eq users_sign_up_welcome_path @@ -239,20 +194,10 @@ RSpec.shared_examples 'Signup' do context 'with errors' do it "displays the errors" do - existing_user = create(:user) - + create(:user, email: new_user.email) visit new_user_registration_path - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: existing_user.email - fill_in 'new_user_password', with: new_user.password + fill_in_signup_form click_button "Register" expect(current_path).to eq user_registration_path @@ -261,20 +206,10 @@ RSpec.shared_examples 'Signup' do end it 'does not redisplay the password' do - existing_user = create(:user) - + create(:user, email: new_user.email) visit new_user_registration_path - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: existing_user.email - fill_in 'new_user_password', with: new_user.password + fill_in_signup_form click_button "Register" expect(current_path).to eq user_registration_path @@ -287,45 +222,14 @@ RSpec.shared_examples 'Signup' do enforce_terms end - it 'requires the user to check the checkbox' do + it 'renders text that the user confirms terms by clicking register' do visit new_user_registration_path - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password + expect(page).to have_content(/By clicking Register, I agree that I have read and accepted the Terms of Use and Privacy Policy/) + fill_in_signup_form click_button 'Register' - expect(current_path).to eq new_user_session_path - expect(page).to have_content(/you must accept our terms of service/i) - end - - it 'asks the user to accept terms before going to the dashboard' do - visit new_user_registration_path - - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password - check :terms_opt_in - - click_button "Register" - expect(current_path).to eq users_sign_up_welcome_path end end @@ -353,17 +257,7 @@ RSpec.shared_examples 'Signup' do it 'prevents from signing up' do visit new_user_registration_path - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password + fill_in_signup_form expect { click_button 'Register' }.not_to change { User.count } expect(page).to have_content('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.') @@ -374,17 +268,7 @@ RSpec.shared_examples 'Signup' do it 'prevents from signing up' do visit new_user_registration_path - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password + fill_in_signup_form expect { click_button 'Register' }.not_to change { User.count } expect(page).to have_content('That was a bit too quick! Please resubmit.') @@ -393,36 +277,27 @@ RSpec.shared_examples 'Signup' do end it 'redirects to step 2 of the signup process, sets the role and redirects back' do - new_user = build_stubbed(:user) visit new_user_registration_path - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - - if Gitlab::Experimentation.enabled?(:signup_flow) - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - else - fill_in 'new_user_name', with: new_user.name - end - - fill_in 'new_user_password', with: new_user.password + fill_in_signup_form click_button 'Register' + visit new_project_path expect(page).to have_current_path(users_sign_up_welcome_path) select 'Software Developer', from: 'user_role' click_button 'Get started!' - new_user = User.find_by_username(new_user.username) - expect(new_user.software_developer_role?).to be_truthy - expect(new_user.setup_for_company).to be_nil + created_user = User.find_by_username(new_user.username) + + expect(created_user.software_developer_role?).to be_truthy + expect(created_user.setup_for_company).to be_nil expect(page).to have_current_path(new_project_path) end end -RSpec.shared_examples 'Signup name validation' do |field, max_length| +RSpec.shared_examples 'Signup name validation' do |field, max_length, label| before do visit new_user_registration_path end @@ -446,10 +321,10 @@ RSpec.shared_examples 'Signup name validation' do |field, max_length| expect(find('.name')).to have_css '.gl-field-error-outline' end - it "shows an error message if the user\'s fullname is longer than #{max_length} characters" do + it "shows an error message if the user\'s #{label} is longer than #{max_length} characters" do fill_in field, with: 'n' * (max_length + 1) - expect(page).to have_content("Name is too long (maximum is #{max_length} characters).") + expect(page).to have_content("#{label} is too long (maximum is #{max_length} characters).") end it 'shows an error message if the username contains emojis' do @@ -467,7 +342,8 @@ RSpec.describe 'With original flow' do end it_behaves_like 'Signup' - it_behaves_like 'Signup name validation', 'new_user_name', 255 + it_behaves_like 'Signup name validation', 'new_user_first_name', 127, 'First name' + it_behaves_like 'Signup name validation', 'new_user_last_name', 127, 'Last name' end RSpec.describe 'With experimental flow' do @@ -477,30 +353,6 @@ RSpec.describe 'With experimental flow' do end it_behaves_like 'Signup' - it_behaves_like 'Signup name validation', 'new_user_first_name', 127 - it_behaves_like 'Signup name validation', 'new_user_last_name', 127 - - context 'when terms_opt_in experimental is enabled' do - include TermsHelper - - before do - enforce_terms - stub_experiment(signup_flow: true, terms_opt_in: true) - stub_experiment_for_user(signup_flow: true, terms_opt_in: true) - end - - it 'terms are checked by default' do - new_user = build_stubbed(:user) - - visit new_user_registration_path - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - fill_in 'new_user_password', with: new_user.password - click_button 'Register' - - expect(current_path).to eq users_sign_up_welcome_path - end - end + it_behaves_like 'Signup name validation', 'new_user_first_name', 127, 'First name' + it_behaves_like 'Signup name validation', 'new_user_last_name', 127, 'Last name' end |