2018-01-16 06:09:17 +00:00
|
|
|
const Router = require('frappejs/common/router');
|
2018-01-15 11:55:31 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
describe('Router', () => {
|
2018-02-21 09:43:21 +00:00
|
|
|
it('router should sort static routes', () => {
|
|
|
|
let router = new Router();
|
|
|
|
router.add('/a', 'x');
|
|
|
|
router.add('/a/b', 'y');
|
|
|
|
router.add('/a/b/clong/', 'z');
|
2018-01-15 11:55:31 +00:00
|
|
|
|
2018-02-21 09:43:21 +00:00
|
|
|
assert.equal(router.match('/a/b').handler, 'y');
|
|
|
|
assert.equal(router.match('/a').handler, 'x');
|
|
|
|
assert.equal(router.match('/a/b/clong/').handler, 'z');
|
|
|
|
});
|
2018-01-15 11:55:31 +00:00
|
|
|
|
2018-02-21 09:43:21 +00:00
|
|
|
it('router should sort dynamic routes', () => {
|
|
|
|
let router = new Router();
|
|
|
|
router.add('/edit/:doctype', 'catch');
|
|
|
|
router.add('/edit/:doctype/:name', 'all');
|
|
|
|
router.add('/edit/ToDo/:name', 'ToDo');
|
|
|
|
router.add('/edit/ToDo/mytest', 'static');
|
2018-01-15 11:55:31 +00:00
|
|
|
|
2018-02-21 09:43:21 +00:00
|
|
|
assert.equal(router.match('/edit/ToDo/test').handler, 'ToDo');
|
|
|
|
assert.equal(router.match('/edit/user/test').handler, 'all');
|
|
|
|
assert.equal(router.match('/edit/ToDo/mytest').handler, 'static');
|
|
|
|
assert.equal(router.match('/edit/user').handler, 'catch');
|
|
|
|
});
|
2018-01-15 11:55:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
});
|