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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/sidebars')
-rw-r--r--spec/lib/sidebars/groups/menus/observability_menu_spec.rb93
-rw-r--r--spec/lib/sidebars/groups/super_sidebar_menus/monitor_menu_spec.rb22
-rw-r--r--spec/lib/sidebars/groups/super_sidebar_panel_spec.rb1
-rw-r--r--spec/lib/sidebars/organizations/menus/settings_menu_spec.rb52
-rw-r--r--spec/lib/sidebars/organizations/super_sidebar_panel_spec.rb3
-rw-r--r--spec/lib/sidebars/projects/menus/deployments_menu_spec.rb2
-rw-r--r--spec/lib/sidebars/projects/menus/settings_menu_spec.rb12
7 files changed, 67 insertions, 118 deletions
diff --git a/spec/lib/sidebars/groups/menus/observability_menu_spec.rb b/spec/lib/sidebars/groups/menus/observability_menu_spec.rb
deleted file mode 100644
index 573760cddb6..00000000000
--- a/spec/lib/sidebars/groups/menus/observability_menu_spec.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-# 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
diff --git a/spec/lib/sidebars/groups/super_sidebar_menus/monitor_menu_spec.rb b/spec/lib/sidebars/groups/super_sidebar_menus/monitor_menu_spec.rb
deleted file mode 100644
index 759975856b8..00000000000
--- a/spec/lib/sidebars/groups/super_sidebar_menus/monitor_menu_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Sidebars::Groups::SuperSidebarMenus::MonitorMenu, feature_category: :navigation do
- subject { described_class.new({}) }
-
- let(:items) { subject.instance_variable_get(:@items) }
-
- it 'has title and sprite_icon' do
- expect(subject.title).to eq(s_("Navigation|Monitor"))
- expect(subject.sprite_icon).to eq("monitor")
- end
-
- it 'defines list of NilMenuItem placeholders' do
- expect(items.map(&:class).uniq).to eq([Sidebars::NilMenuItem])
- expect(items.map(&:item_id)).to eq([
- :explore,
- :datasources
- ])
- end
-end
diff --git a/spec/lib/sidebars/groups/super_sidebar_panel_spec.rb b/spec/lib/sidebars/groups/super_sidebar_panel_spec.rb
index c939dd870c4..fe1491a736e 100644
--- a/spec/lib/sidebars/groups/super_sidebar_panel_spec.rb
+++ b/spec/lib/sidebars/groups/super_sidebar_panel_spec.rb
@@ -34,7 +34,6 @@ RSpec.describe Sidebars::Groups::SuperSidebarPanel, feature_category: :navigatio
Sidebars::Groups::SuperSidebarMenus::SecureMenu,
Sidebars::Groups::SuperSidebarMenus::DeployMenu,
Sidebars::Groups::SuperSidebarMenus::OperationsMenu,
- Sidebars::Groups::SuperSidebarMenus::MonitorMenu,
Sidebars::Groups::SuperSidebarMenus::AnalyzeMenu,
Sidebars::UncategorizedMenu,
Sidebars::Groups::Menus::SettingsMenu
diff --git a/spec/lib/sidebars/organizations/menus/settings_menu_spec.rb b/spec/lib/sidebars/organizations/menus/settings_menu_spec.rb
new file mode 100644
index 00000000000..fb9f9ee3cce
--- /dev/null
+++ b/spec/lib/sidebars/organizations/menus/settings_menu_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Sidebars::Organizations::Menus::SettingsMenu, feature_category: :navigation do
+ let_it_be(:organization) { build(:organization) }
+
+ let(:user) { build(:user) }
+ let(:context) { Sidebars::Context.new(current_user: user, container: organization) }
+ let(:items) { subject.instance_variable_get(:@items) }
+
+ subject { described_class.new(context) }
+
+ it 'has title and sprite_icon' do
+ expect(subject.title).to eq(_("Settings"))
+ expect(subject.sprite_icon).to eq("settings")
+ end
+
+ describe '#render?' do
+ context 'when user is signed out' do
+ let(:user) { nil }
+
+ it 'returns false' do
+ expect(subject.render?).to eq false
+ end
+ end
+
+ context 'when `current_user` is an admin', :enable_admin_mode do
+ let(:user) { build(:admin) }
+
+ it 'returns true' do
+ expect(subject.render?).to eq true
+ end
+ end
+
+ context 'when `current_user` not an admin' do
+ it 'returns false' do
+ expect(subject.render?).to eq false
+ end
+ end
+ end
+
+ describe 'Menu items' do
+ subject { described_class.new(context).renderable_items.find { |e| e.item_id == item_id } }
+
+ describe 'General' do
+ let(:item_id) { :organization_settings_general }
+
+ it { is_expected.not_to be_nil }
+ end
+ end
+end
diff --git a/spec/lib/sidebars/organizations/super_sidebar_panel_spec.rb b/spec/lib/sidebars/organizations/super_sidebar_panel_spec.rb
index b8ceda615c4..b9025b69926 100644
--- a/spec/lib/sidebars/organizations/super_sidebar_panel_spec.rb
+++ b/spec/lib/sidebars/organizations/super_sidebar_panel_spec.rb
@@ -22,7 +22,8 @@ RSpec.describe Sidebars::Organizations::SuperSidebarPanel, feature_category: :na
let(:category_menu) do
[
Sidebars::StaticMenu,
- Sidebars::Organizations::Menus::ManageMenu
+ Sidebars::Organizations::Menus::ManageMenu,
+ Sidebars::Organizations::Menus::SettingsMenu
]
end
diff --git a/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb b/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb
index 75f612e9c7c..3224c4cdd33 100644
--- a/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb
+++ b/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb
@@ -73,7 +73,7 @@ RSpec.describe Sidebars::Projects::Menus::DeploymentsMenu, feature_category: :na
let(:item_id) { :pages }
before do
- allow(project).to receive(:pages_available?).and_return(pages_enabled)
+ allow(::Gitlab::Pages).to receive(:enabled?).and_return(pages_enabled)
end
describe 'when pages are enabled' do
diff --git a/spec/lib/sidebars/projects/menus/settings_menu_spec.rb b/spec/lib/sidebars/projects/menus/settings_menu_spec.rb
index 605cec8be5e..81ca9670ac6 100644
--- a/spec/lib/sidebars/projects/menus/settings_menu_spec.rb
+++ b/spec/lib/sidebars/projects/menus/settings_menu_spec.rb
@@ -59,6 +59,18 @@ RSpec.describe Sidebars::Projects::Menus::SettingsMenu, feature_category: :navig
let(:item_id) { :access_tokens }
it_behaves_like 'access rights checks'
+
+ describe 'when the user is not an admin but has manage_resource_access_tokens' do
+ before do
+ allow(Ability).to receive(:allowed?).and_call_original
+ allow(Ability).to receive(:allowed?).with(user, :admin_project, project).and_return(false)
+ allow(Ability).to receive(:allowed?).with(user, :manage_resource_access_tokens, project).and_return(true)
+ end
+
+ it 'includes access token menu item' do
+ expect(subject.title).to eql('Access Tokens')
+ end
+ end
end
describe 'Repository' do