meid.js 3.9 KB

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