Commit e5f446b7 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Merge branch 'quick-submit-fixture' into 'master'

Replace static fixture for behaviors/quick_submit_spec.js

See merge request !9086
parents 828776ed 128d8b61
---
title: Replace static fixture for behaviors/quick_submit_spec.js
merge_request: 9086
author: winniehell
...@@ -5,73 +5,83 @@ require('~/behaviors/quick_submit'); ...@@ -5,73 +5,83 @@ require('~/behaviors/quick_submit');
(function() { (function() {
describe('Quick Submit behavior', function() { describe('Quick Submit behavior', function() {
var keydownEvent; var keydownEvent;
preloadFixtures('static/behaviors/quick_submit.html.raw'); preloadFixtures('issues/open-issue.html.raw');
beforeEach(function() { beforeEach(function() {
loadFixtures('static/behaviors/quick_submit.html.raw'); loadFixtures('issues/open-issue.html.raw');
$('form').submit(function(e) { $('form').submit(function(e) {
// 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 input of type submit', function() {
$('textarea').trigger(keydownEvent()); const submitButton = $('.js-quick-submit input[type=submit]');
expect($('input[type=submit]')).toBeDisabled(); this.textarea.trigger(keydownEvent());
return expect($('button[type=submit]')).toBeDisabled(); expect(submitButton).toBeDisabled();
});
it('disables button of type submit', function() {
// button doesn't exist in fixture, add it manually
const submitButton = $('<button type="submit">Submit it</button>');
submitButton.insertAfter(this.textarea);
this.textarea.trigger(keydownEvent());
expect(submitButton).toBeDisabled();
}); });
// We cannot stub `navigator.userAgent` for CI's `rake karma` task, so we'll // We cannot stub `navigator.userAgent` for CI's `rake karma` task, so we'll
// 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' }
%input{ type: 'text', class: 'quick-submit-input'}
%textarea
%input{ type: 'submit'} Submit
%button.btn{ 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