keyboard_shortcuts_spec.rb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Copyright (C) 2012-2022 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([*hot_keys, 'd'])
  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([*hot_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. within :active_content do
  26. send_keys([*hot_keys, 's'])
  27. end
  28. end
  29. it 'changes focus to search input' do
  30. expect(page).to have_selector('#global-search:focus')
  31. end
  32. end
  33. context 'for Notifications' do
  34. let(:popover_notification_selector) { '.popover--notifications.js-notificationsContainer' }
  35. before do
  36. send_keys([*hot_keys, 'a'])
  37. end
  38. it 'shows notifications popover' do
  39. within popover_notification_selector do
  40. expect(page).to have_text 'Notifications'
  41. end
  42. end
  43. it 'hides notifications popover when re-pressed' do
  44. within popover_notification_selector do
  45. send_keys([*hot_keys, 'a'])
  46. end
  47. expect(page).to have_no_selector popover_notification_selector
  48. end
  49. end
  50. context 'for New Ticket' do
  51. before do
  52. send_keys([*hot_keys, 'n'])
  53. end
  54. it 'opens a new ticket page' do
  55. within :active_content do
  56. expect(page).to have_selector('.newTicket h1', text: 'New Ticket')
  57. end
  58. end
  59. end
  60. context 'for Logout' do
  61. before do
  62. send_keys([*hot_keys, 'e'])
  63. end
  64. it 'goes to sign in page' do
  65. expect(page).to have_title('Sign in')
  66. end
  67. end
  68. context 'for list of shortcuts' do
  69. before do
  70. send_keys([*hot_keys, 'h'])
  71. wait.until_exists { find :active_modal_content }
  72. end
  73. it 'shows list of shortcuts' do
  74. within :active_modal_content do
  75. expect(page).to have_selector('h1.modal-title', text: 'Keyboard Shortcuts')
  76. end
  77. end
  78. it 'hides list of shortcuts when re-pressed' do
  79. within :active_modal_content do
  80. send_keys([*hot_keys, 'h'])
  81. end
  82. expect(page).to have_no_selector :active_modal_content
  83. end
  84. end
  85. context 'for Close current tab' do
  86. before do
  87. send_keys([*hot_keys, 'n']) # opens a new ticket
  88. within :active_content, '.newTicket' do # make sure to close new ticket
  89. send_keys([*hot_keys, 'w'])
  90. end
  91. end
  92. it 'closes current tab' do
  93. within :active_content do
  94. expect(page).to have_no_selector('.newTicket')
  95. end
  96. end
  97. end
  98. context 'with tab as shortcut' do
  99. before do
  100. # The current hotkey for the next/previous tab is not working on linux/windows, skip for now.
  101. skip('current hotkey for the next/previous tab is not working on linux/windows')
  102. visit 'ticket/create'
  103. within :active_content, '.newTicket' do
  104. find('[data-type="phone-in"]').click
  105. visit 'ticket/create'
  106. end
  107. within :active_content, '.newTicket' do
  108. find('[data-type="phone-out"]').click
  109. visit 'ticket/create'
  110. end
  111. within :active_content, '.newTicket' do
  112. find('[data-type="email-out"]').click
  113. send_keys([*hot_keys, *tab]) # open next/prev tab
  114. end
  115. end
  116. context 'for Next in tab' do
  117. let(:tab) { [:tab] }
  118. it 'show the next tab' do
  119. within :active_content, 'form.ticket-create' do
  120. expect(page).to have_title 'Inbound Call'
  121. end
  122. end
  123. end
  124. context 'shows the previous tab' do
  125. let(:tab) { %i[shift tab] }
  126. it 'shows the previous tab' do
  127. within :active_content, 'form.ticket-create' do
  128. expect(page).to have_title 'Outbound Call'
  129. end
  130. end
  131. end
  132. end
  133. end
  134. end