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

3
describe 'Pipelines', :feature, :js do
4
  include WaitForVueResource
K
Kamil Trzcinski 已提交
5 6 7

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

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

11 12 13
    before do
      login_as(user)
      project.team << [user, :developer]
14 15
    end

16 17 18 19 20 21 22 23 24 25 26
    describe 'GET /:project/pipelines' do
      let(:project) { create(:project) }

      let!(:pipeline) do
        create(
          :ci_empty_pipeline,
          project: project,
          ref: 'master',
          status: 'running',
          sha: project.commit.id,
        )
27 28
      end

29 30 31 32 33
      [:all, :running, :branches].each do |scope|
        context "when displaying #{scope}" do
          before do
            visit_project_pipelines(scope: scope)
          end
34

35 36 37
          it 'contains pipeline commit short SHA' do
            expect(page).to have_content(pipeline.short_sha)
          end
38 39 40 41

          it 'contains branch name' do
            expect(page).to have_content(pipeline.ref)
          end
42
        end
R
Regis 已提交
43
      end
K
Kamil Trzcinski 已提交
44

45 46 47 48 49 50
      context 'when pipeline is cancelable' do
        let!(:build) do
          create(:ci_build, pipeline: pipeline,
                            stage: 'test',
                            commands: 'test')
        end
K
Kamil Trzcinski 已提交
51

52 53 54 55
        before do
          build.run
          visit_project_pipelines
        end
K
Kamil Trzcinski 已提交
56

57 58 59 60
        it 'indicates that pipeline can be canceled' do
          expect(page).to have_link('Cancel')
          expect(page).to have_selector('.ci-running')
        end
61

62 63
        context 'when canceling' do
          before { click_link('Cancel') }
64

65 66 67 68
          it 'indicated that pipelines was canceled' do
            expect(page).not_to have_link('Cancel')
            expect(page).to have_selector('.ci-canceled')
          end
69
        end
70
      end
71

72 73 74 75 76 77
      context 'when pipeline is retryable' do
        let!(:build) do
          create(:ci_build, pipeline: pipeline,
                            stage: 'test',
                            commands: 'test')
        end
R
Regis 已提交
78

79
        before do
80 81
          build.drop
          visit_project_pipelines
82
        end
83

84 85 86 87
        it 'indicates that pipeline can be retried' do
          expect(page).to have_link('Retry')
          expect(page).to have_selector('.ci-failed')
        end
88 89 90 91

        context 'when retrying' do
          before { click_link('Retry') }

92 93 94 95
          it 'shows running pipeline that is not retryable' do
            expect(page).not_to have_link('Retry')
            expect(page).to have_selector('.ci-running')
          end
96
        end
97 98
      end

99 100 101 102 103 104 105
      context 'when pipeline has configuration errors' do
        let(:pipeline) do
          create(:ci_pipeline, :invalid, project: project)
        end

        before { visit_project_pipelines }

106
        it 'contains badge that indicates errors' do
107 108 109 110 111 112 113 114 115 116
          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
      end

117 118 119
      context 'with manual actions' do
        let!(:manual) do
          create(:ci_build, :manual,
R
Regis 已提交
120
            pipeline: pipeline,
121 122 123
            name: 'manual build',
            stage: 'test',
            commands: 'test')
R
Regis 已提交
124
        end
125

126
        before { visit_project_pipelines }
127

128 129
        it 'has a dropdown with play button' do
          expect(page).to have_selector('.dropdown-toggle.btn.btn-default .icon-play')
130 131
        end

132 133 134
        it 'has link to the manual action' do
          find('.js-pipeline-dropdown-manual-actions').click

135
          expect(page).to have_link('manual build')
136
        end
137

138 139 140
        context 'when manual action was played' do
          before do
            find('.js-pipeline-dropdown-manual-actions').click
141
            click_link('manual build')
142
          end
143

144 145 146
          it 'enqueues manual action job' do
            expect(manual.reload).to be_pending
          end
147
        end
148 149
      end

150 151 152 153 154 155
      context 'for generic statuses' do
        context 'when running' do
          let!(:running) do
            create(:generic_commit_status,
              status: 'running',
              pipeline: pipeline,
156
              stage: 'test')
157
          end
158

159 160 161 162 163
          before { visit_project_pipelines }

          it 'is cancelable' do
            expect(page).to have_link('Cancel')
          end
164

165 166 167 168 169 170 171
          it 'has pipeline running' do
            expect(page).to have_selector('.ci-running')
          end

          context 'when canceling' do
            before { click_link('Cancel') }

172 173 174 175
            it 'indicates that pipeline was canceled' do
              expect(page).not_to have_link('Cancel')
              expect(page).to have_selector('.ci-canceled')
            end
176
          end
177 178
        end

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
        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
            expect(page).not_to have_link('Retry')
          end

          it 'has failed pipeline' do
            expect(page).to have_selector('.ci-failed')
          end
198 199 200
        end
      end

201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
      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

          before { visit_project_pipelines }

          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
221 222 223 224 225 226 227 228

          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 已提交
229
        end
K
Kamil Trzcinski 已提交
230

231 232 233 234 235 236 237
        context 'with artifacts expired' do
          let!(:with_artifacts_expired) do
            create(:ci_build, :artifacts_expired, :success,
              pipeline: pipeline,
              name: 'rspec',
              stage: 'test')
          end
238

239 240 241
          before { visit_project_pipelines }

          it { expect(page).not_to have_selector('.build-artifacts') }
242 243
        end

244 245 246 247 248 249 250 251 252
        context 'without artifacts' do
          let!(:without_artifacts) do
            create(:ci_build, :success,
              pipeline: pipeline,
              name: 'rspec',
              stage: 'test')
          end

          before { visit_project_pipelines }
253

254
          it { expect(page).not_to have_selector('.build-artifacts') }
255
        end
K
Kamil Trzcinski 已提交
256
      end
K
Kamil Trzcinski 已提交
257

258
      context 'mini pipeline graph' do
259
        let!(:build) do
260 261 262
          create(:ci_build, :pending, pipeline: pipeline,
                                      stage: 'build',
                                      name: 'build')
R
Regis 已提交
263
        end
264

265
        before { visit_project_pipelines }
266

267 268 269 270 271
        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

272
        context 'when clicking a stage badge' do
273 274
          it 'should open a dropdown' do
            find('.js-builds-dropdown-button').trigger('click')
275

276 277
            expect(page).to have_link build.name
          end
K
Kamil Trzcinski 已提交
278

279
          it 'should be possible to cancel pending build' do
280
            find('.js-builds-dropdown-button').trigger('click')
281
            find('a.js-ci-action-icon').trigger('click')
282

283 284
            expect(page).to have_content('canceled')
            expect(build.reload).to be_canceled
285 286
          end
        end
K
Kamil Trzcinski 已提交
287
      end
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309

      context 'with pagination' do
        before do
          create_list(:ci_empty_pipeline, 40, project: project)
        end

        it 'should render pagination' do
          visit namespace_project_pipelines_path(project.namespace, project)
          wait_for_vue_resource

          expect(page).to have_css('.gl-pagination')
          expect(page.find_all('tbody tr').length).to eq(20)
        end

        it "should render second page of pipelines" do
          visit namespace_project_pipelines_path(project.namespace, project, page: '2')
          wait_for_vue_resource

          expect(page).to have_css('.gl-pagination')
          expect(page.find_all('tbody tr').length).to eq(20)
        end
      end
K
Kamil Trzcinski 已提交
310
    end
311

312 313 314 315 316
    describe 'POST /:project/pipelines' do
      let(:project) { create(:project) }

      before do
        visit new_namespace_project_pipeline_path(project.namespace, project)
317 318
      end

319 320
      context 'for valid commit' do
        before { fill_in('pipeline[ref]', with: 'master') }
321

322 323
        context 'with gitlab-ci.yml' do
          before { stub_ci_pipeline_to_return_yaml_file }
324

325 326 327 328
          it 'creates a new pipeline' do
            expect { click_on 'Create pipeline' }
              .to change { Ci::Pipeline.count }.by(1)
          end
329 330
        end

331 332
        context 'without gitlab-ci.yml' do
          before { click_on 'Create pipeline' }
333

334
          it { expect(page).to have_content('Missing .gitlab-ci.yml file') }
335 336
        end
      end
K
Kamil Trzcinski 已提交
337

338 339 340 341 342
      context 'for invalid commit' do
        before do
          fill_in('pipeline[ref]', with: 'invalid-reference')
          click_on 'Create pipeline'
        end
K
Kamil Trzcinski 已提交
343

344 345
        it { expect(page).to have_content('Reference not found') }
      end
R
Regis 已提交
346
    end
K
Kamil Trzcinski 已提交
347

348 349
    describe 'Create pipelines' do
      let(:project) { create(:project) }
350

351 352 353
      before do
        visit new_namespace_project_pipeline_path(project.namespace, project)
      end
354

355 356 357 358
      describe 'new pipeline page' do
        it 'has field to add a new pipeline' do
          expect(page).to have_field('pipeline[ref]')
          expect(page).to have_content('Create for')
R
Regis 已提交
359
        end
K
Kamil Trzcinski 已提交
360
      end
K
Kamil Trzcinski 已提交
361

362 363 364 365
      describe 'find pipelines' do
        it 'shows filtered pipelines', js: true do
          fill_in('pipeline[ref]', with: 'fix')
          find('input#ref').native.send_keys(:keydown)
366

367 368 369 370
          within('.ui-autocomplete') do
            expect(page).to have_selector('li', text: 'fix')
          end
        end
K
Kamil Trzcinski 已提交
371 372
      end
    end
K
Kamil Trzcinski 已提交
373
  end
U
ubudzisz 已提交
374

375
  context 'when user is not logged in' do
U
ubudzisz 已提交
376
    before do
377
      visit namespace_project_pipelines_path(project.namespace, project)
U
ubudzisz 已提交
378 379
    end

380 381 382 383 384
    context 'when project is public' do
      let(:project) { create(:project, :public) }

      it { expect(page).to have_content 'No pipelines to show' }
      it { expect(page).to have_http_status(:success) }
U
ubudzisz 已提交
385 386
    end

387 388
    context 'when project is private' do
      let(:project) { create(:project, :private) }
U
ubudzisz 已提交
389

390
      it { expect(page).to have_content 'You need to sign in' }
U
ubudzisz 已提交
391 392
    end
  end
393 394 395 396 397

  def visit_project_pipelines(**query)
    visit namespace_project_pipelines_path(project.namespace, project, query)
    wait_for_vue_resource
  end
K
Kamil Trzcinski 已提交
398
end