diff options
Diffstat (limited to 'spec/lib/sidebars')
9 files changed, 122 insertions, 286 deletions
diff --git a/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb b/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb index 4a60dfde674..3149c316c63 100644 --- a/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/deployments_menu_spec.rb @@ -39,33 +39,22 @@ RSpec.describe Sidebars::Projects::Menus::DeploymentsMenu do end end - shared_examples 'feature flag :sidebar_refactor disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - specify { is_expected.to be_nil } - end - describe 'Feature Flags' do let(:item_id) { :feature_flags } it_behaves_like 'access rights checks' - it_behaves_like 'feature flag :sidebar_refactor disabled' end describe 'Environments' do let(:item_id) { :environments } it_behaves_like 'access rights checks' - it_behaves_like 'feature flag :sidebar_refactor disabled' end describe 'Releases' do let(:item_id) { :releases } it_behaves_like 'access rights checks' - it_behaves_like 'feature flag :sidebar_refactor disabled' end end end diff --git a/spec/lib/sidebars/projects/menus/infrastructure_menu_spec.rb b/spec/lib/sidebars/projects/menus/infrastructure_menu_spec.rb new file mode 100644 index 00000000000..2415598da9c --- /dev/null +++ b/spec/lib/sidebars/projects/menus/infrastructure_menu_spec.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::Projects::Menus::InfrastructureMenu do + let(:project) { build(:project) } + let(:user) { project.owner } + let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project, show_cluster_hint: false) } + + describe '#render?' do + subject { described_class.new(context) } + + context 'when menu does not have any 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 + + describe '#link' do + subject { described_class.new(context) } + + context 'when Kubernetes menu item is visible' do + it 'menu link points to Kubernetes page' do + expect(subject.link).to eq find_menu_item(:kubernetes).link + end + end + + context 'when Kubernetes menu item is not visible' do + before do + subject.renderable_items.delete(find_menu_item(:kubernetes)) + end + + it 'menu link points to Serverless page' do + expect(subject.link).to eq find_menu_item(:serverless).link + end + + context 'when Serverless menu is not visible' do + before do + subject.renderable_items.delete(find_menu_item(:serverless)) + end + + it 'menu link points to Terraform page' do + expect(subject.link).to eq find_menu_item(:terraform).link + end + end + end + + def find_menu_item(menu_item) + subject.renderable_items.find { |i| i.item_id == menu_item } + end + end + + describe '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 'Kubernetes' do + let(:item_id) { :kubernetes } + + it_behaves_like 'access rights checks' + end + + describe 'Serverless' do + let(:item_id) { :serverless } + + it_behaves_like 'access rights checks' + end + + describe 'Terraform' do + let(:item_id) { :terraform } + + it_behaves_like 'access rights checks' + end + end +end diff --git a/spec/lib/sidebars/projects/menus/issues_menu_spec.rb b/spec/lib/sidebars/projects/menus/issues_menu_spec.rb index ac62cd7594a..e5d486bbe8f 100644 --- a/spec/lib/sidebars/projects/menus/issues_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/issues_menu_spec.rb @@ -65,22 +65,4 @@ RSpec.describe Sidebars::Projects::Menus::IssuesMenu do end end end - - describe 'Menu Items' do - subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } } - - describe 'Labels' do - let(:item_id) { :labels } - - specify { is_expected.to be_nil } - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - specify { is_expected.not_to be_nil } - end - end - end end diff --git a/spec/lib/sidebars/projects/menus/labels_menu_spec.rb b/spec/lib/sidebars/projects/menus/labels_menu_spec.rb deleted file mode 100644 index e1420f9e61b..00000000000 --- a/spec/lib/sidebars/projects/menus/labels_menu_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Sidebars::Projects::Menus::LabelsMenu do - let(:project) { build(:project) } - let(:user) { project.owner } - let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) } - - subject { described_class.new(context) } - - it 'does not contain any sub menu' do - expect(subject.has_items?).to eq false - end - - describe '#render?' do - let(:issues_enabled) { true } - - before do - allow(project).to receive(:issues_enabled?).and_return(issues_enabled) - end - - context 'when feature flag :sidebar_refactor is enabled' do - let(:issues_enabled) { false } - - it 'returns false' do - expect(subject.render?).to be_falsey - end - end - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - context 'when user can read labels' do - context 'when issues feature is enabled' do - it 'returns false' do - expect(subject.render?).to be_falsey - end - end - - context 'when issues feature is disabled' do - let(:issues_enabled) { false } - - it 'returns true' do - expect(subject.render?).to be_truthy - end - end - end - - context 'when user cannot read labels' do - let(:user) { nil } - - it 'returns false' do - expect(subject.render?).to be_falsey - end - end - end - end -end diff --git a/spec/lib/sidebars/projects/menus/members_menu_spec.rb b/spec/lib/sidebars/projects/menus/members_menu_spec.rb deleted file mode 100644 index dcc085c2957..00000000000 --- a/spec/lib/sidebars/projects/menus/members_menu_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Sidebars::Projects::Menus::MembersMenu do - let(:project) { build(:project) } - let(:user) { project.owner } - let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) } - - subject { described_class.new(context) } - - describe '#render?' do - it 'returns false' do - expect(subject.render?).to eq false - end - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - it 'returns true' do - expect(subject.render?).to eq true - end - - context 'when user cannot access members' do - let(:user) { nil } - - it 'returns false' do - expect(subject.render?).to eq false - 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 93618fa3321..381842be5ab 100644 --- a/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/monitor_menu_spec.rb @@ -41,43 +41,30 @@ RSpec.describe Sidebars::Projects::Menus::MonitorMenu do it 'returns "Monitor"' do expect(subject.title).to eq 'Monitor' end - - context 'when feature flag :sidebar_refactor is disabled' do - it 'returns "Operations"' do - stub_feature_flags(sidebar_refactor: false) - - expect(subject.title).to eq 'Operations' - end - 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 - - context 'when feature flag :sidebar_refactor is disabled' do - it 'returns "shortcuts-operations"' do - stub_feature_flags(sidebar_refactor: false) - - expect(subject.extra_container_html_options).to eq(class: 'shortcuts-operations') - end - end end describe '#link' do - context 'when metrics dashboard is visible' do - it 'returns link to the metrics dashboard page' do - expect(subject.link).to include('/-/environments/metrics') - end + let(:foo_path) { '/foo_path'} + + let(:foo_menu) do + ::Sidebars::MenuItem.new( + title: 'foo', + link: foo_path, + active_routes: {}, + item_id: :foo + ) end - context 'when metrics dashboard is not visible' do - it 'returns link to the feature flags page' do - project.project_feature.update!(operations_access_level: Featurable::DISABLED) + 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 include('/-/feature_flags') - end + expect(subject.link).to eq foo_path end end @@ -130,76 +117,6 @@ RSpec.describe Sidebars::Projects::Menus::MonitorMenu do it_behaves_like 'access rights checks' end - describe 'Serverless' do - let(:item_id) { :serverless } - - specify { is_expected.to be_nil } - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - it_behaves_like 'access rights checks' - end - end - - describe 'Terraform' do - let(:item_id) { :terraform } - - specify { is_expected.to be_nil } - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - it_behaves_like 'access rights checks' - end - end - - describe 'Kubernetes' do - let(:item_id) { :kubernetes } - - specify { is_expected.to be_nil } - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - it_behaves_like 'access rights checks' - end - end - - describe 'Environments' do - let(:item_id) { :environments } - - specify { is_expected.to be_nil } - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - it_behaves_like 'access rights checks' - end - end - - describe 'Feature Flags' do - let(:item_id) { :feature_flags } - - specify { is_expected.to be_nil } - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - it_behaves_like 'access rights checks' - end - end - describe 'Product Analytics' do let(:item_id) { :product_analytics } diff --git a/spec/lib/sidebars/projects/menus/project_information_menu_spec.rb b/spec/lib/sidebars/projects/menus/project_information_menu_spec.rb index 748796bc7ee..7e8d0ab0518 100644 --- a/spec/lib/sidebars/projects/menus/project_information_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/project_information_menu_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Sidebars::Projects::Menus::ProjectInformationMenu do - let_it_be(:project) { create(:project, :repository) } + let_it_be_with_reload(:project) { create(:project, :repository) } let(:user) { project.owner } let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) } @@ -12,59 +12,36 @@ RSpec.describe Sidebars::Projects::Menus::ProjectInformationMenu do subject { described_class.new(context).container_html_options } specify { is_expected.to match(hash_including(class: 'shortcuts-project-information has-sub-items')) } - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - specify { is_expected.to match(hash_including(class: 'shortcuts-project rspec-project-link has-sub-items')) } - end end describe 'Menu Items' do subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } } - describe 'Releases' do - let(:item_id) { :releases } + describe 'Labels' do + let(:item_id) { :labels } - specify { is_expected.to be_nil } + specify { is_expected.not_to be_nil } - context 'when feature flag :sidebar_refactor is disabled' do + context 'when merge requests are disabled' do before do - stub_feature_flags(sidebar_refactor: false) + project.project_feature.update_attribute(:merge_requests_access_level, Featurable::DISABLED) end - context 'when project repository is empty' do - it 'does not include releases menu item' do - allow(project).to receive(:empty_repo?).and_return(true) + specify { is_expected.not_to be_nil } + end - is_expected.to be_nil - end + context 'when issues are disabled' do + before do + project.project_feature.update_attribute(:issues_access_level, Featurable::DISABLED) end - context 'when project repository is not empty' do - context 'when user can download code' do - specify { is_expected.not_to be_nil } - end - - context 'when user cannot download code' do - let(:user) { nil } - - specify { is_expected.to be_nil } - end - end + specify { is_expected.not_to be_nil } end - end - - describe 'Labels' do - let(:item_id) { :labels } - - specify { is_expected.not_to be_nil } - context 'when feature flag :sidebar_refactor is disabled' do + context 'when merge requests and issues are disabled' do before do - stub_feature_flags(sidebar_refactor: false) + project.project_feature.update_attribute(:merge_requests_access_level, Featurable::DISABLED) + project.project_feature.update_attribute(:issues_access_level, Featurable::DISABLED) end specify { is_expected.to be_nil } @@ -76,10 +53,8 @@ RSpec.describe Sidebars::Projects::Menus::ProjectInformationMenu do specify { is_expected.not_to be_nil } - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end + describe 'when the user does not have access' do + let(:user) { nil } specify { is_expected.to be_nil } end diff --git a/spec/lib/sidebars/projects/menus/scope_menu_spec.rb b/spec/lib/sidebars/projects/menus/scope_menu_spec.rb index f84d458a2e1..5040ef9b0ff 100644 --- a/spec/lib/sidebars/projects/menus/scope_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/scope_menu_spec.rb @@ -11,13 +11,5 @@ RSpec.describe Sidebars::Projects::Menus::ScopeMenu do subject { described_class.new(context).container_html_options } specify { is_expected.to match(hash_including(class: 'shortcuts-project rspec-project-link')) } - - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - specify { is_expected.to eq(aria: { label: project.name }) } - end end end diff --git a/spec/lib/sidebars/projects/menus/settings_menu_spec.rb b/spec/lib/sidebars/projects/menus/settings_menu_spec.rb index 6817f0e6ed6..9b79614db20 100644 --- a/spec/lib/sidebars/projects/menus/settings_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/settings_menu_spec.rb @@ -99,14 +99,6 @@ RSpec.describe Sidebars::Projects::Menus::SettingsMenu do specify { expect(subject.title).to eq 'Monitor' } - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - specify { expect(subject.title).to eq 'Operations' } - end - describe 'when the user does not have access' do let(:user) { nil } @@ -159,14 +151,6 @@ RSpec.describe Sidebars::Projects::Menus::SettingsMenu do specify { is_expected.not_to be_nil } - context 'when feature flag :sidebar_refactor is disabled' do - before do - stub_feature_flags(sidebar_refactor: false) - end - - specify { is_expected.to be_nil } - end - describe 'when the user does not have access' do let(:user) { nil } |