debian-mirror-gitlab/spec/javascripts/behaviors/requires_input_spec.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import '~/behaviors/requires_input';
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
describe('requiresInput', () => {
let submitButton;
preloadFixtures('branches/new_branch.html.raw');
beforeEach(() => {
loadFixtures('branches/new_branch.html.raw');
submitButton = $('button[type="submit"]');
});
it('disables submit when any field is required', () => {
$('.js-requires-input').requiresInput();
expect(submitButton).toBeDisabled();
});
it('enables submit when no field is required', () => {
$('*[required=required]').removeAttr('required');
$('.js-requires-input').requiresInput();
expect(submitButton).not.toBeDisabled();
});
it('enables submit when all required fields are pre-filled', () => {
$('*[required=required]').remove();
$('.js-requires-input').requiresInput();
expect($('.submit')).not.toBeDisabled();
});
it('enables submit when all required fields receive input', () => {
$('.js-requires-input').requiresInput();
$('#required1').val('input1').change();
expect(submitButton).toBeDisabled();
$('#optional1').val('input1').change();
expect(submitButton).toBeDisabled();
$('#required2').val('input2').change();
$('#required3').val('input3').change();
$('#required4').val('input4').change();
$('#required5').val('1').change();
expect($('.submit')).not.toBeDisabled();
2016-09-13 17:45:13 +05:30
});
2018-03-17 18:26:18 +05:30
});