addEventSource.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. describe('addEventSource', function() {
  2. var eventArray = [
  3. { id: 0, title: 'event zero', start: '2014-06-24', className: 'event-zero' },
  4. { id: 1, title: 'event one', start: '2014-06-24', className: 'event-non-zero event-one' },
  5. { id: 2, title: 'event two', start: '2014-06-24', className: 'event-non-zero event-two' }
  6. ]
  7. pushOptions({
  8. defaultDate: '2014-06-24',
  9. defaultView: 'month'
  10. })
  11. it('correctly adds an array source', function(done) {
  12. go(
  13. function() {
  14. currentCalendar.addEventSource(eventArray)
  15. },
  16. null,
  17. done
  18. )
  19. })
  20. it('correctly adds a function source', function(done) {
  21. go(
  22. function() {
  23. currentCalendar.addEventSource(function(start, end, timezone, callback) {
  24. callback(eventArray)
  25. })
  26. },
  27. null,
  28. done
  29. )
  30. })
  31. it('correctly adds an extended array source', function(done) {
  32. go(
  33. function() {
  34. currentCalendar.addEventSource({
  35. className: 'arraysource',
  36. events: eventArray
  37. })
  38. },
  39. function() {
  40. expect($('.arraysource').length).toEqual(3)
  41. },
  42. done
  43. )
  44. })
  45. it('correctly adds an extended array source', function(done) {
  46. go(
  47. function() {
  48. currentCalendar.addEventSource({
  49. className: 'funcsource',
  50. events: function(start, end, timezone, callback) {
  51. callback(eventArray)
  52. }
  53. })
  54. },
  55. function() {
  56. expect($('.funcsource').length).toEqual(3)
  57. },
  58. done
  59. )
  60. })
  61. function go(addFunc, extraTestFunc, doneFunc) {
  62. var callCnt = 0
  63. var options = {}
  64. options.eventAfterAllRender = function() {
  65. callCnt++
  66. if (callCnt === 2) { // once for initial render. second time for addEventSource
  67. checkAllEvents()
  68. if (extraTestFunc) {
  69. extraTestFunc()
  70. }
  71. // move the calendar back out of view, then back in (for issue 2191)
  72. currentCalendar.next()
  73. currentCalendar.prev()
  74. // otherwise, prev/next would be cancelled out by doneFunc's calendar destroy
  75. setTimeout(function() {
  76. checkAllEvents()
  77. if (extraTestFunc) {
  78. extraTestFunc()
  79. }
  80. doneFunc()
  81. }, 0)
  82. }
  83. }
  84. initCalendar(options)
  85. addFunc()
  86. }
  87. // Checks to make sure all events have been rendered and that the calendar
  88. // has internal info on all the events.
  89. function checkAllEvents() {
  90. expect(currentCalendar.clientEvents().length).toEqual(3)
  91. expect($('.fc-event').length).toEqual(3)
  92. }
  93. })