agent_ticket_attachment_test.rb 9.9 KB

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