BigW Consortium Gitlab

pipeline_spec.rb 8.07 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Pipeline', :feature, :js do
4 5 6 7 8 9 10 11 12 13
  include GitlabRoutingHelper

  let(:project) { create(:empty_project) }
  let(:user) { create(:user) }

  before do
    login_as(user)
    project.team << [user, :developer]
  end

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
  shared_context 'pipeline builds' do
    let!(:build_passed) do
      create(:ci_build, :success,
             pipeline: pipeline, stage: 'build', name: 'build')
    end

    let!(:build_failed) do
      create(:ci_build, :failed,
             pipeline: pipeline, stage: 'test', name: 'test', commands: 'test')
    end

    let!(:build_running) do
      create(:ci_build, :running,
             pipeline: pipeline, stage: 'deploy', name: 'deploy')
    end

    let!(:build_manual) do
      create(:ci_build, :manual,
             pipeline: pipeline, stage: 'deploy', name: 'manual-build')
    end

    let!(:build_external) do
      create(:generic_commit_status, status: 'success',
                                     pipeline: pipeline,
                                     name: 'jenkins',
39 40
                                     stage: 'external',
                                     target_url: 'http://gitlab.com/status')
41 42 43
    end
  end

44
  describe 'GET /:project/pipelines/:id' do
45 46
    include_context 'pipeline builds'

47
    let(:project) { create(:project) }
48
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id, user: user) }
49 50 51

    before { visit namespace_project_pipeline_path(project.namespace, project, pipeline) }

Filipa Lacerda committed
52 53 54
    it 'shows the pipeline graph' do
      expect(page).to have_selector('.pipeline-visualization')
      expect(page).to have_content('Build')
55 56
      expect(page).to have_content('Test')
      expect(page).to have_content('Deploy')
dimitrieh committed
57
      expect(page).to have_content('Retry')
58 59 60 61 62 63 64
      expect(page).to have_content('Cancel running')
    end

    it 'shows Pipeline tab pane as active' do
      expect(page).to have_css('#js-tab-pipeline.active')
    end

Filipa Lacerda committed
65 66 67
    describe 'pipeline graph' do
      context 'when pipeline has running builds' do
        it 'shows a running icon and a cancel action for the running build' do
68
          page.within('#ci-badge-deploy') do
Filipa Lacerda committed
69
            expect(page).to have_selector('.js-ci-status-icon-running')
Filipa Lacerda committed
70
            expect(page).to have_selector('.js-icon-action-cancel')
71
            expect(page).to have_content('deploy')
Filipa Lacerda committed
72
          end
Filipa Lacerda committed
73 74
        end

Filipa Lacerda committed
75
        it 'should be possible to cancel the running build' do
76
          find('#ci-badge-deploy .ci-action-icon-container').trigger('click')
Filipa Lacerda committed
77

Filipa Lacerda committed
78 79
          expect(page).not_to have_content('Cancel running')
        end
80 81
      end

Filipa Lacerda committed
82
      context 'when pipeline has successful builds' do
83 84
        it 'shows the success icon and a retry action for the successful build' do
          page.within('#ci-badge-build') do
Filipa Lacerda committed
85
            expect(page).to have_selector('.js-ci-status-icon-success')
Filipa Lacerda committed
86 87
            expect(page).to have_content('build')
          end
Filipa Lacerda committed
88

89
          page.within('#ci-badge-build .ci-action-icon-container') do
Filipa Lacerda committed
90
            expect(page).to have_selector('.js-icon-action-retry')
Filipa Lacerda committed
91
          end
Filipa Lacerda committed
92 93
        end

Filipa Lacerda committed
94
        it 'should be possible to retry the success job' do
95
          find('#ci-badge-build .ci-action-icon-container').trigger('click')
Filipa Lacerda committed
96

Filipa Lacerda committed
97
          expect(page).not_to have_content('Retry job')
98 99 100
        end
      end

Filipa Lacerda committed
101 102
      context 'when pipeline has failed builds' do
        it 'shows the failed icon and a retry action for the failed build' do
103
          page.within('#ci-badge-test') do
Filipa Lacerda committed
104
            expect(page).to have_selector('.js-ci-status-icon-failed')
Filipa Lacerda committed
105 106
            expect(page).to have_content('test')
          end
Filipa Lacerda committed
107

108
          page.within('#ci-badge-test .ci-action-icon-container') do
Filipa Lacerda committed
109
            expect(page).to have_selector('.js-icon-action-retry')
Filipa Lacerda committed
110
          end
Filipa Lacerda committed
111 112
        end

Filipa Lacerda committed
113
        it 'should be possible to retry the failed build' do
114
          find('#ci-badge-test .ci-action-icon-container').trigger('click')
Filipa Lacerda committed
115

Filipa Lacerda committed
116
          expect(page).not_to have_content('Retry job')
117 118 119
        end
      end

Filipa Lacerda committed
120
      context 'when pipeline has manual jobs' do
Filipa Lacerda committed
121
        it 'shows the skipped icon and a play action for the manual build' do
122
          page.within('#ci-badge-manual-build') do
Filipa Lacerda committed
123
            expect(page).to have_selector('.js-ci-status-icon-manual')
Filipa Lacerda committed
124 125
            expect(page).to have_content('manual')
          end
Filipa Lacerda committed
126

127
          page.within('#ci-badge-manual-build .ci-action-icon-container') do
Filipa Lacerda committed
128
            expect(page).to have_selector('.js-icon-action-play')
Filipa Lacerda committed
129
          end
130 131
        end

Filipa Lacerda committed
132
        it 'should be possible to play the manual job' do
133
          find('#ci-badge-manual-build .ci-action-icon-container').trigger('click')
Filipa Lacerda committed
134

Filipa Lacerda committed
135
          expect(page).not_to have_content('Play job')
136 137
        end
      end
Filipa Lacerda committed
138

Filipa Lacerda committed
139
      context 'when pipeline has external job' do
Filipa Lacerda committed
140
        it 'shows the success icon and the generic comit status build' do
Filipa Lacerda committed
141
          expect(page).to have_selector('.js-ci-status-icon-success')
Filipa Lacerda committed
142
          expect(page).to have_content('jenkins')
143
          expect(page).to have_link('jenkins', href: 'http://gitlab.com/status')
Filipa Lacerda committed
144
        end
Filipa Lacerda committed
145
      end
146 147
    end

148
    context 'page tabs' do
Filipa Lacerda committed
149
      it 'shows Pipeline and Jobs tabs with link' do
150
        expect(page).to have_link('Pipeline')
Filipa Lacerda committed
151
        expect(page).to have_link('Jobs')
152 153
      end

Filipa Lacerda committed
154
      it 'shows counter in Jobs tab' do
155 156 157 158 159 160 161 162
        expect(page.find('.js-builds-counter').text).to eq(pipeline.statuses.count.to_s)
      end

      it 'shows Pipeline tab as active' do
        expect(page).to have_css('.js-pipeline-tab-link.active')
      end
    end

Filipa Lacerda committed
163
    context 'retrying jobs' do
164 165 166
      it { expect(page).not_to have_content('retried') }

      context 'when retrying' do
Filipa Lacerda committed
167
        before { find('.js-retry-button').trigger('click') }
168

dimitrieh committed
169
        it { expect(page).not_to have_content('Retry') }
170 171 172
      end
    end

Filipa Lacerda committed
173
    context 'canceling jobs' do
174 175 176 177 178 179 180 181 182 183 184
      it { expect(page).not_to have_selector('.ci-canceled') }

      context 'when canceling' do
        before { click_on 'Cancel running' }

        it { expect(page).not_to have_content('Cancel running') }
      end
    end
  end

  describe 'GET /:project/pipelines/:id/builds' do
185 186
    include_context 'pipeline builds'

187 188 189 190
    let(:project) { create(:project) }
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }

    before do
191
      visit builds_namespace_project_pipeline_path(project.namespace, project, pipeline)
192 193
    end

Filipa Lacerda committed
194
    it 'shows a list of jobs' do
195
      expect(page).to have_content('Test')
196
      expect(page).to have_content(build_passed.id)
197
      expect(page).to have_content('Deploy')
198 199 200
      expect(page).to have_content(build_failed.id)
      expect(page).to have_content(build_running.id)
      expect(page).to have_content(build_external.id)
dimitrieh committed
201
      expect(page).to have_content('Retry')
202 203 204 205
      expect(page).to have_content('Cancel running')
      expect(page).to have_link('Play')
    end

Filipa Lacerda committed
206
    it 'shows jobs tab pane as active' do
207 208 209 210
      expect(page).to have_css('#js-tab-builds.active')
    end

    context 'page tabs' do
Filipa Lacerda committed
211
      it 'shows Pipeline and Jobs tabs with link' do
212
        expect(page).to have_link('Pipeline')
Filipa Lacerda committed
213
        expect(page).to have_link('Jobs')
214 215
      end

Filipa Lacerda committed
216
      it 'shows counter in Jobs tab' do
217 218 219
        expect(page.find('.js-builds-counter').text).to eq(pipeline.statuses.count.to_s)
      end

Filipa Lacerda committed
220
      it 'shows Jobs tab as active' do
221 222 223 224
        expect(page).to have_css('li.js-builds-tab-link.active')
      end
    end

Filipa Lacerda committed
225
    context 'retrying jobs' do
226 227 228
      it { expect(page).not_to have_content('retried') }

      context 'when retrying' do
Filipa Lacerda committed
229
        before { find('.js-retry-button').trigger('click') }
230

dimitrieh committed
231
        it { expect(page).not_to have_content('Retry') }
232 233 234 235
        it { expect(page).to have_selector('.retried') }
      end
    end

Filipa Lacerda committed
236
    context 'canceling jobs' do
237 238 239 240 241 242 243 244 245 246
      it { expect(page).not_to have_selector('.ci-canceled') }

      context 'when canceling' do
        before { click_on 'Cancel running' }

        it { expect(page).not_to have_content('Cancel running') }
        it { expect(page).to have_selector('.ci-canceled') }
      end
    end

Filipa Lacerda committed
247
    context 'playing manual job' do
248 249 250 251 252 253
      before do
        within '.pipeline-holder' do
          click_link('Play')
        end
      end

254
      it { expect(build_manual.reload).to be_pending }
255 256 257
    end
  end
end