Commit d4317e4d authored by winniehell's avatar winniehell

Use textarea for quick submit spec

parent 8a1441fb
......@@ -12,31 +12,33 @@ require('~/behaviors/quick_submit');
// Prevent a form submit from moving us off the testing page
return e.preventDefault();
});
return this.spies = {
this.spies = {
submit: spyOnEvent('form', 'submit')
};
this.textarea = $('.js-quick-submit textarea').first();
});
it('does not respond to other keyCodes', function() {
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
keyCode: 32
}));
return expect(this.spies.submit).not.toHaveBeenTriggered();
});
it('does not respond to Enter alone', function() {
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
ctrlKey: false,
metaKey: false
}));
return expect(this.spies.submit).not.toHaveBeenTriggered();
});
it('does not respond to repeated events', function() {
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
repeat: true
}));
return expect(this.spies.submit).not.toHaveBeenTriggered();
});
it('disables submit buttons', function() {
$('textarea').trigger(keydownEvent());
this.textarea.trigger(keydownEvent());
expect($('input[type=submit]')).toBeDisabled();
return expect($('button[type=submit]')).toBeDisabled();
});
......@@ -44,34 +46,34 @@ require('~/behaviors/quick_submit');
// only run the tests that apply to the current platform
if (navigator.userAgent.match(/Macintosh/)) {
it('responds to Meta+Enter', function() {
$('input.quick-submit-input').trigger(keydownEvent());
this.textarea.trigger(keydownEvent());
return expect(this.spies.submit).toHaveBeenTriggered();
});
it('excludes other modifier keys', function() {
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
altKey: true
}));
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
ctrlKey: true
}));
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
shiftKey: true
}));
return expect(this.spies.submit).not.toHaveBeenTriggered();
});
} else {
it('responds to Ctrl+Enter', function() {
$('input.quick-submit-input').trigger(keydownEvent());
this.textarea.trigger(keydownEvent());
return expect(this.spies.submit).toHaveBeenTriggered();
});
it('excludes other modifier keys', function() {
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
altKey: true
}));
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
metaKey: true
}));
$('input.quick-submit-input').trigger(keydownEvent({
this.textarea.trigger(keydownEvent({
shiftKey: true
}));
return expect(this.spies.submit).not.toHaveBeenTriggered();
......
%form.js-quick-submit{ action: '/foo' }
%input{ type: 'text', class: 'quick-submit-input'}
%textarea
%input{ type: 'submit'} Submit
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment