2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2017-06-06 11:39:54 -04:00
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe ProfilesHelper do
|
2018-11-07 06:00:21 -05:00
|
|
|
describe '#commit_email_select_options' do
|
|
|
|
it 'returns an array with private commit email along with all the verified emails' do
|
|
|
|
user = create(:user)
|
2018-11-14 13:09:33 -05:00
|
|
|
create(:email, user: user)
|
|
|
|
confirmed_email1 = create(:email, :confirmed, user: user)
|
|
|
|
confirmed_email2 = create(:email, :confirmed, user: user)
|
|
|
|
|
2018-11-07 06:00:21 -05:00
|
|
|
private_email = user.private_commit_email
|
|
|
|
|
|
|
|
emails = [
|
2021-08-29 23:09:16 -04:00
|
|
|
[s_('Use primary email (%{email})') % { email: user.email }, ''],
|
|
|
|
[s_("Profiles|Use a private email - %{email}").html_safe % { email: private_email }, Gitlab::PrivateCommitEmail::TOKEN],
|
2018-11-14 13:09:33 -05:00
|
|
|
user.email,
|
|
|
|
confirmed_email1.email,
|
|
|
|
confirmed_email2.email
|
2018-11-07 06:00:21 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
expect(helper.commit_email_select_options(user)).to match_array(emails)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-06 11:39:54 -04:00
|
|
|
describe '#email_provider_label' do
|
|
|
|
it "returns nil for users without external email" do
|
|
|
|
user = create(:user)
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
|
2017-08-29 04:57:41 -04:00
|
|
|
expect(helper.attribute_provider_label(:email)).to be_nil
|
2017-06-06 11:39:54 -04:00
|
|
|
end
|
|
|
|
|
2017-08-29 04:57:41 -04:00
|
|
|
it "returns omniauth provider label for users with external attributes" do
|
|
|
|
stub_omniauth_setting(sync_profile_from_provider: ['cas3'])
|
|
|
|
stub_omniauth_setting(sync_profile_attributes: true)
|
2017-06-06 11:39:54 -04:00
|
|
|
stub_cas_omniauth_provider
|
2017-08-29 04:57:41 -04:00
|
|
|
cas_user = create(:omniauth_user, provider: 'cas3')
|
|
|
|
cas_user.create_user_synced_attributes_metadata(provider: 'cas3', name_synced: true, email_synced: true, location_synced: true)
|
2017-06-06 11:39:54 -04:00
|
|
|
allow(helper).to receive(:current_user).and_return(cas_user)
|
|
|
|
|
2017-08-29 04:57:41 -04:00
|
|
|
expect(helper.attribute_provider_label(:email)).to eq('CAS')
|
|
|
|
expect(helper.attribute_provider_label(:name)).to eq('CAS')
|
|
|
|
expect(helper.attribute_provider_label(:location)).to eq('CAS')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the correct omniauth provider label for users with some external attributes" do
|
|
|
|
stub_omniauth_setting(sync_profile_from_provider: ['cas3'])
|
|
|
|
stub_omniauth_setting(sync_profile_attributes: true)
|
|
|
|
stub_cas_omniauth_provider
|
|
|
|
cas_user = create(:omniauth_user, provider: 'cas3')
|
|
|
|
cas_user.create_user_synced_attributes_metadata(provider: 'cas3', name_synced: false, email_synced: true, location_synced: false)
|
|
|
|
allow(helper).to receive(:current_user).and_return(cas_user)
|
|
|
|
|
|
|
|
expect(helper.attribute_provider_label(:name)).to be_nil
|
|
|
|
expect(helper.attribute_provider_label(:email)).to eq('CAS')
|
|
|
|
expect(helper.attribute_provider_label(:location)).to be_nil
|
2017-06-06 11:39:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 'LDAP' for users with external email but no email provider" do
|
2017-08-29 04:57:41 -04:00
|
|
|
ldap_user = create(:omniauth_user)
|
|
|
|
ldap_user.create_user_synced_attributes_metadata(email_synced: true)
|
2017-06-06 11:39:54 -04:00
|
|
|
allow(helper).to receive(:current_user).and_return(ldap_user)
|
|
|
|
|
2017-08-29 04:57:41 -04:00
|
|
|
expect(helper.attribute_provider_label(:email)).to eq('LDAP')
|
2017-06-06 11:39:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-17 10:09:28 -05:00
|
|
|
describe "#user_status_set_to_busy?" do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:availability, :result) do
|
|
|
|
"busy" | true
|
|
|
|
"not_set" | false
|
|
|
|
"" | false
|
|
|
|
nil | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it { expect(helper.user_status_set_to_busy?(OpenStruct.new(availability: availability))).to eq(result) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#show_status_emoji?" do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:message, :emoji, :result) do
|
|
|
|
"Some message" | UserStatus::DEFAULT_EMOJI | true
|
|
|
|
"Some message" | "" | true
|
|
|
|
"" | "basketball" | true
|
|
|
|
"" | "basketball" | true
|
|
|
|
"" | UserStatus::DEFAULT_EMOJI | false
|
|
|
|
"" | UserStatus::DEFAULT_EMOJI | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it { expect(helper.show_status_emoji?(OpenStruct.new(message: message, emoji: emoji))).to eq(result) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-12 08:09:15 -04:00
|
|
|
describe "#ssh_key_expiration_tooltip" do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Key).to receive(:enforce_ssh_key_expiration_feature_available?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
error_message = 'Key type is forbidden. Must be DSA, ECDSA, or ED25519'
|
|
|
|
|
|
|
|
where(:error, :expired, :result) do
|
|
|
|
false | false | nil
|
|
|
|
true | false | error_message
|
|
|
|
false | true | 'Key usable beyond expiration date.'
|
|
|
|
true | true | error_message
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
let_it_be(:key) do
|
|
|
|
build(:personal_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
key.expires_at = expired ? 2.days.ago : 2.days.from_now
|
|
|
|
key.errors.add(:base, error_message) if error
|
|
|
|
|
|
|
|
expect(helper.ssh_key_expiration_tooltip(key)).to eq(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#ssh_key_expires_field_description" do
|
|
|
|
before do
|
|
|
|
allow(Key).to receive(:enforce_ssh_key_expiration_feature_available?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the description' do
|
|
|
|
expect(helper.ssh_key_expires_field_description).to eq('Key can still be used after expiration.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-25 20:09:31 -04:00
|
|
|
describe '#middle_dot_divider_classes' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:stacking, :breakpoint, :expected) do
|
|
|
|
nil | nil | %w(gl-mb-3 gl-display-inline-block middle-dot-divider)
|
|
|
|
true | nil | %w(gl-mb-3 middle-dot-divider-sm gl-display-block gl-sm-display-inline-block)
|
|
|
|
nil | :sm | %w(gl-mb-3 gl-display-inline-block middle-dot-divider-sm)
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'returns CSS classes needed to render the middle dot divider' do
|
|
|
|
expect(helper.middle_dot_divider_classes(stacking, breakpoint)).to eq expected
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-06 11:39:54 -04:00
|
|
|
def stub_cas_omniauth_provider
|
|
|
|
provider = OpenStruct.new(
|
|
|
|
'name' => 'cas3',
|
|
|
|
'label' => 'CAS'
|
|
|
|
)
|
|
|
|
|
|
|
|
stub_omniauth_setting(providers: [provider])
|
|
|
|
end
|
|
|
|
end
|