Parsley

  • Base

    • should provide a actualizeOptions() method4ms

      $('body').append('<input type="email" data-parsley-pattern="[A-F][0-9]{5}" data-parsley-required id="element" />');
      var parsleyField = $('#element').parsley({
        foo: 'bar'
      });
      expect(parsleyField.options.pattern).to.eql('[A-F][0-9]{5}');
      expect(parsleyField.options.required).to.eql('');
      $('#element').removeAttr('data-parsley-pattern');
      parsleyField.actualizeOptions();
      expect(parsleyField.options.pattern).to.be(undefined);
      expect(parsleyField.options.required).to.eql('');
    • should use reset() on field5ms

      $('body').append('<input type="email" data-parsley-pattern="[A-F][0-9]{5}" data-parsley-required id="element" />');
      var parsleyField = $('#element').parsley();
      parsleyField.validate();
      expect($('#parsley-id-' + parsleyField.__id__ + ' li').length).to.be(1);
      parsleyField.reset();
      expect($('#parsley-id-' + parsleyField.__id__ + ' li').length).to.be(0);
    • should use reset() on form8ms

      done => {
            $('body').append('<form id="element">' + '<input id="field1" type="text" required />' + '<div id="field2"></div>' + '<textarea id="field2"></textarea>' + '</form>');
            var parsleyForm = $('#element').parsley();
            parsleyForm.validate();
            expect($('#parsley-id-' + $('#field1').psly().__id__ + ' li').length).to.be(1);
            $
              done();
            });
            parsleyForm.reset();
            expect($('#parsley-id-' + $('#field1').psly().__id__ + ' li').length).to.be(0);
    • should use destroy() on field2ms

      done => {
            $('body').append('<input type="email" data-parsley-pattern="[A-F][0-9]{5}" data-parsley-required id="element" />');
            var parsleyField = $('#element').parsley();
            $
              done();
            });
            expect($('#element').data('Parsley')).to.have.key('__class__');
            expect($('#element').data('Parsley').__class__).to.be('Field');
            parsleyField.destroy();
            expect($('#element').data('Parsley')).to.be(undefined);
    • should use destroy() on form5ms

      done => {
            $('body').append('<form id="element">' + '<input id="field1" type="text"/>' + '<div id="field2"></div>' + '<textarea id="field2"></textarea>' + '</form>');
            var parsleyForm = $('#element').parsley();
            var fieldEventsCount = 0;
            var formEventsCount = 0; // Test that a subscribed field event on parent form would be triggered by fields too
            // Here we only have field1 and field2 as valid parsley fields
            $
              fieldEventsCount++;
            });
            $('#element').parsley().on('form:destroy', () => {
              formEventsCount++;
            });
            expect($('#element').data('Parsley')).to.have.key('__class__');
            expect($('#element').data('Parsley').__class__).to.be('Form');
            expect($('#field1').data('Parsley')).to.have.key('__class__');
            expect($('#field1').data('Parsley').__class__).to.be('Field');
            parsleyForm.destroy();
            expect(fieldEventsCount).to.be(2);
            expect(formEventsCount).to.be(1); // we should never enter here since parsley form instance is destroyed
            Parsley.on('form:validate', () => {
              expect(true).to.be(false);
            }); // test that a submit event does not trigger parsley validation anymore
            $('#element').on('submit', e => {
              e.preventDefault();
              expect($('#element').data('Parsley')).to.be(undefined);
              expect($('#field1').data('Parsley')).to.be(undefined);
              Parsley.off('form:validate');
              done();
            });
            $('#element').submit();
  • Field

    • should be a function0ms

      expect(Field).to.be.a('function');
    • should throw an error if no parsleyInstance given0ms

      expect(Field).to.throwException();
    • should properly bind DOM constraints1ms

      $('body').append('<input type="text" id="element" data-parsley-required />');
      var parsleyField = $('#element').parsley();
      expect(parsleyField.constraints.length).to.be(1);
      expect(parsleyField.constraints[0].name).to.be('required');
      expect(parsleyField.constraints[0].isDomConstraint).to.be(true);
    • should properly bind HTML DOM supported constraints0ms

      $('body').append('<input type="email" id="element" />');
      var parsleyField = $('#element').parsley();
      expect(parsleyField.constraints.length).to.be(1);
      expect(parsleyField.constraints[0].name).to.be('type');
      expect(parsleyField.constraints[0].isDomConstraint).to.be(true);
    • should ignore unknown types1ms

      $('body').append('<input type="" id="element" />');
      var parsleyField = $('#element').parsley();
      expect(parsleyField.constraints.length).to.be(0);
    • should ignore mistyped types1ms

      $('body').append('<input type="    email" id="element" />');
      var parsleyField = $('#element').parsley();
      expect(parsleyField.constraints.length).to.be(0);
    • should have a proper addConstraint() javascript method2ms

      $('body').append('<input type="text" id="element" />');
      var parsleyField = $('#element').parsley().addConstraint('required', true);
      expect(parsleyField.constraints.length).to.be(1);
      expect(parsleyField.constraints[0].name).to.be('required');
      expect(parsleyField.constraints[0].requirements).to.be(true);
      expect(parsleyField.constraints[0].priority).to.be(512);
      expect(parsleyField.constraints[0].isDomConstraint).to.be(false); // trying to add an existing constraint result in an update
      parsleyField.addConstraint('required', false, 64);
      expect(parsleyField.constraints.length).to.be(1);
      expect(parsleyField.constraints[0].name).to.be('required');
      expect(parsleyField.constraints[0].requirements).to.be(false);
      expect(parsleyField.constraints[0].priority).to.be(64);
    • should have a proper updateConstraint() javascript method1ms

      $('body').append('<input type="text" id="element" />');
      var parsleyField = $('#element').parsley().addConstraint('required', true); // same as above test where addConstraint resulted in an updateConstraint
      parsleyField.updateConstraint('required', false, 64);
      expect(parsleyField.constraints.length).to.be(1);
      expect(parsleyField.constraints[0].name).to.be('required');
      expect(parsleyField.constraints[0].requirements).to.be(false);
      expect(parsleyField.constraints[0].priority).to.be(64);
    • should have a proper removeConstraint() javascript method1ms

      $('body').append('<input type="text" id="element" />');
      var parsleyField = $('#element').parsley().addConstraint('required', true).addConstraint('notblank', true).removeConstraint('required');
      expect(parsleyField.constraints.length).to.be(1);
      expect(parsleyField.constraints[0].name).to.be('notblank');
      expect(parsleyField._isRequired()).to.be(false);
    • should return true for fields without constraints1ms

      $('body').append('<input type="text" id="element" value="hola" data-parsley-minlength="5" />');
      var parsleyField = $('#element').parsley(); // Start with some validation errors:
      expect(parsleyField.isValid()).to.eql(false); // The remove constraint and check result:
      $('#element').removeAttr('data-parsley-minlength');
      expect(parsleyField.isValid()).to.be(true);
    • should properly bind HTML5 supported constraints1ms

      $('body').append('<input type="email" pattern="\\w+" id="element" required min="5" max="100" minlength="1" maxlength="3" />');
      var parsleyField = $('#element').parsley(); // 5 validators: type=email, pattern, required, (min+max => range) and (minlength+maxlength => length)
      expect(parsleyField.constraints.length).to.be(5);
      $('#element').removeAttr('min'); // still 5 validators, with max instead of range now
      expect(parsleyField.actualizeOptions().constraints.length).to.be(5);
      $('#element').removeAttr('minlength'); // still 5 validators, with maxlength instead of length now
      expect(parsleyField.actualizeOptions().constraints.length).to.be(5);
    • should properly bind HTML5 date inputs

      Error: expected true to equal false
          at Assertion.assert (https://parsleyjs.org/bower_components/expect.js/index.js:96:13)
          at Assertion.be.Assertion.equal (https://parsleyjs.org/bower_components/expect.js/index.js:216:10)
          at Assertion.<computed> [as be] (https://parsleyjs.org/bower_components/expect.js/index.js:69:24)
          at Context.<anonymous> (assets/spec-build.js:2709:41)
      // Uses RFC 3339/ISO 8601 format YYYY-MM-DD
      $('body').append('<input type="date" id="element" max="2000-01-02" min="1999-01-02" value="1998-12-30" />');
      var parsleyField = $('#element').parsley();
      expect(parsleyField.constraints.length).to.be(2); // Type=Date, Range
      expect(parsleyField.isValid()).to.be(false);
      expect(parsleyField.isValid({
        value: '1999-02-03'
      })).to.be(true);
      $('#element').removeAttr('min');
      expect(parsleyField.isValid()).to.be(true);
      expect(parsleyField.constraints.length).to.be(2); // Type=Date, Max
      $('#element').val('2001-03-03');
      expect(parsleyField.isValid()).to.be(false);
      $('#element').val('2001/01/01').removeAttr('max');
      expect(parsleyField.isValid()).to.be(false); // Still invalid because of format
      expect(parsleyField.constraints.length).to.be(1); // Type=Date
    • should follow HTML5 spec to validate "number" type by accepting "1"1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type by accepting "10"1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type by accepting "-2"1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type by accepting "-20"1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type by accepting "4.0"0ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type by accepting "4.00"1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type by rejecting "1.1"1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type by rejecting "4."1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type with attributes step="any" by accepting "-2"1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type with attributes step="any" by accepting "-20"0ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);
    • should follow HTML5 spec to validate "number" type with attributes step="any" by accepting "4.3"1ms

      var $input = $(`<input type="number" ${attrs}>`);
      expect($input.parsley().isValid({
        value
      })).to.be(valid);