Browse Source

Fixes #3453 - Removal of referenced webhooks does not provide error toast within UI

Mantas 4 years ago
parent
commit
89c3a5e9c9

+ 2 - 2
app/assets/javascripts/app/controllers/_application_controller/generic_destroy_confirm.coffee

@@ -15,9 +15,9 @@ class App.ControllerGenericDestroyConfirm extends App.ControllerModal
       @close()
       if @callback
         @callback()
-    options.fail = =>
+    options.fail = (xhr, data) =>
       @log 'errors'
-      @close()
+      @showAlert(data.human_error || data.error)
     @item.destroy(options)
 
 class App.ControllerConfirm extends App.ControllerModal

+ 3 - 2
spec/support/capybara/common_actions.rb

@@ -248,12 +248,13 @@ module CommonActions
   # Executes action inside of modal. Makes sure modal has opened and closes
   #
   # @param timeout [Integer] seconds to wait
-  def in_modal(timeout: 4, &block)
+  # @param wait_for_disappear [Bool] wait for modal to close
+  def in_modal(timeout: 4, disappears: true, &block)
     modal_ready(timeout: timeout)
 
     within('.modal', &block)
 
-    modal_disappear(timeout: timeout)
+    modal_disappear(timeout: timeout) if disappears
   end
 end
 

+ 23 - 0
spec/system/manage/webhooks_spec.rb

@@ -0,0 +1,23 @@
+require 'rails_helper'
+
+RSpec.describe 'Manage > Webhook', type: :system do
+  context 'deleting' do
+    let!(:webhook) { create(:webhook) }
+    let!(:trigger) { create(:trigger, perform: { 'notification.webhook' => { 'webhook_id' => webhook.id.to_s } }) }
+
+    it 'referenced webhook shows error message' do
+      visit '/#manage/webhook'
+
+      within :active_content do
+        click '.js-action'
+        click '.js-delete'
+      end
+
+      in_modal disappears: false do
+        click '.js-submit'
+
+        expect(page).to have_text('Cannot delete').and(have_text("##{trigger.id}"))
+      end
+    end
+  end
+end