2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Ci::PipelineEditorHelper do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
describe 'can_view_pipeline_editor?' do
|
|
|
|
subject { helper.can_view_pipeline_editor?(project) }
|
|
|
|
|
|
|
|
it 'user can view editor if they can collaborate' do
|
|
|
|
allow(helper).to receive(:can_collaborate_with_project?).and_return(true)
|
|
|
|
|
|
|
|
expect(subject).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user can not view editor if they cannot collaborate' do
|
|
|
|
allow(helper).to receive(:can_collaborate_with_project?).and_return(false)
|
|
|
|
|
|
|
|
expect(subject).to be false
|
|
|
|
end
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
describe '#js_pipeline_editor_data' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper)
|
|
|
|
.to receive(:namespace_project_new_merge_request_path)
|
|
|
|
.and_return('/mock/project/-/merge_requests/new')
|
|
|
|
|
|
|
|
allow(helper)
|
|
|
|
.to receive(:image_path)
|
|
|
|
.and_return('foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:pipeline_editor_data) { helper.js_pipeline_editor_data(project) }
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'with a project with commits' do
|
|
|
|
it 'returns pipeline editor data' do
|
|
|
|
expect(pipeline_editor_data).to eq({
|
|
|
|
"ci-config-path": project.ci_config_path_or_default,
|
2021-09-30 23:02:18 +05:30
|
|
|
"ci-examples-help-page-path" => help_page_path('ci/examples/index'),
|
|
|
|
"ci-help-page-path" => help_page_path('ci/index'),
|
|
|
|
"default-branch" => project.default_branch_or_main,
|
2021-06-08 01:23:25 +05:30
|
|
|
"empty-state-illustration-path" => 'foo',
|
2021-09-30 23:02:18 +05:30
|
|
|
"initial-branch-name" => nil,
|
2022-06-21 17:19:12 +05:30
|
|
|
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'check-cicd-syntax'),
|
|
|
|
"lint-unavailable-help-page-path" => help_page_path('ci/pipeline_editor/index', anchor: 'configuration-validation-currently-not-available-message'),
|
2021-10-27 15:23:28 +05:30
|
|
|
"needs-help-page-path" => help_page_path('ci/yaml/index', anchor: 'needs'),
|
2021-06-08 01:23:25 +05:30
|
|
|
"new-merge-request-path" => '/mock/project/-/merge_requests/new',
|
|
|
|
"pipeline_etag" => graphql_etag_pipeline_sha_path(project.commit.sha),
|
|
|
|
"pipeline-page-path" => project_pipelines_path(project),
|
|
|
|
"project-path" => project.path,
|
|
|
|
"project-full-path" => project.full_path,
|
|
|
|
"project-namespace" => project.namespace.full_path,
|
2021-09-30 23:02:18 +05:30
|
|
|
"runner-help-page-path" => help_page_path('ci/runners/index'),
|
2021-06-08 01:23:25 +05:30
|
|
|
"total-branches" => project.repository.branches.length,
|
2021-10-27 15:23:28 +05:30
|
|
|
"yml-help-page-path" => help_page_path('ci/yaml/index')
|
2021-06-08 01:23:25 +05:30
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an empty project' do
|
|
|
|
let(:project) { create(:project, :empty_repo) }
|
|
|
|
|
|
|
|
it 'returns pipeline editor data' do
|
|
|
|
expect(pipeline_editor_data).to eq({
|
|
|
|
"ci-config-path": project.ci_config_path_or_default,
|
2021-09-30 23:02:18 +05:30
|
|
|
"ci-examples-help-page-path" => help_page_path('ci/examples/index'),
|
|
|
|
"ci-help-page-path" => help_page_path('ci/index'),
|
|
|
|
"default-branch" => project.default_branch_or_main,
|
2021-06-08 01:23:25 +05:30
|
|
|
"empty-state-illustration-path" => 'foo',
|
2021-09-30 23:02:18 +05:30
|
|
|
"initial-branch-name" => nil,
|
2022-06-21 17:19:12 +05:30
|
|
|
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'check-cicd-syntax'),
|
|
|
|
"lint-unavailable-help-page-path" => help_page_path('ci/pipeline_editor/index', anchor: 'configuration-validation-currently-not-available-message'),
|
2021-10-27 15:23:28 +05:30
|
|
|
"needs-help-page-path" => help_page_path('ci/yaml/index', anchor: 'needs'),
|
2021-06-08 01:23:25 +05:30
|
|
|
"new-merge-request-path" => '/mock/project/-/merge_requests/new',
|
|
|
|
"pipeline_etag" => '',
|
|
|
|
"pipeline-page-path" => project_pipelines_path(project),
|
|
|
|
"project-path" => project.path,
|
|
|
|
"project-full-path" => project.full_path,
|
|
|
|
"project-namespace" => project.namespace.full_path,
|
2021-09-30 23:02:18 +05:30
|
|
|
"runner-help-page-path" => help_page_path('ci/runners/index'),
|
2021-06-08 01:23:25 +05:30
|
|
|
"total-branches" => 0,
|
2021-10-27 15:23:28 +05:30
|
|
|
"yml-help-page-path" => help_page_path('ci/yaml/index')
|
2021-06-08 01:23:25 +05:30
|
|
|
})
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
context 'with a project with no repository' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
it 'returns pipeline editor data' do
|
|
|
|
expect(pipeline_editor_data).to include({
|
|
|
|
"pipeline_etag" => '',
|
|
|
|
"total-branches" => 0
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
context 'with a non-default branch name' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create_commit('Message', project, user, 'feature')
|
|
|
|
controller.params[:branch_name] = 'feature'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct values' do
|
|
|
|
expect(pipeline_editor_data['initial-branch-name']).to eq('feature')
|
|
|
|
end
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|