diff options
-rw-r--r-- | app/models/service.rb | 11 | ||||
-rw-r--r-- | app/views/shared/_service_settings.html.haml | 4 | ||||
-rw-r--r-- | changelogs/unreleased/ce-jej-integrations-can-hide-trigger-checkboxes.yml | 6 | ||||
-rw-r--r-- | spec/features/projects/services/disable_triggers_spec.rb | 35 |
4 files changed, 54 insertions, 2 deletions
diff --git a/app/models/service.rb b/app/models/service.rb index 369cae2e85f..99bf757ae44 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -129,6 +129,17 @@ class Service < ActiveRecord::Base fields end + def configurable_events + events = self.class.supported_events + + # No need to disable individual triggers when there is only one + if events.count == 1 + [] + else + events + end + end + def supported_events self.class.supported_events end diff --git a/app/views/shared/_service_settings.html.haml b/app/views/shared/_service_settings.html.haml index 61b39afb5d4..355b3ac75ae 100644 --- a/app/views/shared/_service_settings.html.haml +++ b/app/views/shared/_service_settings.html.haml @@ -13,12 +13,12 @@ .col-sm-10 = form.check_box :active, disabled: disable_fields_service?(@service) - - if @service.supported_events.present? + - if @service.configurable_events.present? .form-group = form.label :url, "Trigger", class: 'control-label' .col-sm-10 - - @service.supported_events.each do |event| + - @service.configurable_events.each do |event| %div = form.check_box service_event_field_name(event), class: 'pull-left' .prepend-left-20 diff --git a/changelogs/unreleased/ce-jej-integrations-can-hide-trigger-checkboxes.yml b/changelogs/unreleased/ce-jej-integrations-can-hide-trigger-checkboxes.yml new file mode 100644 index 00000000000..771df06e7a6 --- /dev/null +++ b/changelogs/unreleased/ce-jej-integrations-can-hide-trigger-checkboxes.yml @@ -0,0 +1,6 @@ +--- +title: Avoid showing unnecessary Trigger checkboxes for project Integrations with + only one event +merge_request: 17607 +author: +type: changed diff --git a/spec/features/projects/services/disable_triggers_spec.rb b/spec/features/projects/services/disable_triggers_spec.rb new file mode 100644 index 00000000000..1a13fe03a67 --- /dev/null +++ b/spec/features/projects/services/disable_triggers_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'Disable individual triggers' do + let(:project) { create(:project) } + let(:user) { project.owner } + let(:checkbox_selector) { 'input[type=checkbox][id$=_events]' } + + before do + sign_in(user) + + visit(project_settings_integrations_path(project)) + + click_link(service_name) + end + + context 'service has multiple supported events' do + let(:service_name) { 'HipChat' } + + it 'shows trigger checkboxes' do + event_count = HipchatService.supported_events.count + + expect(page).to have_content "Trigger" + expect(page).to have_css(checkbox_selector, count: event_count) + end + end + + context 'services only has one supported event' do + let(:service_name) { 'Asana' } + + it "doesn't show unnecessary Trigger checkboxes" do + expect(page).not_to have_content "Trigger" + expect(page).not_to have_css(checkbox_selector) + end + end +end |