RenderQueue.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. describe('RenderQueue', function() {
  2. var RenderQueue = $.fullCalendar.RenderQueue;
  3. it('executes atomic events in sequence', function() {
  4. var ops = [];
  5. var q = new RenderQueue();
  6. q.queue('ent0', 'foo', 'init', function() {
  7. ops.push('fooinit');
  8. });
  9. q.queue('ent0', 'foo', 'add', function() {
  10. ops.push('fooremove');
  11. });
  12. q.queue('ent0', 'foo', 'remove', function() {
  13. ops.push('fooadd');
  14. });
  15. q.queue('ent0', 'foo', 'destroy', function() {
  16. ops.push('foodestroy');
  17. });
  18. expect(ops).toEqual([ 'fooinit', 'fooremove', 'fooadd', 'foodestroy' ]);
  19. });
  20. describe('when accumulating', function() {
  21. describe('using clear action', function() {
  22. it('destroys add/remove operations in same entity+namespace', function() {
  23. var ops = [];
  24. var q = new RenderQueue();
  25. q.pause();
  26. q.queue('ent0', 'foo', 'add', function() {
  27. ops.push('fooadd');
  28. });
  29. q.queue('ent0', 'foo', 'remove', function() {
  30. ops.push('fooremove');
  31. });
  32. q.queue('ent0', 'foo', 'destroy', function() {
  33. ops.push('foodestroy');
  34. });
  35. expect(ops).toEqual([]);
  36. q.resume();
  37. expect(ops).toEqual([ 'foodestroy' ]);
  38. });
  39. fit('destroys add/remove operations in same entity+namespace, keeping other entities', function() {
  40. var ops = [];
  41. var q = new RenderQueue();
  42. q.pause();
  43. q.queue('ent0', 'foo', 'add', function() {
  44. ops.push('foo0add');
  45. });
  46. q.queue('ent1', 'foo', 'add', function() {
  47. ops.push('foo1add');
  48. });
  49. q.queue('ent0', 'foo', 'remove', function() {
  50. ops.push('foo0remove');
  51. });
  52. q.queue('ent1', 'foo', 'remove', function() {
  53. ops.push('foo1remove');
  54. });
  55. q.queue('ent0', 'foo', 'destroy', function() {
  56. ops.push('foo0destroy');
  57. });
  58. expect(ops).toEqual([]);
  59. q.resume();
  60. expect(ops).toEqual([ 'foo1add', 'foo1remove', 'foo0destroy' ]);
  61. });
  62. it('is cancelled out by an init in same entity+namespace', function() {
  63. var ops = [];
  64. var q = new RenderQueue();
  65. q.pause();
  66. q.queue('ent0', 'bar', 'init', function() {
  67. ops.push('barinit');
  68. });
  69. q.queue('ent0', 'foo', 'init', function() {
  70. ops.push('fooinit');
  71. });
  72. q.queue('ent0', 'foo', 'add', function() {
  73. ops.push('fooadd');
  74. });
  75. q.queue('ent0', 'foo', 'remove', function() {
  76. ops.push('fooadd');
  77. });
  78. q.queue('ent0', 'foo', 'destroy', function() {
  79. ops.push('fooadd');
  80. });
  81. expect(ops).toEqual([]);
  82. q.resume();
  83. expect(ops).toEqual([ 'barinit' ]);
  84. });
  85. });
  86. });
  87. describe('when namespace has a wait value', function() {
  88. it('unpauses when done', function(done) {
  89. var ops = [];
  90. var q = new RenderQueue({
  91. foo: 100
  92. });
  93. q.queue('ent0', 'foo', 'init', function() {
  94. ops.push('fooinit');
  95. });
  96. q.queue('ent0', 'foo', 'add', function() {
  97. ops.push('fooadd');
  98. });
  99. expect(ops).toEqual([]);
  100. setTimeout(function() {
  101. expect(ops).toEqual([ 'fooinit', 'fooadd' ]);
  102. done();
  103. }, 200);
  104. });
  105. it('restarts timer when new operation happens', function(done) {
  106. var ops = [];
  107. var q = new RenderQueue({
  108. foo: 100
  109. });
  110. q.queue('ent0', 'foo', 'init', function() {
  111. ops.push('fooinit');
  112. });
  113. setTimeout(function() {
  114. q.queue('ent0', 'foo', 'add', function() {
  115. ops.push('fooadd');
  116. });
  117. }, 50);
  118. setTimeout(function() {
  119. expect(ops).toEqual([]);
  120. }, 125);
  121. setTimeout(function() {
  122. expect(ops).toEqual([ 'fooinit', 'fooadd' ]);
  123. done();
  124. }, 175);
  125. });
  126. it('causes waiting tasks to delay subsequent non-waiting tasks', function(done) {
  127. var ops = [];
  128. var q = new RenderQueue({
  129. foo: 100
  130. });
  131. q.queue('ent0', 'foo', 'init', function() {
  132. ops.push('fooinit');
  133. });
  134. q.queue('ent0', 'foo', 'add', function() {
  135. ops.push('fooadd');
  136. });
  137. expect(ops).toEqual([]);
  138. q.queue('ent0', 'bar', 'init', function() {
  139. ops.push('barinit');
  140. });
  141. expect(ops).toEqual([]);
  142. setTimeout(function() {
  143. expect(ops).toEqual([ 'fooinit', 'fooadd', 'barinit' ]);
  144. done();
  145. }, 125);
  146. });
  147. it('causes waiting tasks to ignore subsequent waiting tasks\' timeouts', function(done) {
  148. var ops = [];
  149. var q = new RenderQueue({
  150. foo: 100,
  151. bar: 1000
  152. });
  153. q.queue('ent0', 'foo', 'init', function() {
  154. ops.push('fooinit');
  155. });
  156. q.queue('ent0', 'foo', 'add', function() {
  157. ops.push('fooadd');
  158. });
  159. expect(ops).toEqual([]);
  160. q.queue('ent0', 'bar', 'init', function() {
  161. ops.push('barinit');
  162. });
  163. expect(ops).toEqual([]);
  164. setTimeout(function() {
  165. expect(ops).toEqual([ 'fooinit', 'fooadd', 'barinit' ]);
  166. done();
  167. }, 125);
  168. });
  169. it('resumes non-waiting tasks when unpaused', function(done) {
  170. var ops = [];
  171. var q = new RenderQueue({
  172. foo: 100
  173. });
  174. q.pause();
  175. q.queue('ent0', 'bar', 'init', function() {
  176. ops.push('barinit');
  177. });
  178. q.queue('ent0', 'foo', 'init', function() {
  179. ops.push('fooinit');
  180. });
  181. q.resume();
  182. expect(ops).toEqual([ 'barinit' ]);
  183. setTimeout(function() {
  184. expect(ops).toEqual([ 'barinit', 'fooinit' ]);
  185. done();
  186. }, 200);
  187. });
  188. });
  189. });