admin_drag_drop_to_new_group_test.rb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. require 'browser_test_helper'
  2. class AdminDragDropToNewGroupTest < TestCase
  3. def test_group_via_role
  4. @browser = browser_instance
  5. login(
  6. username: 'master@example.com',
  7. password: 'test',
  8. url: browser_url,
  9. )
  10. new_group_name = add_group
  11. new_role_name = add_role(new_group_name)
  12. open_user_modal do
  13. assign_role(new_role_name)
  14. end
  15. list_tickets
  16. assert get_group_element(new_group_name)
  17. end
  18. def test_new_group
  19. @browser = browser_instance
  20. login(
  21. username: 'master@example.com',
  22. password: 'test',
  23. url: browser_url,
  24. )
  25. new_group_name = add_group
  26. open_user_modal do
  27. assign_group(new_group_name, scroll: true)
  28. end
  29. list_tickets
  30. assert get_group_element(new_group_name)
  31. end
  32. private
  33. def add_group
  34. name = "dndgroup-#{rand(99_999_999)}"
  35. click(css: '.user-menu a[title=Admin')
  36. click(css: '.content.active a[href="#manage/groups"]')
  37. click(css: '.content.active a[data-type="new"]')
  38. modal_ready
  39. element = @browser.find_element(css: '.modal input[name=name]')
  40. element.clear
  41. element.send_keys(name)
  42. click(css: '.modal button.js-submit')
  43. sleep(1)
  44. name
  45. end
  46. def add_role(group_name)
  47. role_name = "#{group_name}-role"
  48. click(css: '.content.active a[href="#manage/roles"]')
  49. click(css: '.content.active a[data-type="new"]')
  50. modal_ready
  51. element = @browser.find_element(css: '.modal input[name=name]')
  52. element.clear
  53. element.send_keys(role_name)
  54. agent_permission = @browser.find_element(css: '.modal input[data-permission-name="ticket.agent"]')
  55. permission_id = agent_permission.attribute(:value)
  56. scroll_to(agent_permission.location.y)
  57. toggle_checkbox(@browser.find_element(css: '.modal'), "\"#{permission_id}\"") #digit-only selector fails
  58. assign_group(group_name)
  59. click(css: '.modal button.js-submit')
  60. sleep(1)
  61. role_name
  62. end
  63. def open_user_modal
  64. click(css: '.content.active a[href="#manage/users"]')
  65. user_css = '.user-list .js-tableBody tr td'
  66. watch_for(css: user_css)
  67. user_element = @browser.find_elements(css: user_css).find do |el|
  68. el.text.strip == 'master@example.com'
  69. end
  70. user_element.click
  71. modal_ready
  72. yield
  73. click(css: '.modal button.js-submit')
  74. sleep(1)
  75. end
  76. def scroll_to(offset_y = 'el.scrollHeight')
  77. scroll_script = "var el = document.getElementsByClassName('modal')[0];"
  78. scroll_script += "el.scrollTo(0, #{offset_y});"
  79. @browser.execute_script scroll_script
  80. end
  81. def assign_group(group_name, scroll: false)
  82. group_container = @browser.find_elements(css: '.modal .settings-list tbody tr').find do |el|
  83. el.find_element(css: 'td').text == group_name
  84. end
  85. assert_not_nil(group_container)
  86. scroll_to(group_container.location.y) if scroll
  87. toggle_checkbox(group_container, 'full')
  88. end
  89. def assign_role(role_name)
  90. role_container = @browser.find_elements(css: '.modal .checkbox > .inline-label').find do |el|
  91. el.find_elements(css: '.label-text').first&.text == role_name
  92. end
  93. scroll_to role_container.location.y
  94. assert_not_nil role_container
  95. role_id = role_container.find_element(css: 'input').attribute(:value)
  96. toggle_checkbox(role_container, "\"#{role_id}\"") #digit-only selector fails
  97. end
  98. def get_group_element(group_name)
  99. # wait until the scheduler pushes
  100. # the changes to the FE
  101. sleep(1.5)
  102. 10.times do
  103. dnd_element = @browser.find_element(css: '.content.active .js-tableBody .item')
  104. window_height = @browser.execute_script('return window.innerHeight')
  105. offset = window_height - dnd_element.location.y - dnd_element.rect.height - 50
  106. @browser.action.click_and_hold(dnd_element).perform
  107. @browser.action.move_by(0, 100).perform
  108. sleep(0.5)
  109. @browser.action.move_by(0, offset - 100).perform
  110. sleep(1)
  111. group_containers = @browser.find_elements(css: '.batch-overlay-assign-entry[data-action=group_assign]')
  112. new_group_container = group_containers.find do |g|
  113. g.find_element(css: '.batch-overlay-assign-entry-name').text.downcase == group_name
  114. end
  115. verified = verify_group_and_contents(new_group_container)
  116. return true if verified
  117. sleep(0.5)
  118. @browser
  119. .action
  120. .release
  121. .perform
  122. end
  123. false
  124. end
  125. def verify_group_and_contents(group_container)
  126. return false if group_container.nil?
  127. group_description = group_container.find_element(css: '.batch-overlay-assign-entry-detail').text
  128. return false if group_description != '1 PEOPLE'
  129. @browser.action.move_to(group_container).perform
  130. users_in_group = @browser.find_elements(css: '.js-batch-assign-group-inner .batch-overlay-assign-entry[data-action=user_assign]')
  131. users_in_group.count == 1
  132. end
  133. def list_tickets
  134. click(css: '.menu-item[href="#ticket/view"]')
  135. click(css: '.overview-header .tabsHolder a.tab[href="#ticket/view/all_unassigned"]')
  136. end
  137. end