123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- Router = FlowRouter.Router;
- Tinytest.addAsync('Common - Router - validate path definition', function (test, next) {
- // path must start with '/'
- try {
- FlowRouter.route(Random.id());
- } catch(ex) {
- next();
- }
- });
- Tinytest.add('Common - Router - path - generic', function (test) {
- var pathDef = "/blog/:blogId/some/:name";
- var fields = {
- blogId: "1001",
- name: "superb"
- };
- var expectedPath = "/blog/1001/some/superb";
- var path = FlowRouter.path(pathDef, fields);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - queryParams', function (test) {
- var pathDef = "/blog/:blogId/some/:name";
- var fields = {
- blogId: "1001",
- name: "superb"
- };
- var queryParams = {
- aa: "100",
- bb: "200"
- };
- var expectedPath = "/blog/1001/some/superb?aa=100&bb=200";
- var path = FlowRouter.path(pathDef, fields, queryParams);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - just queryParams', function (test) {
- var pathDef = "/blog/abc";
- var queryParams = {
- aa: "100",
- bb: "200"
- };
- var expectedPath = "/blog/abc?aa=100&bb=200";
- var path = FlowRouter.path(pathDef, null, queryParams);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - missing fields', function (test) {
- var pathDef = "/blog/:blogId/some/:name";
- var fields = {
- blogId: "1001",
- };
- var expectedPath = "/blog/1001/some";
- var path = FlowRouter.path(pathDef, fields);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - no fields', function (test) {
- var pathDef = "/blog/blogId/some/name";
- var path = FlowRouter.path(pathDef);
- test.equal(path, pathDef);
- });
- Tinytest.add('Common - Router - path - complex route', function (test) {
- var pathDef = "/blog/:blogId/some/:name(\\d*)+";
- var fields = {
- blogId: "1001",
- name: 20
- };
- var expectedPath = "/blog/1001/some/20";
- var path = FlowRouter.path(pathDef, fields);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - optional last param missing', function (test) {
- var pathDef = "/blog/:blogId/some/:name?";
- var fields = {
- blogId: "1001"
- };
- var expectedPath = "/blog/1001/some";
- var path = FlowRouter.path(pathDef, fields);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - optional last param exists', function (test) {
- var pathDef = "/blog/:blogId/some/:name?";
- var fields = {
- blogId: "1001",
- name: 20
- };
- var expectedPath = "/blog/1001/some/20";
- var path = FlowRouter.path(pathDef, fields);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - remove trailing slashes', function (test) {
- var pathDef = "/blog/:blogId/some/:name//";
- var fields = {
- blogId: "1001",
- name: "superb"
- };
- var expectedPath = "/blog/1001/some/superb";
- var path = FlowRouter.path(pathDef, fields);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - handle multiple slashes', function (test) {
- var pathDef = "/blog///some/hi////";
- var expectedPath = "/blog/some/hi";
- var path = FlowRouter.path(pathDef);
- test.equal(path, expectedPath);
- });
- Tinytest.add('Common - Router - path - keep the root slash', function (test) {
- var pathDef = "/";
- var fields = {};
- var expectedPath = "/";
- var path = FlowRouter.path(pathDef, fields);
- test.equal(path, expectedPath);
- });
|