2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00
books/tests/test_router.js

30 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-01-16 06:09:17 +00:00
const Router = require('frappejs/common/router');
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-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-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-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');
});
});