Merge branch 'quick-submit-fixture' into 'master'
Replace static fixture for behaviors/quick_submit_spec.js See merge request !9086
This commit is contained in:
commit
e5f446b7ca
3 changed files with 32 additions and 24 deletions
4
changelogs/unreleased/quick-submit-fixture.yml
Normal file
4
changelogs/unreleased/quick-submit-fixture.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Replace static fixture for behaviors/quick_submit_spec.js
|
||||
merge_request: 9086
|
||||
author: winniehell
|
|
@ -5,73 +5,83 @@ require('~/behaviors/quick_submit');
|
|||
(function() {
|
||||
describe('Quick Submit behavior', function() {
|
||||
var keydownEvent;
|
||||
preloadFixtures('static/behaviors/quick_submit.html.raw');
|
||||
preloadFixtures('issues/open-issue.html.raw');
|
||||
beforeEach(function() {
|
||||
loadFixtures('static/behaviors/quick_submit.html.raw');
|
||||
loadFixtures('issues/open-issue.html.raw');
|
||||
$('form').submit(function(e) {
|
||||
// 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());
|
||||
expect($('input[type=submit]')).toBeDisabled();
|
||||
return expect($('button[type=submit]')).toBeDisabled();
|
||||
it('disables input of type submit', function() {
|
||||
const submitButton = $('.js-quick-submit input[type=submit]');
|
||||
this.textarea.trigger(keydownEvent());
|
||||
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
|
||||
// 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();
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
%form.js-quick-submit{ action: '/foo' }
|
||||
%input{ type: 'text', class: 'quick-submit-input'}
|
||||
%textarea
|
||||
|
||||
%input{ type: 'submit'} Submit
|
||||
%button.btn{ type: 'submit' } Submit
|
Loading…
Reference in a new issue