Browse Source

Fixes #2669 - Pressing "Cancel" in a new ticket dialog doesn't close it's tab

Mantas Masalskis 3 years ago
parent
commit
2001ac6968

+ 3 - 1
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'))

+ 6 - 2
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

+ 8 - 0
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

+ 27 - 0
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