summaryrefslogtreecommitdiff
path: root/spec/features/projects/jobs/user_browses_jobs_spec.rb
blob: 3b70d177fce70f4cec7ebb27be00d7f5c6db013b (plain)
1
2
3
4
5
6
7
8
9
10
11
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# frozen_string_literal: true

require 'spec_helper'

def visit_jobs_page
  visit(project_jobs_path(project))

  wait_for_requests
end

RSpec.describe 'User browses jobs' do
  describe 'with jobs_table_vue feature flag turned off' do
    let!(:build) { create(:ci_build, :coverage, pipeline: pipeline) }
    let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.sha, ref: 'master') }
    let(:project) { create(:project, :repository, namespace: user.namespace) }
    let(:user) { create(:user) }

    before do
      stub_feature_flags(jobs_table_vue: false)
      project.add_maintainer(user)
      project.enable_ci
      project.update_attribute(:build_coverage_regex, /Coverage (\d+)%/)

      sign_in(user)

      visit(project_jobs_path(project))
    end

    it 'shows the coverage' do
      page.within('td.coverage') do
        expect(page).to have_content('99.9%')
      end
    end

    context 'with a failed job' do
      let!(:build) { create(:ci_build, :coverage, :failed, pipeline: pipeline) }

      it 'displays a tooltip with the failure reason' do
        page.within('.ci-table') do
          failed_job_link = page.find('.ci-failed')
          expect(failed_job_link[:title]).to eq('Failed - (unknown failure)')
        end
      end
    end
  end

  describe 'with jobs_table_vue feature flag turned on', :js do
    let(:project) { create(:project, :repository) }
    let(:user) { create(:user) }

    before do
      stub_feature_flags(jobs_table_vue: true)

      project.add_maintainer(user)
      project.enable_ci

      sign_in(user)
    end

    describe 'header tabs' do
      before do
        visit_jobs_page
      end

      it 'shows a tab for All jobs and count' do
        expect(page.find('[data-testid="jobs-all-tab"]').text).to include('All')
        expect(page.find('[data-testid="jobs-all-tab"] .badge').text).to include('0')
      end

      it 'shows a tab for Finished jobs and count' do
        expect(page.find('[data-testid="jobs-finished-tab"]').text).to include('Finished')
      end

      it 'updates the content when tab is clicked' do
        page.find('[data-testid="jobs-finished-tab"]').click
        wait_for_requests

        expect(page).to have_content('No jobs to show')
      end
    end

    describe 'Empty state' do
      before do
        visit_jobs_page
      end

      it 'renders an empty state' do
        expect(page).to have_content 'Use jobs to automate your tasks'
        expect(page).to have_content 'Create CI/CD configuration file'
      end
    end

    describe 'Job actions' do
      let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: 'master') }

      context 'when a job can be canceled' do
        let!(:job) do
          create(:ci_build, pipeline: pipeline,
                 stage: 'test')
        end

        before do
          job.run

          visit_jobs_page
        end

        it 'cancels a job successfully' do
          page.find('[data-testid="cancel-button"]').click

          wait_for_requests

          expect(page).to have_selector('.ci-canceled')
        end
      end

      context 'when a job can be retried' do
        let!(:job) do
          create(:ci_build, pipeline: pipeline,
                 stage: 'test')
        end

        before do
          job.drop

          visit_jobs_page
        end

        it 'retries a job successfully' do
          page.find('[data-testid="retry"]').click

          wait_for_requests

          expect(page).to have_selector('.ci-pending')
        end
      end

      context 'with a scheduled job' do
        let!(:scheduled_job) { create(:ci_build, :scheduled, pipeline: pipeline, name: 'build') }

        before do
          visit_jobs_page
        end

        it 'plays a job successfully' do
          page.find('[data-testid="play-scheduled"]').click

          page.within '#play-job-modal' do
            page.find_button('OK').click
          end

          wait_for_requests

          expect(page).to have_selector('.ci-pending')
        end

        it 'unschedules a job successfully' do
          page.find('[data-testid="unschedule"]').click

          wait_for_requests

          expect(page).to have_selector('.ci-manual')
        end
      end

      context 'with downloadable artifacts' do
        let!(:with_artifacts) do
          build = create(:ci_build, :success,
                         pipeline: pipeline,
                         name: 'rspec tests',
                         stage: 'test')

          create(:ci_job_artifact, :archive, job: build)
        end

        before do
          visit_jobs_page
        end

        it 'shows the download artifacts button' do
          expect(page).to have_selector('[data-testid="download-artifacts"]')
        end
      end

      context 'with artifacts expired' do
        let!(:with_artifacts_expired) do
          create(:ci_build, :expired, :success,
                 pipeline: pipeline,
                 name: 'rspec',
                 stage: 'test')
        end

        before do
          visit_jobs_page
        end

        it 'does not show the download artifacts button' do
          expect(page).not_to have_selector('[data-testid="download-artifacts"]')
        end
      end
    end

    describe 'Jobs table' do
      let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: 'master') }

      context 'column links' do
        let!(:job) do
          create(:ci_build, pipeline: pipeline,
                 stage: 'test')
        end

        before do
          job.run

          visit_jobs_page
        end

        it 'contains a link to the pipeline' do
          expect(page.find('[data-testid="pipeline-id"]')).to have_content "##{pipeline.id}"
        end

        it 'contains a link to the job sha' do
          expect(page.find('[data-testid="job-sha"]')).to have_content "#{job.sha[0..7]}"
        end

        it 'contains a link to the job id' do
          expect(page.find('[data-testid="job-id-link"]')).to have_content "#{job.id}"
        end

        it 'contains a link to the job ref' do
          expect(page.find('[data-testid="job-ref"]')).to have_content "#{job.ref}"
        end
      end
    end

    describe 'when user is not logged in' do
      before do
        sign_out(user)
      end

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

        context 'without jobs' do
          it 'shows an empty state' do
            visit project_jobs_path(public_project)
            wait_for_requests

            expect(page).to have_content 'Use jobs to automate your tasks'
          end
        end
      end

      context 'when project is private' do
        let(:private_project) { create(:project, :private, :repository) }

        it 'redirects the user to sign_in and displays the flash alert' do
          visit project_jobs_path(private_project)
          wait_for_requests

          expect(page).to have_content 'You need to sign in'
          expect(page).to have_current_path("/users/sign_in")
        end
      end
    end
  end
end