123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe 'Ticket Shared Draft Zoom', authenticated_as: :authenticate, type: :system do
- let(:group) { create(:group, shared_drafts: group_shared_drafts) }
- let(:group_access) { :full }
- let(:group_shared_drafts) { true }
- let(:ticket) { create(:ticket, group: group) }
- let(:ticket_with_draft) { create(:ticket, group: group) }
- let(:draft_body) { 'draft here' }
- let(:draft_type) { 'note' }
- let(:draft_internal) { true }
- let(:draft) do
- create(:ticket_shared_draft_zoom,
- ticket: ticket_with_draft,
- new_article: { body: draft_body, type: draft_type, internal: draft_internal },
- ticket_attributes: { priority_id: '3' })
- end
- let(:user) do
- user = create(:agent)
- user.user_groups.create! group: group, access: group_access
- user
- end
- def authenticate
- draft
- user
- end
- before do
- 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 exist(elem.value)
- end
- end
- end
- context 'buttons' do
- context 'when drafts disabled for the group' do
- let(:group_shared_drafts) { false }
- it 'share button not visible' do
- expect(page).to have_no_selector :draft_share_button
- end
- it 'save button not visible' do
- click '.js-openDropdownMacro'
- expect(page).to have_no_selector :draft_save_button
- end
- end
- context 'when drafts enabled for the group' do
- it 'share button not visible initially' do
- expect(page).to have_no_selector :draft_share_button
- end
- it 'save button visible' do
- expect(page).to have_selector(:draft_save_button, visible: :all)
- end
- it 'share button visible when draft exists' do
- visit "ticket/zoom/#{ticket_with_draft.id}"
- within :active_content do
- expect(page).to have_selector :draft_share_button
- end
- end
- it 'share button appears when other user creates draft' do
- create(:ticket_shared_draft_zoom, ticket: ticket)
- expect(page).to have_selector :draft_share_button
- end
- end
- context 'when insufficient permissions' do
- let(:group_access) { :read }
- it 'share button not visible when draft exists' do
- visit "ticket/zoom/#{ticket_with_draft.id}"
- within :active_content do
- expect(page).to have_no_selector :draft_share_button
- end
- end
- it 'save button not visible' do
- expect(page).to have_no_selector :draft_save_button
- end
- end
- end
- context 'preview' do
- before do
- visit "ticket/zoom/#{ticket_with_draft.id}"
- within :active_content do
- click :draft_share_button
- end
- end
- it 'shows content' do
- in_modal do
- expect(page).to have_text draft_body
- end
- end
- it 'shows author' do
- in_modal do
- expect(page).to have_text(User.find(draft.created_by_id).fullname)
- end
- end
- end
- context 'delete' do
- it 'works as expected' do
- visit "ticket/zoom/#{ticket_with_draft.id}"
- within :active_content do
- click :draft_share_button
- end
- in_modal do
- click '.js-delete'
- end
- click_on 'Yes'
- within :active_content do
- expect(page).to have_no_selector :draft_share_button
- end
- end
- it 'hides button when another user deletes' do
- visit "ticket/zoom/#{ticket_with_draft.id}"
- draft.destroy
- within :active_content do
- expect(page).to have_no_selector :draft_share_button
- end
- end
- end
- context 'save' do
- it 'creates new draft' do
- find('.articleNewEdit-body').send_keys('Some reply')
- click '.js-openDropdownMacro'
- expect { click :draft_save_button }
- .to change { ticket.reload.shared_draft.present? }
- .to true
- end
- context 'with a signature' do
- let(:signature) { create(:signature) }
- let(:group) { create(:group, shared_drafts: group_shared_drafts, signature: signature) }
- # https://github.com/zammad/zammad/issues/4042
- it 'creates a draft without signature' do
- within :active_content do
- find('.articleNewEdit-body').send_keys(draft_body)
- click '.editControls-item.pop-select'
- click '.editControls-icon[data-value="email"]'
- click '.js-openDropdownMacro'
- click '.js-dropdownActionSaveDraft'
- end
- wait.until do
- draft = Ticket::SharedDraftZoom.last
- next false if draft.nil?
- expect(draft.new_article).to include(body: draft_body)
- end
- end
- end
- it 'shows overwrite warning when draft exists' do
- visit "ticket/zoom/#{ticket_with_draft.id}"
- within :active_content do
- find('.articleNewEdit-body').send_keys('another reply')
- click '.js-openDropdownMacro'
- click :draft_save_button
- end
- in_modal do
- click '.js-submit'
- end
- 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}"
- click :draft_share_button
- in_modal do
- click '.js-submit'
- end
- end
- it 'updates existing draft' do
- click '.js-openDropdownMacro'
- click :draft_save_button
- expect(draft.reload.new_article[:body]).to match %r{draft here}
- end
- it 'shows overwrite warning when draft edited after loading' do
- find('.articleNewEdit-body').send_keys('another reply')
- click '.js-openDropdownMacro'
- click :draft_save_button
- in_modal do
- click '.js-submit'
- end
- expect(draft.reload.new_article[:body]).to match %r{another reply}
- end
- end
- end
- context 'apply' do
- before do
- create(:store, :image, o_id: draft.id, object: draft.class.name)
- visit "ticket/zoom/#{ticket_with_draft.id}"
- click :draft_share_button
- in_modal do
- click '.js-submit'
- end
- end
- include_examples 'shared draft ID is present'
- it 'applies new article body' do
- expect(page).to have_text draft_body
- end
- it 'applies sidebar changes' do
- expect(find('[name=priority_id]').value).to eq draft.ticket_attributes[:priority_id]
- end
- it 'applies attachment' do
- expect(page).to have_text('1x1.png')
- end
- context 'with a signature' do
- let(:signature_body) { 'Sample signature here' }
- let(:signature) { create(:signature, body: signature_body) }
- let(:group) { create(:group, shared_drafts: group_shared_drafts, signature: signature) }
- let(:draft_type) { 'email' }
- # https://github.com/zammad/zammad/issues/4042
- it 'applies with a signature' do
- within :active_content do
- expect(page).to have_text(signature_body).and(have_text(draft_body))
- end
- end
- end
- end
- context 'create ticket article' do
- before do
- visit "ticket/zoom/#{ticket_with_draft.id}"
- click :draft_share_button
- in_modal do
- click '.js-submit'
- end
- within :active_content do
- click '.js-submit'
- end
- end
- let(:draft_type) { 'phone' }
- it 'creates article with type' do
- wait.until do
- article = ticket_with_draft.articles.reload.first
- next false if !article
- expect(article).to have_attributes(
- type: Ticket::Article::Type.lookup(name: 'phone'),
- internal: true,
- body: article.body
- )
- end
- end
- context 'when draft is public' do
- let(:draft_internal) { false }
- it 'creates article with selected visibility' do
- wait.until do
- article = ticket_with_draft.articles.reload.first
- next false if !article
- expect(article).to have_attributes(
- type: Ticket::Article::Type.lookup(name: 'phone'),
- internal: false,
- body: article.body
- )
- end
- end
- end
- end
- end
|