keyboard_shortcuts_test.rb 4.9 KB

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