Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pipeline_schedules_spec.rb « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 358c55376d437bba7713e585874be170c7ad0bbc (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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Pipeline Schedules', :js, feature_category: :groups_and_projects do
  include Spec::Support::Helpers::ModalHelpers

  let!(:project) { create(:project, :repository) }
  let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project) }
  let!(:pipeline) { create(:ci_pipeline, pipeline_schedule: pipeline_schedule, project: project) }
  let(:scope) { nil }
  let!(:user) { create(:user) }
  let!(:maintainer) { create(:user) }

  context 'with pipeline_schedules_vue feature flag turned off' do
    before do
      stub_feature_flags(pipeline_schedules_vue: false)
    end

    context 'logged in as the pipeline schedule owner' do
      before do
        project.add_developer(user)
        pipeline_schedule.update!(owner: user)
        gitlab_sign_in(user)
      end

      describe 'GET /projects/pipeline_schedules' do
        before do
          visit_pipelines_schedules
        end

        it 'edits the pipeline' do
          page.within('.pipeline-schedule-table-row') do
            click_link 'Edit'
          end

          expect(page).to have_content('Edit Pipeline Schedule')
        end
      end

      describe 'PATCH /projects/pipelines_schedules/:id/edit' do
        before do
          edit_pipeline_schedule
        end

        it 'displays existing properties' do
          description = find_field('schedule_description').value
          expect(description).to eq('pipeline schedule')
          expect(page).to have_button('master')
          expect(page).to have_button('Select timezone')
        end

        it 'edits the scheduled pipeline' do
          fill_in 'schedule_description', with: 'my brand new description'

          save_pipeline_schedule

          expect(page).to have_content('my brand new description')
        end

        context 'when ref is nil' do
          before do
            pipeline_schedule.update_attribute(:ref, nil)
            edit_pipeline_schedule
          end

          it 'shows the pipeline schedule with default ref' do
            page.within('[data-testid="schedule-target-ref"]') do
              expect(first('.gl-button-text').text).to eq('master')
            end
          end
        end

        context 'when ref is empty' do
          before do
            pipeline_schedule.update_attribute(:ref, '')
            edit_pipeline_schedule
          end

          it 'shows the pipeline schedule with default ref' do
            page.within('[data-testid="schedule-target-ref"]') do
              expect(first('.gl-button-text').text).to eq('master')
            end
          end
        end
      end
    end

    context 'logged in as a project maintainer' do
      before do
        project.add_maintainer(user)
        gitlab_sign_in(user)
      end

      describe 'GET /projects/pipeline_schedules' do
        before do
          visit_pipelines_schedules
        end

        describe 'The view' do
          it 'displays the required information description' do
            page.within('.pipeline-schedule-table-row') do
              expect(page).to have_content('pipeline schedule')
              expect(find("[data-testid='next-run-cell'] time")['title'])
                .to include(pipeline_schedule.real_next_run.strftime('%b %-d, %Y'))
              expect(page).to have_link('master')
              expect(page).to have_link("##{pipeline.id}")
            end
          end

          it 'creates a new scheduled pipeline' do
            click_link 'New schedule'

            expect(page).to have_content('Schedule a new pipeline')
          end

          it 'changes ownership of the pipeline' do
            click_button 'Take ownership'

            page.within('#pipeline-take-ownership-modal') do
              click_link 'Take ownership'
            end

            page.within('.pipeline-schedule-table-row') do
              expect(page).not_to have_content('No owner')
              expect(page).to have_link('Sidney Jones')
            end
          end

          it 'deletes the pipeline' do
            click_link 'Delete'

            accept_gl_confirm(button_text: 'Delete pipeline schedule')

            expect(page).not_to have_css(".pipeline-schedule-table-row")
          end
        end

        context 'when ref is nil' do
          before do
            pipeline_schedule.update_attribute(:ref, nil)
            visit_pipelines_schedules
          end

          it 'shows a list of the pipeline schedules with empty ref column' do
            expect(first('.branch-name-cell').text).to eq('')
          end
        end

        context 'when ref is empty' do
          before do
            pipeline_schedule.update_attribute(:ref, '')
            visit_pipelines_schedules
          end

          it 'shows a list of the pipeline schedules with empty ref column' do
            expect(first('.branch-name-cell').text).to eq('')
          end
        end
      end

      describe 'POST /projects/pipeline_schedules/new' do
        before do
          visit_new_pipeline_schedule
        end

        it 'sets defaults for timezone and target branch' do
          expect(page).to have_button('master')
          expect(page).to have_button('Select timezone')
        end

        it 'creates a new scheduled pipeline' do
          fill_in_schedule_form
          save_pipeline_schedule

          expect(page).to have_content('my fancy description')
        end

        it 'prevents an invalid form from being submitted' do
          save_pipeline_schedule

          expect(page).to have_content('This field is required')
        end
      end

      context 'when user creates a new pipeline schedule with variables' do
        before do
          visit_pipelines_schedules
          click_link 'New schedule'
          fill_in_schedule_form
          all('[name="schedule[variables_attributes][][key]"]')[0].set('AAA')
          all('[name="schedule[variables_attributes][][secret_value]"]')[0].set('AAA123')
          all('[name="schedule[variables_attributes][][key]"]')[1].set('BBB')
          all('[name="schedule[variables_attributes][][secret_value]"]')[1].set('BBB123')
          save_pipeline_schedule
        end

        it 'user sees the new variable in edit window', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/397040' do
          find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
          page.within('.ci-variable-list') do
            expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-key").value).to eq('AAA')
            expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-value", visible: false).value).to eq('AAA123')
            expect(find(".ci-variable-row:nth-child(2) .js-ci-variable-input-key").value).to eq('BBB')
            expect(find(".ci-variable-row:nth-child(2) .js-ci-variable-input-value", visible: false).value).to eq('BBB123')
          end
        end
      end

      context 'when user edits a variable of a pipeline schedule' do
        before do
          create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
            create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule)
          end

          visit_pipelines_schedules
          find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
          find('.js-ci-variable-list-section .js-secret-value-reveal-button').click
          first('.js-ci-variable-input-key').set('foo')
          first('.js-ci-variable-input-value').set('bar')
          click_button 'Save pipeline schedule'
        end

        it 'user sees the updated variable in edit window' do
          find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
          page.within('.ci-variable-list') do
            expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-key").value).to eq('foo')
            expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-value", visible: false).value).to eq('bar')
          end
        end
      end

      context 'when user removes a variable of a pipeline schedule' do
        before do
          create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
            create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule)
          end

          visit_pipelines_schedules
          find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
          find('.ci-variable-list .ci-variable-row-remove-button').click
          click_button 'Save pipeline schedule'
        end

        it 'user does not see the removed variable in edit window' do
          find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
          page.within('.ci-variable-list') do
            expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-key").value).to eq('')
            expect(find(".ci-variable-row:nth-child(1) .js-ci-variable-input-value", visible: false).value).to eq('')
          end
        end
      end

      context 'when active is true and next_run_at is NULL' do
        before do
          create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
            pipeline_schedule.update_attribute(:next_run_at, nil) # Consequently next_run_at will be nil
          end
        end

        it 'user edit and recover the problematic pipeline schedule' do
          visit_pipelines_schedules
          find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
          fill_in 'schedule_cron', with: '* 1 2 3 4'
          click_button 'Save pipeline schedule'

          page.within('.pipeline-schedule-table-row:nth-child(1)') do
            expect(page).to have_css("[data-testid='next-run-cell'] time")
          end
        end
      end
    end

    context 'logged in as non-member' do
      before do
        gitlab_sign_in(user)
      end

      describe 'GET /projects/pipeline_schedules' do
        before do
          visit_pipelines_schedules
        end

        describe 'The view' do
          it 'does not show create schedule button' do
            expect(page).not_to have_link('New schedule')
          end
        end
      end
    end

    context 'not logged in' do
      describe 'GET /projects/pipeline_schedules' do
        before do
          visit_pipelines_schedules
        end

        describe 'The view' do
          it 'does not show create schedule button' do
            expect(page).not_to have_link('New schedule')
          end
        end
      end
    end
  end

  context 'with pipeline_schedules_vue feature flag turned on' do
    context 'logged in as a project maintainer' do
      before do
        project.add_maintainer(maintainer)
        pipeline_schedule.update!(owner: user)
        gitlab_sign_in(maintainer)
      end

      describe 'GET /projects/pipeline_schedules' do
        before do
          visit_pipelines_schedules

          wait_for_requests
        end

        describe 'The view' do
          it 'displays the required information description' do
            page.within('[data-testid="pipeline-schedule-table-row"]') do
              expect(page).to have_content('pipeline schedule')
              expect(find("[data-testid='next-run-cell'] time")['title'])
                .to include(pipeline_schedule.real_next_run.strftime('%b %-d, %Y'))
              expect(page).to have_link('master')
              expect(find("[data-testid='last-pipeline-status'] a")['href']).to include(pipeline.id.to_s)
            end
          end

          it 'changes ownership of the pipeline' do
            click_button 'Take ownership'

            page.within('#pipeline-take-ownership-modal') do
              click_button 'Take ownership'

              wait_for_requests
            end

            page.within('[data-testid="pipeline-schedule-table-row"]') do
              expect(page).not_to have_content('No owner')
              expect(page).to have_link('Sidney Jones')
            end
          end

          it 'runs the pipeline' do
            click_button 'Run pipeline schedule'

            wait_for_requests

            expect(page).to have_content("Successfully scheduled a pipeline to run. Go to the Pipelines page for details.")
          end

          it 'deletes the pipeline' do
            click_button 'Delete pipeline schedule'

            accept_gl_confirm(button_text: 'Delete pipeline schedule')

            expect(page).not_to have_css('[data-testid="pipeline-schedule-table-row"]')
          end
        end
      end
    end

    context 'logged in as non-member' do
      before do
        gitlab_sign_in(user)
      end

      describe 'GET /projects/pipeline_schedules' do
        before do
          visit_pipelines_schedules

          wait_for_requests
        end

        describe 'The view' do
          it 'does not show create schedule button' do
            expect(page).not_to have_link('New schedule')
          end
        end
      end
    end

    context 'not logged in' do
      describe 'GET /projects/pipeline_schedules' do
        before do
          visit_pipelines_schedules

          wait_for_requests
        end

        describe 'The view' do
          it 'does not show create schedule button' do
            expect(page).not_to have_link('New schedule')
          end
        end
      end
    end
  end

  def visit_new_pipeline_schedule
    visit new_project_pipeline_schedule_path(project, pipeline_schedule)
  end

  def edit_pipeline_schedule
    visit edit_project_pipeline_schedule_path(project, pipeline_schedule)
  end

  def visit_pipelines_schedules
    visit project_pipeline_schedules_path(project, scope: scope)
  end

  def select_timezone
    find('[data-testid="schedule-timezone"] .gl-new-dropdown-toggle').click
    find("li", text: "Arizona").click
  end

  def select_target_branch
    click_button 'master'
  end

  def save_pipeline_schedule
    click_button 'Save pipeline schedule'
  end

  def fill_in_schedule_form
    fill_in 'schedule_description', with: 'my fancy description'
    fill_in 'schedule_cron', with: '* 1 2 3 4'

    select_timezone
    select_target_branch
    find('body').click # close dropdown
  end
end