Commit 11a682a9 authored by Justin Ho's avatar Justin Ho

Refactor feature specs to use shared context

Specs that test functionality around project services
can use the shared context to DRY them up when
declaring variables and in common actions.

YouTrack spec is redundant as it's already tested in
user_activates_issue_tracker_spec.rb
parent faec4fc1
......@@ -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)
find('input[name="service[active]"] + button').click 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)
find('input[name="service[active]"] + button').click 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
......@@ -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
......
# 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
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