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 @@ ...@@ -3,16 +3,12 @@
require 'spec_helper' require 'spec_helper'
describe 'Disable individual triggers' do describe 'Disable individual triggers' do
let(:project) { create(:project) } include_context 'project service activation'
let(:user) { project.owner }
let(:checkbox_selector) { 'input[type=checkbox][id$=_events]' } let(:checkbox_selector) { 'input[type=checkbox][id$=_events]' }
before do before do
sign_in(user) visit_project_integration(service_name)
visit(project_settings_integrations_path(project))
click_link(service_name)
end end
context 'service has multiple supported events' do context 'service has multiple supported events' do
......
...@@ -3,26 +3,18 @@ ...@@ -3,26 +3,18 @@
require 'spec_helper' require 'spec_helper'
describe 'Prometheus external alerts', :js do describe 'Prometheus external alerts', :js do
let(:project) { create(:project) } include_context 'project service activation'
let(:user) { create(:user) }
let(:alerts_section_selector) { '.js-prometheus-alerts' } let(:alerts_section_selector) { '.js-prometheus-alerts' }
let(:alerts_section) { page.find(alerts_section_selector) } 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 context 'with manual configuration' do
before do before do
create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true) create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
end end
it 'shows the Alerts section' do 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('Alerts')
expect(alerts_section).to have_content('Receive alerts from manually configured Prometheus servers.') expect(alerts_section).to have_content('Receive alerts from manually configured Prometheus servers.')
...@@ -33,16 +25,10 @@ describe 'Prometheus external alerts', :js do ...@@ -33,16 +25,10 @@ describe 'Prometheus external alerts', :js do
context 'with no configuration' do context 'with no configuration' do
it 'does not show the Alerts section' do it 'does not show the Alerts section' do
visit_project_integration('Prometheus')
wait_for_requests wait_for_requests
expect(page).not_to have_css(alerts_section_selector) expect(page).not_to have_css(alerts_section_selector)
end end
end end
private
def visit_edit_service
visit(project_settings_integrations_path(project))
click_link('Prometheus')
end
end end
...@@ -3,29 +3,17 @@ ...@@ -3,29 +3,17 @@
require 'spec_helper' require 'spec_helper'
describe 'User activates issue tracker', :js do describe 'User activates issue tracker', :js do
let(:user) { create(:user) } include_context 'project service activation'
let(:project) { create(:project) }
let(:url) { 'http://tracker.example.com' } let(:url) { 'http://tracker.example.com' }
def fill_short_form(disabled: false) def fill_form(disable: false, skip_new_issue_url: false)
find('input[name="service[active]"] + button').click if disabled find('input[name="service[active]"] + button').click if disable
fill_in 'service_project_url', with: url fill_in 'service_project_url', with: url
fill_in 'service_issues_url', with: "#{url}/:id" 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 fill_in 'service_new_issue_url', with: url unless skip_new_issue_url
end
before do
project.add_maintainer(user)
sign_in(user)
visit project_settings_integrations_path(project)
end end
shared_examples 'external issue tracker activation' do |tracker:, skip_new_issue_url: false| shared_examples 'external issue tracker activation' do |tracker:, skip_new_issue_url: false|
...@@ -34,16 +22,10 @@ describe 'User activates issue tracker', :js do ...@@ -34,16 +22,10 @@ describe 'User activates issue tracker', :js do
before do before do
stub_request(:head, url).to_return(headers: { 'Content-Type' => 'application/json' }) stub_request(:head, url).to_return(headers: { 'Content-Type' => 'application/json' })
click_link(tracker) visit_project_integration(tracker)
fill_form(skip_new_issue_url: skip_new_issue_url)
if skip_new_issue_url
fill_short_form
else
fill_full_form
end
click_button('Test settings and save changes') click_test_integration
wait_for_requests
end end
it 'activates the service' do it 'activates the service' do
...@@ -62,22 +44,10 @@ describe 'User activates issue tracker', :js do ...@@ -62,22 +44,10 @@ describe 'User activates issue tracker', :js do
it 'activates the service' do it 'activates the service' do
stub_request(:head, url).to_raise(Gitlab::HTTP::Error) stub_request(:head, url).to_raise(Gitlab::HTTP::Error)
click_link(tracker) visit_project_integration(tracker)
fill_form(skip_new_issue_url: skip_new_issue_url)
if skip_new_issue_url
fill_short_form
else
fill_full_form
end
click_button('Test settings and save changes')
wait_for_requests
expect(find('.flash-container-page')).to have_content 'Test failed.' click_test_then_save_integration
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(page).to have_content("#{tracker} activated.")
expect(current_path).to eq(project_settings_integrations_path(project)) expect(current_path).to eq(project_settings_integrations_path(project))
...@@ -87,13 +57,8 @@ describe 'User activates issue tracker', :js do ...@@ -87,13 +57,8 @@ describe 'User activates issue tracker', :js do
describe 'user disables the service' do describe 'user disables the service' do
before do before do
click_link(tracker) visit_project_integration(tracker)
fill_form(disable: true, skip_new_issue_url: skip_new_issue_url)
if skip_new_issue_url
fill_short_form(disabled: true)
else
fill_full_form(disabled: true)
end
click_button('Save changes') click_button('Save changes')
end end
......
...@@ -3,14 +3,13 @@ ...@@ -3,14 +3,13 @@
require 'spec_helper' require 'spec_helper'
describe 'User activates Jira', :js do describe 'User activates Jira', :js do
let(:user) { create(:user) } include_context 'project service activation'
let(:project) { create(:project) }
let(:url) { 'http://jira.example.com' } let(:url) { 'http://jira.example.com' }
let(:test_url) { 'http://jira.example.com/rest/api/2/serverInfo' } let(:test_url) { 'http://jira.example.com/rest/api/2/serverInfo' }
def fill_form(disabled: false) def fill_form(disable: false)
find('input[name="service[active]"] + button').click if disabled find('input[name="service[active]"] + button').click if disable
fill_in 'service_url', with: url fill_in 'service_url', with: url
fill_in 'service_username', with: 'username' fill_in 'service_username', with: 'username'
...@@ -18,23 +17,15 @@ describe 'User activates Jira', :js do ...@@ -18,23 +17,15 @@ describe 'User activates Jira', :js do
fill_in 'service_jira_issue_transition_id', with: '25' fill_in 'service_jira_issue_transition_id', with: '25'
end 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 describe 'user sets and activates Jira Service' do
context 'when Jira connection test succeeds' do context 'when Jira connection test succeeds' do
before do before do
server_info = { key: 'value' }.to_json 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 fill_form
click_button('Test settings and save changes') click_test_integration
wait_for_requests
end end
it 'activates the Jira service' do it 'activates the Jira service' do
...@@ -51,10 +42,10 @@ describe 'User activates Jira', :js do ...@@ -51,10 +42,10 @@ describe 'User activates Jira', :js do
context 'when Jira connection test fails' do context 'when Jira connection test fails' do
it 'shows errors when some required fields are not filled in' 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' fill_in 'service_password', with: 'password'
click_button('Test settings and save changes') click_test_integration
page.within('.service-settings') do page.within('.service-settings') do
expect(page).to have_content('This field is required.') expect(page).to have_content('This field is required.')
...@@ -62,19 +53,12 @@ describe 'User activates Jira', :js do ...@@ -62,19 +53,12 @@ describe 'User activates Jira', :js do
end end
it 'activates the Jira service' do 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'))) .to_raise(JIRA::HTTPError.new(double(message: 'message')))
click_link('Jira') visit_project_integration('Jira')
fill_form fill_form
click_button('Test settings and save changes') click_test_then_save_integration
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
expect(page).to have_content('Jira activated.') expect(page).to have_content('Jira activated.')
expect(current_path).to eq(project_settings_integrations_path(project)) expect(current_path).to eq(project_settings_integrations_path(project))
...@@ -84,8 +68,8 @@ describe 'User activates Jira', :js do ...@@ -84,8 +68,8 @@ describe 'User activates Jira', :js do
describe 'user disables the Jira Service' do describe 'user disables the Jira Service' do
before do before do
click_link('Jira') visit_project_integration('Jira')
fill_form(disabled: true) fill_form(disable: true)
click_button('Save changes') click_button('Save changes')
end end
......
...@@ -3,18 +3,17 @@ ...@@ -3,18 +3,17 @@
require 'spec_helper' require 'spec_helper'
describe 'Set up Mattermost slash commands', :js do describe 'Set up Mattermost slash commands', :js do
let(:user) { create(:user) } describe 'user visits the mattermost slash command config page' do
let(:project) { create(:project) } include_context 'project service activation'
let(:mattermost_enabled) { true }
before do before do
stub_mattermost_setting(enabled: mattermost_enabled) stub_mattermost_setting(enabled: mattermost_enabled)
project.add_maintainer(user) visit_project_integration('Mattermost slash commands')
sign_in(user)
visit edit_project_service_path(project, :mattermost_slash_commands)
end 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 it 'shows a help message' do
expect(page).to have_content("This service allows users to perform common") expect(page).to have_content("This service allows users to perform common")
end end
...@@ -153,8 +152,9 @@ describe 'Set up Mattermost slash commands', :js do ...@@ -153,8 +152,9 @@ describe 'Set up Mattermost slash commands', :js do
teams teams
end end
end
describe 'mattermost service is not enabled' do context 'mattermost service is not enabled' do
let(:mattermost_enabled) { false } let(:mattermost_enabled) { false }
it 'shows the correct trigger url' do it 'shows the correct trigger url' do
......
...@@ -3,13 +3,10 @@ ...@@ -3,13 +3,10 @@
require 'spec_helper' require 'spec_helper'
describe 'Slack slash commands' do describe 'Slack slash commands' do
let(:user) { create(:user) } include_context 'project service activation'
let(:project) { create(:project) }
before do before do
project.add_maintainer(user) visit_project_integration('Slack slash commands')
sign_in(user)
visit edit_project_service_path(project, :slack_slash_commands)
end end
it 'shows a token placeholder' do 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