Commit 361f68fe authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '323471-do-not-list-empty-categories' into 'master'

Skip group categories with no templates

See merge request gitlab-org/gitlab!55762
parents 72770374 9e479213
---
title: Do not display empty description template lists in the dropdown
merge_request: 55762
author:
type: fixed
......@@ -18,7 +18,11 @@ module Gitlab
def all_template_names
template_names = {}
namespace_template_projects_hash.flat_map do |namespace, project|
template_names[category_for(namespace)] = template_names_for(project).values.flatten
project_template_names = template_names_for(project).values.flatten
next if project_template_names.blank?
template_names[category_for(namespace)] = project_template_names
end
if instance_enabled?
......
......@@ -224,6 +224,16 @@ RSpec.describe Gitlab::CustomFileTemplates do
end
describe '#all_template_names' do
RSpec.shared_examples 'does not list an empty category' do
it 'misses subgroup category' do
expect(template_categories).to eq(["Group #{group.full_name}", "Instance"])
end
it 'misses subgroup templates' do
expect(template_file_names).to eq(["group_#{type}", "instance_#{type}"])
end
end
where(:template_finder, :type) do
Gitlab::Template::CustomDockerfileTemplate | :dockerfile
Gitlab::Template::CustomGitignoreTemplate | :gitignore
......@@ -265,12 +275,13 @@ RSpec.describe Gitlab::CustomFileTemplates do
end
context 'in a subgroup' do
let_it_be(:subgroup) { create(:group, parent: group) }
let_it_be(:subproject) { create(:project, namespace: subgroup) }
let_it_be_with_reload(:subgroup) { create(:group, parent: group) }
let_it_be_with_reload(:subproject) { create(:project, namespace: subgroup) }
let_it_be(:subgroup_template_project) { create(:project, :custom_repo, namespace: subgroup, files: template_files('subgroup')) }
let(:target_project) { subproject }
context 'with nested group templates' do
before do
subgroup.update_columns(file_template_project_id: subgroup_template_project.id)
end
......@@ -283,6 +294,25 @@ RSpec.describe Gitlab::CustomFileTemplates do
expect(template_file_names).to eq(["subgroup_#{type}", "group_#{type}", "instance_#{type}"])
end
end
context 'with templates missing for a nested group' do
context 'when subgroup template config points to a project that has no templates' do
before do
subgroup.update_columns(file_template_project_id: subproject.id)
end
it_behaves_like 'does not list an empty category'
end
context 'when subgroup template config is not setup' do
before do
subgroup.update_columns(file_template_project_id: nil)
end
it_behaves_like 'does not list an empty category'
end
end
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment