Commit e3e48fb6 authored by Simon Knox's avatar Simon Knox

Merge branch '345745_01-search-focus-shortcut' into 'master'

Global Search Refactor - Focus search shortcut tests

See merge request gitlab-org/gitlab!76467
parents e0658ad4 9cf260f8
...@@ -57,6 +57,14 @@ RSpec.describe 'Global search' do ...@@ -57,6 +57,14 @@ RSpec.describe 'Global search' do
expect(page).to have_selector('.search-form') expect(page).to have_selector('.search-form')
expect(page).to have_no_selector('#js-header-search') expect(page).to have_no_selector('#js-header-search')
end end
it 'focuses search input when shortcut "s" is pressed', :js do
expect(page).not_to have_selector('#search:focus')
find('body').native.send_key('s')
expect(page).to have_selector('#search:focus')
end
end end
describe 'when new_header_search feature is enabled' do describe 'when new_header_search feature is enabled' do
...@@ -70,5 +78,13 @@ RSpec.describe 'Global search' do ...@@ -70,5 +78,13 @@ RSpec.describe 'Global search' do
expect(page).to have_no_selector('.search-form') expect(page).to have_no_selector('.search-form')
expect(page).to have_selector('#js-header-search') expect(page).to have_selector('#js-header-search')
end end
it 'focuses search input when shortcut "s" is pressed', :js do
expect(page).not_to have_selector('#search:focus')
find('body').native.send_key('s')
expect(page).to have_selector('#search:focus')
end
end end
end end
...@@ -25,6 +25,7 @@ describe('Shortcuts', () => { ...@@ -25,6 +25,7 @@ describe('Shortcuts', () => {
jest.spyOn(document.querySelector('.js-new-note-form .js-md-preview-button'), 'focus'); jest.spyOn(document.querySelector('.js-new-note-form .js-md-preview-button'), 'focus');
jest.spyOn(document.querySelector('.edit-note .js-md-preview-button'), 'focus'); jest.spyOn(document.querySelector('.edit-note .js-md-preview-button'), 'focus');
jest.spyOn(document.querySelector('#search'), 'focus');
new Shortcuts(); // eslint-disable-line no-new new Shortcuts(); // eslint-disable-line no-new
}); });
...@@ -111,4 +112,12 @@ describe('Shortcuts', () => { ...@@ -111,4 +112,12 @@ describe('Shortcuts', () => {
}); });
}); });
}); });
describe('focusSearch', () => {
it('focuses the search bar', () => {
Shortcuts.focusSearch(createEvent('KeyboardEvent'));
expect(document.querySelector('#search').focus).toHaveBeenCalled();
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment