2018-03-17 18:26:18 +05:30
|
|
|
import Shortcuts from '~/shortcuts';
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('Shortcuts', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const fixtureName = 'merge_requests/diff_comment.html.raw';
|
2017-08-17 22:00:37 +05:30
|
|
|
const createEvent = (type, target) => $.Event(type, {
|
|
|
|
target,
|
|
|
|
});
|
|
|
|
|
|
|
|
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(
|
2017-08-17 22:00:37 +05:30
|
|
|
createEvent('KeyboardEvent', document.querySelector('.js-new-note-form .js-note-text'),
|
|
|
|
));
|
|
|
|
|
|
|
|
expect('focus').toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('focues preview button inside edit comment form', (done) => {
|
|
|
|
document.querySelector('.js-note-edit').click();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
Shortcuts.toggleMarkdownPreview(
|
2017-08-17 22:00:37 +05:30
|
|
|
createEvent('KeyboardEvent', document.querySelector('.edit-note .js-note-text'),
|
|
|
|
));
|
|
|
|
|
|
|
|
expect('focus').not.toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
|
|
|
|
expect('focus').toHaveBeenTriggeredOn('.edit-note .js-md-preview-button');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|