123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe 'Keyboard Shortcuts', type: :system do
- context 'Navigation shortcut' do
- context 'for Dashboard' do
- before do
- visit 'ticket/view' # visit a different page first
- send_keys(['h'])
- end
- it 'shows Dashboard page' do
- expect(page).to have_title('Dashboard')
- end
- end
- context 'for Overviews' do
- before do
- visit 'dashboard' # visit a different page first
- send_keys(['o'])
- end
- it 'shows Overviews page' do
- expect(page).to have_title('My Assigned Tickets')
- end
- end
- context 'for Search' do
- before do
- visit '/'
- within :active_content do
- send_keys(['s'])
- end
- end
- it 'changes focus to search input' do
- expect(page).to have_css('#global-search:focus')
- end
- end
- context 'for Notifications' do
- let(:popover_notification_selector) { '.popover--notifications.js-notificationsContainer' }
- before do
- visit '/'
- send_keys(['a'])
- end
- it 'shows notifications popover' do
- within popover_notification_selector do
- expect(page).to have_text 'Notifications'
- end
- end
- it 'hides notifications popover when re-pressed' do
- within popover_notification_selector do
- send_keys(['a'])
- end
- expect(page).to have_no_selector popover_notification_selector
- end
- end
- context 'for New Ticket' do
- before do
- visit '/'
- send_keys(['n'])
- end
- it 'opens a new ticket page' do
- within :active_content do
- expect(page).to have_css('.newTicket h1', text: 'New Ticket')
- end
- end
- end
- context 'for list of shortcuts' do
- before do
- visit '/'
- send_keys(['?'])
- end
- it 'shows list of shortcuts' do
- in_modal do
- expect(page).to have_css('h1', text: 'Keyboard Shortcuts')
- end
- end
- it 'hides list of shortcuts when re-pressed' do
- in_modal do
- send_keys(['?'])
- end
- end
- end
- context 'for Logout' do
- before do
- visit '/'
- within :active_content, '.dashboard' do
- send_keys([:shift, 'l'])
- end
- end
- it 'goes to sign in page' do
- expect(page).to have_title('Sign in')
- end
- end
- context 'for Close current tab' do
- before do
- visit '/'
- send_keys(['n']) # opens a new ticket
- within :active_content, '.newTicket' do # make sure to close new ticket
- send_keys([:shift, 'w'])
- end
- end
- it 'closes current tab' do
- within :active_content do
- expect(page).to have_no_selector('.newTicket')
- end
- end
- end
- context 'for tabs and shortcuts' do
- before do
- visit 'ticket/create'
- within :active_content, '.newTicket' do
- find('[data-type="phone-in"]').click
- visit 'ticket/create'
- end
- within :active_content, '.newTicket' do
- find('[data-type="phone-out"]').click
- visit 'ticket/create'
- end
- within :active_content, '.newTicket' do
- find('[data-type="email-out"]').click
- end
- end
- context 'shows the next tab' do
- it 'show the next tab' do
- await_empty_ajax_queue
- send_keys(%i[shift arrow_right])
- within :active_content, 'form.ticket-create' do
- expect(page).to have_title 'Inbound Call'
- end
- end
- end
- context 'shows the previous tab' do
- it 'shows the previous tab' do
- await_empty_ajax_queue
- send_keys(%i[shift arrow_left])
- within :active_content, 'form.ticket-create' do
- expect(page).to have_title 'Outbound Call'
- end
- end
- end
- end
- end
- context 'Tickets shortcut' do
- context 'for ticket edit' do
- before do
- visit "#ticket/zoom/#{Ticket.first.id}"
- end
- it 'add internal note and submit' do
- send_keys(['x'])
- send_keys(['some text'])
- within :active_content do
- expect(page).to have_css('.article-new .js-textarea', text: 'some text')
- end
- within :active_content do
- expect(page).to have_css('.is-internal')
- end
- send_keys(%i[shift return])
- within :active_content do
- expect(page).to have_css('.article-content', text: 'some text')
- end
- within :active_content do
- expect(page).to have_css('.article-new .js-textarea', text: '')
- end
- end
- it 'add public note and submit' do
- send_keys(['i'])
- send_keys(['x'])
- send_keys(['some text'])
- within :active_content do
- expect(page).to have_css('.article-new .js-textarea', text: 'some text')
- end
- within :active_content do
- expect(page).to have_no_selector('.is-internal')
- end
- send_keys(%i[shift return])
- within :active_content do
- expect(page).to have_css('.article-content', text: 'some text')
- end
- within :active_content do
- expect(page).to have_css('.article-new .js-textarea', text: '')
- end
- end
- end
- end
- context 'Translations shortcut' do
- context 'for inline translations' do
- before do
- visit '/'
- end
- it 'enables translations' do
- within :active_content do
- expect(page).to have_no_selector('.stat-title span.translation')
- end
- expect(page).to have_no_selector('#navigation [href="#dashboard"] span.translation')
- send_keys(['t'])
- within :active_content do
- expect(page).to have_css('.stat-title span.translation')
- end
- expect(page).to have_css('#navigation [href="#dashboard"] span.translation')
- end
- it 'does not enable translations with a modifier (#5312)' do
- within :active_content do
- expect(page).to have_no_selector('.stat-title span.translation')
- end
- expect(page).to have_no_selector('#navigation [href="#dashboard"] span.translation')
- send_keys([:control, 't'])
- within :active_content do
- expect(page).to have_no_css('.stat-title span.translation')
- end
- expect(page).to have_no_css('#navigation [href="#dashboard"] span.translation')
- end
- end
- end
- context 'when toggling switches' do
- before do
- visit 'dashboard' # visit a different page first
- send_keys(['?'])
- end
- context 'when disabling keyboard shortcuts' do
- it 'disables keyboard shortcuts' do
- in_modal do
- uncheck 'Keyboard Shortcuts Enabled', allow_label_click: true
- click '.js-close'
- end
- send_keys(['o'])
- expect(page).to have_title('Dashboard')
- end
- end
- context 'when enabling keyboard shortcuts' do
- it 'enables keyboard shortcuts' do
- in_modal do
- uncheck 'Keyboard Shortcuts Enabled', allow_label_click: true
- check 'Keyboard Shortcuts Enabled', allow_label_click: true
- click '.js-close'
- end
- send_keys(['o'])
- expect(page).to have_title('My Assigned Tickets')
- end
- end
- context 'when switching to old shortcut layout' do
- it 'uses old shortcut layout' do
- in_modal do
- click_on 'Switch back to old layout'
- click '.js-close'
- end
- send_keys(['o'])
- expect(page).to have_title('Dashboard')
- send_keys([*hot_keys, 'o'])
- expect(page).to have_title('My Assigned Tickets')
- end
- end
- context 'when switching to new shortcut layout' do
- it 'uses new shortcut layout' do
- in_modal do
- click_on 'Switch back to old layout'
- click_on 'Switch to new layout'
- click '.js-close'
- end
- send_keys([*hot_keys, 'o'])
- expect(page).to have_title('Dashboard')
- send_keys(['o'])
- expect(page).to have_title('My Assigned Tickets')
- end
- end
- end
- end
|