platform/test/params_test.dart

44 lines
1.2 KiB
Dart
Raw Normal View History

2016-11-27 23:39:03 +00:00
import 'package:angel_route/angel_route.dart';
import 'package:test/test.dart';
main() {
2017-11-28 21:07:14 +00:00
final router = new Router()
2016-11-27 23:39:03 +00:00
..get('/hello', '')
..get('/user/:id', '');
router.group('/book/:id', (router) {
router.get('/reviews', '');
router.get('/readers/:readerId', '');
});
2017-11-28 21:07:14 +00:00
router.mount('/color', new Router()..get('/:name/shades', ''));
2016-11-27 23:39:03 +00:00
setUp(router.dumpTree);
void expectParams(String path, Map<String, dynamic> params) {
final p = {};
final resolved = router.resolveAll(path, path);
print('Resolved $path => ${resolved.map((r) => r.allParams).toList()}');
for (final result in resolved) p.addAll(result.allParams);
expect(p, equals(params));
}
group('top-level', () {
test('no params', () => expectParams('/hello', {}));
test('one param', () => expectParams('/user/0', {'id': '0'}));
});
group('group', () {
2017-10-08 22:44:11 +00:00
//test('root', () => expectParams('/book/1337', {'id': '1337'}));
2016-11-27 23:39:03 +00:00
test('path', () => expectParams('/book/1337/reviews', {'id': '1337'}));
test(
'two params',
() => expectParams(
'/book/1337/readers/foo', {'id': '1337', 'readerId': 'foo'}));
});
test('mount',
() => expectParams('/color/chartreuse/shades', {'name': 'chartreuse'}));
}