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 @@ ...@@ -4,17 +4,17 @@
%ul.nav-links.new-session-tabs.nav-tabs.nav{ class: ('custom-provider-tabs' if any_form_based_providers_enabled?) } %ul.nav-links.new-session-tabs.nav-tabs.nav{ class: ('custom-provider-tabs' if any_form_based_providers_enabled?) }
- if crowd_enabled? - if crowd_enabled?
%li.nav-item %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" = render_if_exists "devise/shared/kerberos_tab"
- ldap_servers.each_with_index do |server, i| - ldap_servers.each_with_index do |server, i|
%li.nav-item %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' = render_if_exists 'devise/shared/tab_smartcard'
- if show_password_form - if show_password_form
%li.nav-item %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? - if render_signup_link && allow_signup?
%li.nav-item %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? - if smartcard_enabled?
%li.nav-item %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 ...@@ -58,13 +58,7 @@ RSpec.describe 'Login' do
it 'correctly renders tabs and panes' do it 'correctly renders tabs and panes' do
subject subject
ensure_tab_pane_correctness(false) ensure_tab_pane_correctness(['Sign in', 'Register'])
end
it 'does not show smartcard login form' do
subject
expect(page).not_to have_selector('.nav-tabs a[href="#smartcard"]')
end end
end end
...@@ -76,16 +70,7 @@ RSpec.describe 'Login' do ...@@ -76,16 +70,7 @@ RSpec.describe 'Login' do
it 'correctly renders tabs and panes' do it 'correctly renders tabs and panes' do
subject subject
expect(page.all('.nav-tabs a[data-toggle="tab"]').length).to be(3) ensure_tab_pane_correctness(%w(Smartcard Standard Register))
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"]')
end end
describe 'with two-factor authentication required', :clean_gitlab_redis_shared_state do describe 'with two-factor authentication required', :clean_gitlab_redis_shared_state do
......
...@@ -594,41 +594,78 @@ RSpec.describe 'Login' do ...@@ -594,41 +594,78 @@ RSpec.describe 'Login' do
describe 'UI tabs and panes' do describe 'UI tabs and panes' do
context 'when no defaults are changed' do context 'when no defaults are changed' do
it 'correctly renders tabs and panes' 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
end end
context 'when signup is disabled' do context 'when signup is disabled' do
before do before do
stub_application_setting(signup_enabled: false) stub_application_setting(signup_enabled: false)
visit new_user_session_path
end end
it 'correctly renders tabs and panes' do it 'correctly renders tabs and panes' do
ensure_tab_pane_correctness ensure_tab_pane_correctness(['Sign in'])
end end
end end
context 'when ldap is enabled' do 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 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 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 end
it 'correctly renders tabs and panes' do it 'correctly renders tabs and panes' do
ensure_tab_pane_correctness(false) ensure_tab_pane_correctness(['Main LDAP', 'Standard', 'Register'])
end end
end end
context 'when crowd is enabled' do context 'when crowd is enabled' do
before 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 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 end
it 'correctly renders tabs and panes' do it 'correctly renders tabs and panes' do
ensure_tab_pane_correctness(false) ensure_tab_pane_correctness(%w(Crowd Standard Register))
end end
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
module UserLoginHelper module UserLoginHelper
def ensure_tab_pane_correctness(visit_path = true) def ensure_tab_pane_correctness(tab_names)
if visit_path ensure_tab_pane_counts(tab_names.size)
visit new_user_session_path ensure_tab_labels(tab_names)
end
ensure_tab_pane_counts
ensure_one_active_tab ensure_one_active_tab
ensure_one_active_pane ensure_one_active_pane
end end
def ensure_tab_pane_counts def ensure_tab_labels(tab_names)
tabs_count = page.all('[role="tab"]').size 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) expect(page).to have_selector('[role="tabpanel"]', visible: :all, count: tabs_count)
end 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