From 81fea3beaae533a27a041850b691c06b900697ac Mon Sep 17 00:00:00 2001 From: Tarun Vellishetty <tarunvelli@gmail.com> Date: Sun, 5 Dec 2021 21:09:25 +0530 Subject: [PATCH] Registration Flow - Don't pre-select role Adds front-end validation to require role and adds empty state guidance message on the role select box in the registration flow Changelog: changed --- .../registrations/welcome/show.html.haml | 2 +- .../features/registrations/welcome_spec.rb | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/views/registrations/welcome/show.html.haml b/app/views/registrations/welcome/show.html.haml index 65a1ffa3e4605..7723bae9fefb3 100644 --- a/app/views/registrations/welcome/show.html.haml +++ b/app/views/registrations/welcome/show.html.haml @@ -18,7 +18,7 @@ .row .form-group.col-sm-12 = f.label :role, _('Role'), class: 'label-bold' - = f.select :role, ::User.roles.keys.map { |role| [role.titleize, role] }, {}, class: 'form-control js-user-role-dropdown', autofocus: true + = f.select :role, ::User.roles.keys.map { |role| [role.titleize, role] }, { include_blank: _('Select a role') }, class: 'form-control js-user-role-dropdown', autofocus: true, required: true - if Feature.enabled?(:user_other_role_details) .row .form-group.col-sm-12.js-other-role-group.hidden diff --git a/ee/spec/features/registrations/welcome_spec.rb b/ee/spec/features/registrations/welcome_spec.rb index fd8371c8b9dfa..62b7a55d05185 100644 --- a/ee/spec/features/registrations/welcome_spec.rb +++ b/ee/spec/features/registrations/welcome_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe 'Welcome screen', :js do - let_it_be(:user) { create(:user) } + let_it_be(:user) { create(:user, role: nil) } context 'when on GitLab.com' do before do @@ -18,9 +18,24 @@ it 'shows the welcome page' do expect(page).to have_content('Welcome to GitLab') + expect(page).to have_content('Select a role') expect(page).to have_content('Continue') end + it 'has validations' do + click_button 'Continue' + + expect(page).to have_field("user_role", valid: false) + expect(page).to have_field("user_setup_for_company_true", valid: false) + + page.select('Software Developer', from: 'user_role') + choose 'user_setup_for_company_true' + + click_button 'Continue' + + expect(page).not_to have_selector('#user_role') + end + it 'allows specifying other for jobs_to_be_done' do expect(page).not_to have_content('Why are you signing up? (Optional)') @@ -32,9 +47,12 @@ end context 'email opt in' do + let(:user) { create(:user, email_opted_in: false) } + it 'does not show the email opt in checkbox when setting up for a company' do expect(page).not_to have_selector('input[name="user[email_opted_in]', visible: true) + page.select('Software Developer', from: 'user_role') choose 'user_setup_for_company_true' expect(page).not_to have_selector('input[name="user[email_opted_in]', visible: true) @@ -44,9 +62,10 @@ expect(user.reload.email_opted_in).to eq(true) end - it 'shows the email opt checkbox in when setting up for just me' do + it 'shows the email opt in checkbox when setting up for just me' do expect(page).not_to have_selector('input[name="user[email_opted_in]', visible: true) + page.select('Software Developer', from: 'user_role') choose 'user_setup_for_company_false' expect(page).to have_selector('input[name="user[email_opted_in]', visible: true) -- GitLab