| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 | 
							- Tinytest.addAsync('Client - Triggers - global enter triggers', function(test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var paths = ['/' + rand2, '/' + rand];
 
-   var done = false;
 
-   FlowRouter.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.triggers.enter([function(context) {
 
-     if(done) return;
 
-     test.equal(context.path, paths.pop());
 
-     log.push(0);
 
-   }]);
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       test.equal(log, [0, 1, 0, 2]);
 
-       done = true;
 
-       setTimeout(next, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - global enter triggers with "only"', function (test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var done = false;
 
-   FlowRouter.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     name: 'foo',
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.triggers.enter([function(context) {
 
-     if(done) return;
 
-     test.equal(context.path, '/' + rand2);
 
-     log.push(8);
 
-   }], {only: ['foo']});
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       test.equal(log, [1, 8, 2]);
 
-       done = true;
 
-       setTimeout(next, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - global enter triggers with "except"', function (test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var done = false;
 
-   FlowRouter.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     name: 'foo',
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.triggers.enter([function(context) {
 
-     if(done) return;
 
-     test.equal(context.path, '/' + rand);
 
-     log.push(8);
 
-   }], {except: ['foo']});
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       test.equal(log, [8, 1, 2]);
 
-       done = true;
 
-       setTimeout(next, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - global exit triggers', function (test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var done =false;
 
-   FlowRouter.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.go('/' + rand);
 
-   FlowRouter.triggers.exit([function(context) {
 
-     if(done) return;
 
-     test.equal(context.path, '/' + rand);
 
-     log.push(0);
 
-   }]);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       test.equal(log, [1, 0, 2]);
 
-       done = true;
 
-       setTimeout(next, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - global exit triggers with "only"', function (test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var done = false;
 
-   FlowRouter.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     name: 'foo',
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.triggers.exit([function(context) {
 
-     if(done) return;
 
-     test.equal(context.path, '/' + rand2);
 
-     log.push(8);
 
-   }], {only: ['foo']});
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       FlowRouter.go('/' + rand);
 
-       setTimeout(function() {
 
-         test.equal(log, [1, 2, 8, 1]);
 
-         done = true;
 
-         setTimeout(next, 100);
 
-       }, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - global exit triggers with "except"', function (test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var done = false;
 
-   FlowRouter.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     name: 'foo',
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.go('/' + rand);
 
-   FlowRouter.triggers.exit([function(context) {
 
-     if(done) return;
 
-     test.equal(context.path, '/' + rand);
 
-     log.push(9);
 
-   }], {except: ['foo']});
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       FlowRouter.go('/' + rand);
 
-       setTimeout(function() {
 
-         test.equal(log, [1, 9, 2, 1]);
 
-         done = true;
 
-         setTimeout(next, 100);
 
-       }, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - route enter triggers', function (test, next) {
 
-   var rand = Random.id();
 
-   var log = [];
 
-   var triggerFn = function (context) {
 
-     test.equal(context.path, '/' + rand);
 
-     log.push(5);
 
-   };
 
-   FlowRouter.route('/' + rand, {
 
-     triggersEnter: [triggerFn],
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     test.equal(log, [5, 1]);
 
-     setTimeout(next, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - router exit triggers', function (test, next) {
 
-   var rand = Random.id();
 
-   var log = [];
 
-   var triggerFn = function (context) {
 
-     test.equal(context.path, '/' + rand);
 
-     log.push(6);
 
-   };
 
-   FlowRouter.route('/' + rand, {
 
-     triggersExit: [triggerFn],
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + Random.id());
 
-     setTimeout(function() {
 
-       test.equal(log, [1, 6]);
 
-       setTimeout(next, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - group enter triggers', function (test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var paths = ['/' + rand2, '/' + rand];
 
-   var triggerFn = function (context) {
 
-     test.equal(context.path, paths.pop());
 
-     log.push(3);
 
-   };
 
-   var group = FlowRouter.group({
 
-     triggersEnter: [triggerFn]
 
-   });
 
-   group.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   group.route('/' + rand2, {
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       test.equal(log, [3, 1, 3, 2]);
 
-       setTimeout(next, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - group exit triggers', function (test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var triggerFn = function (context) {
 
-     log.push(4);
 
-   };
 
-   var group = FlowRouter.group({
 
-     triggersExit: [triggerFn]
 
-   });
 
-   group.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   group.route('/' + rand2, {
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       test.equal(log, [1, 4, 2]);
 
-       setTimeout(next, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - redirect from enter', function(test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   FlowRouter.route('/' + rand, {
 
-     triggersEnter: [function(context, redirect) {
 
-       redirect("/" + rand2);
 
-     }, function() {
 
-       throw new Error("should not execute this trigger");
 
-     }],
 
-     action: function(_params) {
 
-       log.push(1);
 
-     },
 
-     name: rand
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     action: function(_params) {
 
-       log.push(2);
 
-     },
 
-     name: rand2
 
-   });
 
-   FlowRouter.go('/');
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     test.equal(log, [2]);
 
-     next();
 
-   }, 300);
 
- });
 
- Tinytest.addAsync('Client - Triggers - redirect by routeName', function(test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   FlowRouter.route('/' + rand, {
 
-     name: rand,
 
-     triggersEnter: [function(context, redirect) {
 
-       redirect(rand2, null, {aa: "bb"});
 
-     }, function() {
 
-       throw new Error("should not execute this trigger");
 
-     }],
 
-     action: function(_params) {
 
-       log.push(1);
 
-     },
 
-     name: rand
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     name: rand2,
 
-     action: function(_params, queryParams) {
 
-       log.push(2);
 
-       test.equal(queryParams, {aa: "bb"});
 
-     },
 
-     name: rand2
 
-   });
 
-   FlowRouter.go('/');
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     test.equal(log, [2]);
 
-     next();
 
-   }, 300);
 
- });
 
- Tinytest.addAsync('Client - Triggers - redirect from exit', function(test, next) {
 
-   var rand = Random.id(), rand2 = Random.id(), rand3 = Random.id();
 
-   var log = [];
 
-   FlowRouter.route('/' + rand, {
 
-     action: function() {
 
-       log.push(1);
 
-     },
 
-     triggersExit: [
 
-       function(context, redirect) {
 
-         redirect('/' + rand3);
 
-       },
 
-       function() {
 
-         throw new Error("should not call this trigger");
 
-       }
 
-     ]
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     action: function() {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.route('/' + rand3, {
 
-     action: function() {
 
-       log.push(3);
 
-     }
 
-   });
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     
 
-     setTimeout(function() {
 
-       test.equal(log, [1, 3]);
 
-       next();
 
-     }, 100);
 
-   }, 100);
 
- });
 
- Tinytest.addAsync('Client - Triggers - redirect to external URL fails', function(test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   // testing "http://" URLs
 
-   FlowRouter.route('/' + rand, {
 
-     triggersEnter: [function(context, redirect) {
 
-       test.throws(function() {
 
-           redirect("http://example.com/")
 
-       }, "Redirects to URLs outside of the app are not supported")
 
-     }],
 
-     action: function(_params) {
 
-       log.push(1);
 
-     },
 
-     name: rand
 
-   });
 
-   // testing "https://" URLs
 
-   FlowRouter.route('/' + rand2, {
 
-     triggersEnter: [function(context, redirect) {
 
-       test.throws(function() {
 
-           redirect("https://example.com/")
 
-       })
 
-     }],
 
-     action: function(_params) {
 
-       log.push(2);
 
-     },
 
-     name: rand2
 
-   });
 
-   FlowRouter.go('/');
 
-   FlowRouter.go('/' + rand);
 
-   FlowRouter.go('/' + rand2);
 
-   setTimeout(function() {
 
-     test.equal(log, []);
 
-     next();
 
-   }, 300);
 
- });
 
- Tinytest.addAsync('Client - Triggers - stop callback from enter', function(test, next) {
 
-   var rand = Random.id();
 
-   var log = [];
 
-   FlowRouter.route('/' + rand, {
 
-     triggersEnter: [function(context, redirect, stop) {
 
-       log.push(10);
 
-       stop();
 
-     }, function() {
 
-       throw new Error("should not execute this trigger");
 
-     }],
 
-     action: function(_params) {
 
-       throw new Error("should not execute the action");
 
-     }
 
-   });
 
-   FlowRouter.go('/');
 
-   FlowRouter.go('/' + rand);
 
-   setTimeout(function() {
 
-     test.equal(log, [10]);
 
-     next();
 
-   }, 100);
 
- });
 
- Tinytest.addAsync(
 
- 'Client - Triggers - invalidate inside an autorun', 
 
- function(test, next) {
 
-   var rand = Random.id(), rand2 = Random.id();
 
-   var log = [];
 
-   var paths = ['/' + rand2, '/' + rand];
 
-   var done = false;
 
-   FlowRouter.route('/' + rand, {
 
-     action: function(_params) {
 
-       log.push(1);
 
-     }
 
-   });
 
-   FlowRouter.route('/' + rand2, {
 
-     action: function(_params) {
 
-       log.push(2);
 
-     }
 
-   });
 
-   FlowRouter.triggers.enter([function(context) {
 
-     if(done) return;
 
-     test.equal(context.path, paths.pop());
 
-     log.push(0);
 
-   }]);
 
-   Tracker.autorun(function(c) {
 
-     FlowRouter.go('/' + rand);
 
-   });
 
-   setTimeout(function() {
 
-     FlowRouter.go('/' + rand2);
 
-     setTimeout(function() {
 
-       test.equal(log, [0, 1, 0, 2]);
 
-       done = true;
 
-       setTimeout(next, 100);
 
-     }, 100);
 
-   }, 100);
 
- });
 
 
  |