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

analytics_menu_spec.rb « menus « projects « sidebars « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 25a65015847b9b6aab7dce82e3636c8975aaa2bb (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Sidebars::Projects::Menus::AnalyticsMenu do
  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:guest) do
    create(:user).tap { |u| project.add_guest(u) }
  end

  let(:owner) { project.first_owner }
  let(:current_user) { owner }
  let(:context) { Sidebars::Projects::Context.new(current_user: current_user, container: project, current_ref: project.repository.root_ref) }

  subject { described_class.new(context) }

  describe '#render?' do
    context 'whe user cannot read analytics' do
      let(:current_user) { nil }

      it 'returns false' do
        expect(subject.render?).to be false
      end
    end

    context 'whe user can read analytics' do
      it 'returns true' do
        expect(subject.render?).to be true
      end

      context 'when menu does not have any menu items' do
        it 'returns false' do
          allow(subject).to receive(:has_renderable_items?).and_return(false)

          expect(subject.render?).to be false
        end
      end

      context 'when menu has menu items' do
        it 'returns true' do
          expect(subject.render?).to be true
        end
      end
    end
  end

  describe '#link' do
    it 'returns link to the value stream page' do
      expect(subject.link).to include('/-/value_stream_analytics')
    end

    context 'when Value Stream is not visible' do
      it 'returns link to the the first visible menu item' do
        allow(subject).to receive(:cycle_analytics_menu_item).and_return(double(render?: false))

        expect(subject.link).to eq subject.renderable_items.first.link
      end
    end
  end

  describe 'Menu items' do
    subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } }

    describe 'CI/CD' do
      let(:item_id) { :ci_cd_analytics }

      specify { is_expected.not_to be_nil }

      describe 'when the project repository is empty' do
        before do
          allow(project).to receive(:empty_repo?).and_return(true)
        end

        specify { is_expected.to be_nil }
      end

      describe 'when builds access level is DISABLED' do
        before do
          project.project_feature.update!(builds_access_level: Featurable::DISABLED)
        end

        specify { is_expected.to be_nil }
      end

      describe 'when the user does not have access' do
        let(:current_user) { guest }

        specify { is_expected.to be_nil }
      end
    end

    describe 'Repository' do
      let(:item_id) { :repository_analytics }

      specify { is_expected.not_to be_nil }

      describe 'when the project repository is empty' do
        before do
          allow(project).to receive(:empty_repo?).and_return(true)
        end

        specify { is_expected.to be_nil }
      end

      describe 'when a user does not have access to repository graphs' do
        let(:current_user) { guest }

        specify { is_expected.to be_nil }
      end

      describe 'when the user does not have access' do
        let(:current_user) { nil }

        specify { is_expected.to be_nil }
      end
    end

    describe 'Value Stream' do
      let(:item_id) { :cycle_analytics }

      specify { is_expected.not_to be_nil }

      describe 'when the user does not have access' do
        let(:current_user) { nil }

        specify { is_expected.to be_nil }
      end
    end
  end
end