2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-09-18 16:34:14 -04:00
|
|
|
import Shortcuts from '~/behaviors/shortcuts/shortcuts';
|
2017-10-10 05:10:11 -04:00
|
|
|
|
2017-04-21 09:19:08 -04:00
|
|
|
describe('Shortcuts', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
const fixtureName = 'snippets/show.html.raw';
|
|
|
|
const createEvent = (type, target) =>
|
|
|
|
$.Event(type, {
|
|
|
|
target,
|
|
|
|
});
|
2017-04-21 09:19:08 -04:00
|
|
|
|
|
|
|
preloadFixtures(fixtureName);
|
|
|
|
|
|
|
|
describe('toggleMarkdownPreview', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures(fixtureName);
|
|
|
|
|
2017-04-21 11:32:10 -04:00
|
|
|
spyOnEvent('.js-new-note-form .js-md-preview-button', 'focus');
|
|
|
|
spyOnEvent('.edit-note .js-md-preview-button', 'focus');
|
2017-04-21 09:19:08 -04:00
|
|
|
|
2017-10-10 08:01:36 -04:00
|
|
|
new Shortcuts(); // eslint-disable-line no-new
|
2017-04-21 09:19:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('focuses preview button in form', () => {
|
2017-10-10 08:01:36 -04:00
|
|
|
Shortcuts.toggleMarkdownPreview(
|
2018-06-21 08:22:40 -04:00
|
|
|
createEvent('KeyboardEvent', document.querySelector('.js-new-note-form .js-note-text')),
|
|
|
|
);
|
2017-04-21 11:32:10 -04:00
|
|
|
|
|
|
|
expect('focus').toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
|
|
|
|
});
|
2017-04-21 09:19:08 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('focues preview button inside edit comment form', done => {
|
2017-04-21 11:32:10 -04:00
|
|
|
document.querySelector('.js-note-edit').click();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2017-10-10 08:01:36 -04:00
|
|
|
Shortcuts.toggleMarkdownPreview(
|
2018-06-21 08:22:40 -04:00
|
|
|
createEvent('KeyboardEvent', document.querySelector('.edit-note .js-note-text')),
|
|
|
|
);
|
2017-04-21 11:32:10 -04:00
|
|
|
|
|
|
|
expect('focus').not.toHaveBeenTriggeredOn('.js-new-note-form .js-md-preview-button');
|
|
|
|
expect('focus').toHaveBeenTriggeredOn('.edit-note .js-md-preview-button');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-04-21 09:19:08 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|