From 89c3a5e9c9a6dfe7b71c0166d17505eaf41b964a Mon Sep 17 00:00:00 2001 From: Mantas Date: Wed, 24 Mar 2021 11:40:16 +0200 Subject: [PATCH] Fixes #3453 - Removal of referenced webhooks does not provide error toast within UI --- .../generic_destroy_confirm.coffee | 4 ++-- spec/support/capybara/common_actions.rb | 5 ++-- spec/system/manage/webhooks_spec.rb | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 spec/system/manage/webhooks_spec.rb diff --git a/app/assets/javascripts/app/controllers/_application_controller/generic_destroy_confirm.coffee b/app/assets/javascripts/app/controllers/_application_controller/generic_destroy_confirm.coffee index 6cb2a73b2..6baba4c44 100644 --- a/app/assets/javascripts/app/controllers/_application_controller/generic_destroy_confirm.coffee +++ b/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 diff --git a/spec/support/capybara/common_actions.rb b/spec/support/capybara/common_actions.rb index be3c40461..b3da693a7 100644 --- a/spec/support/capybara/common_actions.rb +++ b/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 diff --git a/spec/system/manage/webhooks_spec.rb b/spec/system/manage/webhooks_spec.rb new file mode 100644 index 000000000..6e4c3e9c5 --- /dev/null +++ b/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