diff options
Diffstat (limited to 'spec/lib/sidebars/projects/menus/repository_menu_spec.rb')
-rw-r--r-- | spec/lib/sidebars/projects/menus/repository_menu_spec.rb | 70 |
1 files changed, 67 insertions, 3 deletions
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 |