emailAddress.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. describe('emailAddress', function() {
  2. beforeEach(function () {
  3. $([
  4. '<form class="form-horizontal" id="emailAddressForm">',
  5. '<div id="msg"></div>',
  6. '<div class="form-group">',
  7. '<input type="text" name="email-address" data-bv-emailaddress />',
  8. '</div>',
  9. '</form>'
  10. ].join('\n')).appendTo('body');
  11. $('#emailAddressForm').bootstrapValidator();
  12. this.bv = $('#emailAddressForm').data('bootstrapValidator');
  13. this.$emailAddress = this.bv.getFieldElements('email-address');
  14. });
  15. afterEach(function () {
  16. $('#emailAddressForm').bootstrapValidator('destroy').remove();
  17. });
  18. var validEmailAddresses = [
  19. 'niceandsimple@example.com',
  20. 'very.common@example.com',
  21. 'a.little.lengthy.but.fine@dept.example.com',
  22. 'disposable.style.email.with+symbol@example.com',
  23. 'other.email-with-dash@example.com',
  24. '"much.more unusual"@example.com',
  25. '"very.unusual.@.unusual.com"@example.com',
  26. '"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
  27. '" "@example.org',
  28. 'üñîçøðé@example.com'
  29. ];
  30. var invalidEmailAddresses = [
  31. 'admin@mailserver1',
  32. // "!#$%&'*+-/=?^_`{}|~@example.org", // This is actually passing validation; see https://github.com/nghuuphuoc/bootstrapvalidator/issues/673
  33. 'üñîçøðé@üñîçøðé.com',
  34. 'Abc.example.com',
  35. 'A@b@c@example.com',
  36. 'a"b(c)d,e:f;gi[j\k]l@example.com',
  37. 'just"not"right@example.com',
  38. 'this is"not\allowed@example.com',
  39. 'this\ still\"not\\allowed@example.com'
  40. ];
  41. it('Valid email addresses', function() {
  42. var me = this;
  43. $.each(validEmailAddresses, function(index, emailAddress) {
  44. me.bv.resetForm();
  45. me.$emailAddress.val(emailAddress);
  46. me.bv.validate();
  47. expect(me.bv.isValid()).toBeTruthy();
  48. });
  49. });
  50. it('Invalid email addresses', function() {
  51. var me = this;
  52. $.each(invalidEmailAddresses, function(index, emailAddress) {
  53. me.bv.resetForm();
  54. me.$emailAddress.val(emailAddress);
  55. me.bv.validate();
  56. expect(me.bv.isValid()).toEqual(false);
  57. });
  58. });
  59. });