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