2017-05-14 01:01:02 -04:00
|
|
|
/*
|
|
|
|
* fluro
|
2018-10-25 13:48:02 -04:00
|
|
|
* Created by Yakka
|
|
|
|
* https://theyakka.com
|
|
|
|
*
|
2019-06-19 19:28:28 -04:00
|
|
|
* Copyright (c) 2019 Yakka, LLC. All rights reserved.
|
2017-05-14 01:01:02 -04:00
|
|
|
* See LICENSE for distribution and usage details.
|
|
|
|
*/
|
2018-07-27 21:15:51 -04:00
|
|
|
|
2017-05-06 02:20:37 -04:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2017-05-14 00:55:44 -04:00
|
|
|
import 'package:fluro/fluro.dart';
|
2017-05-06 02:20:37 -04:00
|
|
|
|
|
|
|
void main() {
|
2018-07-27 21:15:51 -04:00
|
|
|
testWidgets("Router correctly parses named parameters",
|
|
|
|
(WidgetTester tester) async {
|
2017-05-06 02:20:37 -04:00
|
|
|
String path = "/users/1234";
|
|
|
|
String route = "/users/:id";
|
2019-07-17 23:19:56 -04:00
|
|
|
Router router = Router();
|
2017-05-06 02:20:37 -04:00
|
|
|
router.define(route, handler: null);
|
|
|
|
AppRouteMatch match = router.match(path);
|
2018-07-27 21:15:51 -04:00
|
|
|
expect(
|
|
|
|
match?.parameters,
|
|
|
|
equals(<String, List<String>>{
|
|
|
|
"id": ["1234"],
|
|
|
|
}));
|
2017-05-06 02:20:37 -04:00
|
|
|
});
|
|
|
|
|
2018-07-27 21:15:51 -04:00
|
|
|
testWidgets("Router correctly parses named parameters with query",
|
|
|
|
(WidgetTester tester) async {
|
2017-05-06 02:20:37 -04:00
|
|
|
String path = "/users/1234?name=luke";
|
|
|
|
String route = "/users/:id";
|
2019-07-17 23:19:56 -04:00
|
|
|
Router router = Router();
|
2017-05-06 02:20:37 -04:00
|
|
|
router.define(route, handler: null);
|
|
|
|
AppRouteMatch match = router.match(path);
|
2018-07-27 21:15:51 -04:00
|
|
|
expect(
|
|
|
|
match?.parameters,
|
|
|
|
equals(<String, List<String>>{
|
|
|
|
"id": ["1234"],
|
|
|
|
"name": ["luke"],
|
|
|
|
}));
|
2017-05-06 02:20:37 -04:00
|
|
|
});
|
|
|
|
|
2018-07-27 21:15:51 -04:00
|
|
|
testWidgets("Router correctly parses query parameters",
|
|
|
|
(WidgetTester tester) async {
|
2017-05-06 02:20:37 -04:00
|
|
|
String path = "/users/create?name=luke&phrase=hello%20world&number=7";
|
|
|
|
String route = "/users/create";
|
2019-07-17 23:19:56 -04:00
|
|
|
Router router = Router();
|
2017-05-06 02:20:37 -04:00
|
|
|
router.define(route, handler: null);
|
|
|
|
AppRouteMatch match = router.match(path);
|
2018-07-27 21:15:51 -04:00
|
|
|
expect(
|
|
|
|
match?.parameters,
|
|
|
|
equals(<String, List<String>>{
|
|
|
|
"name": ["luke"],
|
|
|
|
"phrase": ["hello world"],
|
|
|
|
"number": ["7"],
|
|
|
|
}));
|
2017-05-06 02:20:37 -04:00
|
|
|
});
|
|
|
|
|
2018-07-27 21:15:51 -04:00
|
|
|
testWidgets("Router correctly parses array parameters",
|
|
|
|
(WidgetTester tester) async {
|
|
|
|
String path =
|
|
|
|
"/users/create?name=luke&phrase=hello%20world&number=7&number=10&number=13";
|
2018-01-18 19:21:52 -05:00
|
|
|
String route = "/users/create";
|
2019-07-17 23:19:56 -04:00
|
|
|
Router router = Router();
|
2018-01-18 19:21:52 -05:00
|
|
|
router.define(route, handler: null);
|
|
|
|
AppRouteMatch match = router.match(path);
|
2018-07-27 21:15:51 -04:00
|
|
|
expect(
|
|
|
|
match?.parameters,
|
|
|
|
equals(<String, List<String>>{
|
|
|
|
"name": ["luke"],
|
|
|
|
"phrase": ["hello world"],
|
|
|
|
"number": ["7", "10", "13"],
|
|
|
|
}));
|
2018-01-18 19:21:52 -05:00
|
|
|
});
|
2018-12-13 16:53:54 -05:00
|
|
|
testWidgets("Router correctly matches route and transition type",
|
|
|
|
(WidgetTester tester) async {
|
|
|
|
String path = "/users/1234";
|
|
|
|
String route = "/users/:id";
|
2019-07-17 23:19:56 -04:00
|
|
|
Router router = Router();
|
2018-12-13 16:53:54 -05:00
|
|
|
router.define(route,
|
|
|
|
handler: null, transitionType: TransitionType.inFromRight);
|
|
|
|
AppRouteMatch match = router.match(path);
|
|
|
|
expect(TransitionType.inFromRight, match.route.transitionType);
|
|
|
|
});
|
2018-07-27 21:15:51 -04:00
|
|
|
}
|