diff options
Diffstat (limited to 'spec/lib/sidebars/projects/menus')
4 files changed, 81 insertions, 80 deletions
diff --git a/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb b/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb index 685ba0c31c7..ce971915174 100644 --- a/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb @@ -47,44 +47,16 @@ RSpec.describe Sidebars::Projects::Menus::DeploymentsMenu do end end - shared_examples 'split_operations_visibility_permissions FF disabled' do - before do - stub_feature_flags(split_operations_visibility_permissions: false) - end - - it { is_expected.not_to be_nil } - - context 'and the feature is disabled' do - before do - project.update_attribute("#{item_id}_access_level", 'disabled') - end - - it { is_expected.not_to be_nil } - end - - context 'and operations is disabled' do - before do - project.update_attribute(:operations_access_level, 'disabled') - end - - it do - is_expected.to be_nil if [:environments, :feature_flags].include?(item_id) - end - end - end - describe 'Feature Flags' do let(:item_id) { :feature_flags } it_behaves_like 'access rights checks' - it_behaves_like 'split_operations_visibility_permissions FF disabled' end describe 'Environments' do let(:item_id) { :environments } it_behaves_like 'access rights checks' - it_behaves_like 'split_operations_visibility_permissions FF disabled' end describe 'Releases' do diff --git a/spec/lib/sidebars/projects/menus/infrastructure_menu_spec.rb b/spec/lib/sidebars/projects/menus/infrastructure_menu_spec.rb index 64408ac3b88..116948b7cb0 100644 --- a/spec/lib/sidebars/projects/menus/infrastructure_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/infrastructure_menu_spec.rb @@ -31,43 +31,18 @@ RSpec.describe Sidebars::Projects::Menus::InfrastructureMenu do let(:enabled) { Featurable::PRIVATE } let(:disabled) { Featurable::DISABLED } - where(:operations_access_level, :infrastructure_access_level, :render) do - ref(:disabled) | ref(:enabled) | true - ref(:disabled) | ref(:disabled) | false - ref(:enabled) | ref(:enabled) | true - ref(:enabled) | ref(:disabled) | false + where(:infrastructure_access_level, :render) do + ref(:enabled) | true + ref(:disabled) | false end with_them do it 'renders based on the infrastructure access level' do - project.project_feature.update!(operations_access_level: operations_access_level) project.project_feature.update!(infrastructure_access_level: infrastructure_access_level) expect(subject.render?).to be render end end - - context 'when `split_operations_visibility_permissions` feature flag is disabled' do - before do - stub_feature_flags(split_operations_visibility_permissions: false) - end - - where(:operations_access_level, :infrastructure_access_level, :render) do - ref(:disabled) | ref(:enabled) | false - ref(:disabled) | ref(:disabled) | false - ref(:enabled) | ref(:enabled) | true - ref(:enabled) | ref(:disabled) | true - end - - with_them do - it 'renders based on the operations access level' do - project.project_feature.update!(operations_access_level: operations_access_level) - project.project_feature.update!(infrastructure_access_level: infrastructure_access_level) - - expect(subject.render?).to be render - end - end - end end end diff --git a/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb b/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb index f6a8dd7367d..a1e6ae13e68 100644 --- a/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb @@ -16,40 +16,30 @@ RSpec.describe Sidebars::Projects::Menus::MonitorMenu do let(:enabled) { Featurable::PRIVATE } let(:disabled) { Featurable::DISABLED } - where(:flag_enabled, :operations_access_level, :monitor_level, :render) do - true | ref(:disabled) | ref(:enabled) | true - true | ref(:disabled) | ref(:disabled) | false - true | ref(:enabled) | ref(:enabled) | true - true | ref(:enabled) | ref(:disabled) | false - false | ref(:disabled) | ref(:enabled) | false - false | ref(:disabled) | ref(:disabled) | false - false | ref(:enabled) | ref(:enabled) | true - false | ref(:enabled) | ref(:disabled) | true + where(:monitor_level, :render) do + ref(:enabled) | true + ref(:disabled) | false end with_them do it 'renders when expected to' do - stub_feature_flags(split_operations_visibility_permissions: flag_enabled) - project.project_feature.update!(operations_access_level: operations_access_level) project.project_feature.update!(monitor_access_level: monitor_level) expect(subject.render?).to be render 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) + 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 + 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 + context 'when menu has menu items' do + it 'returns true' do + expect(subject.render?).to be true end end end diff --git a/spec/lib/sidebars/projects/menus/repository_menu_spec.rb b/spec/lib/sidebars/projects/menus/repository_menu_spec.rb index f26433306b6..e7aa2b7edca 100644 --- a/spec/lib/sidebars/projects/menus/repository_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/repository_menu_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Sidebars::Projects::Menus::RepositoryMenu do +RSpec.describe Sidebars::Projects::Menus::RepositoryMenu, feature_category: :source_code_management do let_it_be(:project) { create(:project, :repository) } let(:user) { project.first_owner } @@ -36,12 +36,68 @@ RSpec.describe Sidebars::Projects::Menus::RepositoryMenu do end context 'for menu items' do - subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } } + shared_examples_for 'repository menu item link for' do |item_id| + let(:ref) { 'master' } + let(:item_id) { item_id } + subject { described_class.new(context).renderable_items.find { |e| e.item_id == item_id }.link } + + using RSpec::Parameterized::TableSyntax + + let(:context) do + Sidebars::Projects::Context.new(current_user: user, container: project, current_ref: ref, + ref_type: ref_type) + end + + where(:feature_flag_enabled, :ref_type, :link) do + true | nil | lazy { "#{route}?ref_type=heads" } + true | 'heads' | lazy { "#{route}?ref_type=heads" } + true | 'tags' | lazy { "#{route}?ref_type=tags" } + false | nil | lazy { route } + false | 'heads' | lazy { route } + false | 'tags' | lazy { route } + end + + with_them do + before do + stub_feature_flags(use_ref_type_parameter: feature_flag_enabled) + end + + it 'has a link with the fully qualifed ref route' do + expect(subject).to eq(link) + end + end + + context 'when ref is not the default' do + let(:ref) { 'nonmain' } + + context 'and ref_type is not provided' do + let(:ref_type) { nil } + + it { is_expected.to eq(route) } + end + + context 'and ref_type is provided' do + let(:ref_type) { 'heads' } + + it { is_expected.to eq("#{route}?ref_type=heads") } + end + end + end + + describe 'Commits' do + let_it_be(:item_id) { :commits } + + it_behaves_like 'repository menu item link for', :commits do + let(:route) { "/#{project.full_path}/-/commits/#{ref}" } + end + end describe 'Contributors' do let_it_be(:item_id) { :contributors } context 'when analytics is disabled' do + subject { described_class.new(context).renderable_items.find { |e| e.item_id == item_id } } + before do project.project_feature.update!(analytics_access_level: ProjectFeature::DISABLED) end @@ -54,7 +110,15 @@ RSpec.describe Sidebars::Projects::Menus::RepositoryMenu do project.project_feature.update!(analytics_access_level: ProjectFeature::ENABLED) end - it { is_expected.not_to be_nil } + it_behaves_like 'repository menu item link for', :contributors do + let(:route) { "/#{project.full_path}/-/graphs/#{ref}" } + end + end + end + + describe 'Network' do + it_behaves_like 'repository menu item link for', :graphs do + let(:route) { "/#{project.full_path}/-/network/#{ref}" } end end end |