date.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. describe('date', function() {
  2. beforeEach(function () {
  3. $([
  4. '<form class="form-horizontal" id="dateForm">',
  5. '<div id="msg"></div>',
  6. '<div class="form-group">',
  7. '<input type="text" name="date" data-bv-date />',
  8. '</div>',
  9. '</form>'
  10. ].join('\n')).appendTo('body');
  11. $('#dateForm').bootstrapValidator();
  12. this.bv = $('#dateForm').data('bootstrapValidator');
  13. this.$date = this.bv.getFieldElements('date');
  14. });
  15. afterEach(function () {
  16. $('#dateForm').bootstrapValidator('destroy').remove();
  17. });
  18. it('YYYY/MM/DD', function() {
  19. this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD');
  20. this.$date.val('2000/01/30');
  21. this.bv.validate();
  22. expect(this.bv.isValid()).toBeTruthy();
  23. // Invalid year
  24. this.bv.resetForm();
  25. this.$date.val('100/10/20');
  26. this.bv.validate();
  27. expect(this.bv.isValid()).toEqual(false);
  28. // Invalid month
  29. this.bv.resetForm();
  30. this.$date.val('2000/00/10');
  31. this.bv.validate();
  32. expect(this.bv.isValid()).toEqual(false);
  33. this.bv.resetForm();
  34. this.$date.val('2000/15/10');
  35. this.bv.validate();
  36. expect(this.bv.isValid()).toEqual(false);
  37. // Invalid day
  38. this.bv.resetForm();
  39. this.$date.val('2000/03/00');
  40. this.bv.validate();
  41. expect(this.bv.isValid()).toEqual(false);
  42. this.bv.resetForm();
  43. this.$date.val('2000/10/32');
  44. this.bv.validate();
  45. expect(this.bv.isValid()).toEqual(false);
  46. // Consist invalid characters
  47. // #310
  48. this.bv.resetForm();
  49. this.$date.val('aaaa/');
  50. this.bv.validate();
  51. expect(this.bv.isValid()).toEqual(false);
  52. this.bv.resetForm();
  53. this.$date.val('2004df/1dd1/5ffg');
  54. this.bv.validate();
  55. expect(this.bv.isValid()).toEqual(false);
  56. });
  57. it('number of days in February', function() {
  58. this.bv.updateOption('date', 'date', 'format', 'YYYY/MM/DD');
  59. this.$date.val('2000/02/28');
  60. this.bv.validate();
  61. expect(this.bv.isValid()).toBeTruthy();
  62. this.bv.resetForm();
  63. this.$date.val('2000/02/29');
  64. this.bv.validate();
  65. expect(this.bv.isValid()).toBeTruthy();
  66. this.bv.resetForm();
  67. this.$date.val('2001/02/29');
  68. this.bv.validate();
  69. expect(this.bv.isValid()).toEqual(false);
  70. });
  71. });