Commit ecf8d59f authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'nicolasdular/fix-login-specs' into 'master'

Improve login page provider specs

See merge request gitlab-org/gitlab!45998
parents ec67fbb8 fbe033c0
......@@ -4,17 +4,17 @@
%ul.nav-links.new-session-tabs.nav-tabs.nav{ class: ('custom-provider-tabs' if any_form_based_providers_enabled?) }
- if crowd_enabled?
%li.nav-item
= link_to "Crowd", "#crowd", class: "nav-link #{active_when(form_based_auth_provider_has_active_class?(:crowd))}", 'data-toggle' => 'tab'
= link_to "Crowd", "#crowd", class: "nav-link #{active_when(form_based_auth_provider_has_active_class?(:crowd))}", 'data-toggle' => 'tab', role: 'tab'
= render_if_exists "devise/shared/kerberos_tab"
- ldap_servers.each_with_index do |server, i|
%li.nav-item
= link_to server['label'], "##{server['provider_name']}", class: "nav-link #{active_when(i == 0 && form_based_auth_provider_has_active_class?(:ldapmain))}", data: { toggle: 'tab', qa_selector: 'ldap_tab' }
= link_to server['label'], "##{server['provider_name']}", class: "nav-link #{active_when(i == 0 && form_based_auth_provider_has_active_class?(:ldapmain))}", data: { toggle: 'tab', qa_selector: 'ldap_tab' }, role: 'tab'
= render_if_exists 'devise/shared/tab_smartcard'
- if show_password_form
%li.nav-item
= link_to _('Standard'), '#login-pane', class: 'nav-link', data: { toggle: 'tab', qa_selector: 'standard_tab' }
= link_to _('Standard'), '#login-pane', class: 'nav-link', data: { toggle: 'tab', qa_selector: 'standard_tab' }, role: 'tab'
- if render_signup_link && allow_signup?
%li.nav-item
= link_to 'Register', '#register-pane', class: 'nav-link', data: { toggle: 'tab', qa_selector: 'register_tab' }
= link_to 'Register', '#register-pane', class: 'nav-link', data: { toggle: 'tab', qa_selector: 'register_tab' }, role: 'tab'
- if smartcard_enabled?
%li.nav-item
= link_to _('Smartcard'), '#smartcard', class: "nav-link #{active_when(form_based_auth_provider_has_active_class?(:smartcard))}", 'data-toggle' => 'tab'
= link_to _('Smartcard'), '#smartcard', class: "nav-link #{active_when(form_based_auth_provider_has_active_class?(:smartcard))}", 'data-toggle' => 'tab', role: 'tab'
......@@ -58,13 +58,7 @@ RSpec.describe 'Login' do
it 'correctly renders tabs and panes' do
subject
ensure_tab_pane_correctness(false)
end
it 'does not show smartcard login form' do
subject
expect(page).not_to have_selector('.nav-tabs a[href="#smartcard"]')
ensure_tab_pane_correctness(['Sign in', 'Register'])
end
end
......@@ -76,16 +70,7 @@ RSpec.describe 'Login' do
it 'correctly renders tabs and panes' do
subject
expect(page.all('.nav-tabs a[data-toggle="tab"]').length).to be(3)
ensure_one_active_tab
ensure_one_active_pane
end
it 'shows smartcard login form' do
subject
expect(page).to have_selector('.nav-tabs a[href="#smartcard"]')
ensure_tab_pane_correctness(%w(Smartcard Standard Register))
end
describe 'with two-factor authentication required', :clean_gitlab_redis_shared_state do
......
......@@ -594,41 +594,78 @@ RSpec.describe 'Login' do
describe 'UI tabs and panes' do
context 'when no defaults are changed' do
it 'correctly renders tabs and panes' do
ensure_tab_pane_correctness
visit new_user_session_path
ensure_tab_pane_correctness(['Sign in', 'Register'])
end
end
context 'when signup is disabled' do
before do
stub_application_setting(signup_enabled: false)
visit new_user_session_path
end
it 'correctly renders tabs and panes' do
ensure_tab_pane_correctness
ensure_tab_pane_correctness(['Sign in'])
end
end
context 'when ldap is enabled' do
include LdapHelpers
let(:provider) { 'ldapmain' }
let(:ldap_server_config) do
{
'label' => 'Main LDAP',
'provider_name' => provider,
'attributes' => {},
'encryption' => 'plain',
'uid' => 'uid',
'base' => 'dc=example,dc=com'
}
end
before do
stub_ldap_setting(enabled: true)
allow(::Gitlab::Auth::Ldap::Config).to receive_messages(enabled: true, servers: [ldap_server_config])
allow(Gitlab::Auth::OAuth::Provider).to receive_messages(providers: [provider.to_sym])
Ldap::OmniauthCallbacksController.define_providers!
Rails.application.reload_routes!
allow_next_instance_of(ActionDispatch::Routing::RoutesProxy) do |instance|
allow(instance).to receive(:"user_#{provider}_omniauth_callback_path")
.and_return("/users/auth/#{provider}/callback")
end
visit new_user_session_path
allow(page).to receive(:form_based_providers).and_return([:ldapmain])
allow(page).to receive(:ldap_enabled).and_return(true)
end
it 'correctly renders tabs and panes' do
ensure_tab_pane_correctness(false)
ensure_tab_pane_correctness(['Main LDAP', 'Standard', 'Register'])
end
end
context 'when crowd is enabled' do
before do
allow(Gitlab::Auth::OAuth::Provider).to receive_messages(providers: [:crowd])
stub_application_setting(crowd_enabled: true)
Ldap::OmniauthCallbacksController.define_providers!
Rails.application.reload_routes!
allow_next_instance_of(ActionDispatch::Routing::RoutesProxy) do |instance|
allow(instance).to receive(:user_crowd_omniauth_authorize_path)
.and_return("/users/auth/crowd/callback")
end
visit new_user_session_path
allow(page).to receive(:form_based_providers).and_return([:crowd])
allow(page).to receive(:crowd_enabled?).and_return(true)
end
it 'correctly renders tabs and panes' do
ensure_tab_pane_correctness(false)
ensure_tab_pane_correctness(%w(Crowd Standard Register))
end
end
end
......
# frozen_string_literal: true
module UserLoginHelper
def ensure_tab_pane_correctness(visit_path = true)
if visit_path
visit new_user_session_path
end
ensure_tab_pane_counts
def ensure_tab_pane_correctness(tab_names)
ensure_tab_pane_counts(tab_names.size)
ensure_tab_labels(tab_names)
ensure_one_active_tab
ensure_one_active_pane
end
def ensure_tab_pane_counts
tabs_count = page.all('[role="tab"]').size
def ensure_tab_labels(tab_names)
tab_labels = page.all('[role="tab"]').map(&:text)
expect(tab_names).to match_array(tab_labels)
end
def ensure_tab_pane_counts(tabs_count)
expect(page.all('[role="tab"]').size).to eq(tabs_count)
expect(page).to have_selector('[role="tabpanel"]', visible: :all, count: tabs_count)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment