meid.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. describe('meid', function() {
  2. beforeEach(function () {
  3. $([
  4. '<form class="form-horizontal" id="meidForm">',
  5. '<div id="msg"></div>',
  6. '<div class="form-group">',
  7. '<input type="text" name="meid" data-bv-meid />',
  8. '</div>',
  9. '</form>'
  10. ].join('\n')).appendTo('body');
  11. $('#meidForm').bootstrapValidator();
  12. this.bv = $('#meidForm').data('bootstrapValidator');
  13. this.$meid = this.bv.getFieldElements('meid');
  14. });
  15. afterEach(function () {
  16. $('#meidForm').bootstrapValidator('destroy').remove();
  17. });
  18. it('Valid MEID (14 hex, check digit)', function() {
  19. this.bv.resetForm();
  20. this.$meid.val('A00000049259B16');
  21. this.bv.validate();
  22. expect(this.bv.isValid()).toBeTruthy();
  23. });
  24. it('Valid MEID (14 hex, dashes, check digit)', function() {
  25. this.bv.resetForm();
  26. this.$meid.val('A0-000004-9259B1-6');
  27. this.bv.validate();
  28. expect(this.bv.isValid()).toBeTruthy();
  29. });
  30. it('Valid MEID (14 hex, spaces, check digit)', function() {
  31. this.bv.resetForm();
  32. this.$meid.val('A0 000004 9259B1 6');
  33. this.bv.validate();
  34. expect(this.bv.isValid()).toBeTruthy();
  35. });
  36. it('Valid MEID (18 dec, check digit)', function() {
  37. this.bv.resetForm();
  38. this.$meid.val('2936087365007037100');
  39. this.bv.validate();
  40. expect(this.bv.isValid()).toBeTruthy();
  41. });
  42. it('Valid MEID (18 dec, dashes, check digit)', function() {
  43. this.bv.resetForm();
  44. this.$meid.val('29360-87365-0070-3710-0');
  45. this.bv.validate();
  46. expect(this.bv.isValid()).toBeTruthy();
  47. });
  48. it('Valid MEID (18 dec, spaces, check digit)', function() {
  49. this.bv.resetForm();
  50. this.$meid.val('29360 87365 0070 3710 0');
  51. this.bv.validate();
  52. expect(this.bv.isValid()).toBeTruthy();
  53. });
  54. it('Valid MEID (14 hex)', function() {
  55. this.bv.resetForm();
  56. this.$meid.val('AF0123450ABCDE');
  57. this.bv.validate();
  58. expect(this.bv.isValid()).toBeTruthy();
  59. });
  60. it('Valid MEID (14 hex, dashes)', function() {
  61. this.bv.resetForm();
  62. this.$meid.val('AF-012345-0ABCDE');
  63. this.bv.validate();
  64. expect(this.bv.isValid()).toBeTruthy();
  65. });
  66. it('Valid MEID (14 hex, spaces)', function() {
  67. this.bv.resetForm();
  68. this.$meid.val('AF 012345 0ABCDE');
  69. this.bv.validate();
  70. expect(this.bv.isValid()).toBeTruthy();
  71. });
  72. it('Valid MEID (18 dec)', function() {
  73. this.bv.resetForm();
  74. this.$meid.val('293608736500703710');
  75. this.bv.validate();
  76. expect(this.bv.isValid()).toBeTruthy();
  77. });
  78. it('Valid MEID (18 dec, dashes)', function() {
  79. this.bv.resetForm();
  80. this.$meid.val('29360-87365-0070-3710');
  81. this.bv.validate();
  82. expect(this.bv.isValid()).toBeTruthy();
  83. });
  84. it('Valid MEID (18 dec, spaces)', function() {
  85. this.bv.resetForm();
  86. this.$meid.val('29360 87365 0070 3710');
  87. this.bv.validate();
  88. expect(this.bv.isValid()).toBeTruthy();
  89. });
  90. it('Invalid MEID (14 hex, bad check digit)', function() {
  91. this.bv.resetForm();
  92. this.$meid.val('A00000049259B15');
  93. this.bv.validate();
  94. expect(this.bv.isValid()).toBeFalsy();
  95. });
  96. it('Invalid MEID (13 hex)', function() {
  97. this.bv.resetForm();
  98. this.$meid.val('A00000049259B');
  99. this.bv.validate();
  100. expect(this.bv.isValid()).toBeFalsy();
  101. });
  102. it('Invalid MEID (18 dec, bad check digit)', function() {
  103. this.bv.resetForm();
  104. this.$meid.val('2936087365007037101');
  105. this.bv.validate();
  106. expect(this.bv.isValid()).toBeFalsy();
  107. });
  108. it('Invalid MEID (17 dec)', function() {
  109. this.bv.resetForm();
  110. this.$meid.val('29360873650070371');
  111. this.bv.validate();
  112. expect(this.bv.isValid()).toBeFalsy();
  113. });
  114. });