debian-mirror-gitlab/spec/features/projects/ci/lint_spec.rb

126 lines
3.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'CI Lint', :js do
2020-11-24 15:15:51 +05:30
include Spec::Support::Helpers::Features::EditorLiteSpecHelpers
2018-05-09 12:01:36 +05:30
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
2020-11-24 15:15:51 +05:30
shared_examples 'correct ci linting process' do
describe 'YAML parsing' do
shared_examples 'validates the YAML' do
before do
stub_feature_flags(ci_lint_vue: false)
click_on 'Validate'
end
2018-03-27 19:54:05 +05:30
2020-11-24 15:15:51 +05:30
context 'YAML is correct' do
let(:yaml_content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
2020-11-24 15:15:51 +05:30
it 'parses Yaml and displays the jobs' do
expect(page).to have_content('Status: syntax is correct')
2020-11-24 15:15:51 +05:30
within "table" do
aggregate_failures do
expect(page).to have_content('Job - rspec')
expect(page).to have_content('Job - spinach')
expect(page).to have_content('Deploy Job - staging')
expect(page).to have_content('Deploy Job - production')
end
end
end
2020-10-24 23:57:45 +05:30
end
2020-11-24 15:15:51 +05:30
context 'YAML is incorrect' do
let(:yaml_content) { 'value: cannot have :' }
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
it 'displays information about an error' do
expect(page).to have_content('Status: syntax is incorrect')
expect(page).to have_selector(content_selector, text: yaml_content)
2020-10-24 23:57:45 +05:30
end
end
end
2020-11-24 15:15:51 +05:30
it_behaves_like 'validates the YAML'
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
context 'when Dry Run is checked' do
before do
check 'Simulate a pipeline created for the default branch'
end
2020-11-24 15:15:51 +05:30
it_behaves_like 'validates the YAML'
end
2020-11-24 15:15:51 +05:30
describe 'YAML revalidate' do
let(:yaml_content) { 'my yaml content' }
2020-11-24 15:15:51 +05:30
it 'loads previous YAML content after validation' do
expect(page).to have_field('content', with: 'my yaml content', visible: false, type: 'textarea')
end
end
end
describe 'YAML clearing' do
2020-10-24 23:57:45 +05:30
before do
2020-11-24 15:15:51 +05:30
click_on 'Clear'
end
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
context 'YAML is present' do
let(:yaml_content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
it 'YAML content is cleared' do
expect(page).to have_field('content', with: '', visible: false, type: 'textarea')
end
end
end
2020-11-24 15:15:51 +05:30
end
2020-11-24 15:15:51 +05:30
context 'with ACE editor' do
it_behaves_like 'correct ci linting process' do
let(:content_selector) { '.ace_content' }
2020-11-24 15:15:51 +05:30
before do
stub_feature_flags(monaco_ci: false)
stub_feature_flags(ci_lint_vue: false)
project.add_developer(user)
sign_in(user)
visit project_ci_lint_path(project)
find('#ci-editor')
execute_script("ace.edit('ci-editor').setValue(#{yaml_content.to_json});")
# Ace editor updates a hidden textarea and it happens asynchronously
wait_for('YAML content') do
find(content_selector).text.present?
end
end
end
end
2018-03-27 19:54:05 +05:30
2020-11-24 15:15:51 +05:30
context 'with Editor Lite' do
it_behaves_like 'correct ci linting process' do
let(:content_selector) { '.content .view-lines' }
2018-03-27 19:54:05 +05:30
2020-11-24 15:15:51 +05:30
before do
stub_feature_flags(monaco_ci: true)
stub_feature_flags(ci_lint_vue: false)
project.add_developer(user)
sign_in(user)
2018-03-27 19:54:05 +05:30
2020-11-24 15:15:51 +05:30
visit project_ci_lint_path(project)
editor_set_value(yaml_content)
wait_for('YAML content') do
find(content_selector).text.present?
end
2018-03-27 19:54:05 +05:30
end
end
end
end