BigW Consortium Gitlab

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

3
describe 'Pipeline', :js do
4
  let(:project) { create(:project) }
5 6 7
  let(:user) { create(:user) }

  before do
8
    sign_in(user)
9 10 11
    project.team << [user, :developer]
  end

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
  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',
37 38
                                     stage: 'external',
                                     target_url: 'http://gitlab.com/status')
39 40 41
    end
  end

42
  describe 'GET /:project/pipelines/:id' do
43 44
    include_context 'pipeline builds'

45
    let(:project) { create(:project, :repository) }
46
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id, user: user) }
47

48
    before do
49
      visit project_pipeline_path(project, pipeline)
50
    end
51

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')
Tim Zallmann committed
70
            expect(page).to have_selector('.js-icon-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').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 90
          page.within('#ci-badge-build .ci-action-icon-container.js-icon-retry') do
            expect(page).to have_selector('svg')
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').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 109
          page.within('#ci-badge-test .ci-action-icon-container.js-icon-retry') do
            expect(page).to have_selector('svg')
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').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 128
          page.within('#ci-badge-manual-build .ci-action-icon-container.js-icon-play') do
            expect(page).to have_selector('svg')
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').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
167
        before do
168
          find('.js-retry-button').click
169
        end
170

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

Filipa Lacerda committed
175
    context 'canceling jobs' do
176 177 178
      it { expect(page).not_to have_selector('.ci-canceled') }

      context 'when canceling' do
179 180 181
        before do
          click_on 'Cancel running'
        end
182 183 184 185 186 187 188

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

  describe 'GET /:project/pipelines/:id/builds' do
189 190
    include_context 'pipeline builds'

191
    let(:project) { create(:project, :repository) }
192 193 194
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }

    before do
195
      visit builds_project_pipeline_path(project, pipeline)
196 197
    end

Filipa Lacerda committed
198
    it 'shows a list of jobs' do
199
      expect(page).to have_content('Test')
200
      expect(page).to have_content(build_passed.id)
201
      expect(page).to have_content('Deploy')
202 203 204
      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
205
      expect(page).to have_content('Retry')
206 207 208 209
      expect(page).to have_content('Cancel running')
      expect(page).to have_link('Play')
    end

Filipa Lacerda committed
210
    it 'shows jobs tab pane as active' do
211 212 213 214
      expect(page).to have_css('#js-tab-builds.active')
    end

    context 'page tabs' do
Filipa Lacerda committed
215
      it 'shows Pipeline and Jobs tabs with link' do
216
        expect(page).to have_link('Pipeline')
Filipa Lacerda committed
217
        expect(page).to have_link('Jobs')
218 219
      end

Filipa Lacerda committed
220
      it 'shows counter in Jobs tab' do
221 222 223
        expect(page.find('.js-builds-counter').text).to eq(pipeline.statuses.count.to_s)
      end

Filipa Lacerda committed
224
      it 'shows Jobs tab as active' do
225 226 227 228
        expect(page).to have_css('li.js-builds-tab-link.active')
      end
    end

Filipa Lacerda committed
229
    context 'retrying jobs' do
230 231 232
      it { expect(page).not_to have_content('retried') }

      context 'when retrying' do
233
        before do
234
          find('.js-retry-button').click
235
        end
236

dimitrieh committed
237
        it { expect(page).not_to have_content('Retry') }
238 239 240
      end
    end

Filipa Lacerda committed
241
    context 'canceling jobs' do
242 243 244
      it { expect(page).not_to have_selector('.ci-canceled') }

      context 'when canceling' do
245 246 247
        before do
          click_on 'Cancel running'
        end
248 249 250 251 252

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

Filipa Lacerda committed
253
    context 'playing manual job' do
254 255 256 257 258 259
      before do
        within '.pipeline-holder' do
          click_link('Play')
        end
      end

260
      it { expect(build_manual.reload).to be_pending }
261 262
    end
  end
263 264

  describe 'GET /:project/pipelines/:id/failures' do
265
    let(:project) { create(:project, :repository) }
266
    let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }
267
    let(:pipeline_failures_page) { failures_project_pipeline_path(project, pipeline) }
268 269 270 271 272 273 274 275 276 277
    let!(:failed_build) { create(:ci_build, :failed, pipeline: pipeline) }

    context 'with failed build' do
      before do
        failed_build.trace.set('4 examples, 1 failure')

        visit pipeline_failures_page
      end

      it 'shows jobs tab pane as active' do
278
        expect(page).to have_content('Failed Jobs')
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
        expect(page).to have_css('#js-tab-failures.active')
      end

      it 'lists failed builds' do
        expect(page).to have_content(failed_build.name)
        expect(page).to have_content(failed_build.stage)
      end

      it 'shows build failure logs' do
        expect(page).to have_content('4 examples, 1 failure')
      end
    end

    context 'when missing build logs' do
      before do
        visit pipeline_failures_page
      end

      it 'includes failed jobs' do
        expect(page).to have_content('No job trace')
      end
    end
301 302 303 304 305 306 307 308 309 310 311 312 313 314

    context 'without failures' do
      before do
        failed_build.update!(status: :success)

        visit pipeline_failures_page
      end

      it 'displays the pipeline graph' do
        expect(current_path).to eq(pipeline_path(pipeline))
        expect(page).not_to have_content('Failed Jobs')
        expect(page).to have_selector('.pipeline-visualization')
      end
    end
315
  end
316
end