2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable space-before-function-paren, no-var */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/behaviors/requires_input');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
describe('requiresInput', function() {
|
2017-02-09 18:12:51 -05:00
|
|
|
preloadFixtures('branches/new_branch.html.raw');
|
2016-07-24 16:45:11 -04:00
|
|
|
beforeEach(function() {
|
2017-02-09 18:12:51 -05:00
|
|
|
loadFixtures('branches/new_branch.html.raw');
|
|
|
|
this.submitButton = $('button[type="submit"]');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
it('disables submit when any field is required', function() {
|
|
|
|
$('.js-requires-input').requiresInput();
|
2017-02-09 18:12:51 -05:00
|
|
|
return expect(this.submitButton).toBeDisabled();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
it('enables submit when no field is required', function() {
|
|
|
|
$('*[required=required]').removeAttr('required');
|
|
|
|
$('.js-requires-input').requiresInput();
|
2017-02-09 18:12:51 -05:00
|
|
|
return expect(this.submitButton).not.toBeDisabled();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
it('enables submit when all required fields are pre-filled', function() {
|
|
|
|
$('*[required=required]').remove();
|
|
|
|
$('.js-requires-input').requiresInput();
|
|
|
|
return expect($('.submit')).not.toBeDisabled();
|
|
|
|
});
|
|
|
|
it('enables submit when all required fields receive input', function() {
|
|
|
|
$('.js-requires-input').requiresInput();
|
|
|
|
$('#required1').val('input1').change();
|
2017-02-09 18:12:51 -05:00
|
|
|
expect(this.submitButton).toBeDisabled();
|
2016-07-24 16:45:11 -04:00
|
|
|
$('#optional1').val('input1').change();
|
2017-02-09 18:12:51 -05:00
|
|
|
expect(this.submitButton).toBeDisabled();
|
2016-07-24 16:45:11 -04:00
|
|
|
$('#required2').val('input2').change();
|
|
|
|
$('#required3').val('input3').change();
|
|
|
|
$('#required4').val('input4').change();
|
|
|
|
$('#required5').val('1').change();
|
|
|
|
return expect($('.submit')).not.toBeDisabled();
|
|
|
|
});
|
|
|
|
});
|
2017-02-10 02:29:41 -05:00
|
|
|
}).call(window);
|