BigW Consortium Gitlab

requires_input_spec.js 1.52 KB
Newer Older
1
/* eslint-disable space-before-function-paren, no-var */
Fatih Acet committed
2

3
import '~/behaviors/requires_input';
Fatih Acet committed
4 5 6

(function() {
  describe('requiresInput', function() {
7
    preloadFixtures('branches/new_branch.html.raw');
Fatih Acet committed
8
    beforeEach(function() {
9 10
      loadFixtures('branches/new_branch.html.raw');
      this.submitButton = $('button[type="submit"]');
Fatih Acet committed
11 12 13
    });
    it('disables submit when any field is required', function() {
      $('.js-requires-input').requiresInput();
14
      return expect(this.submitButton).toBeDisabled();
Fatih Acet committed
15 16 17 18
    });
    it('enables submit when no field is required', function() {
      $('*[required=required]').removeAttr('required');
      $('.js-requires-input').requiresInput();
19
      return expect(this.submitButton).not.toBeDisabled();
Fatih Acet committed
20 21 22 23 24 25 26 27 28
    });
    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();
29
      expect(this.submitButton).toBeDisabled();
Fatih Acet committed
30
      $('#optional1').val('input1').change();
31
      expect(this.submitButton).toBeDisabled();
Fatih Acet committed
32 33 34 35 36 37 38
      $('#required2').val('input2').change();
      $('#required3').val('input3').change();
      $('#required4').val('input4').change();
      $('#required5').val('1').change();
      return expect($('.submit')).not.toBeDisabled();
    });
  });
39
}).call(window);