diff options
author | Lauri Ojansivu <x@xet7.org> | 2019-04-20 15:18:33 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2019-04-20 15:18:33 +0300 |
commit | 73e265d8fd050ae3daa67472b4465a5c49d68910 (patch) | |
tree | 677b233934a43d8f873e24c794ce289d85e3a9b7 /packages/kadira-flow-router/test/common | |
parent | 6117097a93bfb11c8bd4c87a23c44a50e22ceb87 (diff) | |
download | wekan-73e265d8fd050ae3daa67472b4465a5c49d68910.tar.gz wekan-73e265d8fd050ae3daa67472b4465a5c49d68910.tar.bz2 wekan-73e265d8fd050ae3daa67472b4465a5c49d68910.zip |
Include to Wekan packages directory contents, so that meteor command would build all directly.
This also simplifies build scripts.
Thanks to xet7 !
Diffstat (limited to 'packages/kadira-flow-router/test/common')
6 files changed, 255 insertions, 0 deletions
diff --git a/packages/kadira-flow-router/test/common/fast_render_route.js b/packages/kadira-flow-router/test/common/fast_render_route.js new file mode 100644 index 00000000..d56f1c06 --- /dev/null +++ b/packages/kadira-flow-router/test/common/fast_render_route.js @@ -0,0 +1,48 @@ +FastRenderColl = new Mongo.Collection('fast-render-coll'); + +FlowRouter.route('/the-fast-render-route', { + subscriptions: function() { + this.register('data', Meteor.subscribe('fast-render-data')); + } +}); + +FlowRouter.route('/the-fast-render-route-params/:id', { + subscriptions: function(params, queryParams) { + this.register('data', Meteor.subscribe('fast-render-data-params', params, queryParams)); + } +}); + +FlowRouter.route('/no-fast-render', { + subscriptions: function() { + if(Meteor.isClient) { + this.register('data', Meteor.subscribe('fast-render-data')); + } + } +}); + +var frGroup = FlowRouter.group({ + prefix: "/fr" +}); + +frGroup.route("/have-fr", { + subscriptions: function() { + this.register('data', Meteor.subscribe('fast-render-data')); + } +}); + +if(Meteor.isServer) { + if(!FastRenderColl.findOne()) { + FastRenderColl.insert({_id: "one", aa: 10}); + FastRenderColl.insert({_id: "two", aa: 20}); + } + + Meteor.publish('fast-render-data', function() { + return FastRenderColl.find({}, {sort: {aa: -1}}); + }); + + Meteor.publish('fast-render-data-params', function(params, queryParams) { + var fields = {params: params, queryParams: queryParams}; + this.added('fast-render-coll', 'one', fields); + this.ready(); + }); +}
\ No newline at end of file diff --git a/packages/kadira-flow-router/test/common/group.spec.js b/packages/kadira-flow-router/test/common/group.spec.js new file mode 100644 index 00000000..e6e799cb --- /dev/null +++ b/packages/kadira-flow-router/test/common/group.spec.js @@ -0,0 +1,16 @@ +Tinytest.add('Common - Group - expose group options', function (test) { + var pathDef = "/" + Random.id(); + var name = Random.id(); + var data = {aa: 10}; + var layout = 'blah'; + + var group = FlowRouter.group({ + name: name, + prefix: '/admin', + layout: layout, + someData: data + }); + + test.equal(group.options.someData, data); + test.equal(group.options.layout, layout); +}); diff --git a/packages/kadira-flow-router/test/common/route.spec.js b/packages/kadira-flow-router/test/common/route.spec.js new file mode 100644 index 00000000..9e4c7e5a --- /dev/null +++ b/packages/kadira-flow-router/test/common/route.spec.js @@ -0,0 +1,15 @@ +Router = FlowRouter.Router; + +Tinytest.addAsync('Common - Route - expose route options', function (test, next) { + var pathDef = "/" + Random.id(); + var name = Random.id(); + var data = {aa: 10}; + + FlowRouter.route(pathDef, { + name: name, + someData: data + }); + + test.equal(FlowRouter._routesMap[name].options.someData, data); + next(); +}); diff --git a/packages/kadira-flow-router/test/common/router.addons.spec.js b/packages/kadira-flow-router/test/common/router.addons.spec.js new file mode 100644 index 00000000..f5078734 --- /dev/null +++ b/packages/kadira-flow-router/test/common/router.addons.spec.js @@ -0,0 +1,30 @@ +Router = FlowRouter.Router; + +Tinytest.addAsync('Common - Addons - onRouteRegister basic usage', function (test, done) { + var name = Random.id(); + var customField = Random.id(); + var pathDef = '/' + name; + + FlowRouter.onRouteRegister(function(route) { + test.equal(route, { + pathDef: pathDef, + + // Route.path is deprecated and will be removed in 3.0 + path: pathDef, + + name: name, + options: {customField: customField} + }); + FlowRouter._onRouteCallbacks = []; + done(); + }); + + FlowRouter.route(pathDef, { + name: name, + action: function() {}, + subscriptions: function() {}, + triggersEnter: function() {}, + triggersExit: function() {}, + customField: customField + }); +}); 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); +}); diff --git a/packages/kadira-flow-router/test/common/router.url.spec.js b/packages/kadira-flow-router/test/common/router.url.spec.js new file mode 100644 index 00000000..0dbf4632 --- /dev/null +++ b/packages/kadira-flow-router/test/common/router.url.spec.js @@ -0,0 +1,11 @@ +Tinytest.add('Common - Router - url - generic', function (test) { + var pathDef = "/blog/:blogId/some/:name"; + var fields = { + blogId: "1001", + name: "superb" + }; + var expectedUrl = Meteor.absoluteUrl('blog/1001/some/superb'); + + var path = FlowRouter.url(pathDef, fields); + test.equal(path, expectedUrl); +}); |