Commit b8dc935e authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '213950-refactor-feature-specs-around-project-services' into 'master'

Refactor feature specs around project services

See merge request gitlab-org/gitlab!29470
parents f8036bfc 6b6b779a
......@@ -30,7 +30,7 @@ class Projects::MattermostsController < Projects::ApplicationController
def configure_params
params.require(:mattermost).permit(:trigger, :team_id).merge(
url: service_trigger_url(@service),
icon_url: asset_url('slash-command-logo.png'))
icon_url: asset_url('slash-command-logo.png', skip_pipeline: true))
end
def teams
......
......@@ -57,7 +57,7 @@
.form-group
= label_tag nil, _('Customize icon'), class: 'col-12 col-form-label label-bold'
.col-12
= image_tag(asset_url('slash-command-logo.png'), width: 36, height: 36, class: 'mr-3')
= image_tag(asset_url('slash-command-logo.png', skip_pipeline: true), width: 36, height: 36, class: 'mr-3')
= link_to(_('Download image'), asset_url('gitlab_logo.png'), class: 'btn btn-sm', target: '_blank', rel: 'noopener noreferrer')
.form-group
......
......@@ -5,8 +5,8 @@ require 'spec_helper'
describe 'Prometheus custom metrics', :js do
include PrometheusHelpers
let(:project) { create(:project) }
let(:user) { create(:user) }
include_context 'project service activation'
let!(:prometheus_metric) { create(:prometheus_metric, project: project) }
around do |example|
......@@ -14,30 +14,18 @@ describe 'Prometheus custom metrics', :js do
end
before do
project.add_maintainer(user)
sign_in(user)
visit(project_settings_integrations_path(project))
click_link('Prometheus')
stub_request(:get, prometheus_query_with_time_url('avg(metric)', Time.now.utc))
create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
click_link('Prometheus')
visit_project_integration('Prometheus')
end
it 'Deletes a custom metric' do
wait_for_requests
it 'deletes a custom metric' do
first('.custom-metric-link-bold').click
click_button('Delete')
click_button('Delete metric')
wait_for_requests
expect(all('.custom-metric-link-bold').count).to eq(0)
end
end
......@@ -3,16 +3,12 @@
require 'spec_helper'
describe 'Disable individual triggers' do
let(:project) { create(:project) }
let(:user) { project.owner }
include_context 'project service activation'
let(:checkbox_selector) { 'input[type=checkbox][id$=_events]' }
before do
sign_in(user)
visit(project_settings_integrations_path(project))
click_link(service_name)
visit_project_integration(service_name)
end
context 'service has multiple supported events' do
......
......@@ -3,26 +3,18 @@
require 'spec_helper'
describe 'Prometheus external alerts', :js do
let(:project) { create(:project) }
let(:user) { create(:user) }
include_context 'project service activation'
let(:alerts_section_selector) { '.js-prometheus-alerts' }
let(:alerts_section) { page.find(alerts_section_selector) }
before do
sign_in(user)
project.add_maintainer(user)
visit_edit_service
end
context 'with manual configuration' do
before do
create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
end
it 'shows the Alerts section' do
visit_edit_service
visit_project_integration('Prometheus')
expect(alerts_section).to have_content('Alerts')
expect(alerts_section).to have_content('Receive alerts from manually configured Prometheus servers.')
......@@ -33,16 +25,10 @@ describe 'Prometheus external alerts', :js do
context 'with no configuration' do
it 'does not show the Alerts section' do
visit_project_integration('Prometheus')
wait_for_requests
expect(page).not_to have_css(alerts_section_selector)
end
end
private
def visit_edit_service
visit(project_settings_integrations_path(project))
click_link('Prometheus')
end
end
......@@ -3,29 +3,17 @@
require 'spec_helper'
describe 'User activates issue tracker', :js do
let(:user) { create(:user) }
let(:project) { create(:project) }
include_context 'project service activation'
let(:url) { 'http://tracker.example.com' }
def fill_short_form(disabled: false)
find('input[name="service[active]"] + button').click if disabled
def fill_form(disable: false, skip_new_issue_url: false)
click_active_toggle if disable
fill_in 'service_project_url', with: url
fill_in 'service_issues_url', with: "#{url}/:id"
end
def fill_full_form(disabled: false)
fill_short_form(disabled: disabled)
fill_in 'service_new_issue_url', with: url
end
before do
project.add_maintainer(user)
sign_in(user)
visit project_settings_integrations_path(project)
fill_in 'service_new_issue_url', with: url unless skip_new_issue_url
end
shared_examples 'external issue tracker activation' do |tracker:, skip_new_issue_url: false|
......@@ -34,16 +22,10 @@ describe 'User activates issue tracker', :js do
before do
stub_request(:head, url).to_return(headers: { 'Content-Type' => 'application/json' })
click_link(tracker)
if skip_new_issue_url
fill_short_form
else
fill_full_form
end
visit_project_integration(tracker)
fill_form(skip_new_issue_url: skip_new_issue_url)
click_button('Test settings and save changes')
wait_for_requests
click_test_integration
end
it 'activates the service' do
......@@ -62,22 +44,10 @@ describe 'User activates issue tracker', :js do
it 'activates the service' do
stub_request(:head, url).to_raise(Gitlab::HTTP::Error)
click_link(tracker)
if skip_new_issue_url
fill_short_form
else
fill_full_form
end
click_button('Test settings and save changes')
wait_for_requests
visit_project_integration(tracker)
fill_form(skip_new_issue_url: skip_new_issue_url)
expect(find('.flash-container-page')).to have_content 'Test failed.'
expect(find('.flash-container-page')).to have_content 'Save anyway'
find('.flash-alert .flash-action').click
wait_for_requests
click_test_then_save_integration
expect(page).to have_content("#{tracker} activated.")
expect(current_path).to eq(project_settings_integrations_path(project))
......@@ -87,13 +57,8 @@ describe 'User activates issue tracker', :js do
describe 'user disables the service' do
before do
click_link(tracker)
if skip_new_issue_url
fill_short_form(disabled: true)
else
fill_full_form(disabled: true)
end
visit_project_integration(tracker)
fill_form(disable: true, skip_new_issue_url: skip_new_issue_url)
click_button('Save changes')
end
......
......@@ -3,14 +3,13 @@
require 'spec_helper'
describe 'User activates Jira', :js do
let(:user) { create(:user) }
let(:project) { create(:project) }
include_context 'project service activation'
let(:url) { 'http://jira.example.com' }
let(:test_url) { 'http://jira.example.com/rest/api/2/serverInfo' }
def fill_form(disabled: false)
find('input[name="service[active]"] + button').click if disabled
def fill_form(disable: false)
click_active_toggle if disable
fill_in 'service_url', with: url
fill_in 'service_username', with: 'username'
......@@ -18,23 +17,15 @@ describe 'User activates Jira', :js do
fill_in 'service_jira_issue_transition_id', with: '25'
end
before do
project.add_maintainer(user)
sign_in(user)
visit project_settings_integrations_path(project)
end
describe 'user sets and activates Jira Service' do
context 'when Jira connection test succeeds' do
before do
server_info = { key: 'value' }.to_json
WebMock.stub_request(:get, test_url).with(basic_auth: %w(username password)).to_return(body: server_info)
stub_request(:get, test_url).with(basic_auth: %w(username password)).to_return(body: server_info)
click_link('Jira')
visit_project_integration('Jira')
fill_form
click_button('Test settings and save changes')
wait_for_requests
click_test_integration
end
it 'activates the Jira service' do
......@@ -51,10 +42,10 @@ describe 'User activates Jira', :js do
context 'when Jira connection test fails' do
it 'shows errors when some required fields are not filled in' do
click_link('Jira')
visit_project_integration('Jira')
fill_in 'service_password', with: 'password'
click_button('Test settings and save changes')
click_test_integration
page.within('.service-settings') do
expect(page).to have_content('This field is required.')
......@@ -62,19 +53,12 @@ describe 'User activates Jira', :js do
end
it 'activates the Jira service' do
WebMock.stub_request(:get, test_url).with(basic_auth: %w(username password))
stub_request(:get, test_url).with(basic_auth: %w(username password))
.to_raise(JIRA::HTTPError.new(double(message: 'message')))
click_link('Jira')
visit_project_integration('Jira')
fill_form
click_button('Test settings and save changes')
wait_for_requests
expect(find('.flash-container-page')).to have_content 'Test failed. message'
expect(find('.flash-container-page')).to have_content 'Save anyway'
find('.flash-alert .flash-action').click
wait_for_requests
click_test_then_save_integration
expect(page).to have_content('Jira activated.')
expect(current_path).to eq(project_settings_integrations_path(project))
......@@ -84,8 +68,8 @@ describe 'User activates Jira', :js do
describe 'user disables the Jira Service' do
before do
click_link('Jira')
fill_form(disabled: true)
visit_project_integration('Jira')
fill_form(disable: true)
click_button('Save changes')
end
......
......@@ -3,18 +3,17 @@
require 'spec_helper'
describe 'Set up Mattermost slash commands', :js do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:mattermost_enabled) { true }
describe 'user visits the mattermost slash command config page' do
include_context 'project service activation'
before do
stub_mattermost_setting(enabled: mattermost_enabled)
project.add_maintainer(user)
sign_in(user)
visit edit_project_service_path(project, :mattermost_slash_commands)
visit_project_integration('Mattermost slash commands')
end
describe 'user visits the mattermost slash command config page' do
context 'mattermost service is enabled' do
let(:mattermost_enabled) { true }
it 'shows a help message' do
expect(page).to have_content("This service allows users to perform common")
end
......@@ -29,7 +28,7 @@ describe 'Set up Mattermost slash commands', :js do
token = ('a'..'z').to_a.join
fill_in 'service_token', with: token
find('input[name="service[active]"] + button').click
click_active_toggle
click_on 'Save changes'
expect(current_path).to eq(project_settings_integrations_path(project))
......@@ -153,8 +152,9 @@ describe 'Set up Mattermost slash commands', :js do
teams
end
end
describe 'mattermost service is not enabled' do
context 'mattermost service is not enabled' do
let(:mattermost_enabled) { false }
it 'shows the correct trigger url' do
......
......@@ -3,13 +3,10 @@
require 'spec_helper'
describe 'Slack slash commands' do
let(:user) { create(:user) }
let(:project) { create(:project) }
include_context 'project service activation'
before do
project.add_maintainer(user)
sign_in(user)
visit edit_project_service_path(project, :slack_slash_commands)
visit_project_integration('Slack slash commands')
end
it 'shows a token placeholder' do
......@@ -24,7 +21,7 @@ describe 'Slack slash commands' do
it 'redirects to the integrations page after saving but not activating', :js do
fill_in 'service_token', with: 'token'
find('input[name="service[active]"] + button').click
click_active_toggle
click_on 'Save'
expect(current_path).to eq(project_settings_integrations_path(project))
......
# frozen_string_literal: true
require 'spec_helper'
describe 'User activates issue tracker', :js do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:url) { 'http://tracker.example.com' }
def fill_form(disabled: false)
find('input[name="service[active]"] + button').click if disabled
fill_in 'service_project_url', with: url
fill_in 'service_issues_url', with: "#{url}/:id"
end
before do
project.add_maintainer(user)
sign_in(user)
visit project_settings_integrations_path(project)
end
shared_examples 'external issue tracker activation' do |tracker:|
describe 'user sets and activates the Service' do
context 'when the connection test succeeds' do
before do
stub_request(:head, url).to_return(headers: { 'Content-Type' => 'application/json' })
click_link(tracker)
fill_form
click_button('Test settings and save changes')
wait_for_requests
end
it 'activates the service' do
expect(page).to have_content("#{tracker} activated.")
expect(current_path).to eq(project_settings_integrations_path(project))
end
it 'shows the link in the menu' do
page.within('.nav-sidebar') do
expect(page).to have_link(tracker, href: url)
end
end
end
context 'when the connection test fails' do
it 'activates the service' do
stub_request(:head, url).to_raise(Gitlab::HTTP::Error)
click_link(tracker)
fill_form
click_button('Test settings and save changes')
wait_for_requests
expect(find('.flash-container-page')).to have_content 'Test failed.'
expect(find('.flash-container-page')).to have_content 'Save anyway'
find('.flash-alert .flash-action').click
wait_for_requests
expect(page).to have_content("#{tracker} activated.")
expect(current_path).to eq(project_settings_integrations_path(project))
end
end
end
describe 'user disables the service' do
before do
click_link(tracker)
fill_form(disabled: true)
click_button('Save changes')
end
it 'saves but does not activate the service' do
expect(page).to have_content("#{tracker} settings saved, but not activated.")
expect(current_path).to eq(project_settings_integrations_path(project))
end
it 'does not show the external tracker link in the menu' do
page.within('.nav-sidebar') do
expect(page).not_to have_link(tracker, href: url)
end
end
end
end
it_behaves_like 'external issue tracker activation', tracker: 'YouTrack'
end
......@@ -18,6 +18,10 @@ shared_context 'project service activation' do
click_link(name)
end
def click_active_toggle
find('input[name="service[active]"] + button').click
end
def click_test_integration
click_button('Test settings and save changes')
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment