2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2022-07-16 23:28:13 +05:30
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
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;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
loadHTMLFixture('branches/new_branch.html');
|
2018-03-17 18:26:18 +05:30
|
|
|
submitButton = $('button[type="submit"]');
|
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('disables submit when any field is required', () => {
|
|
|
|
$('.js-requires-input').requiresInput();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(submitButton).toBeDisabled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enables submit when no field is required', () => {
|
2018-03-27 19:54:05 +05:30
|
|
|
$('*[required=required]').prop('required', false);
|
2018-03-17 18:26:18 +05:30
|
|
|
$('.js-requires-input').requiresInput();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(submitButton).not.toBeDisabled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enables submit when all required fields are pre-filled', () => {
|
|
|
|
$('*[required=required]').remove();
|
|
|
|
$('.js-requires-input').requiresInput();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect($('.submit')).not.toBeDisabled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('enables submit when all required fields receive input', () => {
|
|
|
|
$('.js-requires-input').requiresInput();
|
2021-03-08 18:12:59 +05:30
|
|
|
$('#required1').val('input1').change();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(submitButton).toBeDisabled();
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
$('#optional1').val('input1').change();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(submitButton).toBeDisabled();
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
$('#required2').val('input2').change();
|
|
|
|
$('#required3').val('input3').change();
|
|
|
|
$('#required4').val('input4').change();
|
|
|
|
$('#required5').val('1').change();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect($('.submit')).not.toBeDisabled();
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|