debian-mirror-gitlab/spec/views/devise/sessions/new.html.haml_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

144 lines
3.9 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe 'devise/sessions/new' do
2021-09-30 23:02:18 +05:30
describe 'marketing text' do
subject { render(template: 'devise/sessions/new', layout: 'layouts/devise') }
before do
stub_devise
disable_captcha
2022-08-27 11:52:29 +05:30
stub_feature_flags(restyle_login_page: false)
2022-05-07 20:08:51 +05:30
allow(Gitlab).to receive(:com?).and_return(true)
2021-09-30 23:02:18 +05:30
end
it 'when flash is anything it renders marketing text' do
flash[:notice] = "You can't do that"
subject
expect(rendered).to have_content('A complete DevOps platform')
end
it 'when flash notice is devise confirmed message it hides marketing text' do
flash[:notice] = t(:confirmed, scope: [:devise, :confirmations])
subject
expect(rendered).not_to have_content('A complete DevOps platform')
end
end
2022-08-27 11:52:29 +05:30
flag_values = [true, false]
flag_values.each do |val|
2019-12-26 22:10:19 +05:30
before do
2022-08-27 11:52:29 +05:30
stub_feature_flags(restyle_login_page: val)
2019-12-26 22:10:19 +05:30
end
2022-08-27 11:52:29 +05:30
describe 'ldap' do
include LdapHelpers
2019-12-26 22:10:19 +05:30
2022-08-27 11:52:29 +05:30
let(:server) { { provider_name: 'ldapmain', label: 'LDAP' }.with_indifferent_access }
2019-12-26 22:10:19 +05:30
2022-08-27 11:52:29 +05:30
before do
enable_ldap
stub_devise
disable_captcha
disable_sign_up
disable_other_signin_methods
2019-12-26 22:10:19 +05:30
2022-08-27 11:52:29 +05:30
allow(view).to receive(:experiment_enabled?).and_return(false)
end
2019-12-26 22:10:19 +05:30
2022-08-27 11:52:29 +05:30
it 'is shown when enabled' do
render
2019-12-26 22:10:19 +05:30
2022-08-27 11:52:29 +05:30
expect(rendered).to have_selector('.new-session-tabs')
expect(rendered).to have_selector('[data-qa-selector="ldap_tab"]') # rubocop:disable QA/SelectorUsage
expect(rendered).to have_field('LDAP Username')
end
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
it 'is not shown when LDAP sign in is disabled' do
disable_ldap_sign_in
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
render
expect(rendered).to have_content('No authentication methods configured')
expect(rendered).not_to have_selector('[data-qa-selector="ldap_tab"]') # rubocop:disable QA/SelectorUsage
expect(rendered).not_to have_field('LDAP Username')
end
2022-08-13 15:12:31 +05:30
end
2022-08-27 11:52:29 +05:30
describe 'Google Tag Manager' do
let!(:gtm_id) { 'GTM-WWKMTWS' }
subject { rendered }
2022-08-13 15:12:31 +05:30
before do
2022-08-27 11:52:29 +05:30
stub_devise
disable_captcha
stub_config(extra: { google_tag_manager_id: gtm_id, google_tag_manager_nonce_id: gtm_id })
2022-08-13 15:12:31 +05:30
end
2022-08-27 11:52:29 +05:30
describe 'when Google Tag Manager is enabled' do
before do
enable_gtm
render
end
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
it { is_expected.to match /www.googletagmanager.com/ }
2022-08-13 15:12:31 +05:30
end
2022-08-27 11:52:29 +05:30
describe 'when Google Tag Manager is disabled' do
before do
disable_gtm
render
end
it { is_expected.not_to match /www.googletagmanager.com/ }
end
2022-08-13 15:12:31 +05:30
end
end
2019-12-26 22:10:19 +05:30
def disable_other_signin_methods
allow(view).to receive(:password_authentication_enabled_for_web?).and_return(false)
allow(view).to receive(:omniauth_enabled?).and_return(false)
end
def disable_sign_up
allow(view).to receive(:allow_signup?).and_return(false)
end
def stub_devise
allow(view).to receive(:devise_mapping).and_return(Devise.mappings[:user])
allow(view).to receive(:resource).and_return(spy)
allow(view).to receive(:resource_name).and_return(:user)
end
def enable_ldap
stub_ldap_setting(enabled: true)
2020-05-24 23:13:21 +05:30
allow(view).to receive(:ldap_servers).and_return([server])
2019-12-26 22:10:19 +05:30
allow(view).to receive(:form_based_providers).and_return([:ldapmain])
allow(view).to receive(:omniauth_callback_path).with(:user, 'ldapmain').and_return('/ldapmain')
end
def disable_ldap_sign_in
allow(view).to receive(:ldap_sign_in_enabled?).and_return(false)
2020-05-24 23:13:21 +05:30
allow(view).to receive(:ldap_servers).and_return([])
2019-12-26 22:10:19 +05:30
end
def disable_captcha
allow(view).to receive(:captcha_enabled?).and_return(false)
allow(view).to receive(:captcha_on_login_required?).and_return(false)
end
2022-08-13 15:12:31 +05:30
def disable_gtm
allow(view).to receive(:google_tag_manager_enabled?).and_return(false)
end
def enable_gtm
allow(view).to receive(:google_tag_manager_enabled?).and_return(true)
end
2019-12-26 22:10:19 +05:30
end