summaryrefslogtreecommitdiff
path: root/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb
blob: 381842be5ab82a7142f641e5c50e2bc4f01e679a (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
131
132
133
134
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Sidebars::Projects::Menus::MonitorMenu do
  let_it_be_with_refind(:project) { create(:project) }

  let(:user) { project.owner }
  let(:show_cluster_hint) { true }
  let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project, show_cluster_hint: show_cluster_hint) }

  subject { described_class.new(context) }

  describe '#render?' do
    context 'when operations feature is disabled' do
      it 'returns false' do
        project.project_feature.update!(operations_access_level: Featurable::DISABLED)

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

    context 'when operation feature is enabled' do
      context 'when menu does not have any renderable 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 '#title' do
    it 'returns "Monitor"' do
      expect(subject.title).to eq 'Monitor'
    end
  end

  describe '#extra_container_html_options' do
    it 'returns "shortcuts-monitor"' do
      expect(subject.extra_container_html_options).to eq(class: 'shortcuts-monitor')
    end
  end

  describe '#link' do
    let(:foo_path) { '/foo_path'}

    let(:foo_menu) do
      ::Sidebars::MenuItem.new(
        title: 'foo',
        link: foo_path,
        active_routes: {},
        item_id: :foo
      )
    end

    it 'returns first visible item link' do
      subject.insert_element_before(subject.renderable_items, subject.renderable_items.first.item_id, foo_menu)

      expect(subject.link).to eq foo_path
    end
  end

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

    shared_examples 'access rights checks' do
      specify { is_expected.not_to be_nil }

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

        specify { is_expected.to be_nil }
      end
    end

    describe 'Metrics Dashboard' do
      let(:item_id) { :metrics }

      it_behaves_like 'access rights checks'
    end

    describe 'Logs' do
      let(:item_id) { :logs }

      it_behaves_like 'access rights checks'
    end

    describe 'Tracing' do
      let(:item_id) { :tracing }

      it_behaves_like 'access rights checks'
    end

    describe 'Error Tracking' do
      let(:item_id) { :error_tracking }

      it_behaves_like 'access rights checks'
    end

    describe 'Alert Management' do
      let(:item_id) { :alert_management }

      it_behaves_like 'access rights checks'
    end

    describe 'Incidents' do
      let(:item_id) { :incidents }

      it_behaves_like 'access rights checks'
    end

    describe 'Product Analytics' do
      let(:item_id) { :product_analytics }

      specify { is_expected.not_to be_nil }

      describe 'when feature flag :product_analytics is disabled' do
        specify do
          stub_feature_flags(product_analytics: false)

          is_expected.to be_nil
        end
      end
    end
  end
end