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

4
describe 'Pipelines', :feature, :js do
K
Kamil Trzcinski 已提交
5
  include GitlabRoutingHelper
6
  include WaitForVueResource
7
  include WaitForAjax
K
Kamil Trzcinski 已提交
8 9 10 11

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

K
Kamil Trzcinski 已提交
12 13 14 15 16
  before do
    login_as(user)
    project.team << [user, :developer]
  end

17 18 19
  describe 'GET /:project/pipelines', feature: true, js: true do
    include WaitForVueResource

20
    let(:project) { create(:project) }
R
Regis 已提交
21 22 23 24 25
    let!(:pipeline) do
      create(
        :ci_empty_pipeline,
        project: project,
        ref: 'master',
26 27
        status: 'running',
        sha: project.commit.id,
R
Regis 已提交
28 29
      )
    end
K
Kamil Trzcinski 已提交
30

31
    [:all, :running, :branches].each do |scope|
32
      context "displaying #{scope}" do
R
Regis 已提交
33 34 35 36 37
        before do
          visit namespace_project_pipelines_path(
            project.namespace,
            project, scope: scope
          )
38
          wait_for_vue_resource
R
Regis 已提交
39
        end
40

41 42 43
        it do
          expect(page).to have_content(pipeline.short_sha)
        end
44 45 46
      end
    end

47
    context 'anonymous access' do
R
Regis 已提交
48 49
      before do
        visit namespace_project_pipelines_path(project.namespace, project)
50
        wait_for_vue_resource
R
Regis 已提交
51
      end
52 53 54 55

      it { expect(page).to have_http_status(:success) }
    end

K
Kamil Trzcinski 已提交
56
    context 'cancelable pipeline' do
R
Regis 已提交
57 58 59
      let!(:build) do
        create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test')
      end
K
Kamil Trzcinski 已提交
60

61
      before do
62
        build.run
63
        visit namespace_project_pipelines_path(project.namespace, project)
64 65 66
        wait_for_vue_resource
      end

67 68 69
      it { expect(page).to have_link('Cancel') }

      it { expect(page).to have_selector('.ci-running') }
K
Kamil Trzcinski 已提交
70 71

      context 'when canceling' do
72 73 74 75
        before do
          wait_for_vue_resource
          click_link('Cancel')
        end
K
Kamil Trzcinski 已提交
76

77
        it { expect(page).not_to have_link('Cancel') }
78

79
        it { expect(page).to have_selector('.ci-canceled') }
K
Kamil Trzcinski 已提交
80 81 82 83
      end
    end

    context 'retryable pipelines' do
R
Regis 已提交
84 85 86
      let!(:build) do
        create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test')
      end
K
Kamil Trzcinski 已提交
87

88
      before do
89
        build.drop
90 91
        visit namespace_project_pipelines_path(project.namespace, project)
      end
K
Kamil Trzcinski 已提交
92 93 94 95 96

      it { expect(page).to have_link('Retry') }
      it { expect(page).to have_selector('.ci-failed') }

      context 'when retrying' do
97 98 99 100
        before do
          wait_for_vue_resource
          click_link('Retry')
        end
K
Kamil Trzcinski 已提交
101

102
        it { expect(page).not_to have_link('Retry') }
K
Kamil Trzcinski 已提交
103
        it { expect(page).to have_selector('.ci-running') }
K
Kamil Trzcinski 已提交
104 105 106
      end
    end

107
    context 'with manual actions' do
R
Regis 已提交
108 109 110 111 112 113 114 115 116 117
      let!(:manual) do
        create(
          :ci_build,
          :manual,
          pipeline: pipeline,
          name: 'manual build',
          stage: 'test',
          commands: 'test'
        )
      end
118

R
Regis 已提交
119 120
      before do
        visit namespace_project_pipelines_path(project.namespace, project)
121

122 123
        wait_for_vue_resource
      end
124

125 126
      it 'has a dropdown with play button' do
        expect(page).to have_selector('.dropdown-toggle.btn.btn-default .icon-play')
127
      end
128

129
      it 'has link to the manual action' do
F
Filipa Lacerda 已提交
130
        find('.js-pipeline-dropdown-manual-actions').click
131

132 133
        expect(page).to have_link('Manual build')
      end
R
Regis 已提交
134

135
      context 'when manual action was played' do
136
        before do
F
Filipa Lacerda 已提交
137
          find('.js-pipeline-dropdown-manual-actions').click
138 139
          click_link('Manual build')
        end
140

141 142 143
        it 'enqueues manual action job' do
          expect(manual.reload).to be_pending
        end
144 145 146
      end
    end

147 148
    context 'for generic statuses' do
      context 'when running' do
R
Regis 已提交
149 150 151 152 153 154 155 156
        let!(:running) do
          create(
            :generic_commit_status,
            status: 'running',
            pipeline: pipeline,
            stage: 'test'
          )
        end
157

158 159
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
R
Regis 已提交
160
          wait_for_vue_resource
161
        end
162

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

167
        it 'has pipeline running' do
168 169
          expect(page).to have_selector('.ci-running')
        end
170 171 172 173 174 175 176

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

          it { expect(page).not_to have_link('Cancel') }
          it { expect(page).to have_selector('.ci-canceled') }
        end
177 178 179
      end

      context 'when failed' do
R
Regis 已提交
180 181 182 183 184 185 186 187
        let!(:status) do
          create(
            :generic_commit_status,
            :pending,
            pipeline: pipeline,
            stage: 'test'
          )
        end
188

189
        before do
190
          status.drop
191 192
          visit namespace_project_pipelines_path(project.namespace, project)
        end
193

194
        it 'is not retryable' do
K
Kamil Trzcinski 已提交
195
          expect(page).not_to have_link('Retry')
196 197
        end

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

K
Kamil Trzcinski 已提交
204 205
    context 'downloadable pipelines' do
      context 'with artifacts' do
R
Regis 已提交
206 207 208 209 210 211 212 213 214 215
        let!(:with_artifacts) do
          create(
            :ci_build,
            :artifacts,
            :success,
            pipeline: pipeline,
            name: 'rspec tests',
            stage: 'test'
          )
        end
K
Kamil Trzcinski 已提交
216

R
Regis 已提交
217 218
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
K
Kamil Trzcinski 已提交
219

220
          wait_for_vue_resource
221 222 223
        end

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

227
        it 'has artifacts download dropdown' do
F
Filipa Lacerda 已提交
228
          find('.js-pipeline-dropdown-download').click
229

230 231
          expect(page).to have_link(with_artifacts.name)
        end
K
Kamil Trzcinski 已提交
232
      end
K
Kamil Trzcinski 已提交
233

234
      context 'with artifacts expired' do
R
Regis 已提交
235 236 237 238 239 240 241 242 243 244
        let!(:with_artifacts_expired) do
          create(
            :ci_build,
            :artifacts_expired,
            :success,
            pipeline: pipeline,
            name: 'rspec',
            stage: 'test'
          )
        end
245

R
Regis 已提交
246 247 248
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
        end
249 250 251 252

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

K
Kamil Trzcinski 已提交
253
      context 'without artifacts' do
R
Regis 已提交
254 255 256 257 258 259 260 261 262
        let!(:without_artifacts) do
          create(
            :ci_build,
            :success,
            pipeline: pipeline,
            name: 'rspec',
            stage: 'test'
          )
        end
K
Kamil Trzcinski 已提交
263

R
Regis 已提交
264 265 266
        before do
          visit namespace_project_pipelines_path(project.namespace, project)
        end
267

268
        it { expect(page).not_to have_selector('.build-artifacts') }
K
Kamil Trzcinski 已提交
269 270
      end
    end
271 272 273 274 275 276 277 278

    context 'mini pipleine graph' do
      let!(:build) do
        create(:ci_build, pipeline: pipeline, stage: 'build', name: 'build')
      end

      before do
        visit namespace_project_pipelines_path(project.namespace, project)
279
        wait_for_vue_resource
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
      end

      context 'when clicking a graph stage' do
        it 'should open a dropdown' do
          find('.js-builds-dropdown-button').trigger('click')

          expect(page).to have_link build.name
        end

        it 'should be possible to retry the failed build' do
          find('.js-builds-dropdown-button').trigger('click')

          find('a.ci-action-icon-container').trigger('click')
          expect(page).not_to have_content('Cancel running')
        end
      end
    end
K
Kamil Trzcinski 已提交
297 298
  end

299
  describe 'POST /:project/pipelines', feature: true, js: true do
K
Kamil Trzcinski 已提交
300 301
    let(:project) { create(:project) }

R
Regis 已提交
302 303 304
    before do
      visit new_namespace_project_pipeline_path(project.namespace, project)
    end
K
Kamil Trzcinski 已提交
305 306

    context 'for valid commit' do
U
ubudzisz 已提交
307
      before { fill_in('pipeline[ref]', with: 'master') }
308 309

      context 'with gitlab-ci.yml' do
310
        before { stub_ci_pipeline_to_return_yaml_file }
311

312 313 314
        it 'creates a new pipeline' do
          expect { click_on 'Create pipeline' }
            .to change { Ci::Pipeline.count }.by(1)
R
Regis 已提交
315
        end
K
Kamil Trzcinski 已提交
316
      end
K
Kamil Trzcinski 已提交
317

318 319 320 321 322
      context 'without gitlab-ci.yml' do
        before { click_on 'Create pipeline' }

        it { expect(page).to have_content('Missing .gitlab-ci.yml file') }
      end
K
Kamil Trzcinski 已提交
323 324 325 326
    end

    context 'for invalid commit' do
      before do
U
ubudzisz 已提交
327
        fill_in('pipeline[ref]', with: 'invalid-reference')
K
Kamil Trzcinski 已提交
328 329 330 331 332
        click_on 'Create pipeline'
      end

      it { expect(page).to have_content('Reference not found') }
    end
K
Kamil Trzcinski 已提交
333
  end
U
ubudzisz 已提交
334

335
  describe 'Create pipelines', feature: true, js: true do
U
ubudzisz 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
    let(:project) { create(:project) }

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

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

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

        within('.ui-autocomplete') do
          expect(page).to have_selector('li', text: 'fix')
        end
      end
    end
  end
K
Kamil Trzcinski 已提交
360
end