diff options
Diffstat (limited to 'spec/lib/sidebars/user_settings')
15 files changed, 326 insertions, 0 deletions
diff --git a/spec/lib/sidebars/user_settings/menus/access_tokens_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/access_tokens_menu_spec.rb new file mode 100644 index 00000000000..fa33e7bedfb --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/access_tokens_menu_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::AccessTokensMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/personal_access_tokens', + title: _('Access Tokens'), + icon: 'token', + active_routes: { controller: :personal_access_tokens } + + describe '#render?' do + subject { described_class.new(context) } + + let_it_be(:user) { build(:user) } + + context 'when personal access tokens are disabled' do + before do + allow(::Gitlab::CurrentSettings).to receive_messages(personal_access_tokens_disabled?: true) + end + + context 'when user is logged in' do + let(:context) { Sidebars::Context.new(current_user: user, container: nil) } + + it 'does not render' do + expect(subject.render?).to be false + end + end + + context 'when user is not logged in' do + let(:context) { Sidebars::Context.new(current_user: nil, container: nil) } + + subject { described_class.new(context) } + + it 'does not render' do + expect(subject.render?).to be false + end + end + end + + context 'when personal access tokens are enabled' do + before do + allow(::Gitlab::CurrentSettings).to receive_messages(personal_access_tokens_disabled?: false) + end + + context 'when user is logged in' do + let(:context) { Sidebars::Context.new(current_user: user, container: nil) } + + it 'renders' do + expect(subject.render?).to be true + end + end + + context 'when user is not logged in' do + let(:context) { Sidebars::Context.new(current_user: nil, container: nil) } + + subject { described_class.new(context) } + + it 'does not render' do + expect(subject.render?).to be false + end + end + end + end +end diff --git a/spec/lib/sidebars/user_settings/menus/account_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/account_menu_spec.rb new file mode 100644 index 00000000000..d5810d9c5ae --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/account_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::AccountMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/account', + title: _('Account'), + icon: 'account', + active_routes: { controller: [:accounts, :two_factor_auths] } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/active_sessions_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/active_sessions_menu_spec.rb new file mode 100644 index 00000000000..be5f826ee58 --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/active_sessions_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::ActiveSessionsMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/active_sessions', + title: _('Active Sessions'), + icon: 'monitor-lines', + active_routes: { controller: :active_sessions } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/applications_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/applications_menu_spec.rb new file mode 100644 index 00000000000..eeda4fb844c --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/applications_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::ApplicationsMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/applications', + title: _('Applications'), + icon: 'applications', + active_routes: { controller: 'oauth/applications' } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/authentication_log_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/authentication_log_menu_spec.rb new file mode 100644 index 00000000000..33be5050c37 --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/authentication_log_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::AuthenticationLogMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/audit_log', + title: _('Authentication Log'), + icon: 'log', + active_routes: { path: 'profiles#audit_log' } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/chat_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/chat_menu_spec.rb new file mode 100644 index 00000000000..2a0587e2504 --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/chat_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::ChatMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/chat', + title: _('Chat'), + icon: 'comment', + active_routes: { controller: :chat_names } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/emails_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/emails_menu_spec.rb new file mode 100644 index 00000000000..2f16c68e601 --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/emails_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::EmailsMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/emails', + title: _('Emails'), + icon: 'mail', + active_routes: { controller: :emails } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/gpg_keys_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/gpg_keys_menu_spec.rb new file mode 100644 index 00000000000..1f4340ad29c --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/gpg_keys_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::GpgKeysMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/gpg_keys', + title: _('GPG Keys'), + icon: 'key', + active_routes: { controller: :gpg_keys } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/notifications_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/notifications_menu_spec.rb new file mode 100644 index 00000000000..282324056d4 --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/notifications_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::NotificationsMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/notifications', + title: _('Notifications'), + icon: 'notifications', + active_routes: { controller: :notifications } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/password_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/password_menu_spec.rb new file mode 100644 index 00000000000..168019fea5d --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/password_menu_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::PasswordMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/password', + title: _('Password'), + icon: 'lock', + active_routes: { controller: :passwords } + + describe '#render?' do + subject { described_class.new(context) } + + let_it_be(:user) { build(:user) } + let(:context) { Sidebars::Context.new(current_user: user, container: nil) } + + context 'when password authentication is enabled' do + before do + allow(user).to receive(:allow_password_authentication?).and_return(true) + end + + it 'renders' do + expect(subject.render?).to be true + end + end + + context 'when password authentication is disabled' do + before do + allow(user).to receive(:allow_password_authentication?).and_return(false) + end + + it 'renders' do + expect(subject.render?).to be false + end + end + end +end diff --git a/spec/lib/sidebars/user_settings/menus/preferences_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/preferences_menu_spec.rb new file mode 100644 index 00000000000..83a67a40081 --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/preferences_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::PreferencesMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/preferences', + title: _('Preferences'), + icon: 'preferences', + active_routes: { controller: :preferences } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/profile_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/profile_menu_spec.rb new file mode 100644 index 00000000000..8410ba7cfcd --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/profile_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::ProfileMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile', + title: _('Profile'), + icon: 'profile', + active_routes: { path: 'profiles#show' } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/menus/saved_replies_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/saved_replies_menu_spec.rb new file mode 100644 index 00000000000..ea1a2a3539f --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/saved_replies_menu_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::SavedRepliesMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/saved_replies', + title: _('Saved Replies'), + icon: 'symlink', + active_routes: { controller: :saved_replies } + + describe '#render?' do + subject { described_class.new(context) } + + let_it_be(:user) { build(:user) } + + context 'when saved replies are enabled' do + before do + allow(subject).to receive(:saved_replies_enabled?).and_return(true) + end + + context 'when user is logged in' do + let(:context) { Sidebars::Context.new(current_user: user, container: nil) } + + it 'does not render' do + expect(subject.render?).to be true + end + end + + context 'when user is not logged in' do + let(:context) { Sidebars::Context.new(current_user: nil, container: nil) } + + subject { described_class.new(context) } + + it 'does not render' do + expect(subject.render?).to be false + end + end + end + + context 'when saved replies are disabled' do + before do + allow(subject).to receive(:saved_replies_enabled?).and_return(false) + end + + context 'when user is logged in' do + let(:context) { Sidebars::Context.new(current_user: user, container: nil) } + + it 'renders' do + expect(subject.render?).to be false + end + end + + context 'when user is not logged in' do + let(:context) { Sidebars::Context.new(current_user: nil, container: nil) } + + subject { described_class.new(context) } + + it 'does not render' do + expect(subject.render?).to be false + end + end + end + end +end diff --git a/spec/lib/sidebars/user_settings/menus/ssh_keys_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/ssh_keys_menu_spec.rb new file mode 100644 index 00000000000..8c781cc743b --- /dev/null +++ b/spec/lib/sidebars/user_settings/menus/ssh_keys_menu_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Menus::SshKeysMenu, feature_category: :navigation do + it_behaves_like 'User settings menu', + link: '/-/profile/keys', + title: _('SSH Keys'), + icon: 'key', + active_routes: { controller: :keys } + + it_behaves_like 'User settings menu #render? method' +end diff --git a/spec/lib/sidebars/user_settings/panel_spec.rb b/spec/lib/sidebars/user_settings/panel_spec.rb new file mode 100644 index 00000000000..aa05d99912a --- /dev/null +++ b/spec/lib/sidebars/user_settings/panel_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::UserSettings::Panel, feature_category: :navigation do + let_it_be(:user) { create(:user) } + + let(:context) { Sidebars::Context.new(current_user: user, container: nil) } + + subject { described_class.new(context) } + + it 'implements #super_sidebar_context_header' do + expect(subject.super_sidebar_context_header).to eq({ title: _('User settings'), avatar: user.avatar_url }) + end +end |