platform/packages/route/test/navigate_test.dart

45 lines
932 B
Dart
Raw Normal View History

2016-11-25 23:22:33 +00:00
import 'package:angel_route/angel_route.dart';
import 'package:test/test.dart';
2021-02-21 02:47:23 +00:00
void main() {
2019-11-28 17:40:32 +00:00
final router = Router();
2016-11-25 23:22:33 +00:00
2017-11-27 02:21:19 +00:00
router.get('/', 'GET').name = 'root';
2016-11-25 23:22:33 +00:00
router.get('/user/:id', 'GET');
2017-11-27 02:21:19 +00:00
router.get('/first/:first/last/:last', 'GET').name = 'full_name';
2016-11-25 23:22:33 +00:00
2021-04-03 05:50:52 +00:00
String navigate(params) {
2018-08-20 18:59:51 +00:00
final uri = router.navigate(params as Iterable);
2016-11-25 23:22:33 +00:00
print('Uri: $uri');
return uri;
}
2017-11-27 02:21:19 +00:00
router.dumpTree();
2016-11-25 23:22:33 +00:00
group('top-level', () {
test('named', () {
expect(navigate(['root']), equals('/'));
});
test('params', () {
expect(
navigate([
'user/:id',
{'id': 1337}
]),
equals('/user/1337'));
expect(
navigate([
'full_name',
{'first': 'John', 'last': 'Smith'}
]),
equals('/first/John/last/Smith'));
});
test('root', () {
expect(navigate(['/']), equals('/'));
});
});
}