gitlab-org--gitlab-foss/spec/features/projects/pipeline_schedules_spec.rb

290 lines
9.5 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2017-06-29 05:33:24 -04:00
feature 'Pipeline Schedules', :feature, js: true do
include PipelineSchedulesHelper
let!(:project) { create(:project) }
2017-05-23 14:32:21 -04:00
let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project ) }
let!(:pipeline) { create(:ci_pipeline, pipeline_schedule: pipeline_schedule) }
let(:scope) { nil }
let!(:user) { create(:user) }
before do
project.add_master(user)
gitlab_sign_in(user)
end
describe 'GET /projects/pipeline_schedules' do
2017-06-29 05:33:24 -04:00
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')
2017-06-29 13:22:05 -04:00
expect(find(".next-run-cell time")['data-original-title'])
2017-07-01 02:23:09 -04:00
.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_link 'Take ownership'
page.within('.pipeline-schedule-table-row') do
expect(page).not_to have_content('No owner')
expect(page).to have_link('John Doe')
end
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
it 'deletes the pipeline' do
click_link 'Delete'
2017-06-29 13:22:05 -04:00
expect(page).not_to have_css(".pipeline-schedule-table-row")
end
end
2017-05-25 06:20:24 -04:00
2017-05-26 08:16:29 -04:00
context 'when ref is nil' do
2017-05-25 06:20:24 -04:00
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
end
2017-06-29 05:33:24 -04:00
describe 'POST /projects/pipeline_schedules/new' do
before do
visit_new_pipeline_schedule
end
2017-05-12 21:15:27 -04:00
it 'sets defaults for timezone and target branch' do
expect(page).to have_button('master')
expect(page).to have_button('UTC')
end
it 'it creates a new scheduled pipeline' do
fill_in_schedule_form
save_pipeline_schedule
expect(page).to have_content('my fancy description')
end
it 'it prevents an invalid form from being submitted' do
save_pipeline_schedule
expect(page).to have_content('This field is required')
end
it 'sets a variable' do
fill_in_schedule_form
fill_in_variable
save_pipeline_schedule
expect(Ci::PipelineSchedule.last.job_variables).to eq([{ key: 'foo', value: 'bar', public: false }])
end
end
2017-06-29 05:33:24 -04:00
describe 'PATCH /projects/pipelines_schedules/:id/edit' do
before do
edit_pipeline_schedule
end
it '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('UTC')
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
2017-05-25 06:20:24 -04:00
it 'adds a new variable' do
fill_in_variable
save_pipeline_schedule
expect(Ci::PipelineSchedule.last.job_variables).to eq([{ key: 'foo', value: 'bar', public: false }])
end
2017-05-26 08:16:29 -04:00
context 'when ref is nil' do
2017-05-25 06:20:24 -04:00
before do
pipeline_schedule.update_attribute(:ref, nil)
edit_pipeline_schedule
end
it 'shows the pipeline schedule with default ref' do
page.within('.js-target-branch-dropdown') do
2017-05-25 06:20:24 -04:00
expect(first('.dropdown-toggle-text').text).to eq('master')
end
end
end
context 'when variables already exist' do
before do
create(:ci_pipeline_schedule_variable, key: 'some_key', value: 'some_value', pipeline_schedule: pipeline_schedule)
edit_pipeline_schedule
end
it 'edits existing variable' do
expect(first('[name="schedule[variables_attributes][][key]"]').value).to eq('some_key')
expect(first('[name="schedule[variables_attributes][][value]"]').value).to eq('some_value')
fill_in_variable
save_pipeline_schedule
expect(Ci::PipelineSchedule.last.job_variables).to eq([{ key: 'foo', value: 'bar', public: false }])
end
it 'removes an existing variable' do
remove_variable
save_pipeline_schedule
expect(Ci::PipelineSchedule.last.job_variables).to eq([])
end
it 'adds another variable' do
fill_in_variable(1)
save_pipeline_schedule
expect(Ci::PipelineSchedule.last.job_variables).to eq([
{ key: 'some_key', value: 'some_value', public: false },
{ key: 'foo', value: 'bar', public: false }
])
end
end
2017-06-29 05:33:24 -04:00
end
2017-06-29 05:33:24 -04:00
context 'when user creates a new pipeline schedule with variables' do
background 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][][value]"]')[0].set('AAA123')
all('[name="schedule[variables_attributes][][key]"]')[1].set('BBB')
all('[name="schedule[variables_attributes][][value]"]')[1].set('BBB123')
save_pipeline_schedule
end
2017-06-29 05:33:24 -04:00
scenario 'user sees the new variable in edit window' do
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
2017-06-29 13:22:05 -04:00
page.within('.pipeline-variable-list') do
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('AAA')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('AAA123')
expect(find(".pipeline-variable-row:nth-child(2) .pipeline-variable-key-input").value).to eq('BBB')
expect(find(".pipeline-variable-row:nth-child(2) .pipeline-variable-value-input").value).to eq('BBB123')
end
2017-06-29 05:33:24 -04:00
end
end
2017-06-29 05:33:24 -04:00
context 'when user edits a variable of a pipeline schedule' do
background do
2017-06-29 13:22:05 -04:00
create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
2017-06-29 05:33:24 -04:00
create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule)
end
2017-06-29 05:33:24 -04:00
visit_pipelines_schedules
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
all('[name="schedule[variables_attributes][][key]"]')[0].set('foo')
all('[name="schedule[variables_attributes][][value]"]')[0].set('bar')
click_button 'Save pipeline schedule'
end
2017-06-29 05:33:24 -04:00
scenario '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
2017-06-29 13:22:05 -04:00
page.within('.pipeline-variable-list') do
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('foo')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('bar')
end
2017-06-29 05:33:24 -04:00
end
end
2017-06-29 05:33:24 -04:00
context 'when user removes a variable of a pipeline schedule' do
background do
2017-06-29 13:22:05 -04:00
create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
2017-06-29 05:33:24 -04:00
create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule)
end
2017-06-29 05:33:24 -04:00
visit_pipelines_schedules
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
2017-06-29 13:22:05 -04:00
find('.pipeline-variable-list .pipeline-variable-row-remove-button').click
2017-06-29 05:33:24 -04:00
click_button 'Save pipeline schedule'
end
2017-06-29 05:33:24 -04:00
scenario '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
2017-06-29 13:22:05 -04:00
page.within('.pipeline-variable-list') do
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('')
end
end
end
def visit_new_pipeline_schedule
visit new_namespace_project_pipeline_schedule_path(project.namespace, project, pipeline_schedule)
end
def edit_pipeline_schedule
visit edit_namespace_project_pipeline_schedule_path(project.namespace, project, pipeline_schedule)
end
def visit_pipelines_schedules
visit namespace_project_pipeline_schedules_path(project.namespace, project, scope: scope)
end
def select_timezone
find('.js-timezone-dropdown').click
click_link 'American Samoa'
end
def select_target_branch
find('.js-target-branch-dropdown').click
click_link 'master'
end
def save_pipeline_schedule
click_button 'Save pipeline schedule'
end
def fill_in_variable(index = 0)
all('[name="schedule[variables_attributes][][key]"]')[index].set('foo')
all('[name="schedule[variables_attributes][][value]"]')[index].set('bar')
end
def remove_variable
first('.js-pipeline-variable-list .js-row-remove-button').click
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
end
end