idoit_browser_test.rb 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'browser_test_helper'
  3. class IntegrationIdoitTest < TestCase
  4. def test_idoit_objects_corrects_saves_on_ticket_creation
  5. # Read i-doit credentials from ENV
  6. if !ENV['IDOIT_API_TOKEN']
  7. raise "ERROR: Need IDOIT_API_TOKEN - hint IDOIT_API_TOKEN='1234'"
  8. end
  9. api_token = ENV['IDOIT_API_TOKEN']
  10. if !ENV['IDOIT_API_ENDPOINT']
  11. raise "ERROR: Need IDOIT_API_ENDPOINT - hint IDOIT_API_ENDPOINT='1234'"
  12. end
  13. api_endpoint = ENV['IDOIT_API_ENDPOINT']
  14. if !ENV['IDOIT_API_CATEGORY']
  15. raise "ERROR: Need IDOIT_API_CATEGORY - hint IDOIT_API_CATEGORY='Building'"
  16. end
  17. api_category = ENV['IDOIT_API_CATEGORY']
  18. @browser = browser_instance
  19. login(
  20. username: 'admin@example.com',
  21. password: 'test',
  22. url: browser_url,
  23. auto_wizard: true,
  24. )
  25. # turn on i-doit integration
  26. click(css: 'a[href="#manage"]')
  27. click(css: 'a[href="#system/integration"]')
  28. click(css: 'a[href="#system/integration/idoit"]')
  29. switch(
  30. css: '.content.active .js-switch',
  31. type: 'on'
  32. )
  33. # fill in i-doit login details
  34. set(
  35. css: '.content.active .main input[name="api_token"]',
  36. value: api_token,
  37. )
  38. set(
  39. css: '.content.active .main input[name="endpoint"]',
  40. value: api_endpoint,
  41. )
  42. click(css: '.content.active .main .js-submit')
  43. watch_for(
  44. css: '#notify',
  45. value: 'update successful',
  46. )
  47. # new create a new ticket with an i-doit object
  48. ticket_create(
  49. data: {
  50. customer: 'nico',
  51. group: 'Users',
  52. title: 'subject - i-doit integration #1',
  53. body: 'body - i-doit integration',
  54. },
  55. do_not_submit: true,
  56. )
  57. # open the i-doit selection modal
  58. click(css: '.content.active .tabsSidebar svg.icon-printer')
  59. click(css: '.content.active .sidebar[data-tab="idoit"] .js-headline')
  60. click(css: '.content.active .sidebar[data-tab="idoit"] .dropdown-menu')
  61. # wait for the API call to populate the dropdown menu
  62. watch_for(css: '.content.active .modal form input.js-input')
  63. # open the dropdown menu and choose the Building option
  64. click(css: '.content.active .modal form input.js-input')
  65. click(css: ".content.active .modal form li.js-option[title='#{api_category}']")
  66. # wait for the building results to populate from the API
  67. watch_for(css: '.content.active .modal form.js-result table.table')
  68. # click the check box from the first row and note its entry ID
  69. checkbox = @browser.find_elements(css: '.content.active .modal form.js-result tbody :first-child input')[0]
  70. entry_id = checkbox.attribute('value')
  71. checkbox.click
  72. # submit the i-doit object selections
  73. click(css: '.content.active .modal form button.js-submit')
  74. # confirm that the entry have been successfully recorded
  75. watch_for(
  76. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  77. )
  78. # reselect the customer and verify if object is still shown in sidebar
  79. ticket_customer_select(
  80. css: '.content.active .newTicket',
  81. customer: 'admin',
  82. )
  83. watch_for(
  84. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  85. )
  86. # now submit the ticket
  87. click(css: '.content.active .newTicket button.js-submit')
  88. watch_for(
  89. css: '.content.active .ticketZoom-header .ticket-number',
  90. )
  91. watch_for(
  92. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  93. )
  94. tasks_close_all
  95. # new create a new ticket with an i-doit object
  96. ticket_create(
  97. data: {
  98. customer: 'nico',
  99. group: 'Users',
  100. title: 'subject - i-doit integration #2',
  101. body: 'body - i-doit integration',
  102. },
  103. do_not_submit: true,
  104. )
  105. # open the i-doit selection modal
  106. click(css: '.content.active .tabsSidebar svg.icon-printer')
  107. click(css: '.content.active .sidebar[data-tab="idoit"] .js-headline')
  108. click(css: '.content.active .sidebar[data-tab="idoit"] .dropdown-menu')
  109. # wait for the API call to populate the dropdown menu
  110. watch_for(css: '.content.active .modal form input.js-input')
  111. # open the dropdown menu and choose the Building option
  112. click(css: '.content.active .modal form input.js-input')
  113. click(css: ".content.active .modal form li.js-option[title='#{api_category}']")
  114. # wait for the building results to populate from the API
  115. watch_for(css: '.content.active .modal form.js-result table.table')
  116. # click the check box from the first row and note its entry ID
  117. checkbox = @browser.find_elements(css: '.content.active .modal form.js-result tbody :first-child input')[0]
  118. entry_id = checkbox.attribute('value')
  119. checkbox.click
  120. # submit the i-doit object selections
  121. click(css: '.content.active .modal form button.js-submit')
  122. # confirm that the entry have been successfully recorded
  123. watch_for(
  124. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  125. )
  126. # now submit the ticket
  127. click(css: '.content.active .newTicket button.js-submit')
  128. watch_for(
  129. css: '.content.active .ticketZoom-header .ticket-number',
  130. )
  131. # open the i-doit sidebar again and verify that the entry is still there
  132. click(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="idoit"]')
  133. watch_for(
  134. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  135. )
  136. # remove i-doit object
  137. click(css: ".content.active .sidebar[data-tab='idoit'] .js-delete[data-object-id=\"#{entry_id}\"]")
  138. watch_for_disappear(
  139. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  140. )
  141. # reload browser and check if it's still removed
  142. sleep 3
  143. reload
  144. watch_for(
  145. css: '.content.active .ticketZoom-header .ticket-number',
  146. )
  147. click(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="idoit"]')
  148. watch_for(
  149. css: ".content.active .sidebar[data-tab='idoit'] .sidebar-content",
  150. )
  151. match(
  152. css: ".content.active .sidebar[data-tab='idoit'] .sidebar-content",
  153. value: 'none',
  154. )
  155. exists_not(
  156. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  157. )
  158. # add item again
  159. click(css: '.content.active .sidebar[data-tab="idoit"] .js-actions .dropdown-toggle')
  160. click(css: '.content.active .sidebar[data-tab="idoit"] .js-actions [data-type="objects-change"]')
  161. modal_ready
  162. # wait for the API call to populate the dropdown menu
  163. watch_for(css: '.content.active .modal form input.js-input')
  164. # open the dropdown menu and choose the Building option
  165. click(css: '.content.active .modal form input.js-input')
  166. click(css: ".content.active .modal form li.js-option[title='#{api_category}']")
  167. # wait for the building results to populate from the API
  168. watch_for(css: '.content.active .modal form.js-result table.table')
  169. # click the check box from the first row and note its entry ID
  170. checkbox = @browser.find_elements(css: '.content.active .modal form.js-result tbody :first-child input')[0]
  171. entry_id = checkbox.attribute('value')
  172. checkbox.click
  173. # submit the i-doit object selections
  174. click(css: '.content.active .modal form button.js-submit')
  175. # confirm that the entry have been successfully recorded
  176. watch_for(
  177. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  178. )
  179. # reload browser and check if it's still removed
  180. sleep 3
  181. reload
  182. watch_for(
  183. css: '.content.active .ticketZoom-header .ticket-number',
  184. )
  185. # open the i-doit sidebar again and verify that the entry is still there
  186. click(css: '.content.active .tabsSidebar .tabsSidebar-tab[data-tab="idoit"]')
  187. watch_for(
  188. css: ".content.active .sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']",
  189. )
  190. # finally turn off i-doit integration
  191. click(css: 'a[href="#manage"]')
  192. click(css: 'a[href="#system/integration"]')
  193. click(css: 'a[href="#system/integration/idoit"]')
  194. switch(
  195. css: '.content.active .js-switch',
  196. type: 'off'
  197. )
  198. end
  199. end