Fixes #3981 - Draft Sharing: Draft stays after new ticket creation.

This commit is contained in:
Mantas Masalskis 2022-03-02 13:24:16 +01:00 committed by Rolf Schmidt
parent c6d9abd96e
commit 0fcbb11684
6 changed files with 65 additions and 1 deletions

View file

@ -181,7 +181,8 @@ class App.TicketCreate extends App.Controller
show: =>
@navupdate("#ticket/create/id/#{@id}#{@split}", type: 'menu')
@autosaveStart()
@controllerBind('ticket_create_rerender', (template) => @renderQueue(template))
@controllerBind('ticket_create_rerender', (template) => @renderQueue(template))
@controllerBind('ticket_create_shared_draft_saved', @sharedDraftSaved)
@controllerBind('ticket_create_import_draft_attachments', @importDraftAttachments)
# initially hide sidebar on mobile
@ -192,6 +193,7 @@ class App.TicketCreate extends App.Controller
hide: =>
@autosaveStop()
@controllerUnbind('ticket_create_rerender', (template) => @renderQueue(template))
@controllerUnbind('ticket_create_shared_draft_saved')
@controllerUnbind('ticket_create_import_draft_attachments')
changed: =>
@ -305,6 +307,11 @@ class App.TicketCreate extends App.Controller
error: ->
App.Event.trigger(options.callbackName, { success: false })
sharedDraftSaved: (options) =>
@el
.find('.ticket-create input[name=shared_draft_id]')
.val(options.shared_draft_id)
updateTaskManagerAttachments: (attribute, attachments) =>
taskData = App.TaskManager.get(@taskKey)
return if _.isEmpty(taskData)

View file

@ -1016,6 +1016,7 @@ class App.TicketZoom extends App.Controller
data: JSON.stringify(params)
success: (data, status, xhr) =>
App.Collection.loadAssets(data.assets)
App.Event.trigger 'ui::ticket::shared_draft_saved', { ticket_id: @ticket_id, shared_draft_id: data.shared_draft_id }
@draftFetched()
error: =>
@draftFetched()

View file

@ -80,6 +80,7 @@ class App.TicketZoomArticleNew extends App.Controller
)
@controllerBind('ui::ticket::import_draft_attachments', @importDraftAttachments)
@controllerBind('ui::ticket::shared_draft_saved', @sharedDraftSaved)
# add article attachment
@controllerBind('ui::ticket::addArticleAttachent', (data) =>
@ -659,6 +660,13 @@ class App.TicketZoomArticleNew extends App.Controller
error: ->
App.Event.trigger(options.callbackName, { success: false })
sharedDraftSaved: (options) =>
return if @ticket.id != options.ticket_id
@el
.find('input[name=shared_draft_id]')
.val(options.shared_draft_id)
actions: ->
actionConfig = App.Config.get('TicketZoomArticleAction')
keys = _.keys(actionConfig).sort()

View file

@ -66,6 +66,7 @@ class App.WidgetSharedDraft extends App.Controller
success: (data, status, xhr) =>
App.Collection.loadAssets(data.assets)
App.Event.trigger 'ticket_create_shared_draft_saved', { shared_draft_id: data.shared_draft_id }
@render()
highlightError: ->

View file

@ -31,6 +31,16 @@ RSpec.describe 'Ticket Shared Draft Start', type: :system, authenticated_as: :au
click '.settings.add'
end
shared_examples 'shared draft ID is present' do
it 'sets shared draft ID' do
within :active_content do
elem = find('.ticket-create input[name=shared_draft_id]', visible: :all)
expect(Ticket::SharedDraftStart).to be_exist(elem.value)
end
end
end
context 'sidebar' do
context 'given multiple groups' do
let(:another_group) { create(:group, shared_drafts: false) }
@ -96,6 +106,18 @@ RSpec.describe 'Ticket Shared Draft Start', type: :system, authenticated_as: :au
.by 1
end
end
context 'draft saved' do
before do
within :draft_sidebar do
find('.js-name').fill_in with: 'Draft Name'
click '.js-create'
end
end
include_examples 'shared draft ID is present'
end
end
context 'update' do
@ -207,6 +229,8 @@ RSpec.describe 'Ticket Shared Draft Start', type: :system, authenticated_as: :au
end
end
include_examples 'shared draft ID is present'
it 'applies body' do
within :active_content do
expect(page).to have_text draft_body

View file

@ -32,6 +32,16 @@ RSpec.describe 'Ticket Shared Draft Zoom', type: :system, authenticated_as: :aut
visit "ticket/zoom/#{ticket.id}"
end
shared_examples 'shared draft ID is present' do
it 'sets shared draft ID' do
within :active_content do
elem = find('.article-add input[name=shared_draft_id]', visible: :all)
expect(Ticket::SharedDraftZoom).to be_exist(elem.value)
end
end
end
context 'buttons' do
context 'when drafts disabled for the group' do
let(:group_shared_drafts) { false }
@ -169,6 +179,17 @@ RSpec.describe 'Ticket Shared Draft Zoom', type: :system, authenticated_as: :aut
expect(draft.reload.new_article[:body]).to match %r{another reply}
end
context 'draft saved' do
before do
find('.articleNewEdit-body').send_keys('Some reply')
click '.js-openDropdownMacro'
click :draft_save_button
end
include_examples 'shared draft ID is present'
end
context 'draft loaded' do
before do
visit "ticket/zoom/#{ticket_with_draft.id}"
@ -214,6 +235,8 @@ RSpec.describe 'Ticket Shared Draft Zoom', type: :system, authenticated_as: :aut
end
end
include_examples 'shared draft ID is present'
it 'applies new article body' do
expect(page).to have_text draft_body
end