From 3530ea7787f177bef1d4db924262879627ac1e1b Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Tue, 8 Dec 2020 10:17:21 +0100 Subject: [PATCH] Fixes #2925 - Macros with notes not working on overview "drop bar". --- .../app/controllers/ticket_overview.coffee | 3 ++ .../javascripts/app/models/ticket.coffee | 2 +- spec/support/capybara/browser_test_helper.rb | 10 +++++++ spec/support/capybara/selectors.rb | 2 +- spec/system/ticket/view_spec.rb | 30 +++++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_overview.coffee b/app/assets/javascripts/app/controllers/ticket_overview.coffee index 0fa8e19d6..7751af440 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.coffee +++ b/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++ diff --git a/app/assets/javascripts/app/models/ticket.coffee b/app/assets/javascripts/app/models/ticket.coffee index 75088b62e..db99eca84 100644 --- a/app/assets/javascripts/app/models/ticket.coffee +++ b/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 diff --git a/spec/support/capybara/browser_test_helper.rb b/spec/support/capybara/browser_test_helper.rb index 02baeef72..3a06958b5 100644 --- a/spec/support/capybara/browser_test_helper.rb +++ b/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 diff --git a/spec/support/capybara/selectors.rb b/spec/support/capybara/selectors.rb index ba4dab2d5..9dac52163 100644 --- a/spec/support/capybara/selectors.rb +++ b/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 diff --git a/spec/system/ticket/view_spec.rb b/spec/system/ticket/view_spec.rb index e4fe74a49..da1097cdc 100644 --- a/spec/system/ticket/view_spec.rb +++ b/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