2017-05-16 17:01:51 -04:00
|
|
|
import '~/behaviors/quick_submit';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-08-10 09:08:57 -04:00
|
|
|
describe('Quick Submit behavior', () => {
|
|
|
|
const keydownEvent = (options = { keyCode: 13, metaKey: true }) => $.Event('keydown', options);
|
2017-02-09 06:03:41 -05:00
|
|
|
|
2017-08-10 09:08:57 -04:00
|
|
|
preloadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
2017-06-27 12:06:38 -04:00
|
|
|
|
2017-08-10 09:08:57 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
|
2017-08-24 20:41:35 -04:00
|
|
|
$('body').attr('data-page', 'projects:merge_requests:show');
|
2017-08-10 09:08:57 -04:00
|
|
|
$('form').submit((e) => {
|
|
|
|
// Prevent a form submit from moving us off the testing page
|
|
|
|
e.preventDefault();
|
2017-02-09 06:47:55 -05:00
|
|
|
});
|
2017-08-10 09:08:57 -04:00
|
|
|
this.spies = {
|
|
|
|
submit: spyOnEvent('form', 'submit'),
|
|
|
|
};
|
2017-06-27 12:06:38 -04:00
|
|
|
|
2017-08-10 09:08:57 -04:00
|
|
|
this.textarea = $('.js-quick-submit textarea').first();
|
|
|
|
});
|
2017-06-27 12:06:38 -04:00
|
|
|
|
2017-10-06 16:36:15 -04:00
|
|
|
afterEach(() => {
|
|
|
|
// Undo what we did to the shared <body>
|
|
|
|
$('body').removeAttr('data-page');
|
|
|
|
});
|
|
|
|
|
2017-08-10 09:08:57 -04:00
|
|
|
it('does not respond to other keyCodes', () => {
|
|
|
|
this.textarea.trigger(keydownEvent({
|
|
|
|
keyCode: 32,
|
|
|
|
}));
|
|
|
|
expect(this.spies.submit).not.toHaveBeenTriggered();
|
|
|
|
});
|
2017-06-27 12:06:38 -04:00
|
|
|
|
2017-08-10 09:08:57 -04:00
|
|
|
it('does not respond to Enter alone', () => {
|
|
|
|
this.textarea.trigger(keydownEvent({
|
|
|
|
ctrlKey: false,
|
|
|
|
metaKey: false,
|
|
|
|
}));
|
|
|
|
expect(this.spies.submit).not.toHaveBeenTriggered();
|
|
|
|
});
|
2017-06-27 12:06:38 -04:00
|
|
|
|
2017-08-10 09:08:57 -04:00
|
|
|
it('does not respond to repeated events', () => {
|
|
|
|
this.textarea.trigger(keydownEvent({
|
|
|
|
repeat: true,
|
|
|
|
}));
|
|
|
|
expect(this.spies.submit).not.toHaveBeenTriggered();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disables input of type submit', () => {
|
|
|
|
const submitButton = $('.js-quick-submit input[type=submit]');
|
|
|
|
this.textarea.trigger(keydownEvent());
|
|
|
|
|
|
|
|
expect(submitButton).toBeDisabled();
|
|
|
|
});
|
|
|
|
it('disables button of type submit', () => {
|
|
|
|
const submitButton = $('.js-quick-submit input[type=submit]');
|
|
|
|
this.textarea.trigger(keydownEvent());
|
|
|
|
|
|
|
|
expect(submitButton).toBeDisabled();
|
|
|
|
});
|
|
|
|
it('only clicks one submit', () => {
|
|
|
|
const existingSubmit = $('.js-quick-submit input[type=submit]');
|
|
|
|
// Add an extra submit button
|
|
|
|
const newSubmit = $('<button type="submit">Submit it</button>');
|
|
|
|
newSubmit.insertAfter(this.textarea);
|
|
|
|
|
|
|
|
const oldClick = spyOnEvent(existingSubmit, 'click');
|
|
|
|
const newClick = spyOnEvent(newSubmit, 'click');
|
|
|
|
|
|
|
|
this.textarea.trigger(keydownEvent());
|
|
|
|
|
|
|
|
expect(oldClick).not.toHaveBeenTriggered();
|
|
|
|
expect(newClick).toHaveBeenTriggered();
|
|
|
|
});
|
|
|
|
// We cannot stub `navigator.userAgent` for CI's `rake karma` task, so we'll
|
|
|
|
// only run the tests that apply to the current platform
|
|
|
|
if (navigator.userAgent.match(/Macintosh/)) {
|
|
|
|
describe('In Macintosh', () => {
|
|
|
|
it('responds to Meta+Enter', () => {
|
2017-02-09 06:03:41 -05:00
|
|
|
this.textarea.trigger(keydownEvent());
|
2016-07-24 16:45:11 -04:00
|
|
|
return expect(this.spies.submit).toHaveBeenTriggered();
|
|
|
|
});
|
2017-08-10 09:08:57 -04:00
|
|
|
|
|
|
|
it('excludes other modifier keys', () => {
|
2017-02-09 06:03:41 -05:00
|
|
|
this.textarea.trigger(keydownEvent({
|
2017-08-10 09:08:57 -04:00
|
|
|
altKey: true,
|
2016-07-24 16:45:11 -04:00
|
|
|
}));
|
2017-02-09 06:03:41 -05:00
|
|
|
this.textarea.trigger(keydownEvent({
|
2017-08-10 09:08:57 -04:00
|
|
|
ctrlKey: true,
|
2016-07-24 16:45:11 -04:00
|
|
|
}));
|
2017-02-09 06:03:41 -05:00
|
|
|
this.textarea.trigger(keydownEvent({
|
2017-08-10 09:08:57 -04:00
|
|
|
shiftKey: true,
|
2016-07-24 16:45:11 -04:00
|
|
|
}));
|
|
|
|
return expect(this.spies.submit).not.toHaveBeenTriggered();
|
|
|
|
});
|
2017-08-10 09:08:57 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
it('responds to Ctrl+Enter', () => {
|
|
|
|
this.textarea.trigger(keydownEvent());
|
|
|
|
return expect(this.spies.submit).toHaveBeenTriggered();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('excludes other modifier keys', () => {
|
|
|
|
this.textarea.trigger(keydownEvent({
|
|
|
|
altKey: true,
|
|
|
|
}));
|
|
|
|
this.textarea.trigger(keydownEvent({
|
|
|
|
metaKey: true,
|
|
|
|
}));
|
|
|
|
this.textarea.trigger(keydownEvent({
|
|
|
|
shiftKey: true,
|
|
|
|
}));
|
|
|
|
return expect(this.spies.submit).not.toHaveBeenTriggered();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|