idoit_browser_test.rb 8.2 KB

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