form_ticket_perform_action.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. // ticket_perform_action
  2. QUnit.test( "ticket_perform_action check", assert => {
  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. include_attachments: 'false',
  53. },
  54. },
  55. ticket_perform_action3: {
  56. 'ticket.state_id': {
  57. value: '3'
  58. },
  59. }
  60. }
  61. new App.ControllerForm({
  62. el: el,
  63. model: {
  64. configure_attributes: [
  65. {
  66. name: 'ticket_perform_action1',
  67. display: 'TicketPerformAction1',
  68. tag: 'ticket_perform_action',
  69. null: true,
  70. },
  71. {
  72. name: 'ticket_perform_action2',
  73. display: 'TicketPerformAction2',
  74. tag: 'ticket_perform_action',
  75. null: false,
  76. notification: true,
  77. },
  78. {
  79. name: 'ticket_perform_action3',
  80. display: 'TicketPerformAction3',
  81. tag: 'ticket_perform_action',
  82. null: true,
  83. notification: true,
  84. },
  85. ]
  86. },
  87. params: defaults,
  88. autofocus: true
  89. })
  90. var params = App.ControllerForm.params(el)
  91. var test_params = {
  92. ticket_perform_action1: {
  93. 'ticket.state_id': {
  94. value: '2'
  95. }
  96. },
  97. ticket_perform_action2: {
  98. 'notification.email': {
  99. body: 'some body',
  100. internal: 'false',
  101. recipient: ['ticket_owner', 'ticket_customer'],
  102. subject: 'some subject',
  103. include_attachments: 'false',
  104. },
  105. 'ticket.priority_id': {
  106. value: '2'
  107. },
  108. 'ticket.state_id': {
  109. value: '1'
  110. },
  111. },
  112. ticket_perform_action3: {
  113. 'ticket.state_id': {
  114. value: '3'
  115. }
  116. }
  117. }
  118. assert.deepEqual(params, test_params, 'form param check')
  119. // add email notification
  120. $('[data-attribute-name="ticket_perform_action3"] .js-add').trigger('click')
  121. $('[data-attribute-name="ticket_perform_action3"] .js-attributeSelector .form-control').last().val('notification.email').trigger('change')
  122. $('[data-attribute-name="ticket_perform_action3"] .js-setNotification [name="ticket_perform_action3::notification.email::subject"]').val('some subject').trigger('change')
  123. $('[data-attribute-name="ticket_perform_action3"] .js-setNotification [data-name="ticket_perform_action3::notification.email::body"]').html('some body').trigger('change')
  124. $('[data-attribute-name="ticket_perform_action3"] .js-setNotification .js-recipient .js-option[data-value="ticket_owner"]').trigger('click')
  125. params = App.ControllerForm.params(el)
  126. test_params = {
  127. ticket_perform_action1: {
  128. 'ticket.state_id': {
  129. value: '2'
  130. }
  131. },
  132. ticket_perform_action2: {
  133. 'notification.email': {
  134. body: 'some body',
  135. internal: 'false',
  136. recipient: ['ticket_owner', 'ticket_customer'],
  137. subject: 'some subject',
  138. include_attachments: 'false',
  139. },
  140. 'ticket.priority_id': {
  141. value: '2'
  142. },
  143. 'ticket.state_id': {
  144. value: '1'
  145. },
  146. },
  147. ticket_perform_action3: {
  148. 'notification.email': {
  149. body: 'some body',
  150. internal: 'false',
  151. recipient: ['ticket_owner'],
  152. subject: 'some subject',
  153. include_attachments: 'false',
  154. },
  155. 'ticket.state_id': {
  156. value: '3'
  157. }
  158. }
  159. }
  160. assert.deepEqual(params, test_params, 'form param check')
  161. // remove recipient
  162. $('[data-attribute-name="ticket_perform_action2"] .js-setNotification .js-recipient .js-remove.js-option[data-value="ticket_owner"]').trigger('click')
  163. params = App.ControllerForm.params(el)
  164. test_params = {
  165. ticket_perform_action1: {
  166. 'ticket.state_id': {
  167. value: '2'
  168. }
  169. },
  170. ticket_perform_action2: {
  171. 'notification.email': {
  172. body: 'some body',
  173. internal: 'false',
  174. recipient: ['ticket_customer'],
  175. subject: 'some subject',
  176. include_attachments: 'false',
  177. },
  178. 'ticket.priority_id': {
  179. value: '2'
  180. },
  181. 'ticket.state_id': {
  182. value: '1'
  183. },
  184. },
  185. ticket_perform_action3: {
  186. 'notification.email': {
  187. body: 'some body',
  188. internal: 'false',
  189. recipient: ['ticket_owner'],
  190. subject: 'some subject',
  191. include_attachments: 'false',
  192. },
  193. 'ticket.state_id': {
  194. value: '3'
  195. }
  196. }
  197. }
  198. assert.deepEqual(params, test_params, 'form param check')
  199. // set notification to internal
  200. $('[data-attribute-name="ticket_perform_action2"] .js-internal select').val('true').trigger('change')
  201. params = App.ControllerForm.params(el)
  202. test_params = {
  203. ticket_perform_action1: {
  204. 'ticket.state_id': {
  205. value: '2'
  206. }
  207. },
  208. ticket_perform_action2: {
  209. 'notification.email': {
  210. body: 'some body',
  211. internal: 'true',
  212. recipient: ['ticket_customer'],
  213. subject: 'some subject',
  214. include_attachments: 'false',
  215. },
  216. 'ticket.priority_id': {
  217. value: '2'
  218. },
  219. 'ticket.state_id': {
  220. value: '1'
  221. },
  222. },
  223. ticket_perform_action3: {
  224. 'notification.email': {
  225. body: 'some body',
  226. internal: 'false',
  227. recipient: ['ticket_owner'],
  228. subject: 'some subject',
  229. include_attachments: 'false',
  230. },
  231. 'ticket.state_id': {
  232. value: '3'
  233. }
  234. }
  235. }
  236. assert.deepEqual(params, test_params, 'form param check')
  237. // add pending time
  238. $('[data-attribute-name="ticket_perform_action3"] .js-add').last().trigger('click')
  239. var row = $('[data-attribute-name="ticket_perform_action3"] .js-filterElement').last()
  240. var date_string = '2010-07-15T12:00:00.000Z'
  241. var date_parsed = new Date(date_string) // make sure it works regardless of browser locale
  242. row.find('.js-attributeSelector .form-control').last().val('ticket.pending_time').trigger('change')
  243. row.find('.js-datepicker').val(date_parsed.toLocaleDateString()).trigger('blur')
  244. row.find('.js-datepicker').datepicker('setDate')
  245. row.find('.js-timepicker').val(date_parsed.getHours() + ':' + date_parsed.getMinutes()).trigger('blur')
  246. test_params = {
  247. ticket_perform_action1: {
  248. 'ticket.state_id': {
  249. value: '2'
  250. }
  251. },
  252. ticket_perform_action2: {
  253. 'notification.email': {
  254. body: 'some body',
  255. internal: 'true',
  256. recipient: ['ticket_customer'],
  257. subject: 'some subject',
  258. include_attachments: 'false',
  259. },
  260. 'ticket.priority_id': {
  261. value: '2'
  262. },
  263. 'ticket.state_id': {
  264. value: '1'
  265. },
  266. },
  267. ticket_perform_action3: {
  268. 'notification.email': {
  269. body: 'some body',
  270. internal: 'false',
  271. recipient: ['ticket_owner'],
  272. subject: 'some subject',
  273. include_attachments: 'false',
  274. },
  275. 'ticket.pending_time': {
  276. operator: 'static',
  277. value: date_string
  278. },
  279. 'ticket.state_id': {
  280. value: '3'
  281. }
  282. }
  283. }
  284. var done = assert.async()
  285. setTimeout(function(){
  286. params = App.ControllerForm.params(el)
  287. assert.deepEqual(params, test_params, 'form param check')
  288. done()
  289. }, 0);
  290. // switch pending time to relative
  291. row.find('.js-operator select').val('relative').trigger('change')
  292. row.find('.js-range').val('day').trigger('change')
  293. row.find('.js-value').val('10').trigger('change')
  294. params = App.ControllerForm.params(el)
  295. test_params = {
  296. ticket_perform_action1: {
  297. 'ticket.state_id': {
  298. value: '2'
  299. }
  300. },
  301. ticket_perform_action2: {
  302. 'notification.email': {
  303. body: 'some body',
  304. internal: 'true',
  305. recipient: ['ticket_customer'],
  306. subject: 'some subject',
  307. include_attachments: 'false',
  308. },
  309. 'ticket.priority_id': {
  310. value: '2'
  311. },
  312. 'ticket.state_id': {
  313. value: '1'
  314. },
  315. },
  316. ticket_perform_action3: {
  317. 'notification.email': {
  318. body: 'some body',
  319. internal: 'false',
  320. recipient: ['ticket_owner'],
  321. subject: 'some subject',
  322. include_attachments: 'false',
  323. },
  324. 'ticket.pending_time': {
  325. operator: 'relative',
  326. range: 'day',
  327. value: '10'
  328. },
  329. 'ticket.state_id': {
  330. value: '3'
  331. }
  332. }
  333. }
  334. assert.deepEqual(params, test_params, 'form param check')
  335. });
  336. // Test for backwards compatibility after issue is fixed https://github.com/zammad/zammad/issues/2782
  337. QUnit.test( "ticket_perform_action backwards check after issue #2782", assert => {
  338. $('#forms').append('<hr><h1>ticket_perform_action check</h1><form id="form2"></form>')
  339. var el = $('#form2')
  340. var defaults = {
  341. ticket_perform_action5: {
  342. 'notification.email': {
  343. body: 'some body',
  344. recipient: ['ticket_owner', 'ticket_customer'],
  345. subject: 'some subject',
  346. include_attachments: 'true',
  347. },
  348. },
  349. }
  350. new App.ControllerForm({
  351. el: el,
  352. model: {
  353. configure_attributes: [
  354. {
  355. name: 'ticket_perform_action5',
  356. display: 'TicketPerformAction5',
  357. tag: 'ticket_perform_action',
  358. null: true,
  359. },
  360. ]
  361. },
  362. params: defaults,
  363. autofocus: true
  364. })
  365. var params = App.ControllerForm.params(el)
  366. var test_params = {
  367. ticket_perform_action5: {
  368. 'notification.email': {
  369. body: 'some body',
  370. internal: 'false',
  371. recipient: ['ticket_owner', 'ticket_customer'],
  372. subject: 'some subject',
  373. include_attachments: 'true',
  374. },
  375. }
  376. }
  377. assert.deepEqual(params, test_params, 'form param check')
  378. });
  379. QUnit.test( "ticket_perform_action rows manipulation", assert => {
  380. App.TicketPriority.refresh([
  381. {
  382. id: 2,
  383. name: '2 normal',
  384. active: false,
  385. },
  386. {
  387. id: 1,
  388. name: '1 low',
  389. active: true,
  390. },
  391. ])
  392. App.TicketState.refresh([
  393. {
  394. id: 1,
  395. name: 'new',
  396. active: true,
  397. },
  398. {
  399. id: 2,
  400. name: 'open',
  401. active: true,
  402. },
  403. {
  404. id: 3,
  405. name: 'closed',
  406. active: false,
  407. },
  408. ])
  409. $('#forms').append('<hr><h1>ticket_perform_action rows manipulation</h1><form id="form99"></form>')
  410. var el = $('#form99')
  411. var defaults = {
  412. ticket_perform_action1: {
  413. 'ticket.state_id': {
  414. value: '2'
  415. }
  416. }
  417. }
  418. new App.ControllerForm({
  419. el: el,
  420. model: {
  421. configure_attributes: [
  422. {
  423. name: 'ticket_perform_action99',
  424. display: 'TicketPerformAction99',
  425. tag: 'ticket_perform_action',
  426. null: true,
  427. },
  428. ]
  429. },
  430. params: defaults,
  431. autofocus: true
  432. })
  433. assert.equal(true, true)
  434. var selector = '[data-attribute-name="ticket_perform_action99"] '
  435. $(selector + '.js-remove').trigger('click')
  436. assert.equal($(selector + '.js-filterElement').length, 1, 'prevents removing single initial row')
  437. $(selector + '.js-add').trigger('click')
  438. assert.equal($(selector + '.js-filterElement').length, 2, 'adds 2nd row')
  439. $(selector + ' .js-remove:last').trigger('click')
  440. assert.equal($(selector + '.js-filterElement').length, 1, 'removes 2nd row')
  441. $(selector + '.js-remove:last').trigger('click')
  442. assert.equal($(selector + ' .js-filterElement').length, 1, 'prevents removing last row')
  443. });
  444. // Test for backwards compatibility after PR https://github.com/zammad/zammad/pull/2862
  445. QUnit.test( "ticket_perform_action backwards check after PR#2862", assert => {
  446. $('#forms').append('<hr><h1>ticket_perform_action check</h1><form id="form3"></form>')
  447. var el = $('#form3')
  448. var defaults = {
  449. ticket_perform_action4: {
  450. 'ticket.pending_time': {
  451. value: '2010-07-15T05:00:00.000Z'
  452. }
  453. }
  454. }
  455. new App.ControllerForm({
  456. el: el,
  457. model: {
  458. configure_attributes: [
  459. {
  460. name: 'ticket_perform_action4',
  461. display: 'TicketPerformAction4',
  462. tag: 'ticket_perform_action',
  463. null: true,
  464. },
  465. ]
  466. },
  467. params: defaults,
  468. autofocus: true
  469. })
  470. var params = App.ControllerForm.params(el)
  471. var test_params = {
  472. ticket_perform_action4: {
  473. 'ticket.pending_time': {
  474. operator: 'static',
  475. value: '2010-07-15T05:00:00.000Z'
  476. }
  477. }
  478. }
  479. assert.deepEqual(params, test_params, 'form param check')
  480. });
  481. QUnit.test( "ticket_perform_action orphan time fields", assert => {
  482. $('#forms').append('<hr><h1>ticket_perform_action orphan time fields</h1><form id="form4"></form>')
  483. var el = $('#form4')
  484. var defaults = {
  485. ticket_perform_action4: {
  486. 'ticket.pending_time': {
  487. operator: 'relative',
  488. value: '1'
  489. }
  490. }
  491. }
  492. new App.ControllerForm({
  493. el: el,
  494. model: {
  495. configure_attributes: [
  496. {
  497. name: 'ticket_perform_action4',
  498. display: 'TicketPerformAction4',
  499. tag: 'ticket_perform_action',
  500. null: true,
  501. },
  502. ]
  503. },
  504. params: defaults,
  505. autofocus: true
  506. })
  507. // change to another attribute
  508. el.find('select:first').val('ticket.tags').trigger('change')
  509. assert.equal(el.find('.js-valueRangeSelector').length, 0)
  510. });
  511. QUnit.test( "ticket_perform_action check possible owner selection", assert => {
  512. $('#forms').append('<hr><h1>ticket_perform_action check possible owner selection</h1><form id="form5"></form>')
  513. var el = $('#form5')
  514. var defaults = {
  515. ticket_perform_action5: {
  516. 'ticket.owner_id': {
  517. pre_condition: 'not_set',
  518. }
  519. }
  520. }
  521. new App.ControllerForm({
  522. el: el,
  523. model: {
  524. configure_attributes: [
  525. {
  526. name: 'ticket_perform_action5',
  527. display: 'TicketPerformAction5',
  528. tag: 'ticket_perform_action',
  529. null: true,
  530. },
  531. ]
  532. },
  533. params: defaults,
  534. autofocus: true
  535. })
  536. var params = App.ControllerForm.params(el)
  537. var test_params = {
  538. ticket_perform_action5: {
  539. 'ticket.owner_id': {
  540. pre_condition: 'not_set',
  541. value: '',
  542. value_completion: ''
  543. }
  544. }
  545. }
  546. assert.deepEqual(params, test_params, 'form param check')
  547. el.find('[name="ticket_perform_action5::ticket.owner_id::pre_condition"]').val('specific').trigger('change')
  548. params = App.ControllerForm.params(el)
  549. test_params = {
  550. ticket_perform_action5: {
  551. 'ticket.owner_id': {
  552. pre_condition: 'specific',
  553. value: '',
  554. value_completion: ''
  555. }
  556. }
  557. }
  558. assert.deepEqual(params, test_params, 'form param check')
  559. });
  560. QUnit.test( "ticket_perform_action check when there's no available webhook", assert => {
  561. $('#forms').append('<hr><h1>ticket_perform_action check when there\'s no available webhook</h1><form id="form6"></form>')
  562. var el = $('#form6')
  563. var defaults = {
  564. ticket_perform_action6: {
  565. 'notification.webhook': {
  566. value: undefined
  567. }
  568. }
  569. }
  570. new App.ControllerForm({
  571. el: el,
  572. model: {
  573. configure_attributes: [
  574. {
  575. name: 'ticket_perform_action6',
  576. display: 'TicketPerformAction6',
  577. tag: 'ticket_perform_action',
  578. null: true,
  579. notification: true,
  580. },
  581. ]
  582. },
  583. params: defaults,
  584. autofocus: true
  585. })
  586. var params = App.ControllerForm.params(el)
  587. assert.deepEqual(params, {}, 'form param check')
  588. var testNoticeMessage = 'No webhook available, please create a new one or activate an existing one at "Manage > Webhook"'
  589. var noticeMessage = el.find('.controls.js-webhooks div').text()
  590. assert.equal(noticeMessage, testNoticeMessage, 'form shows message when webhook is not available')
  591. });
  592. QUnit.test( "ticket_perform_action check when there's an available webhook", assert => {
  593. $('#forms').append('<hr><h1>ticket_perform_action check when there\'s an available webhook</h1><form id="form7"></form>')
  594. var el = $('#form7')
  595. var defaults = {
  596. ticket_perform_action7: {
  597. 'notification.webhook': {
  598. webhook_id: 'c-1'
  599. }
  600. }
  601. }
  602. App.Webhook.refresh([
  603. {
  604. name: 'Webhook test',
  605. endpoint: 'https://target.example.com/webhook',
  606. active: true,
  607. id: 'c-1'
  608. }
  609. ], { clear: true })
  610. new App.ControllerForm({
  611. el: el,
  612. model: {
  613. configure_attributes: [
  614. {
  615. name: 'ticket_perform_action7',
  616. display: 'TicketPerformAction7',
  617. tag: 'ticket_perform_action',
  618. null: true,
  619. notification: true,
  620. },
  621. ]
  622. },
  623. params: defaults,
  624. autofocus: true
  625. })
  626. var params = App.ControllerForm.params(el)
  627. var test_params = {
  628. 'ticket_perform_action7': {
  629. 'notification.webhook': {
  630. 'webhook_id': 'c-1'
  631. }
  632. }
  633. }
  634. assert.deepEqual(params, test_params, 'form param check')
  635. var testNoticeMessage = 'No webhook available, please create a new one or activate an existing one at "Manage > Webhook"'
  636. var noticeMessage = el.find('.controls.js-webhooks').text()
  637. assert.notEqual(noticeMessage, testNoticeMessage, 'form does not show notice message when webhook is available')
  638. var noticeMessage = el.find('.controls.js-webhooks select option').eq(1).text()
  639. assert.equal(noticeMessage, 'Webhook test (https://target.example.com/webhook)', 'form shows available webhook when webhook is available')
  640. });
  641. QUnit.test( "ticket_perform_action check template attributes", assert => {
  642. $('#forms').append('<hr><h1>ticket_perform_action check template attributes</h1><form id="form8"></form>')
  643. var el = $('#form8')
  644. var defaults = {
  645. ticket_perform_action8: {
  646. 'article.body': {
  647. value: 'foobar',
  648. },
  649. 'ticket.foo': {
  650. value: 'bar',
  651. },
  652. },
  653. }
  654. new App.ControllerForm({
  655. el: el,
  656. model: {
  657. configure_attributes: [
  658. {
  659. name: 'ticket_perform_action8',
  660. display: 'TicketPerformAction8',
  661. tag: 'ticket_perform_action',
  662. user_action: false,
  663. article_body_cc_only: true,
  664. sender_type: true,
  665. no_richtext_uploads: true,
  666. skip_unknown_attributes: true,
  667. null: true,
  668. },
  669. ],
  670. },
  671. params: defaults,
  672. autofocus: true,
  673. })
  674. var params = App.ControllerForm.params(el)
  675. var test_params = {
  676. 'ticket_perform_action8': {
  677. 'article.body': {
  678. value: 'foobar',
  679. },
  680. },
  681. }
  682. assert.deepEqual(params, test_params, 'form param check')
  683. var row = $('[data-attribute-name="ticket_perform_action8"] .js-filterElement').last()
  684. var select = row.find('.js-attributeSelector .form-control').first()
  685. var options = select.find('option').map((index, option) => option.value).toArray().sort()
  686. var test_options = [
  687. 'article.body',
  688. 'article.cc',
  689. 'ticket.customer_id',
  690. 'ticket.formSenderType',
  691. 'ticket.group_id',
  692. 'ticket.organization_id',
  693. 'ticket.owner_id',
  694. 'ticket.pending_time',
  695. 'ticket.priority_id',
  696. 'ticket.state_id',
  697. 'ticket.tags',
  698. 'ticket.title',
  699. ]
  700. assert.deepEqual(options, test_options, 'select options check')
  701. var articleBody = row.find('[data-name="ticket_perform_action8::article.body::value"]')
  702. assert.equal(articleBody.html(), 'foobar', 'article body text check')
  703. });
  704. QUnit.test( "ticket_perform_action allows to load data from external data source", assert => {
  705. var testOptions = [
  706. {
  707. value: 1,
  708. label: 'A',
  709. },
  710. {
  711. value: 2,
  712. label: 'B',
  713. },
  714. {
  715. value: 3,
  716. label: 'C',
  717. },
  718. ]
  719. App.ExternalDataSourceAjaxSelect.TEST_SEARCH_RESULT_CACHE = {
  720. 'Ticket+external_data_source1+*': {
  721. result: testOptions,
  722. },
  723. 'Ticket+external_data_source1+': {
  724. result: testOptions,
  725. },
  726. }
  727. $('#forms').append('<hr><h1>ticket_perform_action allows to load data from external data source</h1><form id="form9"></form>')
  728. var el = $('#form9')
  729. App.Ticket.configure_attributes.push({
  730. name: 'external_data_source1',
  731. display: 'ExternalDataSource1',
  732. tag: 'autocompletion_ajax_external_data_source',
  733. null: true,
  734. })
  735. new App.ControllerForm({
  736. el: el,
  737. model: {
  738. configure_attributes: [
  739. {
  740. name: 'ticket_perform_action6',
  741. display: 'TicketPerformAction6',
  742. tag: 'ticket_perform_action',
  743. null: true,
  744. },
  745. ]
  746. },
  747. params: {},
  748. autofocus: true
  749. })
  750. $('[data-attribute-name="ticket_perform_action6"] .js-attributeSelector .form-control')
  751. .last()
  752. .val('ticket.external_data_source1')
  753. .trigger('change')
  754. $('[data-attribute-name="ticket_perform_action6"] .js-input')
  755. .trigger('focus')
  756. .val('*')
  757. .trigger('input')
  758. var entries = $('[data-attribute-name="ticket_perform_action6"]').find('.js-optionsList li').length
  759. assert.equal(entries, 3, 'dropdown count')
  760. $('[data-attribute-name="ticket_perform_action6"]').find('.js-optionsList li:first').trigger('click')
  761. var params = App.ControllerForm.params(el)
  762. var test_params = {
  763. ticket_perform_action6: {
  764. 'ticket.external_data_source1': {
  765. 'value': {
  766. label: 'A',
  767. value: 1
  768. }
  769. }
  770. }
  771. }
  772. assert.deepEqual(params, test_params, 'form param check')
  773. });