creditCard.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. describe('creditCard', function() {
  2. // Get the fake credit card number at http://www.getcreditcardnumbers.com/
  3. // Override the default options
  4. $.extend($.fn.bootstrapValidator.DEFAULT_OPTIONS, {
  5. feedbackIcons: {
  6. valid: 'glyphicon glyphicon-ok',
  7. invalid: 'glyphicon glyphicon-remove',
  8. validating: 'glyphicon glyphicon-refresh'
  9. }
  10. });
  11. beforeEach(function() {
  12. var html = [
  13. '<div class="container">',
  14. '<form class="form-horizontal" id="form">',
  15. '<div class="form-group">',
  16. '<input type="text" name="cc" data-bv-creditcard />',
  17. '</div>',
  18. '</form>',
  19. '</div>'
  20. ].join('\n');
  21. $(html).appendTo('body');
  22. $('#form').bootstrapValidator();
  23. this._bs = $('#form').data('bootstrapValidator');
  24. this._$field = this._bs.getFieldElements('cc');
  25. });
  26. afterEach(function() {
  27. $('#form').bootstrapValidator('destroy').remove();
  28. });
  29. it('accept spaces', function() {
  30. this._$field.val('5267 9789 9451 9654');
  31. this._bs.validate();
  32. expect(this._bs.isValidField('cc')).toBeTruthy();
  33. });
  34. it('accept dashes', function() {
  35. this._$field.val('6011-2649-6840-4521');
  36. this._bs.validate();
  37. expect(this._bs.isValidField('cc')).toBeTruthy();
  38. });
  39. it('invalid format', function() {
  40. this._$field.val('4539.1870.2954.3862');
  41. this._bs.validate();
  42. expect(this._bs.isValidField('cc')).toEqual(false);
  43. });
  44. it('American Express', function() {
  45. this._$field.val('340653705597107');
  46. this._bs.validate();
  47. expect(this._bs.isValidField('cc')).toBeTruthy();
  48. });
  49. it('American Express invalid length', function() {
  50. this._$field.val('3744148309166730');
  51. this._bs.validate();
  52. expect(this._bs.isValidField('cc')).toEqual(false);
  53. });
  54. it('American Express invalid prefix', function() {
  55. this._$field.val('356120148436654');
  56. this._bs.validate();
  57. expect(this._bs.isValidField('cc')).toEqual(false);
  58. });
  59. it('Diners Club', function() {
  60. this._$field.val('30130708434187');
  61. this._bs.validate();
  62. expect(this._bs.isValidField('cc')).toBeTruthy();
  63. });
  64. it('Diners Club (US)', function() {
  65. this._$field.val('5517479515603901');
  66. this._bs.validate();
  67. expect(this._bs.isValidField('cc')).toBeTruthy();
  68. });
  69. it('Discover', function() {
  70. this._$field.val('6011734674929094');
  71. this._bs.validate();
  72. expect(this._bs.isValidField('cc')).toBeTruthy();
  73. });
  74. it('JCB', function() {
  75. this._$field.val('3566002020360505');
  76. this._bs.validate();
  77. expect(this._bs.isValidField('cc')).toBeTruthy();
  78. });
  79. it('Laser', function() {
  80. this._$field.val('6304 9000 1774 0292 441');
  81. this._bs.validate();
  82. expect(this._bs.isValidField('cc')).toBeTruthy();
  83. });
  84. it('Maestro', function() {
  85. this._$field.val('6762835098779303');
  86. this._bs.validate();
  87. expect(this._bs.isValidField('cc')).toBeTruthy();
  88. });
  89. it('Mastercard', function() {
  90. this._$field.val('5303765013600904');
  91. this._bs.validate();
  92. expect(this._bs.isValidField('cc')).toBeTruthy();
  93. });
  94. it('Solo', function() {
  95. this._$field.val('6334580500000000');
  96. this._bs.validate();
  97. expect(this._bs.isValidField('cc')).toBeTruthy();
  98. });
  99. it('Visa', function() {
  100. this._$field.val('4929248980295542');
  101. this._bs.validate();
  102. expect(this._bs.isValidField('cc')).toBeTruthy();
  103. });
  104. it('Visa invalid check digit', function() {
  105. this._$field.val('4532599916257826');
  106. this._bs.validate();
  107. expect(this._bs.isValidField('cc')).toEqual(false);
  108. });
  109. });