router.subs_ready.spec.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. Tinytest.addAsync('Client - Router - subsReady - with no args - all subscriptions ready', function (test, next) {
  2. var rand = Random.id();
  3. FlowRouter.route('/' + rand, {
  4. subscriptions: function(params) {
  5. this.register('bar', Meteor.subscribe('bar'));
  6. this.register('foo', Meteor.subscribe('foo'));
  7. }
  8. });
  9. FlowRouter.subscriptions = function () {
  10. this.register('baz', Meteor.subscribe('baz'));
  11. };
  12. FlowRouter.go('/' + rand);
  13. Tracker.autorun(function(c) {
  14. if(FlowRouter.subsReady()) {
  15. FlowRouter.subscriptions = Function.prototype;
  16. next();
  17. c.stop();
  18. }
  19. });
  20. });
  21. Tinytest.addAsync('Client - Router - subsReady - with no args - all subscriptions does not ready', function (test, next) {
  22. var rand = Random.id();
  23. FlowRouter.route('/' + rand, {
  24. subscriptions: function(params) {
  25. this.register('fooNotReady', Meteor.subscribe('fooNotReady'));
  26. }
  27. });
  28. FlowRouter.subscriptions = function () {
  29. this.register('bazNotReady', Meteor.subscribe('bazNotReady'));
  30. };
  31. FlowRouter.go('/' + rand);
  32. setTimeout(function() {
  33. test.isTrue(!FlowRouter.subsReady());
  34. FlowRouter.subscriptions = Function.prototype;
  35. next();
  36. }, 100);
  37. });
  38. Tinytest.addAsync('Client - Router - subsReady - with no args - global subscriptions does not ready', function (test, next) {
  39. var rand = Random.id();
  40. FlowRouter.route('/' + rand, {
  41. subscriptions: function(params) {
  42. this.register('bar', Meteor.subscribe('bar'));
  43. this.register('foo', Meteor.subscribe('foo'));
  44. }
  45. });
  46. FlowRouter.subscriptions = function () {
  47. this.register('bazNotReady', Meteor.subscribe('bazNotReady'));
  48. };
  49. FlowRouter.go('/' + rand);
  50. setTimeout(function() {
  51. test.isTrue(!FlowRouter.subsReady());
  52. FlowRouter.subscriptions = Function.prototype;
  53. next();
  54. }, 100);
  55. });
  56. Tinytest.addAsync('Client - Router - subsReady - with no args - current subscriptions does not ready', function (test, next) {
  57. var rand = Random.id();
  58. FlowRouter.route('/' + rand, {
  59. subscriptions: function(params) {
  60. this.register('bar', Meteor.subscribe('bar'));
  61. this.register('fooNotReady', Meteor.subscribe('fooNotReady'));
  62. }
  63. });
  64. FlowRouter.subscriptions = function () {
  65. this.register('baz', Meteor.subscribe('baz'));
  66. };
  67. FlowRouter.go('/' + rand);
  68. setTimeout(function() {
  69. test.isTrue(!FlowRouter.subsReady());
  70. FlowRouter.subscriptions = Function.prototype;
  71. next();
  72. }, 100);
  73. });
  74. Tinytest.addAsync('Client - Router - subsReady - with args - all subscriptions ready', function (test, next) {
  75. var rand = Random.id();
  76. FlowRouter.route('/' + rand, {
  77. subscriptions: function(params) {
  78. this.register('bar', Meteor.subscribe('bar'));
  79. this.register('foo', Meteor.subscribe('foo'));
  80. }
  81. });
  82. FlowRouter.subscriptions = function () {
  83. this.register('baz', Meteor.subscribe('baz'));
  84. };
  85. FlowRouter.go('/' + rand);
  86. Tracker.autorun(function(c) {
  87. if(FlowRouter.subsReady('foo', 'baz')) {
  88. FlowRouter.subscriptions = Function.prototype;
  89. next();
  90. c.stop();
  91. }
  92. });
  93. });
  94. Tinytest.addAsync('Client - Router - subsReady - with args - all subscriptions does not ready', function (test, next) {
  95. var rand = Random.id();
  96. FlowRouter.route('/' + rand, {
  97. subscriptions: function(params) {
  98. this.register('fooNotReady', Meteor.subscribe('fooNotReady'));
  99. }
  100. });
  101. FlowRouter.subscriptions = function () {
  102. this.register('bazNotReady', Meteor.subscribe('bazNotReady'));
  103. };
  104. FlowRouter.go('/' + rand);
  105. setTimeout(function() {
  106. test.isTrue(!FlowRouter.subsReady('fooNotReady', 'bazNotReady'));
  107. FlowRouter.subscriptions = Function.prototype;
  108. next();
  109. }, 100);
  110. });
  111. Tinytest.addAsync('Client - Router - subsReady - with args - global subscriptions does not ready', function (test, next) {
  112. var rand = Random.id();
  113. FlowRouter.route('/' + rand, {
  114. subscriptions: function(params) {
  115. this.register('bar', Meteor.subscribe('bar'));
  116. this.register('foo', Meteor.subscribe('foo'));
  117. }
  118. });
  119. FlowRouter.subscriptions = function () {
  120. this.register('bazNotReady', Meteor.subscribe('bazNotReady'));
  121. };
  122. FlowRouter.go('/' + rand);
  123. setTimeout(function() {
  124. test.isTrue(!FlowRouter.subsReady('foo', 'bazNotReady'));
  125. FlowRouter.subscriptions = Function.prototype;
  126. next();
  127. }, 100);
  128. });
  129. Tinytest.addAsync('Client - Router - subsReady - with args - current subscriptions does not ready', function (test, next) {
  130. var rand = Random.id();
  131. FlowRouter.route('/' + rand, {
  132. subscriptions: function(params) {
  133. this.register('bar', Meteor.subscribe('bar'));
  134. this.register('fooNotReady', Meteor.subscribe('fooNotReady'));
  135. }
  136. });
  137. FlowRouter.subscriptions = function () {
  138. this.register('baz', Meteor.subscribe('baz'));
  139. };
  140. FlowRouter.go('/' + rand);
  141. setTimeout(function() {
  142. test.isTrue(!FlowRouter.subsReady('fooNotReady', 'baz'));
  143. FlowRouter.subscriptions = Function.prototype;
  144. next();
  145. }, 100);
  146. });
  147. Tinytest.addAsync('Client - Router - subsReady - with args - subscribe with wrong name', function (test, next) {
  148. var rand = Random.id();
  149. FlowRouter.route('/' + rand, {
  150. subscriptions: function(params) {
  151. this.register('bar', Meteor.subscribe('bar'));
  152. }
  153. });
  154. FlowRouter.subscriptions = function () {
  155. this.register('baz', Meteor.subscribe('baz'));
  156. };
  157. FlowRouter.go('/' + rand);
  158. setTimeout(function() {
  159. test.isTrue(!FlowRouter.subsReady('baz', 'xxx', 'baz'));
  160. FlowRouter.subscriptions = Function.prototype;
  161. next();
  162. }, 100);
  163. });
  164. Tinytest.addAsync('Client - Router - subsReady - with args - same route two different subs', function (test, next) {
  165. var rand = Random.id();
  166. var count = 0;
  167. FlowRouter.route('/' + rand, {
  168. subscriptions: function(params) {
  169. if(++count == 1) {
  170. this.register('not-exisitng', Meteor.subscribe('not-exisitng'));
  171. }
  172. }
  173. });
  174. FlowRouter.subscriptions = Function.prototype;
  175. FlowRouter.go('/' + rand);
  176. setTimeout(function() {
  177. test.isFalse(FlowRouter.subsReady());
  178. FlowRouter.go('/' + rand, {}, {param: "111"});
  179. setTimeout(function() {
  180. test.isTrue(FlowRouter.subsReady());
  181. next();
  182. }, 100)
  183. }, 100);
  184. });
  185. Tinytest.addAsync('Client - Router - subsReady - no subscriptions - simple', function (test, next) {
  186. var rand = Random.id();
  187. FlowRouter.route('/' + rand, {});
  188. FlowRouter.subscriptions = Function.prototype;
  189. FlowRouter.go('/' + rand);
  190. setTimeout(function() {
  191. test.isTrue(FlowRouter.subsReady());
  192. next();
  193. }, 100);
  194. });