summaryrefslogtreecommitdiff
path: root/spec/features/projects/integrations/user_uses_inherited_settings_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/features/projects/integrations/user_uses_inherited_settings_spec.rb')
-rw-r--r--spec/features/projects/integrations/user_uses_inherited_settings_spec.rb91
1 files changed, 91 insertions, 0 deletions
diff --git a/spec/features/projects/integrations/user_uses_inherited_settings_spec.rb b/spec/features/projects/integrations/user_uses_inherited_settings_spec.rb
new file mode 100644
index 00000000000..f46cade9d5f
--- /dev/null
+++ b/spec/features/projects/integrations/user_uses_inherited_settings_spec.rb
@@ -0,0 +1,91 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'User uses inherited settings', :js do
+ include JiraServiceHelper
+
+ include_context 'project service activation'
+
+ before do
+ stub_jira_integration_test
+ end
+
+ shared_examples 'inherited settings' do
+ let_it_be(:project_settings) { { url: 'http://project.com', password: 'project' } }
+
+ describe 'switching from inherited to custom settings' do
+ let_it_be(:integration) { create(:jira_integration, project: project, inherit_from_id: parent_integration.id, **project_settings) }
+
+ it 'clears the form fields and saves the entered values' do
+ visit_project_integration('Jira')
+
+ expect(page).not_to have_button('Use custom settings')
+ expect(page).to have_field('Web URL', with: parent_settings[:url], readonly: true)
+ expect(page).to have_field('Enter new password or API token', with: '', readonly: true)
+
+ click_on 'Use default settings'
+ click_on 'Use custom settings'
+
+ expect(page).not_to have_button('Use default settings')
+ expect(page).to have_field('Web URL', with: project_settings[:url], readonly: false)
+ expect(page).to have_field('Enter new password or API token', with: '', readonly: false)
+
+ fill_in 'Web URL', with: 'http://custom.com'
+ fill_in 'Enter new password or API token', with: 'custom'
+
+ click_save_integration
+
+ expect(page).to have_text('Jira settings saved and active.')
+ expect(integration.reload).to have_attributes(
+ inherit_from_id: nil,
+ url: 'http://custom.com',
+ password: 'custom'
+ )
+ end
+ end
+
+ describe 'switching from custom to inherited settings' do
+ let_it_be(:integration) { create(:jira_integration, project: project, **project_settings) }
+
+ it 'resets the form fields, makes them read-only, and saves the inherited values' do
+ visit_project_integration('Jira')
+
+ expect(page).not_to have_button('Use default settings')
+ expect(page).to have_field('URL', with: project_settings[:url], readonly: false)
+ expect(page).to have_field('Enter new password or API token', with: '', readonly: false)
+
+ click_on 'Use custom settings'
+ click_on 'Use default settings'
+
+ expect(page).not_to have_button('Use custom settings')
+ expect(page).to have_field('URL', with: parent_settings[:url], readonly: true)
+ expect(page).to have_field('Enter new password or API token', with: '', readonly: true)
+
+ click_save_integration
+
+ expect(page).to have_text('Jira settings saved and active.')
+ expect(integration.reload).to have_attributes(
+ inherit_from_id: parent_integration.id,
+ **parent_settings
+ )
+ end
+ end
+ end
+
+ context 'with instance settings' do
+ let_it_be(:parent_settings) { { url: 'http://instance.com', password: 'instance' } }
+ let_it_be(:parent_integration) { create(:jira_integration, :instance, **parent_settings) }
+
+ it_behaves_like 'inherited settings'
+ end
+
+ context 'with group settings' do
+ let_it_be(:group) { create(:group) }
+ let_it_be(:project) { create(:project, group: group) }
+ let_it_be(:parent_settings) { { url: 'http://group.com', password: 'group' } }
+ let_it_be(:parent_integration) { create(:jira_integration, group: group, project: nil, **parent_settings) }
+
+ it_behaves_like 'inherited settings'
+ end
+end