2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
|
|
|
|
include_context 'project issuable templates context'
|
|
|
|
|
|
|
|
describe '#issuable_templates' do
|
|
|
|
let_it_be(:inherited_from) { nil }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:parent_group, reload: true) { create(:group) }
|
|
|
|
let_it_be(:project, reload: true) { create(:project, :custom_repo, files: issuable_template_files) }
|
|
|
|
let_it_be(:group_member) { create(:group_member, :developer, group: parent_group, user: user) }
|
|
|
|
let_it_be(:project_member) { create(:project_member, :developer, user: user, project: project) }
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'returns empty hash when template type does not exist' do
|
|
|
|
expect(helper.issuable_templates(build(:project), 'non-existent-template-type')).to eq({})
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
context 'with cached issuable templates' do
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'does not call TemplateFinder' do
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(Gitlab::Template::IssueTemplate).to receive(:template_names).once.and_call_original
|
|
|
|
expect(Gitlab::Template::MergeRequestTemplate).to receive(:template_names).once.and_call_original
|
|
|
|
|
|
|
|
helper.issuable_templates(project, 'issues')
|
|
|
|
helper.issuable_templates(project, 'merge_request')
|
2021-03-11 19:13:27 +05:30
|
|
|
helper.issuable_templates(project, 'issues')
|
|
|
|
helper.issuable_templates(project, 'merge_request')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project has no parent group' do
|
|
|
|
it_behaves_like 'project issuable templates'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project has parent group' do
|
|
|
|
before do
|
|
|
|
project.update!(group: parent_group)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project parent group does not have a file template project' do
|
|
|
|
it_behaves_like 'project issuable templates'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#issuable_templates_names' do
|
2021-04-17 20:07:23 +05:30
|
|
|
let_it_be(:project) { build(:project) }
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
before do
|
2021-03-11 19:13:27 +05:30
|
|
|
allow(helper).to receive(:ref_project).and_return(project)
|
|
|
|
allow(helper).to receive(:issuable_templates).and_return(templates)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
context 'with project templates' do
|
2021-04-17 20:07:23 +05:30
|
|
|
let(:templates) do
|
2021-09-04 01:27:46 +05:30
|
|
|
{
|
|
|
|
"" => [
|
2021-10-27 15:23:28 +05:30
|
|
|
{ name: "another_issue_template", id: "another_issue_template" },
|
|
|
|
{ name: "custom_issue_template", id: "custom_issue_template" }
|
2021-09-04 01:27:46 +05:30
|
|
|
]
|
|
|
|
}
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns project templates only' do
|
|
|
|
expect(helper.issuable_templates_names(Issue.new)).to eq(%w[another_issue_template custom_issue_template])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
context 'without matching project templates' do
|
|
|
|
let(:templates) do
|
|
|
|
{
|
|
|
|
"Project Templates" => [
|
|
|
|
{ name: "another_issue_template", id: "another_issue_template", project_id: non_existing_record_id },
|
|
|
|
{ name: "custom_issue_template", id: "custom_issue_template", project_id: non_existing_record_id }
|
|
|
|
]
|
|
|
|
}
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'returns empty array' do
|
|
|
|
expect(helper.issuable_templates_names(Issue.new)).to eq([])
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are not templates in the project' do
|
|
|
|
let(:templates) { {} }
|
|
|
|
|
|
|
|
it 'returns empty array' do
|
|
|
|
expect(helper.issuable_templates_names(Issue.new)).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|