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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Groups::Menus::ObservabilityMenu, feature_category: :navigation do
let(:owner) { build_stubbed(:user) }
let(:root_group) do
build(:group, :private).tap do |g|
g.add_owner(owner)
end
end
let(:group) { root_group }
let(:user) { owner }
let(:context) { Sidebars::Groups::Context.new(current_user: user, container: group) }
let(:menu) { described_class.new(context) }
describe '#render?' do
before do
allow(menu).to receive(:can?).and_call_original
end
context 'when observability#explore is allowed' do
before do
allow(Gitlab::Observability).to receive(:allowed_for_action?).with(user, group, :explore).and_return(true)
end
it 'returns true' do
expect(menu.render?).to eq true
expect(Gitlab::Observability).to have_received(:allowed_for_action?).with(user, group, :explore)
end
end
context 'when observability#explore is not allowed' do
before do
allow(Gitlab::Observability).to receive(:allowed_for_action?).with(user, group, :explore).and_return(false)
end
it 'returns false' do
expect(menu.render?).to eq false
expect(Gitlab::Observability).to have_received(:allowed_for_action?).with(user, group, :explore)
end
end
end
describe "Menu items" do
before do
allow(Gitlab::Observability).to receive(:allowed_for_action?).and_return(false)
end
subject { find_menu(menu, item_id) }
shared_examples 'observability menu entry' do
context 'when action is allowed' do
before do
allow(Gitlab::Observability).to receive(:allowed_for_action?).with(user, group, item_id).and_return(true)
end
it 'the menu item is added to list of menu items' do
is_expected.not_to be_nil
end
end
context 'when action is not allowed' do
before do
allow(Gitlab::Observability).to receive(:allowed_for_action?).with(user, group, item_id).and_return(false)
end
it 'the menu item is added to list of menu items' do
is_expected.to be_nil
end
end
end
describe 'Explore' do
it_behaves_like 'observability menu entry' do
let(:item_id) { :explore }
end
end
describe 'Datasources' do
it_behaves_like 'observability menu entry' do
let(:item_id) { :datasources }
end
end
end
private
def find_menu(menu, item)
menu.renderable_items.find { |i| i.item_id == item }
end
end
|