Commit bfac8b7a authored by Fatih Acet's avatar Fatih Acet

Merge branch 'improve-require-input-spec' into 'master'

Improve require input spec

See merge request gitlab-org/gitlab-ce!15654
parents e35e5c7e bf0bbd7b
/* eslint-disable space-before-function-paren, no-var */
import '~/behaviors/requires_input'; import '~/behaviors/requires_input';
(function() { describe('requiresInput', () => {
describe('requiresInput', function() { let submitButton;
preloadFixtures('branches/new_branch.html.raw'); preloadFixtures('branches/new_branch.html.raw');
beforeEach(function() {
beforeEach(() => {
loadFixtures('branches/new_branch.html.raw'); loadFixtures('branches/new_branch.html.raw');
this.submitButton = $('button[type="submit"]'); submitButton = $('button[type="submit"]');
}); });
it('disables submit when any field is required', function() {
it('disables submit when any field is required', () => {
$('.js-requires-input').requiresInput(); $('.js-requires-input').requiresInput();
return expect(this.submitButton).toBeDisabled(); expect(submitButton).toBeDisabled();
}); });
it('enables submit when no field is required', function() {
it('enables submit when no field is required', () => {
$('*[required=required]').removeAttr('required'); $('*[required=required]').removeAttr('required');
$('.js-requires-input').requiresInput(); $('.js-requires-input').requiresInput();
return expect(this.submitButton).not.toBeDisabled(); expect(submitButton).not.toBeDisabled();
}); });
it('enables submit when all required fields are pre-filled', function() {
it('enables submit when all required fields are pre-filled', () => {
$('*[required=required]').remove(); $('*[required=required]').remove();
$('.js-requires-input').requiresInput(); $('.js-requires-input').requiresInput();
return expect($('.submit')).not.toBeDisabled(); expect($('.submit')).not.toBeDisabled();
}); });
it('enables submit when all required fields receive input', function() {
it('enables submit when all required fields receive input', () => {
$('.js-requires-input').requiresInput(); $('.js-requires-input').requiresInput();
$('#required1').val('input1').change(); $('#required1').val('input1').change();
expect(this.submitButton).toBeDisabled(); expect(submitButton).toBeDisabled();
$('#optional1').val('input1').change(); $('#optional1').val('input1').change();
expect(this.submitButton).toBeDisabled(); expect(submitButton).toBeDisabled();
$('#required2').val('input2').change(); $('#required2').val('input2').change();
$('#required3').val('input3').change(); $('#required3').val('input3').change();
$('#required4').val('input4').change(); $('#required4').val('input4').change();
$('#required5').val('1').change(); $('#required5').val('1').change();
return expect($('.submit')).not.toBeDisabled(); expect($('.submit')).not.toBeDisabled();
});
}); });
}).call(window); });
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