Skip to content

Commit

Permalink
add redirect to test
Browse files Browse the repository at this point in the history
  • Loading branch information
cedvdb committed Oct 3, 2024
1 parent b2a0df7 commit e03887c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5492,6 +5492,11 @@ void main() {
builder: (BuildContext context, GoRouterState state) =>
const Text('/grand-child-route'),
),
GoRoute(
path: 'redirected-grand-child-route',
redirect: (BuildContext context, GoRouterState state) =>
'/child-route',
),
],
)
],
Expand All @@ -5500,10 +5505,17 @@ void main() {

final GoRouter router = await createRouter(routes, tester,
initialLocation: '/child-route/grand-child-route');
final RouteMatchList matches = router.routerDelegate.currentConfiguration;
RouteMatchList matches = router.routerDelegate.currentConfiguration;
expect(matches.matches, hasLength(3));
expect(matches.uri.toString(), '/child-route/grand-child-route');
expect(find.text('/grand-child-route'), findsOneWidget);

router.go('/child-route/redirected-grand-child-route');
await tester.pumpAndSettle();
matches = router.routerDelegate.currentConfiguration;
expect(matches.matches, hasLength(2));
expect(matches.uri.toString(), '/child-route');
expect(find.text('/child-route'), findsOneWidget);
});

testWidgets('should allow route paths with leading /',
Expand All @@ -5524,6 +5536,11 @@ void main() {
builder: (BuildContext context, GoRouterState state) =>
const Text('/grand-child-route'),
),
GoRoute(
path: '/redirected-grand-child-route',
redirect: (BuildContext context, GoRouterState state) =>
'/child-route',
),
],
)
],
Expand All @@ -5532,10 +5549,17 @@ void main() {

final GoRouter router = await createRouter(routes, tester,
initialLocation: '/child-route/grand-child-route');
final RouteMatchList matches = router.routerDelegate.currentConfiguration;
RouteMatchList matches = router.routerDelegate.currentConfiguration;
expect(matches.matches, hasLength(3));
expect(matches.uri.toString(), '/child-route/grand-child-route');
expect(find.text('/grand-child-route'), findsOneWidget);

router.go('/child-route/redirected-grand-child-route');
await tester.pumpAndSettle();
matches = router.routerDelegate.currentConfiguration;
expect(matches.matches, hasLength(2));
expect(matches.uri.toString(), '/child-route');
expect(find.text('/child-route'), findsOneWidget);
});
}

Expand Down

0 comments on commit e03887c

Please sign in to comment.