admin_drag_drop_to_new_group_test.rb 5.6 KB

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