Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lint_spec.rb « ci « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ce435151b8464dcc443f3a6b5a43a37688046468 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'CI Lint', :js do
  include Spec::Support::Helpers::Features::EditorLiteSpecHelpers

  let(:project) { create(:project, :repository) }
  let(:user) { create(:user) }

  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

        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
        end

        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(content_selector, text: yaml_content)
          end
        end
      end

      it_behaves_like 'validates the YAML'

      context 'when Dry Run is checked' do
        before do
          check 'Simulate a pipeline created for the default branch'
        end

        it_behaves_like 'validates the YAML'
      end

      describe 'YAML revalidate' do
        let(:yaml_content) { 'my yaml content' }

        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
      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
  end

  context 'with ACE editor' do
    it_behaves_like 'correct ci linting process' do
      let(:content_selector) { '.ace_content' }

      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

  context 'with Editor Lite' do
    it_behaves_like 'correct ci linting process' do
      let(:content_selector) { '.content .view-lines' }

      before do
        stub_feature_flags(monaco_ci: true)
        stub_feature_flags(ci_lint_vue: false)
        project.add_developer(user)
        sign_in(user)

        visit project_ci_lint_path(project)
        editor_set_value(yaml_content)

        wait_for('YAML content') do
          find(content_selector).text.present?
        end
      end
    end
  end
end