Commit d4317e4d authored by winniehell's avatar winniehell

Use textarea for quick submit spec

parent 8a1441fb
...@@ -12,31 +12,33 @@ require('~/behaviors/quick_submit'); ...@@ -12,31 +12,33 @@ require('~/behaviors/quick_submit');
// Prevent a form submit from moving us off the testing page // Prevent a form submit from moving us off the testing page
return e.preventDefault(); return e.preventDefault();
}); });
return this.spies = { this.spies = {
submit: spyOnEvent('form', 'submit') submit: spyOnEvent('form', 'submit')
}; };
this.textarea = $('.js-quick-submit textarea').first();
}); });
it('does not respond to other keyCodes', function() { it('does not respond to other keyCodes', function() {
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
keyCode: 32 keyCode: 32
})); }));
return expect(this.spies.submit).not.toHaveBeenTriggered(); return expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
it('does not respond to Enter alone', function() { it('does not respond to Enter alone', function() {
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
ctrlKey: false, ctrlKey: false,
metaKey: false metaKey: false
})); }));
return expect(this.spies.submit).not.toHaveBeenTriggered(); return expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
it('does not respond to repeated events', function() { it('does not respond to repeated events', function() {
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
repeat: true repeat: true
})); }));
return expect(this.spies.submit).not.toHaveBeenTriggered(); return expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
it('disables submit buttons', function() { it('disables submit buttons', function() {
$('textarea').trigger(keydownEvent()); this.textarea.trigger(keydownEvent());
expect($('input[type=submit]')).toBeDisabled(); expect($('input[type=submit]')).toBeDisabled();
return expect($('button[type=submit]')).toBeDisabled(); return expect($('button[type=submit]')).toBeDisabled();
}); });
...@@ -44,34 +46,34 @@ require('~/behaviors/quick_submit'); ...@@ -44,34 +46,34 @@ require('~/behaviors/quick_submit');
// only run the tests that apply to the current platform // only run the tests that apply to the current platform
if (navigator.userAgent.match(/Macintosh/)) { if (navigator.userAgent.match(/Macintosh/)) {
it('responds to Meta+Enter', function() { it('responds to Meta+Enter', function() {
$('input.quick-submit-input').trigger(keydownEvent()); this.textarea.trigger(keydownEvent());
return expect(this.spies.submit).toHaveBeenTriggered(); return expect(this.spies.submit).toHaveBeenTriggered();
}); });
it('excludes other modifier keys', function() { it('excludes other modifier keys', function() {
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
altKey: true altKey: true
})); }));
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
ctrlKey: true ctrlKey: true
})); }));
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
shiftKey: true shiftKey: true
})); }));
return expect(this.spies.submit).not.toHaveBeenTriggered(); return expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
} else { } else {
it('responds to Ctrl+Enter', function() { it('responds to Ctrl+Enter', function() {
$('input.quick-submit-input').trigger(keydownEvent()); this.textarea.trigger(keydownEvent());
return expect(this.spies.submit).toHaveBeenTriggered(); return expect(this.spies.submit).toHaveBeenTriggered();
}); });
it('excludes other modifier keys', function() { it('excludes other modifier keys', function() {
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
altKey: true altKey: true
})); }));
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
metaKey: true metaKey: true
})); }));
$('input.quick-submit-input').trigger(keydownEvent({ this.textarea.trigger(keydownEvent({
shiftKey: true shiftKey: true
})); }));
return expect(this.spies.submit).not.toHaveBeenTriggered(); return expect(this.spies.submit).not.toHaveBeenTriggered();
......
%form.js-quick-submit{ action: '/foo' } %form.js-quick-submit{ action: '/foo' }
%input{ type: 'text', class: 'quick-submit-input'}
%textarea %textarea
%input{ type: 'submit'} Submit %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