keyboard_shortcuts_spec.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. end
  72. it 'shows list of shortcuts' do
  73. in_modal do
  74. expect(page).to have_selector('h1', text: 'Keyboard Shortcuts')
  75. end
  76. end
  77. it 'hides list of shortcuts when re-pressed' do
  78. in_modal do
  79. send_keys([*hot_keys, 'h'])
  80. end
  81. end
  82. end
  83. context 'for Close current tab' do
  84. before do
  85. send_keys([*hot_keys, 'n']) # opens a new ticket
  86. within :active_content, '.newTicket' do # make sure to close new ticket
  87. send_keys([*hot_keys, 'w'])
  88. end
  89. end
  90. it 'closes current tab' do
  91. within :active_content do
  92. expect(page).to have_no_selector('.newTicket')
  93. end
  94. end
  95. end
  96. context 'with tab as shortcut' do
  97. before do
  98. # The current hotkey for the next/previous tab is not working on linux/windows, skip for now.
  99. skip('current hotkey for the next/previous tab is not working on linux/windows')
  100. visit 'ticket/create'
  101. within :active_content, '.newTicket' do
  102. find('[data-type="phone-in"]').click
  103. visit 'ticket/create'
  104. end
  105. within :active_content, '.newTicket' do
  106. find('[data-type="phone-out"]').click
  107. visit 'ticket/create'
  108. end
  109. within :active_content, '.newTicket' do
  110. find('[data-type="email-out"]').click
  111. send_keys([*hot_keys, *tab]) # open next/prev tab
  112. end
  113. end
  114. context 'shows the next tab' do
  115. let(:tab) { [:tab] }
  116. it 'show the next tab' do
  117. within :active_content, 'form.ticket-create' do
  118. expect(page).to have_title 'Inbound Call'
  119. end
  120. end
  121. end
  122. context 'shows the previous tab' do
  123. let(:tab) { %i[shift tab] }
  124. it 'shows the previous tab' do
  125. within :active_content, 'form.ticket-create' do
  126. expect(page).to have_title 'Outbound Call'
  127. end
  128. end
  129. end
  130. end
  131. end
  132. end