debian-mirror-gitlab/spec/features/triggers_spec.rb

152 lines
5.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-09-25 12:07:36 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Triggers', :js do
2017-08-17 22:00:37 +05:30
let(:trigger_title) { 'trigger desc' }
2015-10-24 18:46:33 +05:30
let(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
let(:user2) { create(:user) }
let(:guest_user) { create(:user) }
2015-09-25 12:07:36 +05:30
before do
2017-09-10 17:25:29 +05:30
sign_in(user)
@project = create(:project)
2018-11-18 11:00:15 +05:30
@project.add_maintainer(user)
@project.add_maintainer(user2)
2018-03-17 18:26:18 +05:30
@project.add_guest(guest_user)
2017-09-10 17:25:29 +05:30
visit project_settings_ci_cd_path(@project)
2015-09-25 12:07:36 +05:30
end
2021-01-03 14:25:43 +05:30
shared_examples 'triggers page' do
describe 'create trigger workflow' do
it 'prevents adding new trigger with no description' do
fill_in 'trigger_description', with: ''
click_button 'Add trigger'
# See if input has error due to empty value
expect(page.find('form.gl-show-field-errors .gl-field-error')).to be_visible
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
it 'adds new trigger with description' do
fill_in 'trigger_description', with: 'trigger desc'
click_button 'Add trigger'
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
aggregate_failures 'display creation notice and trigger is created' do
2022-04-04 11:22:00 +05:30
expect(page.find('[data-testid="alert-info"]')).to have_content 'Trigger was created successfully.'
2021-01-03 14:25:43 +05:30
expect(page.find('.triggers-list')).to have_content 'trigger desc'
expect(page.find('.triggers-list .trigger-owner')).to have_content user.name
end
end
2017-08-17 22:00:37 +05:30
end
2021-01-03 14:25:43 +05:30
describe 'edit trigger workflow' do
let(:new_trigger_title) { 'new trigger' }
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
it 'click on edit trigger opens edit trigger page' do
create(:ci_trigger, owner: user, project: @project, description: trigger_title)
visit project_settings_ci_cd_path(@project)
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
# See if edit page has correct descrption
find('a[title="Edit"]').send_keys(:return)
expect(page.find('#trigger_description').value).to have_content 'trigger desc'
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
it 'edit trigger and save' do
create(:ci_trigger, owner: user, project: @project, description: trigger_title)
visit project_settings_ci_cd_path(@project)
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
# See if edit page opens, then fill in new description and save
find('a[title="Edit"]').send_keys(:return)
fill_in 'trigger_description', with: new_trigger_title
click_button 'Save trigger'
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
aggregate_failures 'display update notice and trigger is updated' do
2022-04-04 11:22:00 +05:30
expect(page.find('[data-testid="alert-info"]')).to have_content 'Trigger was successfully updated.'
2021-01-03 14:25:43 +05:30
expect(page.find('.triggers-list')).to have_content new_trigger_title
expect(page.find('.triggers-list .trigger-owner')).to have_content user.name
end
end
2017-08-17 22:00:37 +05:30
end
2021-01-03 14:25:43 +05:30
describe 'trigger "Revoke" workflow' do
before do
2021-12-11 22:18:48 +05:30
stub_feature_flags(bootstrap_confirmation_modals: false)
2021-01-03 14:25:43 +05:30
create(:ci_trigger, owner: user2, project: @project, description: trigger_title)
visit project_settings_ci_cd_path(@project)
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
it 'button "Revoke" has correct alert' do
expected_alert = 'By revoking a trigger you will break any processes making use of it. Are you sure?'
expect(page.find('[data-testid="trigger_revoke_button"]')['data-confirm']).to eq expected_alert
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
it 'revoke trigger' do
# See if "Revoke" on trigger works post trigger creation
page.accept_confirm do
find('[data-testid="trigger_revoke_button"]').send_keys(:return)
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
aggregate_failures 'trigger is removed' do
2022-04-04 11:22:00 +05:30
expect(page.find('[data-testid="alert-info"]')).to have_content 'Trigger removed'
2021-01-03 14:25:43 +05:30
expect(page).to have_css('[data-testid="no_triggers_content"]')
end
end
2017-08-17 22:00:37 +05:30
end
2021-01-03 14:25:43 +05:30
describe 'show triggers workflow' do
it 'contains trigger description placeholder' do
expect(page.find('#trigger_description')['placeholder']).to eq 'Trigger description'
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
it 'show "invalid" badge for trigger with owner having insufficient permissions' do
create(:ci_trigger, owner: guest_user, project: @project, description: trigger_title)
visit project_settings_ci_cd_path(@project)
aggregate_failures 'has invalid badge and no edit link' do
expect(page.find('.triggers-list')).to have_content 'invalid'
expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]')
end
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
it 'do not show "Edit" or full token for not owned trigger' do
# Create trigger with user different from current_user
create(:ci_trigger, owner: user2, project: @project, description: trigger_title)
visit project_settings_ci_cd_path(@project)
aggregate_failures 'shows truncated token, no clipboard button and no edit link' do
expect(page.find('.triggers-list')).to have_content(@project.triggers.first.token[0..3])
expect(page.find('.triggers-list')).not_to have_selector('[data-testid="clipboard-btn"]')
expect(page.find('.triggers-list .trigger-owner')).not_to have_content user.name
expect(page.find('.triggers-list')).not_to have_selector('a[title="Edit"]')
end
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
it 'show "Edit" and full token for owned trigger' do
create(:ci_trigger, owner: user, project: @project, description: trigger_title)
visit project_settings_ci_cd_path(@project)
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
aggregate_failures 'shows full token, clipboard button and edit link' do
expect(page.find('.triggers-list')).to have_content @project.triggers.first.token
expect(page.find('.triggers-list')).to have_selector('[data-testid="clipboard-btn"]')
expect(page.find('.triggers-list .trigger-owner')).to have_content user.name
expect(page.find('.triggers-list')).to have_selector('a[title="Edit"]')
end
end
2017-08-17 22:00:37 +05:30
end
2021-01-03 14:25:43 +05:30
end
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
context 'when ci_pipeline_triggers_settings_vue_ui is enabled' do
it_behaves_like 'triggers page'
end
2015-09-25 12:07:36 +05:30
2021-01-03 14:25:43 +05:30
context 'when ci_pipeline_triggers_settings_vue_ui is disabled' do
before do
stub_feature_flags(ci_pipeline_triggers_settings_vue_ui: false)
2015-09-25 12:07:36 +05:30
end
2021-01-03 14:25:43 +05:30
it_behaves_like 'triggers page'
2015-09-25 12:07:36 +05:30
end
end