Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_uses_inherited_settings_spec.rb « integrations « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e0063a9c733cae570552f19b57cdab30843dd5e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'User uses inherited settings', :js, feature_category: :integrations do
  include JiraIntegrationHelpers

  include_context 'project integration 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: group, **parent_settings) }

    it_behaves_like 'inherited settings'
  end
end