pipelines_spec.rb 16.5 KB
Newer Older
K
Kamil Trzcinski 已提交
1 2
require 'spec_helper'

3
describe 'Pipelines', :js do
4
  let(:project) { create(:project) }
K
Kamil Trzcinski 已提交
5

6 7
  context 'when user is logged in' do
    let(:user) { create(:user) }
8

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

14
    describe 'GET /:project/pipelines' do
15
      let(:project) { create(:project, :repository) }
16 17 18 19 20 21 22

      let!(:pipeline) do
        create(
          :ci_empty_pipeline,
          project: project,
          ref: 'master',
          status: 'running',
23
          sha: project.commit.id
24
        )
25 26
      end

27 28 29 30 31 32 33
      context 'scope' do
        before do
          create(:ci_empty_pipeline, status: 'pending', project: project, sha: project.commit.id, ref: 'master')
          create(:ci_empty_pipeline, status: 'running', project: project, sha: project.commit.id, ref: 'master')
          create(:ci_empty_pipeline, status: 'created', project: project, sha: project.commit.id, ref: 'master')
          create(:ci_empty_pipeline, status: 'success', project: project, sha: project.commit.id, ref: 'master')
        end
34

35 36 37 38 39 40 41 42 43
        [:all, :running, :pending, :finished, :branches].each do |scope|
          context "when displaying #{scope}" do
            before do
              visit_project_pipelines(scope: scope)
            end

            it 'contains pipeline commit short SHA' do
              expect(page).to have_content(pipeline.short_sha)
            end
44

45 46 47
            it 'contains branch name' do
              expect(page).to have_content(pipeline.ref)
            end
48
          end
49
        end
R
Regis 已提交
50
      end
K
Kamil Trzcinski 已提交
51

52 53
      context 'header tabs' do
        before do
54
          visit project_pipelines_path(project)
55
          wait_for_requests
56 57 58
        end

        it 'shows a tab for All pipelines and count' do
59
          expect(page.find('.js-pipelines-tab-all').text).to include('All')
60 61 62 63
          expect(page.find('.js-pipelines-tab-all .badge').text).to include('1')
        end

        it 'shows a tab for Pending pipelines and count' do
64
          expect(page.find('.js-pipelines-tab-pending').text).to include('Pending')
65 66 67 68
          expect(page.find('.js-pipelines-tab-pending .badge').text).to include('0')
        end

        it 'shows a tab for Running pipelines and count' do
69
          expect(page.find('.js-pipelines-tab-running').text).to include('Running')
70 71 72 73
          expect(page.find('.js-pipelines-tab-running .badge').text).to include('1')
        end

        it 'shows a tab for Finished pipelines and count' do
74
          expect(page.find('.js-pipelines-tab-finished').text).to include('Finished')
75 76 77 78
          expect(page.find('.js-pipelines-tab-finished .badge').text).to include('0')
        end

        it 'shows a tab for Branches' do
79
          expect(page.find('.js-pipelines-tab-branches').text).to include('Branches')
80 81 82
        end

        it 'shows a tab for Tags' do
83 84 85 86 87 88 89
          expect(page.find('.js-pipelines-tab-tags').text).to include('Tags')
        end

        it 'updates content when tab is clicked' do
          page.find('.js-pipelines-tab-pending').click
          wait_for_requests
          expect(page).to have_content('No pipelines to show.')
90 91 92
        end
      end

93 94 95 96 97 98
      context 'when pipeline is cancelable' do
        let!(:build) do
          create(:ci_build, pipeline: pipeline,
                            stage: 'test',
                            commands: 'test')
        end
K
Kamil Trzcinski 已提交
99

100 101 102 103
        before do
          build.run
          visit_project_pipelines
        end
K
Kamil Trzcinski 已提交
104

105
        it 'indicates that pipeline can be canceled' do
106
          expect(page).to have_selector('.js-pipelines-cancel-button')
107 108
          expect(page).to have_selector('.ci-running')
        end
109

110
        context 'when canceling' do
111
          before do
112
            accept_confirm { find('.js-pipelines-cancel-button').click }
113
            wait_for_requests
114
          end
115

116
          it 'indicated that pipelines was canceled' do
117
            expect(page).not_to have_selector('.js-pipelines-cancel-button')
118 119
            expect(page).to have_selector('.ci-canceled')
          end
120
        end
121
      end
122

123 124 125 126 127 128
      context 'when pipeline is retryable' do
        let!(:build) do
          create(:ci_build, pipeline: pipeline,
                            stage: 'test',
                            commands: 'test')
        end
R
Regis 已提交
129

130
        before do
131 132
          build.drop
          visit_project_pipelines
133
        end
134

135
        it 'indicates that pipeline can be retried' do
136
          expect(page).to have_selector('.js-pipelines-retry-button')
137 138
          expect(page).to have_selector('.ci-failed')
        end
139 140

        context 'when retrying' do
141 142
          before do
            find('.js-pipelines-retry-button').click
143
            wait_for_requests
144
          end
145

146
          it 'shows running pipeline that is not retryable' do
147
            expect(page).not_to have_selector('.js-pipelines-retry-button')
148 149
            expect(page).to have_selector('.ci-running')
          end
150
        end
151 152
      end

153 154 155 156 157
      context 'when pipeline has configuration errors' do
        let(:pipeline) do
          create(:ci_pipeline, :invalid, project: project)
        end

158 159 160
        before do
          visit_project_pipelines
        end
161

162
        it 'contains badge that indicates errors' do
163 164 165 166 167 168 169 170
          expect(page).to have_content 'yaml invalid'
        end

        it 'contains badge with tooltip which contains error' do
          expect(pipeline).to have_yaml_errors
          expect(page).to have_selector(
            %Q{span[data-original-title="#{pipeline.yaml_errors}"]})
        end
171 172 173 174 175 176 177 178 179 180

        it 'contains badge that indicates failure reason' do
          expect(page).to have_content 'error'
        end

        it 'contains badge with tooltip which contains failure reason' do
          expect(pipeline.failure_reason?).to eq true
          expect(page).to have_selector(
            %Q{span[data-original-title="#{pipeline.present.failure_reason}"]})
        end
181 182
      end

183 184 185
      context 'with manual actions' do
        let!(:manual) do
          create(:ci_build, :manual,
R
Regis 已提交
186
            pipeline: pipeline,
187 188 189
            name: 'manual build',
            stage: 'test',
            commands: 'test')
R
Regis 已提交
190
        end
191

192 193 194
        before do
          visit_project_pipelines
        end
195

196
        it 'has a dropdown with play button' do
197
          expect(page).to have_selector('.dropdown-new.btn.btn-default .icon-play')
198 199
        end

200 201 202
        it 'has link to the manual action' do
          find('.js-pipeline-dropdown-manual-actions').click

203
          expect(page).to have_button('manual build')
204
        end
205

206 207 208
        context 'when manual action was played' do
          before do
            find('.js-pipeline-dropdown-manual-actions').click
209
            click_button('manual build')
210
          end
211

212
          it 'enqueues manual action job' do
213
            expect(page).to have_selector('.js-pipeline-dropdown-manual-actions:disabled')
214
          end
215
        end
216 217
      end

218 219 220 221 222 223
      context 'for generic statuses' do
        context 'when running' do
          let!(:running) do
            create(:generic_commit_status,
              status: 'running',
              pipeline: pipeline,
224
              stage: 'test')
225
          end
226

227 228 229
          before do
            visit_project_pipelines
          end
230 231

          it 'is cancelable' do
232
            expect(page).to have_selector('.js-pipelines-cancel-button')
233
          end
234

235 236 237 238 239
          it 'has pipeline running' do
            expect(page).to have_selector('.ci-running')
          end

          context 'when canceling' do
240
            before do
241
              accept_alert { find('.js-pipelines-cancel-button').click }
242
            end
243

244
            it 'indicates that pipeline was canceled' do
245
              expect(page).not_to have_selector('.js-pipelines-cancel-button')
246 247
              expect(page).to have_selector('.ci-canceled')
            end
248
          end
249 250
        end

251 252 253 254 255 256 257 258 259 260 261 262 263
        context 'when failed' do
          let!(:status) do
            create(:generic_commit_status, :pending,
              pipeline: pipeline,
              stage: 'test')
          end

          before do
            status.drop
            visit_project_pipelines
          end

          it 'is not retryable' do
264
            expect(page).not_to have_selector('.js-pipelines-retry-button')
265 266 267 268 269
          end

          it 'has failed pipeline' do
            expect(page).to have_selector('.ci-failed')
          end
270 271 272
        end
      end

273 274 275 276 277 278 279 280 281
      context 'downloadable pipelines' do
        context 'with artifacts' do
          let!(:with_artifacts) do
            create(:ci_build, :artifacts, :success,
              pipeline: pipeline,
              name: 'rspec tests',
              stage: 'test')
          end

282 283 284
          before do
            visit_project_pipelines
          end
285 286 287 288 289 290 291 292 293 294

          it 'has artifats' do
            expect(page).to have_selector('.build-artifacts')
          end

          it 'has artifacts download dropdown' do
            find('.js-pipeline-dropdown-download').click

            expect(page).to have_link(with_artifacts.name)
          end
295 296 297 298 299 300 301 302

          it 'has download attribute on download links' do
            find('.js-pipeline-dropdown-download').click
            expect(page).to have_selector('a', text: 'Download')
            page.all('.build-artifacts a', text: 'Download').each do |link|
              expect(link[:download]).to eq ''
            end
          end
R
Regis 已提交
303
        end
K
Kamil Trzcinski 已提交
304

305 306 307 308 309 310 311
        context 'with artifacts expired' do
          let!(:with_artifacts_expired) do
            create(:ci_build, :artifacts_expired, :success,
              pipeline: pipeline,
              name: 'rspec',
              stage: 'test')
          end
312

313 314 315
          before do
            visit_project_pipelines
          end
316 317

          it { expect(page).not_to have_selector('.build-artifacts') }
318 319
        end

320 321 322 323 324 325 326 327
        context 'without artifacts' do
          let!(:without_artifacts) do
            create(:ci_build, :success,
              pipeline: pipeline,
              name: 'rspec',
              stage: 'test')
          end

328 329 330
          before do
            visit_project_pipelines
          end
331

332
          it { expect(page).not_to have_selector('.build-artifacts') }
333
        end
K
Kamil Trzcinski 已提交
334
      end
K
Kamil Trzcinski 已提交
335

336
      context 'mini pipeline graph' do
337
        let!(:build) do
338 339 340
          create(:ci_build, :pending, pipeline: pipeline,
                                      stage: 'build',
                                      name: 'build')
R
Regis 已提交
341
        end
342

343 344 345
        before do
          visit_project_pipelines
        end
346

347 348 349 350 351
        it 'should render a mini pipeline graph' do
          expect(page).to have_selector('.js-mini-pipeline-graph')
          expect(page).to have_selector('.js-builds-dropdown-button')
        end

352
        context 'when clicking a stage badge' do
353
          it 'should open a dropdown' do
354
            find('.js-builds-dropdown-button').click
355

356 357
            expect(page).to have_link build.name
          end
K
Kamil Trzcinski 已提交
358

359
          it 'should be possible to cancel pending build' do
360 361
            find('.js-builds-dropdown-button').click
            find('a.js-ci-action-icon').click
362

363 364
            expect(page).to have_content('canceled')
            expect(build.reload).to be_canceled
365 366
          end
        end
367 368 369

        context 'dropdown jobs list' do
          it 'should keep the dropdown open when the user ctr/cmd + clicks in the job name' do
370
            find('.js-builds-dropdown-button').click
371 372
            dropdown_item = find('.mini-pipeline-graph-dropdown-item').native

373
            %i(alt control).each do |meta_key|
374
              page.driver.browser.action
375
                .key_down(meta_key)
376
                .click(dropdown_item)
377
                .key_up(meta_key)
378 379
                .perform
            end
380 381 382 383

            expect(page).to have_selector('.js-ci-action-icon')
          end
        end
K
Kamil Trzcinski 已提交
384
      end
385 386 387

      context 'with pagination' do
        before do
388 389
          allow(Ci::Pipeline).to receive(:default_per_page).and_return(1)
          create(:ci_empty_pipeline,  project: project)
390 391 392
        end

        it 'should render pagination' do
393
          visit project_pipelines_path(project)
394
          wait_for_requests
395

396
          expect(page).to have_selector('.gl-pagination')
397 398
        end

399
        it 'should render second page of pipelines' do
400
          visit project_pipelines_path(project, page: '2')
401
          wait_for_requests
402

403
          expect(page).to have_selector('.gl-pagination .page', count: 2)
404
        end
405 406 407 408 409 410 411 412

        it 'should show updated content' do
          visit project_pipelines_path(project)
          wait_for_requests
          page.find('.js-next-button a').click

          expect(page).to have_selector('.gl-pagination .page', count: 2)
        end
413
      end
K
Kamil Trzcinski 已提交
414
    end
415

416
    describe 'GET /:project/pipelines/show' do
417
      let(:project) { create(:project, :repository) }
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436

      let(:pipeline) do
        create(:ci_empty_pipeline,
              project: project,
              sha: project.commit.id,
              user: user)
      end

      before do
        create_build('build', 0, 'build', :success)
        create_build('test', 1, 'rspec 0:2', :pending)
        create_build('test', 1, 'rspec 1:2', :running)
        create_build('test', 1, 'spinach 0:2', :created)
        create_build('test', 1, 'spinach 1:2', :created)
        create_build('test', 1, 'audit', :created)
        create_build('deploy', 2, 'production', :created)

        create(:generic_commit_status, pipeline: pipeline, stage: 'external', name: 'jenkins', stage_idx: 3)

437
        visit project_pipeline_path(project, pipeline)
438
        wait_for_requests
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
      end

      it 'shows a graph with grouped stages' do
        expect(page).to have_css('.js-pipeline-graph')

        # header
        expect(page).to have_text("##{pipeline.id}")
        expect(page).to have_selector(%Q(img[alt$="#{pipeline.user.name}'s avatar"]))
        expect(page).to have_link(pipeline.user.name, href: user_path(pipeline.user))

        # stages
        expect(page).to have_text('Build')
        expect(page).to have_text('Test')
        expect(page).to have_text('Deploy')
        expect(page).to have_text('External')

        # builds
        expect(page).to have_text('rspec')
        expect(page).to have_text('spinach')
Z
Z.J. van de Weg 已提交
458
        expect(page).to have_text('rspec')
459 460 461 462 463 464 465 466 467
        expect(page).to have_text('production')
        expect(page).to have_text('jenkins')
      end

      def create_build(stage, stage_idx, name, status)
        create(:ci_build, pipeline: pipeline, stage: stage, stage_idx: stage_idx, name: name, status: status)
      end
    end

468
    describe 'POST /:project/pipelines' do
469
      let(:project) { create(:project, :repository) }
470 471

      before do
472
        visit new_project_pipeline_path(project)
473 474
      end

475
      context 'for valid commit', :js do
476 477 478 479 480 481 482
        before do
          click_button project.default_branch

          page.within '.dropdown-menu' do
            click_link 'master'
          end
        end
483

484
        context 'with gitlab-ci.yml' do
485 486 487
          before do
            stub_ci_pipeline_to_return_yaml_file
          end
488

489 490 491
          it 'creates a new pipeline' do
            expect { click_on 'Create pipeline' }
              .to change { Ci::Pipeline.count }.by(1)
492 493

            expect(Ci::Pipeline.last).to be_web
494
          end
495 496
        end

497
        context 'without gitlab-ci.yml' do
498 499 500
          before do
            click_on 'Create pipeline'
          end
501

502
          it { expect(page).to have_content('Missing .gitlab-ci.yml file') }
503 504
        end
      end
R
Regis 已提交
505
    end
K
Kamil Trzcinski 已提交
506

507
    describe 'Create pipelines' do
508
      let(:project) { create(:project, :repository) }
509

510
      before do
511
        visit new_project_pipeline_path(project)
512
      end
513

514 515
      describe 'new pipeline page' do
        it 'has field to add a new pipeline' do
516 517
          expect(page).to have_selector('.js-branch-select')
          expect(find('.js-branch-select')).to have_content project.default_branch
518
          expect(page).to have_content('Create for')
R
Regis 已提交
519
        end
K
Kamil Trzcinski 已提交
520
      end
K
Kamil Trzcinski 已提交
521

522
      describe 'find pipelines' do
523
        it 'shows filtered pipelines', :js do
524
          click_button project.default_branch
525

526 527 528 529 530 531
          page.within '.dropdown-menu' do
            find('.dropdown-input-field').native.send_keys('fix')

            page.within '.dropdown-content' do
              expect(page).to have_content('fix')
            end
532 533
          end
        end
K
Kamil Trzcinski 已提交
534 535
      end
    end
K
Kamil Trzcinski 已提交
536
  end
U
ubudzisz 已提交
537

538
  context 'when user is not logged in' do
U
ubudzisz 已提交
539
    before do
540
      visit project_pipelines_path(project)
U
ubudzisz 已提交
541 542
    end

543
    context 'when project is public' do
544
      let(:project) { create(:project, :public, :repository) }
545

546
      it { expect(page).to have_content 'Build with confidence' }
U
ubudzisz 已提交
547 548
    end

549
    context 'when project is private' do
550
      let(:project) { create(:project, :private, :repository) }
U
ubudzisz 已提交
551

552
      it { expect(page).to have_content 'You need to sign in' }
U
ubudzisz 已提交
553 554
    end
  end
555 556

  def visit_project_pipelines(**query)
557
    visit project_pipelines_path(project, query)
558
    wait_for_requests
559
  end
K
Kamil Trzcinski 已提交
560
end