Browse Source

Fixes #2925 - Macros with notes not working on overview "drop bar".

Rolf Schmidt 4 years ago
parent
commit
3530ea7787

+ 3 - 0
app/assets/javascripts/app/controllers/ticket_overview.coffee

@@ -243,10 +243,13 @@ class App.TicketOverview extends App.Controller
       for item in items
         #console.log "perform action #{action} with id #{id} on ", $(item).val()
         ticket = App.Ticket.find($(item).val())
+        article = {}
         App.Ticket.macro(
           macro: macro.perform
           ticket: ticket
+          article: article
         )
+        ticket.article = article
         ticket.save(
           done: (r) =>
             @batchCountIndex++

+ 1 - 1
app/assets/javascripts/app/models/ticket.coffee

@@ -167,7 +167,7 @@ class App.Ticket extends App.Model
       else if attributes[0] is 'article'
 
         # preload required attributes
-        if attributes[1]
+        if !content.type_id
           type = App.TicketArticleType.findByAttribute('name', attributes[1])
           if type
             params.article.type_id = type.id

+ 10 - 0
spec/support/capybara/browser_test_helper.rb

@@ -83,6 +83,16 @@ module BrowserTestHelper
     page.driver.browser.action.move_by(x_axis, y_axis).perform
   end
 
+  # Moves the mouse to element.
+  #
+  # @example
+  # move_mouse_to(page.find('button.hover_me'))
+  #
+  def move_mouse_to(element)
+    element.in_fixed_position
+    page.driver.browser.action.move_to_location(element.native.location.x, element.native.location.y).perform
+  end
+
   # Clicks and hold (without releasing) in the middle of the given element.
   #
   # @example

+ 1 - 1
spec/support/capybara/selectors.rb

@@ -33,7 +33,7 @@ Capybara.add_selector(:macro) do
 end
 
 Capybara.add_selector(:macro_batch) do
-  css { |id| %(.batch-overlay-macro-entry[data-id='#{id}']) }
+  css { |id| %(.batch-overlay-macro-entry[data-id='#{id}'] .batch-overlay-macro-entry-name) }
 end
 
 Capybara.add_selector(:table_row) do

+ 30 - 0
spec/system/ticket/view_spec.rb

@@ -5,6 +5,7 @@ RSpec.describe 'Ticket views', type: :system do
     let!(:group1)              { create :group }
     let!(:group2)              { create :group }
     let!(:macro_without_group) { create :macro }
+    let!(:macro_note)          { create :macro, perform: { 'article.note'=>{ 'body' => 'macro body', 'internal' => 'true', 'subject' => 'macro note' } } }
     let!(:macro_group1)        { create :macro, groups: [group1] }
     let!(:macro_group2)        { create :macro, groups: [group2] }
 
@@ -85,6 +86,35 @@ RSpec.describe 'Ticket views', type: :system do
 
       end
     end
+
+    it 'can use macro to create article', authenticated_as: true do
+      refresh
+      visit '#ticket/view/all_open'
+
+      within(:active_content) do
+        ticket = page.find(:table_row, Ticket.first.id).native
+
+        # click and hold first ticket in table
+        click_and_hold(ticket)
+
+        # move ticket to y -ticket.location.y
+        move_mouse_by(0, -ticket.location.y + 5)
+
+        # move a bit to the left to display macro batches
+        move_mouse_by(-250, 0)
+
+        expect(page).to have_selector(:macro_batch, macro_note.id, wait: 10)
+
+        macro = find(:macro_batch, macro_note.id)
+        move_mouse_to(macro)
+
+        release_mouse
+
+        await_empty_ajax_queue
+
+        expect(Ticket.first.articles.last.subject).to eq('macro note')
+      end
+    end
   end
 
   context 'bulk note', authenticated_as: :user do