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 ...@@ -18,7 +18,11 @@ module Gitlab
def all_template_names def all_template_names
template_names = {} template_names = {}
namespace_template_projects_hash.flat_map do |namespace, project| 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 end
if instance_enabled? if instance_enabled?
......
...@@ -224,6 +224,16 @@ RSpec.describe Gitlab::CustomFileTemplates do ...@@ -224,6 +224,16 @@ RSpec.describe Gitlab::CustomFileTemplates do
end end
describe '#all_template_names' do 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 where(:template_finder, :type) do
Gitlab::Template::CustomDockerfileTemplate | :dockerfile Gitlab::Template::CustomDockerfileTemplate | :dockerfile
Gitlab::Template::CustomGitignoreTemplate | :gitignore Gitlab::Template::CustomGitignoreTemplate | :gitignore
...@@ -265,22 +275,42 @@ RSpec.describe Gitlab::CustomFileTemplates do ...@@ -265,22 +275,42 @@ RSpec.describe Gitlab::CustomFileTemplates do
end end
context 'in a subgroup' do context 'in a subgroup' do
let_it_be(:subgroup) { create(:group, parent: group) } let_it_be_with_reload(:subgroup) { create(:group, parent: group) }
let_it_be(:subproject) { create(:project, namespace: subgroup) } 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_it_be(:subgroup_template_project) { create(:project, :custom_repo, namespace: subgroup, files: template_files('subgroup')) }
let(:target_project) { subproject } let(:target_project) { subproject }
before do context 'with nested group templates' do
subgroup.update_columns(file_template_project_id: subgroup_template_project.id) before do
end subgroup.update_columns(file_template_project_id: subgroup_template_project.id)
end
it 'has the group names and instance as category' do it 'has the group names and instance as category' do
expect(template_categories).to eq(["Group #{subgroup.full_name}", "Group #{group.full_name}", "Instance"]) expect(template_categories).to eq(["Group #{subgroup.full_name}", "Group #{group.full_name}", "Instance"])
end
it 'orders results from most specific to least specific' do
expect(template_file_names).to eq(["subgroup_#{type}", "group_#{type}", "instance_#{type}"])
end
end end
it 'orders results from most specific to least specific' do context 'with templates missing for a nested group' do
expect(template_file_names).to eq(["subgroup_#{type}", "group_#{type}", "instance_#{type}"]) 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 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