2020-10-30 08:08:44 -04:00
|
|
|
# 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-09 11:09:10 -04:00
|
|
|
|
|
|
|
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-05-04 14:10:03 -04:00
|
|
|
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-06-28 08:38:12 -04:00
|
|
|
"ci-examples-help-page-path" => help_page_path('ci/examples/index'),
|
2021-06-28 11:08:03 -04:00
|
|
|
"ci-help-page-path" => help_page_path('ci/index'),
|
2021-05-04 14:10:03 -04:00
|
|
|
"commit-sha" => project.commit.sha,
|
|
|
|
"default-branch" => project.default_branch,
|
|
|
|
"empty-state-illustration-path" => 'foo',
|
|
|
|
"initial-branch-name": nil,
|
|
|
|
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'),
|
2021-05-11 11:10:20 -04:00
|
|
|
"needs-help-page-path" => help_page_path('ci/yaml/README', anchor: 'needs'),
|
2021-05-04 14:10:03 -04:00
|
|
|
"new-merge-request-path" => '/mock/project/-/merge_requests/new',
|
|
|
|
"pipeline_etag" => graphql_etag_pipeline_sha_path(project.commit.sha),
|
2021-05-11 11:10:20 -04:00
|
|
|
"pipeline-page-path" => project_pipelines_path(project),
|
2021-05-04 14:10:03 -04:00
|
|
|
"project-path" => project.path,
|
|
|
|
"project-full-path" => project.full_path,
|
|
|
|
"project-namespace" => project.namespace.full_path,
|
2021-06-28 08:38:12 -04:00
|
|
|
"runner-help-page-path" => help_page_path('ci/runners/index'),
|
2021-05-13 14:10:32 -04:00
|
|
|
"total-branches" => project.repository.branches.length,
|
2021-05-04 14:10:03 -04:00
|
|
|
"yml-help-page-path" => help_page_path('ci/yaml/README')
|
|
|
|
})
|
|
|
|
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-06-28 08:38:12 -04:00
|
|
|
"ci-examples-help-page-path" => help_page_path('ci/examples/index'),
|
2021-06-28 11:08:03 -04:00
|
|
|
"ci-help-page-path" => help_page_path('ci/index'),
|
2021-05-04 14:10:03 -04:00
|
|
|
"commit-sha" => '',
|
|
|
|
"default-branch" => project.default_branch,
|
|
|
|
"empty-state-illustration-path" => 'foo',
|
|
|
|
"initial-branch-name": nil,
|
|
|
|
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'),
|
2021-05-11 11:10:20 -04:00
|
|
|
"needs-help-page-path" => help_page_path('ci/yaml/README', anchor: 'needs'),
|
2021-05-04 14:10:03 -04:00
|
|
|
"new-merge-request-path" => '/mock/project/-/merge_requests/new',
|
|
|
|
"pipeline_etag" => '',
|
2021-05-11 11:10:20 -04:00
|
|
|
"pipeline-page-path" => project_pipelines_path(project),
|
2021-05-04 14:10:03 -04:00
|
|
|
"project-path" => project.path,
|
|
|
|
"project-full-path" => project.full_path,
|
|
|
|
"project-namespace" => project.namespace.full_path,
|
2021-06-28 08:38:12 -04:00
|
|
|
"runner-help-page-path" => help_page_path('ci/runners/index'),
|
2021-05-13 14:10:32 -04:00
|
|
|
"total-branches" => 0,
|
2021-05-04 14:10:03 -04:00
|
|
|
"yml-help-page-path" => help_page_path('ci/yaml/README')
|
|
|
|
})
|
|
|
|
end
|
2021-04-09 11:09:10 -04:00
|
|
|
end
|
|
|
|
end
|
2020-10-30 08:08:44 -04:00
|
|
|
end
|