diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index 987b49ca1..33b4a02e1 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -442,7 +442,9 @@ class App.TicketCreate extends App.Controller cancel: (e) -> e.preventDefault() - @navigate '#' + + worker = App.TaskManager.worker(@taskKey) + App.Event.trigger('taskClose', [worker.taskKey]) params: => params = @formParam(@$('.main form')) diff --git a/app/assets/javascripts/app/controllers/taskbar_widget.coffee b/app/assets/javascripts/app/controllers/taskbar_widget.coffee index 940d91c89..3bde554d5 100644 --- a/app/assets/javascripts/app/controllers/taskbar_widget.coffee +++ b/app/assets/javascripts/app/controllers/taskbar_widget.coffee @@ -59,6 +59,10 @@ class App.TaskbarWidget extends App.CollectionController @controllerBind('taskCollectionOrderSet', (taskKeys) => @collectionOrderSet(taskKeys) ) + @controllerBind('taskClose', (tasks) => + for task in tasks + @remove(null, task) + ) itemGet: (key) -> App.TaskManager.get(key) @@ -74,8 +78,8 @@ class App.TaskbarWidget extends App.CollectionController @locationVerify(e) remove: (e, key = false, force = false) => - e.preventDefault() - e.stopPropagation() + e?.preventDefault() + e?.stopPropagation() if !key key = $(e.target).parents('a').data('key') if !key diff --git a/spec/support/capybara/selectors.rb b/spec/support/capybara/selectors.rb index 9dac52163..1dc0ed9a3 100644 --- a/spec/support/capybara/selectors.rb +++ b/spec/support/capybara/selectors.rb @@ -43,3 +43,11 @@ end Capybara.add_selector(:link_containing) do xpath { |text| ".//a//*[text()[contains(.,\"#{text}\")]]" } end + +Capybara.add_selector(:task_active) do + css { '.tasks .task.is-active' } +end + +Capybara.add_selector(:task_with) do + css { |task_key| ".tasks .task[data-key='#{task_key}']" } +end diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index 56da031fe..3d3ad97b8 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -449,4 +449,31 @@ RSpec.describe 'Ticket Create', type: :system do end end end + + # https://github.com/zammad/zammad/issues/2669 + context 'when canceling new ticket creation' do + it 'closes the dialog' do + visit 'ticket/create' + + task_key = find(:task_active)['data-key'] + + expect { click('.js-cancel') }.to change { has_selector?(:task_with, task_key, wait: 0) }.to(false) + end + + it 'asks for confirmation if the dialog was modified' do + visit 'ticket/create' + + task_key = find(:task_active)['data-key'] + + find('[name=title]').fill_in with: 'Title' + + click '.js-cancel' + + in_modal do + click '.js-submit' + end + + expect(page).to have_no_selector(:task_with, task_key) + end + end end