view_spec.rb 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. require 'rails_helper'
  2. RSpec.describe 'Ticket views', type: :system do
  3. context 'macros' do
  4. let!(:group1) { create :group }
  5. let!(:group2) { create :group }
  6. let!(:macro_without_group) { create :macro }
  7. let!(:macro_note) { create :macro, perform: { 'article.note'=>{ 'body' => 'macro body', 'internal' => 'true', 'subject' => 'macro note' } } }
  8. let!(:macro_group1) { create :macro, groups: [group1] }
  9. let!(:macro_group2) { create :macro, groups: [group2] }
  10. it 'supports group-dependent macros' do
  11. ticket1 = create :ticket, group: group1
  12. ticket2 = create :ticket, group: group2
  13. # give user access to all groups including those created
  14. # by using FactoryBot outside of the example
  15. group_names_access_map = Group.all.pluck(:name).each_with_object({}) do |group_name, result|
  16. result[group_name] = 'full'.freeze
  17. end
  18. current_user do |user|
  19. user.group_names_access_map = group_names_access_map
  20. user.save!
  21. end
  22. # refresh browser to get macro accessable
  23. refresh
  24. visit '#ticket/view/all_open'
  25. within(:active_content) do
  26. ticket = page.find(:table_row, 1).native
  27. # click and hold first ticket in table
  28. click_and_hold(ticket)
  29. # move ticket to y -ticket.location.y
  30. move_mouse_by(0, -ticket.location.y + 5)
  31. # move a bit to the left to display macro batches
  32. move_mouse_by(-250, 0)
  33. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  34. expect(page).to have_no_selector(:macro_batch, macro_group1.id)
  35. expect(page).to have_no_selector(:macro_batch, macro_group2.id)
  36. release_mouse
  37. refresh
  38. ticket = page.find(:table_row, ticket1.id).native
  39. # click and hold first ticket in table
  40. click_and_hold(ticket)
  41. # move ticket to y -ticket.location.y
  42. move_mouse_by(0, -ticket.location.y + 5)
  43. # move a bit to the left to display macro batches
  44. move_mouse_by(-250, 0)
  45. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  46. expect(page).to have_selector(:macro_batch, macro_group1.id)
  47. expect(page).to have_no_selector(:macro_batch, macro_group2.id)
  48. release_mouse
  49. refresh
  50. ticket = page.find(:table_row, ticket2.id).native
  51. # click and hold first ticket in table
  52. click_and_hold(ticket)
  53. # move ticket to y -ticket.location.y
  54. move_mouse_by(0, -ticket.location.y + 5)
  55. # move a bit to the left to display macro batches
  56. move_mouse_by(-250, 0)
  57. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  58. expect(page).to have_no_selector(:macro_batch, macro_group1.id)
  59. expect(page).to have_selector(:macro_batch, macro_group2.id)
  60. end
  61. end
  62. it 'can use macro to create article', authenticated_as: true do
  63. refresh
  64. visit '#ticket/view/all_open'
  65. within(:active_content) do
  66. ticket = page.find(:table_row, Ticket.first.id).native
  67. # click and hold first ticket in table
  68. click_and_hold(ticket)
  69. # move ticket to y -ticket.location.y
  70. move_mouse_by(0, -ticket.location.y + 5)
  71. # move a bit to the left to display macro batches
  72. move_mouse_by(-250, 0)
  73. expect(page).to have_selector(:macro_batch, macro_note.id, wait: 10)
  74. macro = find(:macro_batch, macro_note.id)
  75. move_mouse_to(macro)
  76. release_mouse
  77. await_empty_ajax_queue
  78. expect(Ticket.first.articles.last.subject).to eq('macro note')
  79. end
  80. end
  81. end
  82. context 'when performing a Bulk action' do
  83. context 'when creating a Note', authenticated_as: :user do
  84. let(:group) { create :group }
  85. let(:user) { create :admin, groups: [group] }
  86. let!(:ticket1) { create(:ticket, state_name: 'open', owner: user, group: group) }
  87. let!(:ticket2) { create(:ticket, state_name: 'open', owner: user, group: group) }
  88. let(:note) { Faker::Lorem.sentence }
  89. it 'adds note to all selected tickets' do
  90. visit 'ticket/view/my_assigned'
  91. within :active_content do
  92. all('.js-checkbox-field', count: 2).each(&:click)
  93. click '.js-confirm'
  94. find('.js-confirm-step textarea').fill_in with: note
  95. click '.js-submit'
  96. end
  97. expect do
  98. wait(10, interval: 0.1).until { [ ticket1.articles.last&.body, ticket2.articles.last&.body ] == [note, note] }
  99. end.not_to raise_error
  100. end
  101. end
  102. # https://github.com/zammad/zammad/issues/3568
  103. # We need a manual ticket creation to test the correct behaviour of the bulk functionality, because of some
  104. # leftovers after the creation in the the javascript assets store.
  105. context 'when performed a manual Ticket creation', authenticated_as: :agent do
  106. let(:customer) { create(:customer) }
  107. let(:group) { Group.find_by(name: 'Users') }
  108. let(:agent) { create(:agent, groups: [group]) }
  109. let!(:template) { create(:template, :dummy_data, group: group, owner: agent, customer: customer) }
  110. before do
  111. visit 'ticket/create'
  112. within(:active_content) do
  113. use_template(template)
  114. click('.js-submit')
  115. find('.ticket-article-item')
  116. end
  117. end
  118. it 'check that no duplicated article was created after usage of bulk action' do
  119. click('.menu-item[href="#ticket/view"]')
  120. created_ticket_id = Ticket.last.id
  121. within(:active_content) do
  122. click("tr[data-id='#{created_ticket_id}'] .js-checkbox-field")
  123. find('select[name="priority_id"] option[value="1"]').select_option
  124. click('.js-confirm')
  125. click('.js-submit')
  126. await_empty_ajax_queue
  127. # Check if still only one article exists on the ticket.
  128. click("tr[data-id='#{created_ticket_id}'] a")
  129. expect(page).to have_css('.ticket-article-item', count: 1)
  130. end
  131. end
  132. end
  133. end
  134. context 'Setting "ui_table_group_by_show_count"', authenticated_as: :authenticate, db_strategy: :reset do
  135. let!(:ticket1) { create(:ticket, group: Group.find_by(name: 'Users')) }
  136. let!(:ticket2) { create(:ticket, group: Group.find_by(name: 'Users')) }
  137. let!(:ticket3) { create(:ticket, group: Group.find_by(name: 'Users')) }
  138. let!(:ticket4) { create(:ticket, group: Group.find_by(name: 'Users')) }
  139. def authenticate
  140. create :object_manager_attribute_select, name: 'grouptest'
  141. ObjectManager::Attribute.migration_execute
  142. ticket1
  143. ticket2.update(grouptest: 'key_1')
  144. ticket3.update(grouptest: 'key_2')
  145. ticket4.update(grouptest: 'key_1')
  146. Overview.find_by(name: 'Open').update(group_by: 'grouptest')
  147. Setting.set('ui_table_group_by_show_count', true)
  148. true
  149. end
  150. it 'shows correct ticket counts' do
  151. visit 'ticket/view/all_open'
  152. within(:active_content) do
  153. page.find('.js-tableBody td b', text: '(1)')
  154. page.find('.js-tableBody td b', text: 'value_1 (2)')
  155. page.find('.js-tableBody td b', text: 'value_2 (1)')
  156. end
  157. end
  158. end
  159. context 'Customer', authenticated_as: :authenticate do
  160. let(:customer) { create(:customer, :with_org) }
  161. let(:ticket) { create(:ticket, customer: customer) }
  162. def authenticate
  163. ticket
  164. customer
  165. end
  166. it 'does basic view test of tickets' do
  167. visit 'ticket/view/my_tickets'
  168. expect(page).to have_text(ticket.title)
  169. click_on 'My Organization Tickets'
  170. expect(page).to have_text(ticket.title)
  171. end
  172. end
  173. describe 'Grouping' do
  174. context 'when sorted by custom object date', authenticated_as: :authenticate, db_strategy: :reset do
  175. let(:ticket1) { create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2018-01-17') }
  176. let(:ticket2) { create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2018-08-19') }
  177. let(:ticket3) { create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2019-01-19') }
  178. let(:ticket4) { create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2021-08-18') }
  179. def authenticate
  180. create :object_manager_attribute_date, name: 'cdate'
  181. ObjectManager::Attribute.migration_execute
  182. ticket4
  183. ticket3
  184. ticket2
  185. ticket1
  186. Overview.find_by(link: 'all_unassigned').update(group_by: 'cdate')
  187. true
  188. end
  189. it 'does show the date groups sorted' do
  190. visit 'ticket/view/all_unassigned'
  191. text = page.find('.js-tableBody').text(:all)
  192. expect(text.index('01/17/2018') < text.index('08/19/2018')).to eq(true)
  193. expect(text.index('08/19/2018') < text.index('01/19/2019')).to eq(true)
  194. expect(text.index('01/19/2019') < text.index('08/18/2021')).to eq(true)
  195. end
  196. end
  197. end
  198. end