Welcome to mirror list, hosted at ThFree Co, Russian Federation.

access_tokens_menu_spec.rb « menus « user_settings « sidebars « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eebd089ad3f946cdaab06dcb3305e2a23301b2b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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: '/-/user_settings/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