keyboard_shortcuts_spec.rb 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Keyboard Shortcuts', type: :system do
  4. context 'Navigation shortcut' do
  5. context 'for Dashboard' do
  6. before do
  7. visit 'ticket/view' # visit a different page first
  8. send_keys(['h'])
  9. end
  10. it 'shows Dashboard page' do
  11. expect(page).to have_title('Dashboard')
  12. end
  13. end
  14. context 'for Overviews' do
  15. before do
  16. visit 'dashboard' # visit a different page first
  17. send_keys(['o'])
  18. end
  19. it 'shows Overviews page' do
  20. expect(page).to have_title('My Assigned Tickets')
  21. end
  22. end
  23. context 'for Search' do
  24. before do
  25. visit '/'
  26. within :active_content do
  27. send_keys(['s'])
  28. end
  29. end
  30. it 'changes focus to search input' do
  31. expect(page).to have_css('#global-search:focus')
  32. end
  33. end
  34. context 'for Notifications' do
  35. let(:popover_notification_selector) { '.popover--notifications.js-notificationsContainer' }
  36. before do
  37. visit '/'
  38. send_keys(['a'])
  39. end
  40. it 'shows notifications popover' do
  41. within popover_notification_selector do
  42. expect(page).to have_text 'Notifications'
  43. end
  44. end
  45. it 'hides notifications popover when re-pressed' do
  46. within popover_notification_selector do
  47. send_keys(['a'])
  48. end
  49. expect(page).to have_no_selector popover_notification_selector
  50. end
  51. end
  52. context 'for New Ticket' do
  53. before do
  54. visit '/'
  55. send_keys(['n'])
  56. end
  57. it 'opens a new ticket page' do
  58. within :active_content do
  59. expect(page).to have_css('.newTicket h1', text: 'New Ticket')
  60. end
  61. end
  62. end
  63. context 'for list of shortcuts' do
  64. before do
  65. visit '/'
  66. send_keys(['?'])
  67. end
  68. it 'shows list of shortcuts' do
  69. in_modal do
  70. expect(page).to have_css('h1', text: 'Keyboard Shortcuts')
  71. end
  72. end
  73. it 'hides list of shortcuts when re-pressed' do
  74. in_modal do
  75. send_keys(['?'])
  76. end
  77. end
  78. end
  79. context 'for Logout' do
  80. before do
  81. visit '/'
  82. within :active_content, '.dashboard' do
  83. send_keys([:shift, 'l'])
  84. end
  85. end
  86. it 'goes to sign in page' do
  87. expect(page).to have_title('Sign in')
  88. end
  89. end
  90. context 'for Close current tab' do
  91. before do
  92. visit '/'
  93. send_keys(['n']) # opens a new ticket
  94. within :active_content, '.newTicket' do # make sure to close new ticket
  95. send_keys([:shift, 'w'])
  96. end
  97. end
  98. it 'closes current tab' do
  99. within :active_content do
  100. expect(page).to have_no_selector('.newTicket')
  101. end
  102. end
  103. end
  104. context 'for tabs and shortcuts' do
  105. before do
  106. visit 'ticket/create'
  107. within :active_content, '.newTicket' do
  108. find('[data-type="phone-in"]').click
  109. visit 'ticket/create'
  110. end
  111. within :active_content, '.newTicket' do
  112. find('[data-type="phone-out"]').click
  113. visit 'ticket/create'
  114. end
  115. within :active_content, '.newTicket' do
  116. find('[data-type="email-out"]').click
  117. end
  118. end
  119. context 'shows the next tab' do
  120. it 'show the next tab' do
  121. await_empty_ajax_queue
  122. send_keys(%i[shift arrow_right])
  123. within :active_content, 'form.ticket-create' do
  124. expect(page).to have_title 'Inbound Call'
  125. end
  126. end
  127. end
  128. context 'shows the previous tab' do
  129. it 'shows the previous tab' do
  130. await_empty_ajax_queue
  131. send_keys(%i[shift arrow_left])
  132. within :active_content, 'form.ticket-create' do
  133. expect(page).to have_title 'Outbound Call'
  134. end
  135. end
  136. end
  137. end
  138. end
  139. context 'Tickets shortcut' do
  140. context 'for ticket edit' do
  141. before do
  142. visit "#ticket/zoom/#{Ticket.first.id}"
  143. end
  144. it 'add internal note and submit' do
  145. send_keys(['x'])
  146. send_keys(['some text'])
  147. within :active_content do
  148. expect(page).to have_css('.article-new .js-textarea', text: 'some text')
  149. end
  150. within :active_content do
  151. expect(page).to have_css('.is-internal')
  152. end
  153. send_keys(%i[shift return])
  154. within :active_content do
  155. expect(page).to have_css('.article-content', text: 'some text')
  156. end
  157. within :active_content do
  158. expect(page).to have_css('.article-new .js-textarea', text: '')
  159. end
  160. end
  161. it 'add public note and submit' do
  162. send_keys(['i'])
  163. send_keys(['x'])
  164. send_keys(['some text'])
  165. within :active_content do
  166. expect(page).to have_css('.article-new .js-textarea', text: 'some text')
  167. end
  168. within :active_content do
  169. expect(page).to have_no_selector('.is-internal')
  170. end
  171. send_keys(%i[shift return])
  172. within :active_content do
  173. expect(page).to have_css('.article-content', text: 'some text')
  174. end
  175. within :active_content do
  176. expect(page).to have_css('.article-new .js-textarea', text: '')
  177. end
  178. end
  179. end
  180. end
  181. context 'Translations shortcut' do
  182. context 'for inline translations' do
  183. before do
  184. visit '/'
  185. end
  186. it 'enables translations' do
  187. within :active_content do
  188. expect(page).to have_no_selector('.stat-title span.translation')
  189. end
  190. expect(page).to have_no_selector('#navigation [href="#dashboard"] span.translation')
  191. send_keys(['t'])
  192. within :active_content do
  193. expect(page).to have_css('.stat-title span.translation')
  194. end
  195. expect(page).to have_css('#navigation [href="#dashboard"] span.translation')
  196. end
  197. it 'does not enable translations with a modifier (#5312)' do
  198. within :active_content do
  199. expect(page).to have_no_selector('.stat-title span.translation')
  200. end
  201. expect(page).to have_no_selector('#navigation [href="#dashboard"] span.translation')
  202. send_keys([:control, 't'])
  203. within :active_content do
  204. expect(page).to have_no_css('.stat-title span.translation')
  205. end
  206. expect(page).to have_no_css('#navigation [href="#dashboard"] span.translation')
  207. end
  208. end
  209. end
  210. context 'when toggling switches' do
  211. before do
  212. visit 'dashboard' # visit a different page first
  213. send_keys(['?'])
  214. end
  215. context 'when disabling keyboard shortcuts' do
  216. it 'disables keyboard shortcuts' do
  217. in_modal do
  218. uncheck 'Keyboard Shortcuts Enabled', allow_label_click: true
  219. click '.js-close'
  220. end
  221. send_keys(['o'])
  222. expect(page).to have_title('Dashboard')
  223. end
  224. end
  225. context 'when enabling keyboard shortcuts' do
  226. it 'enables keyboard shortcuts' do
  227. in_modal do
  228. uncheck 'Keyboard Shortcuts Enabled', allow_label_click: true
  229. check 'Keyboard Shortcuts Enabled', allow_label_click: true
  230. click '.js-close'
  231. end
  232. send_keys(['o'])
  233. expect(page).to have_title('My Assigned Tickets')
  234. end
  235. end
  236. context 'when switching to old shortcut layout' do
  237. it 'uses old shortcut layout' do
  238. in_modal do
  239. click_on 'Switch back to old layout'
  240. click '.js-close'
  241. end
  242. send_keys(['o'])
  243. expect(page).to have_title('Dashboard')
  244. send_keys([*hot_keys, 'o'])
  245. expect(page).to have_title('My Assigned Tickets')
  246. end
  247. end
  248. context 'when switching to new shortcut layout' do
  249. it 'uses new shortcut layout' do
  250. in_modal do
  251. click_on 'Switch back to old layout'
  252. click_on 'Switch to new layout'
  253. click '.js-close'
  254. end
  255. send_keys([*hot_keys, 'o'])
  256. expect(page).to have_title('Dashboard')
  257. send_keys(['o'])
  258. expect(page).to have_title('My Assigned Tickets')
  259. end
  260. end
  261. end
  262. end