form_ticket_perform_action.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. // ticket_perform_action
  2. test( "ticket_perform_action check", function() {
  3. App.TicketPriority.refresh([
  4. {
  5. id: 2,
  6. name: '2 normal',
  7. active: false,
  8. },
  9. {
  10. id: 1,
  11. name: '1 low',
  12. active: true,
  13. },
  14. ])
  15. App.TicketState.refresh([
  16. {
  17. id: 1,
  18. name: 'new',
  19. active: true,
  20. },
  21. {
  22. id: 2,
  23. name: 'open',
  24. active: true,
  25. },
  26. {
  27. id: 3,
  28. name: 'closed',
  29. active: false,
  30. },
  31. ])
  32. $('#forms').append('<hr><h1>ticket_perform_action check</h1><form id="form1"></form>')
  33. var el = $('#form1')
  34. var defaults = {
  35. ticket_perform_action1: {
  36. 'ticket.state_id': {
  37. value: '2'
  38. }
  39. },
  40. ticket_perform_action2: {
  41. 'ticket.state_id': {
  42. value: '1'
  43. },
  44. 'ticket.priority_id': {
  45. value: '2'
  46. },
  47. 'notification.email': {
  48. body: 'some body',
  49. internal: 'false',
  50. recipient: ['ticket_owner', 'ticket_customer'],
  51. subject: 'some subject'
  52. },
  53. },
  54. ticket_perform_action3: {
  55. 'ticket.state_id': {
  56. value: '3'
  57. },
  58. }
  59. }
  60. new App.ControllerForm({
  61. el: el,
  62. model: {
  63. configure_attributes: [
  64. {
  65. name: 'ticket_perform_action1',
  66. display: 'TicketPerformAction1',
  67. tag: 'ticket_perform_action',
  68. null: true,
  69. },
  70. {
  71. name: 'ticket_perform_action2',
  72. display: 'TicketPerformAction2',
  73. tag: 'ticket_perform_action',
  74. null: false,
  75. notification: true,
  76. },
  77. {
  78. name: 'ticket_perform_action3',
  79. display: 'TicketPerformAction3',
  80. tag: 'ticket_perform_action',
  81. null: true,
  82. notification: true,
  83. },
  84. ]
  85. },
  86. params: defaults,
  87. autofocus: true
  88. })
  89. var params = App.ControllerForm.params(el)
  90. var test_params = {
  91. ticket_perform_action1: {
  92. 'ticket.state_id': {
  93. value: '2'
  94. }
  95. },
  96. ticket_perform_action2: {
  97. 'notification.email': {
  98. body: 'some body',
  99. internal: 'false',
  100. recipient: ['ticket_owner', 'ticket_customer'],
  101. subject: 'some subject'
  102. },
  103. 'ticket.priority_id': {
  104. value: '2'
  105. },
  106. 'ticket.state_id': {
  107. value: '1'
  108. },
  109. },
  110. ticket_perform_action3: {
  111. 'ticket.state_id': {
  112. value: '3'
  113. }
  114. }
  115. }
  116. deepEqual(params, test_params, 'form param check')
  117. // add email notification
  118. $('[data-attribute-name="ticket_perform_action3"] .js-add').click()
  119. $('[data-attribute-name="ticket_perform_action3"] .js-attributeSelector .form-control').last().val('notification.email').trigger('change')
  120. $('[data-attribute-name="ticket_perform_action3"] .js-setNotification [name="ticket_perform_action3::notification.email::subject"]').val('some subject').trigger('change')
  121. $('[data-attribute-name="ticket_perform_action3"] .js-setNotification [data-name="ticket_perform_action3::notification.email::body"]').html('some body').trigger('change')
  122. $('[data-attribute-name="ticket_perform_action3"] .js-setNotification .js-recipient .js-option[data-value="ticket_owner"]').click()
  123. params = App.ControllerForm.params(el)
  124. test_params = {
  125. ticket_perform_action1: {
  126. 'ticket.state_id': {
  127. value: '2'
  128. }
  129. },
  130. ticket_perform_action2: {
  131. 'notification.email': {
  132. body: 'some body',
  133. internal: 'false',
  134. recipient: ['ticket_owner', 'ticket_customer'],
  135. subject: 'some subject'
  136. },
  137. 'ticket.priority_id': {
  138. value: '2'
  139. },
  140. 'ticket.state_id': {
  141. value: '1'
  142. },
  143. },
  144. ticket_perform_action3: {
  145. 'notification.email': {
  146. body: 'some body',
  147. internal: 'false',
  148. recipient: 'ticket_owner',
  149. subject: 'some subject'
  150. },
  151. 'ticket.state_id': {
  152. value: '3'
  153. }
  154. }
  155. }
  156. deepEqual(params, test_params, 'form param check')
  157. // remove recipient
  158. $('[data-attribute-name="ticket_perform_action2"] .js-setNotification .js-recipient .js-remove.js-option[data-value="ticket_owner"]').click()
  159. params = App.ControllerForm.params(el)
  160. test_params = {
  161. ticket_perform_action1: {
  162. 'ticket.state_id': {
  163. value: '2'
  164. }
  165. },
  166. ticket_perform_action2: {
  167. 'notification.email': {
  168. body: 'some body',
  169. internal: 'false',
  170. recipient: 'ticket_customer',
  171. subject: 'some subject'
  172. },
  173. 'ticket.priority_id': {
  174. value: '2'
  175. },
  176. 'ticket.state_id': {
  177. value: '1'
  178. },
  179. },
  180. ticket_perform_action3: {
  181. 'notification.email': {
  182. body: 'some body',
  183. internal: 'false',
  184. recipient: 'ticket_owner',
  185. subject: 'some subject'
  186. },
  187. 'ticket.state_id': {
  188. value: '3'
  189. }
  190. }
  191. }
  192. deepEqual(params, test_params, 'form param check')
  193. // set notification to internal
  194. $('[data-attribute-name="ticket_perform_action2"] .js-internal select').val('true').trigger('change')
  195. params = App.ControllerForm.params(el)
  196. test_params = {
  197. ticket_perform_action1: {
  198. 'ticket.state_id': {
  199. value: '2'
  200. }
  201. },
  202. ticket_perform_action2: {
  203. 'notification.email': {
  204. body: 'some body',
  205. internal: 'true',
  206. recipient: 'ticket_customer',
  207. subject: 'some subject'
  208. },
  209. 'ticket.priority_id': {
  210. value: '2'
  211. },
  212. 'ticket.state_id': {
  213. value: '1'
  214. },
  215. },
  216. ticket_perform_action3: {
  217. 'notification.email': {
  218. body: 'some body',
  219. internal: 'false',
  220. recipient: 'ticket_owner',
  221. subject: 'some subject'
  222. },
  223. 'ticket.state_id': {
  224. value: '3'
  225. }
  226. }
  227. }
  228. deepEqual(params, test_params, 'form param check')
  229. });
  230. // Test for backwards compatibility after issue is fixed https://github.com/zammad/zammad/issues/2782
  231. test( "ticket_perform_action backwards check after issue #2782", function() {
  232. $('#forms').append('<hr><h1>ticket_perform_action check</h1><form id="form2"></form>')
  233. var el = $('#form2')
  234. var defaults = {
  235. ticket_perform_action5: {
  236. 'notification.email': {
  237. body: 'some body',
  238. recipient: ['ticket_owner', 'ticket_customer'],
  239. subject: 'some subject'
  240. },
  241. },
  242. }
  243. new App.ControllerForm({
  244. el: el,
  245. model: {
  246. configure_attributes: [
  247. {
  248. name: 'ticket_perform_action5',
  249. display: 'TicketPerformAction5',
  250. tag: 'ticket_perform_action',
  251. null: true,
  252. },
  253. ]
  254. },
  255. params: defaults,
  256. autofocus: true
  257. })
  258. var params = App.ControllerForm.params(el)
  259. var test_params = {
  260. ticket_perform_action5: {
  261. 'notification.email': {
  262. body: 'some body',
  263. internal: 'false',
  264. recipient: ['ticket_owner', 'ticket_customer'],
  265. subject: 'some subject'
  266. },
  267. }
  268. }
  269. deepEqual(params, test_params, 'form param check')
  270. });
  271. test( "ticket_perform_action rows manipulation", function() {
  272. App.TicketPriority.refresh([
  273. {
  274. id: 2,
  275. name: '2 normal',
  276. active: false,
  277. },
  278. {
  279. id: 1,
  280. name: '1 low',
  281. active: true,
  282. },
  283. ])
  284. App.TicketState.refresh([
  285. {
  286. id: 1,
  287. name: 'new',
  288. active: true,
  289. },
  290. {
  291. id: 2,
  292. name: 'open',
  293. active: true,
  294. },
  295. {
  296. id: 3,
  297. name: 'closed',
  298. active: false,
  299. },
  300. ])
  301. $('#forms').append('<hr><h1>ticket_perform_action rows manipulation</h1><form id="form99"></form>')
  302. var el = $('#form99')
  303. var defaults = {
  304. ticket_perform_action1: {
  305. 'ticket.state_id': {
  306. value: '2'
  307. }
  308. }
  309. }
  310. new App.ControllerForm({
  311. el: el,
  312. model: {
  313. configure_attributes: [
  314. {
  315. name: 'ticket_perform_action99',
  316. display: 'TicketPerformAction99',
  317. tag: 'ticket_perform_action',
  318. null: true,
  319. },
  320. ]
  321. },
  322. params: defaults,
  323. autofocus: true
  324. })
  325. equal(true, true)
  326. var selector = '[data-attribute-name="ticket_perform_action99"] '
  327. $(selector + '.js-remove').click()
  328. equal($(selector + '.js-filterElement').length, 1, 'prevents removing single initial row')
  329. $(selector + '.js-add').click()
  330. equal($(selector + '.js-filterElement').length, 2, 'adds 2nd row')
  331. $(selector + ' .js-remove:last').click()
  332. equal($(selector + '.js-filterElement').length, 1, 'removes 2nd row')
  333. $(selector + '.js-remove:last').click()
  334. equal($(selector + ' .js-filterElement').length, 1, 'prevents removing last row')
  335. });