TaskQueue.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. describe('TaskQueue', function() {
  2. var TaskQueue = $.fullCalendar.TaskQueue;
  3. it('executes first task immediately', function() {
  4. var q = new TaskQueue();
  5. var ops = [];
  6. q.on('start', function() {
  7. ops.push('start-event');
  8. });
  9. q.on('stop', function() {
  10. ops.push('stop-event');
  11. });
  12. q.queue(function() {
  13. ops.push('run1');
  14. });
  15. expect(ops).toEqual([ 'start-event', 'run1', 'stop-event' ]);
  16. });
  17. it('executes second task after first has fully completed', function() {
  18. var q = new TaskQueue();
  19. var ops = [];
  20. q.on('start', function() {
  21. ops.push('start-event');
  22. });
  23. q.on('stop', function() {
  24. ops.push('stop-event');
  25. });
  26. q.queue(function() {
  27. ops.push('start1');
  28. q.queue(function() {
  29. ops.push('run2');
  30. });
  31. ops.push('stop1');
  32. });
  33. expect(ops).toEqual([ 'start-event', 'start1', 'stop1', 'run2', 'stop-event' ]);
  34. });
  35. it('executes second task after first promise resolves', function(done) {
  36. var q = new TaskQueue();
  37. var ops = [];
  38. q.on('start', function() {
  39. ops.push('start-event');
  40. });
  41. q.on('stop', function() {
  42. ops.push('stop-event');
  43. });
  44. q.queue(function() {
  45. var deferred = $.Deferred();
  46. ops.push('start1');
  47. q.queue(function() {
  48. ops.push('run2');
  49. });
  50. setTimeout(function() {
  51. ops.push('stop1');
  52. deferred.resolve();
  53. }, 100);
  54. return deferred.promise();
  55. });
  56. setTimeout(function() {
  57. expect(ops).toEqual([ 'start-event', 'start1', 'stop1', 'run2', 'stop-event' ]);
  58. done();
  59. }, 200);
  60. });
  61. it('serially executes two tasks, the first with a promise', function(done) {
  62. var q = new TaskQueue();
  63. var ops = [];
  64. q.on('start', function() {
  65. ops.push('start-event');
  66. });
  67. q.on('stop', function() {
  68. ops.push('stop-event');
  69. });
  70. q.queue(function() {
  71. var deferred = $.Deferred();
  72. ops.push('start1');
  73. setTimeout(function() {
  74. ops.push('stop1');
  75. deferred.resolve();
  76. }, 100);
  77. return deferred.promise();
  78. }, function() {
  79. ops.push('run2');
  80. });
  81. setTimeout(function() {
  82. expect(ops).toEqual([ 'start-event', 'start1', 'stop1', 'run2', 'stop-event' ]);
  83. done();
  84. }, 200);
  85. });
  86. describe('pausing', function() {
  87. it('prevents task from rendering', function() {
  88. var q = new TaskQueue();
  89. var ops = [];
  90. q.on('start', function() {
  91. ops.push('start-event');
  92. });
  93. q.on('stop', function() {
  94. ops.push('stop-event');
  95. });
  96. q.pause();
  97. q.queue(function() {
  98. ops.push('run1');
  99. });
  100. q.queue(function() {
  101. ops.push('run2');
  102. });
  103. expect(ops).toEqual([ ]);
  104. q.resume();
  105. expect(ops).toEqual([ 'start-event', 'run1', 'run2', 'stop-event' ]);
  106. });
  107. });
  108. });