keyboard_shortcuts_test.rb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'browser_test_helper'
  3. class KeyboardShortcutsTest < TestCase
  4. def test_navigation
  5. @browser = browser_instance
  6. login(
  7. username: 'admin@example.com',
  8. password: 'test',
  9. url: browser_url,
  10. )
  11. tasks_close_all
  12. sleep 2
  13. # show shortkeys
  14. shortcut(key: 'h')
  15. # ff issue, sometimes shortcut is not fired in browser test env
  16. if ENV['BROWSER'] && ENV['BROWSER'] =~ %r{firefox}i
  17. exists = false
  18. (1..4).each do |_count|
  19. sleep 1
  20. next if !@browser.find_elements(css: '.modal')[0]
  21. exists = true
  22. end
  23. if !exists
  24. reload
  25. sleep 4
  26. shortcut(key: 'h')
  27. (1..4).each do |_count|
  28. sleep 1
  29. next if !@browser.find_elements(css: '.modal')[0]
  30. exists = true
  31. end
  32. end
  33. if !exists
  34. shortcut(key: 'h')
  35. end
  36. end
  37. modal_ready
  38. # hide shortkeys
  39. shortcut(key: 'h')
  40. modal_disappear
  41. # show shortkeys
  42. shortcut(key: 'h')
  43. modal_ready
  44. # show notifications
  45. shortcut(key: 'a')
  46. watch_for(
  47. css: '.js-notificationsContainer .js-header',
  48. value: 'Notification',
  49. timeout: 10,
  50. )
  51. shortcut(key: 'a')
  52. watch_for_disappear(
  53. css: '.js-notificationsContainer .js-header',
  54. value: 'Notification',
  55. timeout: 2,
  56. )
  57. # go to overviews
  58. shortcut(key: 'o')
  59. watch_for(
  60. css: '.active.content',
  61. value: 'My assigned Tickets',
  62. timeout: 2,
  63. )
  64. # go to dashboard
  65. shortcut(key: 'd')
  66. watch_for(
  67. css: '.active.content',
  68. value: 'My Stats',
  69. timeout: 2,
  70. )
  71. # go to new ticket
  72. shortcut(key: 'n')
  73. watch_for(
  74. css: '.active.content',
  75. value: 'New Ticket',
  76. timeout: 2,
  77. )
  78. # close again
  79. shortcut(key: 'w')
  80. watch_for_disappear(
  81. css: '.active.content',
  82. value: 'New Ticket',
  83. timeout: 2,
  84. )
  85. ticket1 = ticket_create(
  86. data: {
  87. customer: 'nico',
  88. group: 'Users',
  89. title: 'Test Ticket for Shortcuts - ABC123',
  90. body: 'Test Ticket Body for Shortcuts - ABC123',
  91. },
  92. )
  93. sleep 5
  94. # close again
  95. shortcut(key: 'w')
  96. watch_for_disappear(
  97. css: '.active.content',
  98. value: ticket1[:number],
  99. timeout: 2,
  100. )
  101. # search it
  102. shortcut(key: 's')
  103. window_keys(value: ticket1[:number])
  104. exists(css: '#navigation .search.open')
  105. sleep 2
  106. window_keys(value: :arrow_down)
  107. window_keys(value: :arrow_down)
  108. window_keys(value: :enter)
  109. watch_for(
  110. css: '.active.content',
  111. value: ticket1[:number],
  112. timeout: 2,
  113. )
  114. exists_not(css: '#navigation .search.open')
  115. # open ticket
  116. shortcut(key: 's')
  117. window_keys(value: ticket1[:number])
  118. sleep 2
  119. window_keys(value: :arrow_down)
  120. window_keys(value: :arrow_down)
  121. window_keys(value: :enter)
  122. # open new ticket
  123. shortcut(key: 'n')
  124. watch_for(
  125. css: '.active.content',
  126. value: 'New Ticket',
  127. timeout: 2,
  128. )
  129. tab_count = @browser.find_elements(css: '#navigation .tasks .task').count
  130. assert_equal(2, tab_count)
  131. # tab is tab
  132. shortcut(key: :tab)
  133. watch_for(
  134. css: '.active.content',
  135. value: ticket1[:number],
  136. timeout: 2,
  137. )
  138. shortcut(key: 'm')
  139. shortcut(key: 'j')
  140. window_keys(value: 'some note')
  141. sleep 1
  142. shortcut(key: :enter)
  143. watch_for(
  144. css: '.active.content .ticket-article',
  145. value: 'some note',
  146. timeout: 6,
  147. )
  148. exists(css: '.active.content .ticket-article .internal-border')
  149. shortcut(key: 'g')
  150. window_keys(value: 'some reply')
  151. sleep 1
  152. shortcut(key: :enter)
  153. watch_for(
  154. css: '.active.content .ticket-article',
  155. value: 'some reply',
  156. timeout: 6,
  157. )
  158. shortcut(key: 'c')
  159. watch_for(
  160. css: '.active.content .sidebar-content .edit',
  161. value: 'closed',
  162. timeout: 6,
  163. )
  164. # open online notification
  165. @browser_agent = browser_instance
  166. login(
  167. browser: @browser_agent,
  168. username: 'agent1@example.com',
  169. password: 'test',
  170. url: browser_url,
  171. )
  172. ticket2 = ticket_create(
  173. browser: @browser_agent,
  174. data: {
  175. customer: 'nico',
  176. group: 'Users',
  177. title: 'Test Ticket for Shortcuts II - ABC123',
  178. body: 'Test Ticket Body for Shortcuts II - ABC123',
  179. },
  180. )
  181. sleep 5
  182. shortcut(key: 'a')
  183. # flanky
  184. watch_for(
  185. css: '.js-notificationsContainer',
  186. value: 'Test Ticket for Shortcuts II',
  187. timeout: 10,
  188. )
  189. window_keys(value: :arrow_down)
  190. window_keys(value: :enter)
  191. watch_for(
  192. css: '.active.content',
  193. value: ticket2[:number],
  194. timeout: 3,
  195. )
  196. shortcut(key: 'e')
  197. watch_for(
  198. css: '#login',
  199. value: 'username',
  200. timeout: 4,
  201. )
  202. end
  203. end