view_spec.rb 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket views', type: :system, authenticated_as: :authenticate do
  4. def authenticate
  5. true
  6. end
  7. context 'macros' do
  8. let(:group1) { create :group }
  9. let(:group2) { create :group }
  10. let(:macro_without_group) { create :macro }
  11. let(:macro_note) { create :macro, perform: { 'article.note'=>{ 'body' => 'macro body', 'internal' => 'true', 'subject' => 'macro note' } } }
  12. let(:macro_group1) { create :macro, groups: [group1] }
  13. let(:macro_group2) { create :macro, groups: [group2] }
  14. let(:ticket1) { create :ticket, group: group1 }
  15. let(:ticket2) { create :ticket, group: group2 }
  16. describe 'group-dependent macros' do
  17. let(:agent) { create(:agent, groups: Group.all) }
  18. def authenticate
  19. ticket1 && ticket2
  20. macro_without_group && macro_group1 && macro_group2
  21. agent
  22. end
  23. it 'shows only non-group macro when ticket does not match any group macros' do
  24. visit '#ticket/view/all_open'
  25. within(:active_content) do
  26. display_macro_batches Ticket.first
  27. expect(page).to have_selector(:macro_batch, macro_without_group.id)
  28. .and(have_no_selector(:macro_batch, macro_group1.id))
  29. .and(have_no_selector(:macro_batch, macro_group2.id))
  30. end
  31. end
  32. it 'shows non-group and matching group macros for matching ticket' do
  33. visit '#ticket/view/all_open'
  34. within(:active_content) do
  35. display_macro_batches ticket1
  36. expect(page).to have_selector(:macro_batch, macro_without_group.id)
  37. .and(have_selector(:macro_batch, macro_group1.id))
  38. .and(have_no_selector(:macro_batch, macro_group2.id))
  39. end
  40. end
  41. end
  42. describe 'macro article creation' do
  43. def authenticate
  44. macro_note
  45. true
  46. end
  47. it 'can use macro to create article' do
  48. visit '#ticket/view/all_open'
  49. within(:active_content) do
  50. display_macro_batches Ticket.first
  51. move_mouse_to find(:macro_batch, macro_note.id)
  52. release_mouse
  53. expect do
  54. wait.until { Ticket.first.articles.last.subject == 'macro note' }
  55. end.not_to raise_error
  56. end
  57. end
  58. end
  59. context 'when saving is blocked by one of selected tickets' do
  60. let(:ticket) { Ticket.first }
  61. let(:core_workflow_action) { { 'ticket.priority_id': { operator: 'remove_option', remove_option: '3' } } }
  62. let(:core_workflow) { create(:core_workflow, :active_and_screen, :perform_action) }
  63. let(:macro_perform) do
  64. {
  65. 'ticket.priority_id': { pre_condition: 'specific', value: 3.to_s }
  66. }
  67. end
  68. let(:macro_priority) { create :macro, perform: macro_perform }
  69. def authenticate
  70. core_workflow && macro_priority && ticket1
  71. true
  72. end
  73. it 'shows modal with blocking ticket title' do
  74. visit '#ticket/view/all_open'
  75. within(:active_content) do
  76. display_macro_batches ticket
  77. move_mouse_to find(:macro_batch, macro_priority.id)
  78. release_mouse
  79. in_modal do
  80. expect(page).to have_text(ticket.title)
  81. end
  82. end
  83. end
  84. end
  85. context 'with macro batch overlay' do
  86. shared_examples "adding 'small' class to macro element" do
  87. it 'adds a "small" class to the macro element' do
  88. within(:active_content) do
  89. display_macro_batches Ticket.first
  90. expect(page).to have_selector('.batch-overlay-macro-entry.small')
  91. end
  92. end
  93. end
  94. shared_examples "not adding 'small' class to macro element" do
  95. it 'does not add a "small" class to the macro element' do
  96. within(:active_content) do
  97. display_macro_batches Ticket.first
  98. expect(page).to have_no_selector('.batch-overlay-macro-entry.small')
  99. end
  100. end
  101. end
  102. shared_examples 'showing all macros' do
  103. it 'shows all macros' do
  104. within(:active_content) do
  105. display_macro_batches Ticket.first
  106. expect(page).to have_selector('.batch-overlay-macro-entry', count: all)
  107. end
  108. end
  109. end
  110. shared_examples 'showing some macros' do |count|
  111. it 'shows all macros' do
  112. within(:active_content) do
  113. display_macro_batches Ticket.first
  114. expect(page).to have_selector('.batch-overlay-macro-entry', count: count)
  115. end
  116. end
  117. end
  118. def authenticate
  119. Macro.destroy_all && (create_list :macro, all)
  120. true
  121. end
  122. before do
  123. visit '#ticket/view/all_open'
  124. end
  125. context 'with few macros' do
  126. let(:all) { 15 }
  127. context 'when on large screen', screen_size: :desktop do
  128. it_behaves_like 'showing all macros'
  129. it_behaves_like "not adding 'small' class to macro element"
  130. end
  131. context 'when on small screen', screen_size: :tablet do
  132. it_behaves_like 'showing all macros'
  133. it_behaves_like "not adding 'small' class to macro element"
  134. end
  135. end
  136. context 'with many macros' do
  137. let(:all) { 50 }
  138. context 'when on large screen', screen_size: :desktop do
  139. it_behaves_like 'showing some macros', 32
  140. end
  141. context 'when on small screen', screen_size: :tablet do
  142. it_behaves_like 'showing some macros', 24
  143. it_behaves_like "adding 'small' class to macro element"
  144. end
  145. end
  146. end
  147. end
  148. context 'when performing a Bulk action' do
  149. context 'when creating a Note', authenticated_as: :user do
  150. let(:group) { create :group }
  151. let(:user) { create :admin, groups: [group] }
  152. let(:ticket1) { create(:ticket, state_name: 'open', owner: user, group: group) }
  153. let(:ticket2) { create(:ticket, state_name: 'open', owner: user, group: group) }
  154. let(:note) { Faker::Lorem.sentence }
  155. it 'adds note to all selected tickets' do
  156. ticket1 && ticket2
  157. visit 'ticket/view/my_assigned'
  158. within :active_content do
  159. all('.js-checkbox-field', count: 2).each(&:click)
  160. click '.js-confirm'
  161. find('.js-confirm-step textarea').fill_in with: note
  162. click '.js-submit'
  163. end
  164. expect do
  165. wait.until { [ ticket1.articles.last&.body, ticket2.articles.last&.body ] == [note, note] }
  166. end.not_to raise_error
  167. end
  168. end
  169. # https://github.com/zammad/zammad/issues/3568
  170. # We need a manual ticket creation to test the correct behaviour of the bulk functionality, because of some
  171. # leftovers after the creation in the the javascript assets store.
  172. context 'when performed a manual Ticket creation', authenticated_as: :agent do
  173. let(:customer) { create(:customer) }
  174. let(:group) { Group.find_by(name: 'Users') }
  175. let(:agent) { create(:agent, groups: [group]) }
  176. let!(:template) { create(:template, :dummy_data, group: group, owner: agent, customer: customer) }
  177. before do
  178. visit 'ticket/create'
  179. within(:active_content) do
  180. use_template(template)
  181. click('.js-submit')
  182. find('.ticket-article-item')
  183. end
  184. end
  185. it 'check that no duplicated article was created after usage of bulk action' do
  186. click('.menu-item[href="#ticket/view"]')
  187. created_ticket_id = Ticket.last.id
  188. within(:active_content) do
  189. click("tr[data-id='#{created_ticket_id}'] .js-checkbox-field")
  190. find('select[name="priority_id"] option[value="1"]').select_option
  191. click('.js-confirm')
  192. click('.js-submit')
  193. await_empty_ajax_queue
  194. # Check if still only one article exists on the ticket.
  195. click("tr[data-id='#{created_ticket_id}'] a")
  196. expect(page).to have_css('.ticket-article-item', count: 1)
  197. end
  198. end
  199. end
  200. context 'when saving is blocked by one of selected tickets', authenticated_as: :pre_authentication do
  201. let(:core_workflow) { create(:core_workflow, :active_and_screen, :perform_action) }
  202. let(:ticket1) { create :ticket, group: Group.first }
  203. def pre_authentication
  204. core_workflow && ticket1
  205. true
  206. end
  207. it 'shows modal with blocking ticket title' do
  208. visit 'ticket/view/all_open'
  209. within(:active_content) do
  210. find("tr[data-id='#{ticket1.id}']").check('bulk', allow_label_click: true)
  211. select '3 high', from: 'priority_id'
  212. click '.js-confirm'
  213. click '.js-submit'
  214. in_modal do
  215. expect(page).to have_text(ticket1.title)
  216. end
  217. end
  218. end
  219. end
  220. end
  221. context 'Setting "ui_table_group_by_show_count"', authenticated_as: :authenticate, db_strategy: :reset do
  222. let(:custom_attribute) { create :object_manager_attribute_select, name: 'grouptest' }
  223. let(:tickets) do
  224. [
  225. create(:ticket, group: Group.find_by(name: 'Users')),
  226. create(:ticket, group: Group.find_by(name: 'Users'), grouptest: 'key_1'),
  227. create(:ticket, group: Group.find_by(name: 'Users'), grouptest: 'key_2'),
  228. create(:ticket, group: Group.find_by(name: 'Users'), grouptest: 'key_1')
  229. ]
  230. end
  231. def authenticate
  232. custom_attribute
  233. ObjectManager::Attribute.migration_execute
  234. tickets
  235. Overview.find_by(name: 'Open Tickets').update(group_by: custom_attribute.name)
  236. Setting.set('ui_table_group_by_show_count', true)
  237. true
  238. end
  239. it 'shows correct ticket counts' do
  240. visit 'ticket/view/all_open'
  241. within(:active_content) do
  242. expect(page).to have_css('.js-tableBody td b', text: '(1)')
  243. .and(have_css('.js-tableBody td b', text: 'value_1 (2)'))
  244. .and(have_css('.js-tableBody td b', text: 'value_2 (1)'))
  245. end
  246. end
  247. end
  248. context 'Customer', authenticated_as: :authenticate do
  249. let(:customer) { create(:customer, :with_org) }
  250. let(:ticket) { create(:ticket, customer: customer) }
  251. def authenticate
  252. ticket
  253. customer
  254. end
  255. it 'shows ticket in my tickets' do
  256. visit 'ticket/view/my_tickets'
  257. expect(page).to have_text(ticket.title)
  258. end
  259. it 'shows ticket in my organization tickets' do
  260. visit 'ticket/view/my_tickets'
  261. click_on 'My Organization Tickets'
  262. expect(page).to have_text(ticket.title)
  263. end
  264. end
  265. describe 'Grouping by custom attribute', authenticated_as: :authenticate, db_strategy: :reset do
  266. def authenticate
  267. custom_attribute
  268. ObjectManager::Attribute.migration_execute
  269. tickets
  270. Overview.find_by(link: 'all_unassigned').update(group_by: custom_attribute.name)
  271. true
  272. end
  273. context 'when sorted by custom object date' do
  274. let(:custom_attribute) { create :object_manager_attribute_date, name: 'cdate' }
  275. let(:tickets) do
  276. [
  277. create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2021-08-18'),
  278. create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2019-01-19'),
  279. create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2018-01-17'),
  280. create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2018-08-19')
  281. ]
  282. end
  283. it 'does show the values grouped and sorted by date key value (yyy-mm-dd) instead of display value' do
  284. visit 'ticket/view/all_unassigned'
  285. headers = all('.js-tableBody td[colspan="6"]').map(&:text)
  286. expect(headers).to eq ['01/17/2018', '08/19/2018', '01/19/2019', '08/18/2021', '-']
  287. end
  288. end
  289. context 'when sorted by custom object select', authenticated_as: :authenticate, db_strategy: :reset do
  290. let(:custom_attribute) do
  291. create :object_manager_attribute_select,
  292. name: 'cselect',
  293. data_option_options: {
  294. 'a' => 'Zzz a',
  295. 'b' => 'Yyy b',
  296. 'c' => 'Xxx c',
  297. }
  298. end
  299. let(:tickets) do
  300. [
  301. create(:ticket, group: Group.find_by(name: 'Users'), cselect: 'a'),
  302. create(:ticket, group: Group.find_by(name: 'Users'), cselect: 'b'),
  303. create(:ticket, group: Group.find_by(name: 'Users'), cselect: 'c')
  304. ]
  305. end
  306. it 'does show the values grouped and sorted by display value instead of key value' do
  307. visit 'ticket/view/all_unassigned'
  308. headers = all('.js-tableBody td[colspan="6"]').map(&:text)
  309. expect(headers).to eq ['-', 'Xxx c', 'Yyy b', 'Zzz a']
  310. end
  311. end
  312. end
  313. end