keyboard_shortcuts_spec.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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([*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. visit '/'
  26. within :active_content do
  27. send_keys([*hot_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([*hot_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([*hot_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([*hot_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 Logout' do
  64. before do
  65. visit '/'
  66. send_keys([*hot_keys, 'e'])
  67. end
  68. it 'goes to sign in page' do
  69. expect(page).to have_title('Sign in')
  70. end
  71. end
  72. context 'for list of shortcuts' do
  73. before do
  74. visit '/'
  75. send_keys([*hot_keys, 'h'])
  76. end
  77. it 'shows list of shortcuts' do
  78. in_modal do
  79. expect(page).to have_css('h1', text: 'Keyboard Shortcuts')
  80. end
  81. end
  82. it 'hides list of shortcuts when re-pressed' do
  83. in_modal do
  84. send_keys([*hot_keys, 'h'])
  85. end
  86. end
  87. end
  88. context 'for Close current tab' do
  89. before do
  90. visit '/'
  91. send_keys([*hot_keys, 'n']) # opens a new ticket
  92. within :active_content, '.newTicket' do # make sure to close new ticket
  93. send_keys([*hot_keys, 'w'])
  94. end
  95. end
  96. it 'closes current tab' do
  97. within :active_content do
  98. expect(page).to have_no_selector('.newTicket')
  99. end
  100. end
  101. end
  102. context 'with tab as shortcut' do
  103. before do
  104. # The current hotkey for the next/previous tab is not working on linux/windows, skip for now.
  105. skip('current hotkey for the next/previous tab is not working on linux/windows')
  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. send_keys([*hot_keys, *tab]) # open next/prev tab
  118. end
  119. end
  120. context 'shows the next tab' do
  121. let(:tab) { [:tab] }
  122. it 'show the next tab' do
  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. let(:tab) { %i[shift tab] }
  130. it 'shows the previous tab' do
  131. within :active_content, 'form.ticket-create' do
  132. expect(page).to have_title 'Outbound Call'
  133. end
  134. end
  135. end
  136. end
  137. end
  138. end