ソースを参照

Add test suite for emailAddress validator.

Kenny Evitt 11 年 前
コミット
6a9f627c58

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.1-dev, built on 2014-08-14 8:41:52 AM
+ * @version     v0.5.1-dev, built on 2014-08-14 3:41:09 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 1 - 1
dist/js/bootstrapValidator.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.1-dev, built on 2014-08-14 8:41:52 AM
+ * @version     v0.5.1-dev, built on 2014-08-14 3:41:09 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 1 - 1
dist/js/bootstrapValidator.min.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.1-dev, built on 2014-08-14 8:41:52 AM
+ * @version     v0.5.1-dev, built on 2014-08-14 3:41:09 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 67 - 0
test/spec.js

@@ -2322,6 +2322,73 @@ describe('ean', function() {
     });
 });
 
+describe('emailAddress', function() {
+    beforeEach(function () {
+        $([
+            '<form class="form-horizontal" id="emailAddressForm">',
+                '<div id="msg"></div>',
+                '<div class="form-group">',
+                    '<input type="text" name="email-address" data-bv-emailaddress />',
+                '</div>',
+            '</form>'
+        ].join('\n')).appendTo('body');
+
+        $('#emailAddressForm').bootstrapValidator();
+
+        this.bv = $('#emailAddressForm').data('bootstrapValidator');
+        this.$emailAddress = this.bv.getFieldElements('email-address');
+    });
+
+    afterEach(function () {
+        $('#emailAddressForm').bootstrapValidator('destroy').remove();
+    });
+
+    var validEmailAddresses = [
+        'niceandsimple@example.com',
+        'very.common@example.com',
+        'a.little.lengthy.but.fine@dept.example.com',
+        'disposable.style.email.with+symbol@example.com',
+        'other.email-with-dash@example.com',
+        '"much.more unusual"@example.com',
+        '"very.unusual.@.unusual.com"@example.com',
+        '"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
+        '" "@example.org',
+        'üñîçøðé@example.com'
+    ];
+
+    var invalidEmailAddresses = [
+        'admin@mailserver1',
+        // "!#$%&'*+-/=?^_`{}|~@example.org",   // This is actually passing validation; see https://github.com/nghuuphuoc/bootstrapvalidator/issues/673
+        'üñîçøðé@üñîçøðé.com',
+        'Abc.example.com',
+        'A@b@c@example.com',
+        'a"b(c)d,e:f;gi[j\k]l@example.com',
+        'just"not"right@example.com',
+        'this is"not\allowed@example.com',
+        'this\ still\"not\\allowed@example.com'
+    ];
+
+    it('Valid email addresses', function() {
+        var me = this;
+        $.each(validEmailAddresses, function(index, emailAddress) {
+            me.bv.resetForm();
+            me.$emailAddress.val(emailAddress);
+            me.bv.validate();
+            expect(me.bv.isValid()).toBeTruthy();
+        });
+    });
+
+    it('Invalid email addresses', function() {
+        var me = this;
+        $.each(invalidEmailAddresses, function(index, emailAddress) {
+            me.bv.resetForm();
+            me.$emailAddress.val(emailAddress);
+            me.bv.validate();
+            expect(me.bv.isValid()).toEqual(false);
+        });
+    });
+});
+
 function greaterThanCompare() {
     var compareTo = $('#greaterThanForm').find('[name="minAge"]').val();
     $('#msg').html('greaterThanCompare() called; compare to ' + compareTo);

+ 66 - 0
test/spec/validator/emailAddress.js

@@ -0,0 +1,66 @@
+describe('emailAddress', function() {
+    beforeEach(function () {
+        $([
+            '<form class="form-horizontal" id="emailAddressForm">',
+                '<div id="msg"></div>',
+                '<div class="form-group">',
+                    '<input type="text" name="email-address" data-bv-emailaddress />',
+                '</div>',
+            '</form>'
+        ].join('\n')).appendTo('body');
+
+        $('#emailAddressForm').bootstrapValidator();
+
+        this.bv = $('#emailAddressForm').data('bootstrapValidator');
+        this.$emailAddress = this.bv.getFieldElements('email-address');
+    });
+
+    afterEach(function () {
+        $('#emailAddressForm').bootstrapValidator('destroy').remove();
+    });
+
+    var validEmailAddresses = [
+        'niceandsimple@example.com',
+        'very.common@example.com',
+        'a.little.lengthy.but.fine@dept.example.com',
+        'disposable.style.email.with+symbol@example.com',
+        'other.email-with-dash@example.com',
+        '"much.more unusual"@example.com',
+        '"very.unusual.@.unusual.com"@example.com',
+        '"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
+        '" "@example.org',
+        'üñîçøðé@example.com'
+    ];
+
+    var invalidEmailAddresses = [
+        'admin@mailserver1',
+        // "!#$%&'*+-/=?^_`{}|~@example.org",   // This is actually passing validation; see https://github.com/nghuuphuoc/bootstrapvalidator/issues/673
+        'üñîçøðé@üñîçøðé.com',
+        'Abc.example.com',
+        'A@b@c@example.com',
+        'a"b(c)d,e:f;gi[j\k]l@example.com',
+        'just"not"right@example.com',
+        'this is"not\allowed@example.com',
+        'this\ still\"not\\allowed@example.com'
+    ];
+
+    it('Valid email addresses', function() {
+        var me = this;
+        $.each(validEmailAddresses, function(index, emailAddress) {
+            me.bv.resetForm();
+            me.$emailAddress.val(emailAddress);
+            me.bv.validate();
+            expect(me.bv.isValid()).toBeTruthy();
+        });
+    });
+
+    it('Invalid email addresses', function() {
+        var me = this;
+        $.each(invalidEmailAddresses, function(index, emailAddress) {
+            me.bv.resetForm();
+            me.$emailAddress.val(emailAddress);
+            me.bv.validate();
+            expect(me.bv.isValid()).toEqual(false);
+        });
+    });
+});