debian-mirror-gitlab/spec/javascripts/shortcuts_spec.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-12-05 23:21:45 +05:30
import Shortcuts from '~/behaviors/shortcuts/shortcuts';
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
describe('Shortcuts', () => {
2019-05-18 00:54:41 +05:30
const fixtureName = 'snippets/show.html';
2018-11-08 19:23:39 +05:30
const createEvent = (type, target) =>
$.Event(type, {
target,
});
2017-08-17 22:00:37 +05:30
preloadFixtures(fixtureName);
describe('toggleMarkdownPreview', () => {
beforeEach(() => {
loadFixtures(fixtureName);
spyOnEvent('.js-new-note-form .js-md-preview-button', 'focus');
spyOnEvent('.edit-note .js-md-preview-button', 'focus');
2018-03-17 18:26:18 +05:30
new Shortcuts(); // eslint-disable-line no-new
2017-08-17 22:00:37 +05:30
});
it('focuses preview button in form', () => {
2018-03-17 18:26:18 +05:30
Shortcuts.toggleMarkdownPreview(
2018-11-08 19:23:39 +05:30
createEvent('KeyboardEvent', document.querySelector('.js-new-note-form .js-note-text')),
);
2017-08-17 22:00:37 +05:30
expect('focus').toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
});
2018-11-08 19:23:39 +05:30
it('focues preview button inside edit comment form', done => {
2017-08-17 22:00:37 +05:30
document.querySelector('.js-note-edit').click();
setTimeout(() => {
2018-03-17 18:26:18 +05:30
Shortcuts.toggleMarkdownPreview(
2018-11-08 19:23:39 +05:30
createEvent('KeyboardEvent', document.querySelector('.edit-note .js-note-text')),
);
2017-08-17 22:00:37 +05:30
expect('focus').not.toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
expect('focus').toHaveBeenTriggeredOn('.edit-note .js-md-preview-button');
done();
});
});
});
});