events-function.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. describe('events as a function', function() {
  2. it('requests the correct dates when days at the start/end of the month are hidden', function(done) {
  3. initCalendar({
  4. defaultView: 'month',
  5. defaultDate: '2013-06-01', // June 2013 has first day as Saturday, and last as Sunday!
  6. weekends: false,
  7. fixedWeekCount: false,
  8. events: function(start, end, timezone, callback) {
  9. expect(start).toEqualMoment('2013-06-03');
  10. expect(end).toEqualMoment('2013-06-29');
  11. done();
  12. }
  13. });
  14. });
  15. it('does not request dates excluded by showNonCurrentDates:false', function(done) {
  16. initCalendar({
  17. defaultView: 'month',
  18. defaultDate: '2013-06-01',
  19. showNonCurrentDates: false,
  20. events: function(start, end, timezone, callback) {
  21. expect(start).toEqualMoment('2013-06-01');
  22. expect(end).toEqualMoment('2013-07-01');
  23. done();
  24. }
  25. });
  26. });
  27. it('requests a timed range when minTime is negative', function(done) {
  28. initCalendar({
  29. defaultView: 'agendaWeek',
  30. defaultDate: '2017-06-08',
  31. minTime: { hours: -2 },
  32. events: function(start, end, timezone, callback) {
  33. expect(start).toEqualMoment('2017-06-03T22:00:00');
  34. expect(end).toEqualMoment('2017-06-11T00:00:00');
  35. done();
  36. }
  37. });
  38. });
  39. it('requests a timed range when maxTime exceeds 24 hours', function(done) {
  40. initCalendar({
  41. defaultView: 'agendaWeek',
  42. defaultDate: '2017-06-08',
  43. maxTime: '26:00',
  44. events: function(start, end, timezone, callback) {
  45. expect(start).toEqualMoment('2017-06-04T00:00:00');
  46. expect(end).toEqualMoment('2017-06-11T02:00:00');
  47. done();
  48. }
  49. });
  50. });
  51. it('calls loading callback', function(done) {
  52. var loadingCallArgs = [];
  53. initCalendar({
  54. loading: function(bool) {
  55. loadingCallArgs.push(bool);
  56. },
  57. events: function(start, end, timezone, callback) {
  58. setTimeout(function() {
  59. expect(loadingCallArgs).toEqual([ true ]);
  60. callback([]);
  61. setTimeout(function() {
  62. expect(loadingCallArgs).toEqual([ true, false ]);
  63. done();
  64. }, 0);
  65. }, 0);
  66. }
  67. });
  68. });
  69. it('calls loading callback only once for multiple sources', function(done) {
  70. var loadingCallArgs = [];
  71. initCalendar({
  72. loading: function(bool) {
  73. loadingCallArgs.push(bool);
  74. },
  75. eventSources: [
  76. function(start, end, timezone, callback) {
  77. setTimeout(function() {
  78. callback([]);
  79. }, 0);
  80. },
  81. function(start, end, timezone, callback) {
  82. setTimeout(function() {
  83. callback([]);
  84. }, 10);
  85. }
  86. ]
  87. });
  88. setTimeout(function() {
  89. expect(loadingCallArgs).toEqual([ true, false ]);
  90. done();
  91. }, 20);
  92. });
  93. });