agent_ticket_attachment_test.rb 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'browser_test_helper'
  3. class AgentTicketAttachmentTest < TestCase
  4. def test_ticket
  5. @browser = browser_instance
  6. login(
  7. username: 'agent1@example.com',
  8. password: 'test',
  9. url: browser_url,
  10. )
  11. tasks_close_all
  12. #
  13. # attachment checks - new ticket
  14. #
  15. # create new ticket with no attachment, attachment check should pop up
  16. ticket_create(
  17. data: {
  18. customer: 'nico',
  19. group: 'Users',
  20. title: 'test 6 - ticket 1',
  21. body: 'test 6 - ticket 1 - with the word attachment, but not attachment atteched it should give an warning on submit',
  22. },
  23. do_not_submit: true,
  24. )
  25. sleep 1
  26. # submit form
  27. click(css: '.content.active .js-submit', expect_alert: true)
  28. # since selenium webdriver with firefox is not able to upload files, skipp here
  29. # https://github.com/w3c/webdriver/issues/1230
  30. return if browser == 'firefox'
  31. # add attachment, attachment check should quiet
  32. file_upload(
  33. css: '.content.active .attachmentPlaceholder-inputHolder input',
  34. files: [Rails.root.join('test/data/upload/upload1.txt'),
  35. Rails.root.join('test/data/upload/upload2.jpg')],
  36. )
  37. # upload might take a while
  38. watch_for(
  39. css: '.content.active .newTicket .attachments',
  40. value: 'upload1.txt',
  41. )
  42. watch_for(
  43. css: '.content.active .newTicket .attachments',
  44. value: 'upload2.jpg',
  45. )
  46. # submit form
  47. click(css: '.content.active .js-submit')
  48. sleep 5
  49. # check if ticket is shown and attachment exists
  50. location_check(url: '#ticket/zoom/')
  51. sleep 2
  52. ticket_number = @browser.find_elements({ css: '.content.active .ticketZoom-header .ticket-number' })[0].text
  53. match(
  54. css: '.content.active .ticket-article-item:nth-child(1) .attachments',
  55. value: 'upload2.jpg',
  56. )
  57. match(
  58. css: '.content.active .ticket-article-item:nth-child(1) .attachments',
  59. value: 'upload1.txt',
  60. )
  61. #
  62. # attachment checks - update ticket
  63. #
  64. # update ticket with no attachment, attachment check should pop up
  65. ticket_update(
  66. data: {
  67. body: 'test 6 - ticket 1-1 - with the word attachment, but not attachment atteched it should give an warning on submit',
  68. },
  69. do_not_submit: true,
  70. )
  71. # submit form
  72. click(css: '.content.active .js-submit', expect_alert: true)
  73. # add attachment, attachment check should quiet
  74. file_upload(
  75. css: '.content.active .attachmentPlaceholder-inputHolder input',
  76. files: [Rails.root.join('test/data/upload/upload1.txt')],
  77. )
  78. # upload might take a while
  79. watch_for(
  80. css: '.content.active .article-add .attachments',
  81. value: 'upload1.txt',
  82. )
  83. # submit form
  84. click(css: '.content.active .js-submit')
  85. # discard changes should gone away
  86. watch_for_disappear(
  87. css: '.content.active .js-reset',
  88. value: '(Discard your unsaved changes.|Verwerfen der)',
  89. no_quote: true,
  90. )
  91. ticket_verify(
  92. data: {
  93. body: '',
  94. },
  95. )
  96. # check content and edit screen in instance 1
  97. watch_for(
  98. css: '.content.active div.ticket-article',
  99. value: 'test 6 - ticket 1-1',
  100. )
  101. match_not(
  102. css: '.content.active .ticket-article-item:nth-child(3) .attachments',
  103. value: 'upload2.jpg',
  104. )
  105. match(
  106. css: '.content.active .ticket-article-item:nth-child(3) .attachments',
  107. value: 'upload1.txt',
  108. )
  109. # add attachment without body
  110. file_upload(
  111. css: '.content.active .attachmentPlaceholder-inputHolder input',
  112. files: [Rails.root.join('test/data/upload/upload1.txt'),
  113. Rails.root.join('test/data/upload/upload2.jpg')],
  114. )
  115. # upload might take a while
  116. watch_for(
  117. css: '.content.active .article-add .attachments',
  118. value: 'upload1.txt',
  119. )
  120. watch_for(
  121. css: '.content.active .article-add .attachments',
  122. value: 'upload2.jpg',
  123. )
  124. # submit form
  125. click(css: '.content.active .js-submit')
  126. # check warning
  127. modal_ready
  128. match(
  129. css: '.content.active .modal',
  130. value: 'missing',
  131. )
  132. click(css: '.content.active .modal .js-cancel')
  133. modal_disappear
  134. ticket_update(
  135. data: {
  136. body: 'now submit should work',
  137. },
  138. do_not_submit: true,
  139. )
  140. # submit form
  141. click(css: '.content.active .js-submit')
  142. sleep 2
  143. # discard changes should gone away
  144. watch_for_disappear(
  145. css: '.content.active .js-reset',
  146. value: '(Discard your unsaved changes.|Verwerfen der)',
  147. no_quote: true,
  148. )
  149. ticket_verify(
  150. data: {
  151. body: '',
  152. },
  153. )
  154. match(
  155. css: '.content.active .ticket-article-item:nth-child(4) .attachments',
  156. value: 'upload2.jpg',
  157. )
  158. match(
  159. css: '.content.active .ticket-article-item:nth-child(4) .attachments',
  160. value: 'upload1.txt',
  161. )
  162. #
  163. # ticket customer change checks
  164. #
  165. # use current session
  166. browser1 = @browser
  167. browser2 = browser_instance
  168. login(
  169. browser: browser2,
  170. username: 'admin@example.com',
  171. password: 'test',
  172. url: browser_url,
  173. )
  174. tasks_close_all(
  175. browser: browser2,
  176. )
  177. random = "ticket-actions-6-test-#{SecureRandom.uuid}"
  178. user_email = "#{random}@example.com"
  179. user_create(
  180. browser: browser2,
  181. data: {
  182. firstname: "Action6 Firstname#{random}",
  183. lastname: "Action6 Lastname#{random}",
  184. email: user_email,
  185. password: 'some-pass',
  186. },
  187. )
  188. # update customer, check if new customer is shown in side bar
  189. ticket_open_by_search(
  190. browser: browser2,
  191. number: ticket_number,
  192. )
  193. ticket_update(
  194. browser: browser2,
  195. data: {
  196. customer: user_email,
  197. },
  198. do_not_submit: true,
  199. )
  200. # check if customer has changed in second browser
  201. click(browser: browser1, css: '.content.active .tabsSidebar-tab[data-tab="customer"]')
  202. watch_for(
  203. browser: browser1,
  204. css: '.content.active .tabsSidebar',
  205. value: user_email,
  206. )
  207. #
  208. # modify customer
  209. #
  210. # modify customer
  211. click(browser: browser1, css: '.content.active .sidebar[data-tab="customer"] .js-actions .dropdown-toggle')
  212. click(browser: browser1, css: '.content.active .sidebar[data-tab="customer"] .js-actions [data-type="customer-edit"]')
  213. modal_ready(browser: browser1)
  214. set(browser: browser1, css: '.modal [name="address"]', value: 'some new address')
  215. click(browser: browser1, css: '.modal .js-submit')
  216. modal_disappear(browser: browser1)
  217. # verify is customer has chnaged other browser too
  218. click(browser: browser2, css: '.content.active .tabsSidebar-tab[data-tab="customer"]')
  219. watch_for(
  220. browser: browser2,
  221. css: '.content.active .sidebar[data-tab="customer"]',
  222. value: 'some new address',
  223. )
  224. #
  225. # ticket customer organization change checks
  226. #
  227. # change org of customer, check if org is shown in sidebar
  228. click(browser: browser1, css: '.content.active .sidebar[data-tab="customer"] .js-actions .dropdown-toggle')
  229. click(browser: browser1, css: '.content.active .sidebar[data-tab="customer"] .js-actions [data-type="customer-edit"]')
  230. modal_ready(browser: browser1)
  231. set(browser: browser1, css: '.modal .js-input', value: 'zammad')
  232. click(browser: browser1, css: '.modal .js-input')
  233. click(browser: browser1, css: '.modal .js-option')
  234. click(browser: browser1, css: '.modal .js-submit')
  235. modal_disappear(browser: browser1)
  236. # check if org has changed in second browser
  237. sleep 3
  238. click(browser: browser2, css: '.content.active .tabsSidebar-tab[data-tab="organization"]')
  239. watch_for(
  240. browser: browser2,
  241. css: '.content.active .sidebar[data-tab="organization"]',
  242. value: 'Zammad Foundation',
  243. )
  244. #
  245. # form change/reset checks
  246. #
  247. # some form reset checks
  248. end
  249. def test_upload_blocks_ticket_updates
  250. # since selenium webdriver with firefox is not able to upload files, skip here
  251. # https://github.com/w3c/webdriver/issues/1230
  252. return if browser == 'firefox'
  253. @browser = browser_instance
  254. login(
  255. username: 'agent1@example.com',
  256. password: 'test',
  257. url: browser_url,
  258. )
  259. tasks_close_all
  260. ticket_create(
  261. data: {
  262. customer: 'Nico',
  263. group: 'Users',
  264. title: 'Ticket 1',
  265. body: 'some body',
  266. },
  267. do_not_submit: true,
  268. )
  269. # First test the attachment uploading for new tickets
  270. file_upload(
  271. css: '.content.active .attachmentPlaceholder-inputHolder input',
  272. files: [large_file],
  273. no_sleep: true,
  274. )
  275. exists(
  276. css: '.content.active .js-submit:disabled',
  277. )
  278. watch_for_disappear(
  279. css: '.content.active .js-submit:disabled',
  280. timeout: 4.minutes,
  281. )
  282. exists(
  283. css: '.content.active .js-submit',
  284. )
  285. click(
  286. css: '.content.active .js-submit',
  287. )
  288. sleep 2
  289. # Next test the attachment uploading for new articles
  290. ticket_update(
  291. data: {
  292. body: 'added attachment',
  293. },
  294. do_not_submit: true,
  295. )
  296. file_upload(
  297. css: '.content.active .attachmentPlaceholder-inputHolder input',
  298. files: [large_file],
  299. no_sleep: true,
  300. )
  301. exists(
  302. css: '.content.active .js-submit:disabled',
  303. )
  304. watch_for_disappear(
  305. css: '.content.active .js-submit:disabled',
  306. timeout: 4.minutes,
  307. )
  308. end
  309. def large_file
  310. file = Tempfile.new
  311. file.binmode
  312. file.write(SecureRandom.random_bytes(6.megabyte))
  313. file.close
  314. file.path
  315. end
  316. end