2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'CI Lint', :js do
|
2018-03-13 13:57:16 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
before do
|
2018-03-13 13:57:16 -04:00
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
2018-02-08 11:14:31 -05:00
|
|
|
|
2018-03-13 13:57:16 -04:00
|
|
|
visit project_ci_lint_path(project)
|
2018-02-08 11:14:31 -05:00
|
|
|
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('.ace_content').text.present?
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2015-12-22 03:40:32 -05:00
|
|
|
describe 'YAML parsing' do
|
2020-08-12 11:10:02 -04:00
|
|
|
shared_examples 'validates the YAML' do
|
|
|
|
before do
|
|
|
|
click_on 'Validate'
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2020-08-12 11:10:02 -04:00
|
|
|
context 'YAML is correct' do
|
|
|
|
let(:yaml_content) do
|
|
|
|
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'parses Yaml and displays the jobs' do
|
|
|
|
expect(page).to have_content('Status: syntax is correct')
|
|
|
|
|
|
|
|
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
|
2015-12-22 02:47:23 -05:00
|
|
|
end
|
|
|
|
|
2020-08-12 11:10:02 -04:00
|
|
|
context 'YAML is incorrect' do
|
|
|
|
let(:yaml_content) { 'value: cannot have :' }
|
|
|
|
|
|
|
|
it 'displays information about an error' do
|
|
|
|
expect(page).to have_content('Status: syntax is incorrect')
|
|
|
|
expect(page).to have_selector('.ace_content', text: yaml_content)
|
2015-12-22 02:47:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-12 11:10:02 -04:00
|
|
|
it_behaves_like 'validates the YAML'
|
2015-12-22 02:47:23 -05:00
|
|
|
|
2020-08-12 11:10:02 -04:00
|
|
|
context 'when Dry Run is checked' do
|
|
|
|
before do
|
|
|
|
check 'Simulate a pipeline created for the default branch'
|
2015-12-22 02:47:23 -05:00
|
|
|
end
|
2020-08-12 11:10:02 -04:00
|
|
|
|
|
|
|
it_behaves_like 'validates the YAML'
|
2015-12-22 02:47:23 -05:00
|
|
|
end
|
2016-01-11 07:34:12 -05:00
|
|
|
|
|
|
|
describe 'YAML revalidate' do
|
|
|
|
let(:yaml_content) { 'my yaml content' }
|
|
|
|
|
|
|
|
it 'loads previous YAML content after validation' do
|
2017-01-04 16:44:16 -05:00
|
|
|
expect(page).to have_field('content', with: 'my yaml content', visible: false, type: 'textarea')
|
2016-01-11 07:34:12 -05:00
|
|
|
end
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
2018-02-08 11:14:31 -05:00
|
|
|
|
|
|
|
describe 'YAML clearing' do
|
|
|
|
before do
|
|
|
|
click_on 'Clear'
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|