shared_draft_zoom_spec.rb 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket Shared Draft Zoom', type: :system, authenticated_as: :authenticate do
  4. let(:group) { create(:group, shared_drafts: group_shared_drafts) }
  5. let(:group_access) { :full }
  6. let(:group_shared_drafts) { true }
  7. let(:ticket) { create(:ticket, group: group) }
  8. let(:ticket_with_draft) { create(:ticket, group: group) }
  9. let(:draft_body) { 'draft here' }
  10. let(:draft) do
  11. create(:ticket_shared_draft_zoom,
  12. ticket: ticket_with_draft,
  13. new_article: { body: draft_body, type: 'note', internal: true },
  14. ticket_attributes: { priority_id: '3' })
  15. end
  16. let(:user) do
  17. user = create(:agent)
  18. user.user_groups.create! group: group, access: group_access
  19. user
  20. end
  21. def authenticate
  22. draft
  23. user
  24. end
  25. before do
  26. visit "ticket/zoom/#{ticket.id}"
  27. end
  28. shared_examples 'shared draft ID is present' do
  29. it 'sets shared draft ID' do
  30. within :active_content do
  31. elem = find('.article-add input[name=shared_draft_id]', visible: :all)
  32. expect(Ticket::SharedDraftZoom).to be_exist(elem.value)
  33. end
  34. end
  35. end
  36. context 'buttons' do
  37. context 'when drafts disabled for the group' do
  38. let(:group_shared_drafts) { false }
  39. it 'share button not visible' do
  40. expect(page).to have_no_selector :draft_share_button
  41. end
  42. it 'save button not visible' do
  43. click '.js-openDropdownMacro'
  44. expect(page).to have_no_selector :draft_save_button
  45. end
  46. end
  47. context 'when drafts enabled for the group' do
  48. it 'share button not visible initially' do
  49. expect(page).to have_no_selector :draft_share_button
  50. end
  51. it 'save button visible' do
  52. expect(page).to have_selector(:draft_save_button, visible: :all)
  53. end
  54. it 'share button visible when draft exists' do
  55. visit "ticket/zoom/#{ticket_with_draft.id}"
  56. within :active_content do
  57. expect(page).to have_selector :draft_share_button
  58. end
  59. end
  60. it 'share button appears when other user creates draft' do
  61. create(:ticket_shared_draft_zoom, ticket: ticket)
  62. expect(page).to have_selector :draft_share_button
  63. end
  64. end
  65. context 'when insufficient permissions' do
  66. let(:group_access) { :read }
  67. it 'share button not visible when draft exists' do
  68. visit "ticket/zoom/#{ticket_with_draft.id}"
  69. within :active_content do
  70. expect(page).to have_no_selector :draft_share_button
  71. end
  72. end
  73. it 'save button not visible' do
  74. click '.js-openDropdownMacro'
  75. expect(page).to have_no_selector :draft_save_button
  76. end
  77. end
  78. end
  79. context 'preview' do
  80. before do
  81. visit "ticket/zoom/#{ticket_with_draft.id}"
  82. within :active_content do
  83. click :draft_share_button
  84. end
  85. end
  86. it 'shows content' do
  87. in_modal disappears: false do
  88. expect(page).to have_text draft_body
  89. end
  90. end
  91. it 'shows author' do
  92. in_modal disappears: false do
  93. expect(page).to have_text(User.find(draft.created_by_id).fullname)
  94. end
  95. end
  96. end
  97. context 'delete' do
  98. it 'works' do
  99. visit "ticket/zoom/#{ticket_with_draft.id}"
  100. within :active_content do
  101. click :draft_share_button
  102. end
  103. in_modal do
  104. click '.js-delete'
  105. end
  106. click_on 'Yes'
  107. within :active_content do
  108. expect(page).to have_no_selector :draft_share_button
  109. end
  110. end
  111. it 'hides button when another user deletes' do
  112. visit "ticket/zoom/#{ticket_with_draft.id}"
  113. draft.destroy
  114. within :active_content do
  115. expect(page).to have_no_selector :draft_share_button
  116. end
  117. end
  118. end
  119. context 'save' do
  120. it 'creates new draft' do
  121. find('.articleNewEdit-body').send_keys('Some reply')
  122. click '.js-openDropdownMacro'
  123. expect { click :draft_save_button }
  124. .to change { ticket.reload.shared_draft.present? }
  125. .to true
  126. end
  127. it 'shows overwrite warning when draft exists' do
  128. visit "ticket/zoom/#{ticket_with_draft.id}"
  129. within :active_content do
  130. find('.articleNewEdit-body').send_keys('another reply')
  131. click '.js-openDropdownMacro'
  132. click :draft_save_button
  133. end
  134. in_modal do
  135. click '.js-submit'
  136. end
  137. expect(draft.reload.new_article[:body]).to match %r{another reply}
  138. end
  139. context 'draft saved' do
  140. before do
  141. find('.articleNewEdit-body').send_keys('Some reply')
  142. click '.js-openDropdownMacro'
  143. click :draft_save_button
  144. end
  145. include_examples 'shared draft ID is present'
  146. end
  147. context 'draft loaded' do
  148. before do
  149. visit "ticket/zoom/#{ticket_with_draft.id}"
  150. click :draft_share_button
  151. in_modal do
  152. click '.js-submit'
  153. end
  154. end
  155. it 'updates existing draft' do
  156. click '.js-openDropdownMacro'
  157. click :draft_save_button
  158. expect(draft.reload.new_article[:body]).to match %r{draft here}
  159. end
  160. it 'shows overwrite warning when draft edited after loading' do
  161. find('.articleNewEdit-body').send_keys('another reply')
  162. click '.js-openDropdownMacro'
  163. click :draft_save_button
  164. in_modal do
  165. click '.js-submit'
  166. end
  167. expect(draft.reload.new_article[:body]).to match %r{another reply}
  168. end
  169. end
  170. end
  171. context 'apply' do
  172. before do
  173. attach(id: draft.id, object_name: draft.class.name)
  174. visit "ticket/zoom/#{ticket_with_draft.id}"
  175. click :draft_share_button
  176. in_modal do
  177. click '.js-submit'
  178. end
  179. end
  180. include_examples 'shared draft ID is present'
  181. it 'applies new article body' do
  182. expect(page).to have_text draft_body
  183. end
  184. it 'applies sidebar changes' do
  185. expect(find('[name=priority_id]').value).to eq draft.ticket_attributes[:priority_id]
  186. end
  187. it 'applies attachment' do
  188. expect(page).to have_text('1x1.png')
  189. end
  190. end
  191. end