isbn.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. describe('isbn', function() {
  2. // Override the default options
  3. $.extend($.fn.bootstrapValidator.DEFAULT_OPTIONS, {
  4. feedbackIcons: {
  5. valid: 'glyphicon glyphicon-ok',
  6. invalid: 'glyphicon glyphicon-remove',
  7. validating: 'glyphicon glyphicon-refresh'
  8. }
  9. });
  10. beforeEach(function() {
  11. var html = [
  12. '<div class="container">',
  13. '<form class="form-horizontal" id="form">',
  14. '<div class="form-group">',
  15. '<input type="text" name="isbn" data-bv-isbn />',
  16. '</div>',
  17. '</form>',
  18. '</div>'
  19. ].join('\n');
  20. $(html).appendTo('body');
  21. $('#form').bootstrapValidator();
  22. this._bs = $('#form').data('bootstrapValidator');
  23. this._$field = this._bs.getFieldElements('isbn');
  24. });
  25. afterEach(function() {
  26. $('#form').bootstrapValidator('destroy').remove();
  27. });
  28. it('isbn10 hyphen', function() {
  29. var samples = ['99921-58-10-7', '9971-5-0210-0', '960-425-059-0', '80-902734-1-6'];
  30. for (var i in samples) {
  31. this._$field.val(samples[i]);
  32. this._bs.validate();
  33. expect(this._bs.isValidField('isbn')).toBeTruthy();
  34. }
  35. });
  36. it('isbn10 space', function() {
  37. var samples = ['85 359 0277 5', '1 84356 028 3', '0 684 84328 5', '0 85131 041 9', '0 943396 04 2'];
  38. for (var i in samples) {
  39. this._$field.val(samples[i]);
  40. this._bs.validate();
  41. expect(this._bs.isValidField('isbn')).toBeTruthy();
  42. }
  43. });
  44. it('isbn10 hyphen with X', function() {
  45. var samples = ['0-8044-2957-X', '0-9752298-0-X'];
  46. for (var i in samples) {
  47. this._$field.val(samples[i]);
  48. this._bs.validate();
  49. expect(this._bs.isValidField('isbn')).toBeTruthy();
  50. }
  51. });
  52. it('isbn10 invalid check digit', function() {
  53. this._$field.val('99921-58-10-6');
  54. this._bs.validate();
  55. expect(this._bs.isValidField('isbn')).toEqual(false);
  56. });
  57. it('isbn13', function() {
  58. this._$field.val('978-0-306-40615-7');
  59. this._bs.validate();
  60. expect(this._bs.isValidField('isbn')).toBeTruthy();
  61. });
  62. it('isbn13 invalid check digit', function() {
  63. this._$field.val('978-0-306-40615-6');
  64. this._bs.validate();
  65. expect(this._bs.isValidField('isbn')).toEqual(false);
  66. });
  67. });