2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-05-16 17:01:51 -04:00
|
|
|
import '~/behaviors/requires_input';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-11-29 13:02:27 -05:00
|
|
|
describe('requiresInput', () => {
|
|
|
|
let submitButton;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-03-26 12:03:28 -04:00
|
|
|
loadFixtures('branches/new_branch.html');
|
2017-11-29 13:02:27 -05:00
|
|
|
submitButton = $('button[type="submit"]');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disables submit when any field is required', () => {
|
|
|
|
$('.js-requires-input').requiresInput();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-29 13:02:27 -05:00
|
|
|
expect(submitButton).toBeDisabled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enables submit when no field is required', () => {
|
2018-02-20 17:20:48 -05:00
|
|
|
$('*[required=required]').prop('required', false);
|
2017-11-29 13:02:27 -05:00
|
|
|
$('.js-requires-input').requiresInput();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-29 13:02:27 -05:00
|
|
|
expect(submitButton).not.toBeDisabled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enables submit when all required fields are pre-filled', () => {
|
|
|
|
$('*[required=required]').remove();
|
|
|
|
$('.js-requires-input').requiresInput();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-29 13:02:27 -05:00
|
|
|
expect($('.submit')).not.toBeDisabled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enables submit when all required fields receive input', () => {
|
|
|
|
$('.js-requires-input').requiresInput();
|
2020-12-23 07:10:26 -05:00
|
|
|
$('#required1').val('input1').change();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-29 13:02:27 -05:00
|
|
|
expect(submitButton).toBeDisabled();
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
$('#optional1').val('input1').change();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-29 13:02:27 -05:00
|
|
|
expect(submitButton).toBeDisabled();
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
$('#required2').val('input2').change();
|
|
|
|
$('#required3').val('input3').change();
|
|
|
|
$('#required4').val('input4').change();
|
|
|
|
$('#required5').val('1').change();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-29 13:02:27 -05:00
|
|
|
expect($('.submit')).not.toBeDisabled();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-11-29 13:02:27 -05:00
|
|
|
});
|