diff options
Diffstat (limited to 'packages/kadira-flow-router/test/common/router.path.spec.js')
-rw-r--r-- | packages/kadira-flow-router/test/common/router.path.spec.js | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/packages/kadira-flow-router/test/common/router.path.spec.js b/packages/kadira-flow-router/test/common/router.path.spec.js new file mode 100644 index 00000000..92f0881e --- /dev/null +++ b/packages/kadira-flow-router/test/common/router.path.spec.js @@ -0,0 +1,135 @@ +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); +}); |