parser_test.dart 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * fluro
  3. * Created by Yakka
  4. * https://theyakka.com
  5. *
  6. * Copyright (c) 2019 Yakka, LLC. All rights reserved.
  7. * See LICENSE for distribution and usage details.
  8. */
  9. import 'package:flutter_test/flutter_test.dart';
  10. import 'package:fluro/fluro.dart';
  11. void main() {
  12. testWidgets("Router correctly parses named parameters",
  13. (WidgetTester tester) async {
  14. String path = "/users/1234";
  15. String route = "/users/:id";
  16. Router router = Router();
  17. router.define(route, handler: null);
  18. AppRouteMatch match = router.match(path);
  19. expect(
  20. match?.parameters,
  21. equals(<String, List<String>>{
  22. "id": ["1234"],
  23. }));
  24. });
  25. testWidgets("Router correctly parses named parameters with query",
  26. (WidgetTester tester) async {
  27. String path = "/users/1234?name=luke";
  28. String route = "/users/:id";
  29. Router router = Router();
  30. router.define(route, handler: null);
  31. AppRouteMatch match = router.match(path);
  32. expect(
  33. match?.parameters,
  34. equals(<String, List<String>>{
  35. "id": ["1234"],
  36. "name": ["luke"],
  37. }));
  38. });
  39. testWidgets("Router correctly parses query parameters",
  40. (WidgetTester tester) async {
  41. String path = "/users/create?name=luke&phrase=hello%20world&number=7";
  42. String route = "/users/create";
  43. Router router = Router();
  44. router.define(route, handler: null);
  45. AppRouteMatch match = router.match(path);
  46. expect(
  47. match?.parameters,
  48. equals(<String, List<String>>{
  49. "name": ["luke"],
  50. "phrase": ["hello world"],
  51. "number": ["7"],
  52. }));
  53. });
  54. testWidgets("Router correctly parses array parameters",
  55. (WidgetTester tester) async {
  56. String path =
  57. "/users/create?name=luke&phrase=hello%20world&number=7&number=10&number=13";
  58. String route = "/users/create";
  59. Router router = Router();
  60. router.define(route, handler: null);
  61. AppRouteMatch match = router.match(path);
  62. expect(
  63. match?.parameters,
  64. equals(<String, List<String>>{
  65. "name": ["luke"],
  66. "phrase": ["hello world"],
  67. "number": ["7", "10", "13"],
  68. }));
  69. });
  70. testWidgets("Router correctly matches route and transition type",
  71. (WidgetTester tester) async {
  72. String path = "/users/1234";
  73. String route = "/users/:id";
  74. Router router = Router();
  75. router.define(route,
  76. handler: null, transitionType: TransitionType.inFromRight);
  77. AppRouteMatch match = router.match(path);
  78. expect(TransitionType.inFromRight, match.route.transitionType);
  79. });
  80. }