From 8b83bd4c1c13e388c7c066fda9b383fb56d3e659 Mon Sep 17 00:00:00 2001 From: Dominik Klein Date: Mon, 26 Jul 2021 12:58:42 +0200 Subject: [PATCH] Fixes #3568 - Duplicated article after bulk action was executed for newly created tickets without a browser refresh in between. --- .../controllers/agent_ticket_create.coffee | 4 + spec/system/ticket/view_spec.rb | 77 +++++++++++++++---- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index 33b4a02e1..b3472e707 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -563,6 +563,10 @@ class App.TicketCreate extends App.Controller ticket.save( done: -> + # Reset article after ticket create, to avoid unwanted sideeffects at other places. + localTicket = App.Ticket.findNative(@id) + localTicket.article = undefined + # notify UI ui.notify type: 'success' diff --git a/spec/system/ticket/view_spec.rb b/spec/system/ticket/view_spec.rb index 2eb65e9f1..80d4c1fb6 100644 --- a/spec/system/ticket/view_spec.rb +++ b/spec/system/ticket/view_spec.rb @@ -232,26 +232,71 @@ RSpec.describe 'Ticket views', type: :system do end end - context 'bulk note', authenticated_as: :user do - let(:group) { create :group } - let(:user) { create :admin, groups: [group] } - let!(:ticket1) { create(:ticket, state_name: 'open', owner: user, group: group) } - let!(:ticket2) { create(:ticket, state_name: 'open', owner: user, group: group) } - let(:note) { Faker::Lorem.sentence } + context 'when performing a Bulk action' do + context 'when creating a Note', authenticated_as: :user do + let(:group) { create :group } + let(:user) { create :admin, groups: [group] } + let!(:ticket1) { create(:ticket, state_name: 'open', owner: user, group: group) } + let!(:ticket2) { create(:ticket, state_name: 'open', owner: user, group: group) } + let(:note) { Faker::Lorem.sentence } - it 'adds note to all selected tickets' do - visit 'ticket/view/my_assigned' + it 'adds note to all selected tickets' do + visit 'ticket/view/my_assigned' - within :active_content do - all('.js-checkbox-field', count: 2).each(&:click) - click '.js-confirm' - find('.js-confirm-step textarea').fill_in with: note - click '.js-submit' + within :active_content do + all('.js-checkbox-field', count: 2).each(&:click) + click '.js-confirm' + find('.js-confirm-step textarea').fill_in with: note + click '.js-submit' + end + + expect do + wait(10, interval: 0.1).until { [ ticket1.articles.last&.body, ticket2.articles.last&.body ] == [note, note] } + end.not_to raise_error + end + end + + # https://github.com/zammad/zammad/issues/3568 + # We need a manual ticket creation to test the correct behaviour of the bulk functionality, because of some + # leftovers after the creation in the the javascript assets store. + context 'when performed a manual Ticket creation', authenticated_as: :agent do + let(:customer) { create(:customer) } + let(:group) { Group.find_by(name: 'Users') } + let(:agent) { create(:agent, groups: [group]) } + let!(:template) { create(:template, :dummy_data, group: group, owner: agent, customer: customer) } + + before do + visit 'ticket/create' + + within(:active_content) do + use_template(template) + + click('.js-submit') + + find('.ticket-article-item') + end end - expect do - wait(10, interval: 0.1).until { [ ticket1.articles.last&.body, ticket2.articles.last&.body ] == [note, note] } - end.not_to raise_error + it 'check that no duplicated article was created after usage of bulk action' do + click('.menu-item[href="#ticket/view"]') + + created_ticket_id = Ticket.last.id + + within(:active_content) do + click("tr[data-id='#{created_ticket_id}'] .js-checkbox-field") + + find('select[name="priority_id"] option[value="1"]').select_option + + click('.js-confirm') + click('.js-submit') + + await_empty_ajax_queue + + # Check if still only one article exists on the ticket. + click("tr[data-id='#{created_ticket_id}'] a") + expect(page).to have_css('.ticket-article-item', count: 1) + end + end end end