monitor_menu_spec.rb 3.2 KB
Newer Older
1 2 3 4
# frozen_string_literal: true

require 'spec_helper'

5
RSpec.describe Sidebars::Projects::Menus::MonitorMenu do
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
  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
24
      context 'when menu does not have any renderable menu items' do
25
        it 'returns false' do
26
          allow(subject).to receive(:has_renderable_items?).and_return(false)
27 28 29 30 31 32 33 34 35 36 37 38 39

          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

40 41 42 43 44 45 46 47 48 49 50 51
  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

52
  describe '#link' do
53 54 55 56 57 58 59 60 61
    let(:foo_path) { '/foo_path'}

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

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

67
      expect(subject.link).to eq foo_path
68 69 70 71
    end
  end

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

74
    shared_examples 'access rights checks' do
75 76 77 78 79 80 81 82 83
      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

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

87 88
      it_behaves_like 'access rights checks'
    end
89

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

93
      it_behaves_like 'access rights checks'
94 95 96 97 98
    end

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

99
      it_behaves_like 'access rights checks'
100 101 102 103 104
    end

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

105
      it_behaves_like 'access rights checks'
106 107 108 109 110
    end

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

111
      it_behaves_like 'access rights checks'
112 113 114 115 116
    end

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

117
      it_behaves_like 'access rights checks'
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    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