diff options
Diffstat (limited to 'spec/frontend/shortcuts_spec.js')
-rw-r--r-- | spec/frontend/shortcuts_spec.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/frontend/shortcuts_spec.js b/spec/frontend/shortcuts_spec.js new file mode 100644 index 00000000000..3d16074154c --- /dev/null +++ b/spec/frontend/shortcuts_spec.js @@ -0,0 +1,46 @@ +import $ from 'jquery'; +import Shortcuts from '~/behaviors/shortcuts/shortcuts'; + +describe('Shortcuts', () => { + const fixtureName = 'snippets/show.html'; + const createEvent = (type, target) => + $.Event(type, { + target, + }); + + preloadFixtures(fixtureName); + + describe('toggleMarkdownPreview', () => { + beforeEach(() => { + loadFixtures(fixtureName); + + jest.spyOn(document.querySelector('.js-new-note-form .js-md-preview-button'), 'focus'); + jest.spyOn(document.querySelector('.edit-note .js-md-preview-button'), 'focus'); + + new Shortcuts(); // eslint-disable-line no-new + }); + + it('focuses preview button in form', () => { + Shortcuts.toggleMarkdownPreview( + createEvent('KeyboardEvent', document.querySelector('.js-new-note-form .js-note-text')), + ); + + expect( + document.querySelector('.js-new-note-form .js-md-preview-button').focus, + ).toHaveBeenCalled(); + }); + + it('focues preview button inside edit comment form', () => { + document.querySelector('.js-note-edit').click(); + + Shortcuts.toggleMarkdownPreview( + createEvent('KeyboardEvent', document.querySelector('.edit-note .js-note-text')), + ); + + expect( + document.querySelector('.js-new-note-form .js-md-preview-button').focus, + ).not.toHaveBeenCalled(); + expect(document.querySelector('.edit-note .js-md-preview-button').focus).toHaveBeenCalled(); + }); + }); +}); |