Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gilder authored and Tom Gilder committed May 27, 2021
1 parent 4d06557 commit 8a7e37e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/routes_rebuild_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,38 @@ void main() {
expect(routeMap1UnknownRoutes.isEmpty, isTrue);
expect(routeMap2UnknownRoutes.isEmpty, isTrue);
});

testWidgets('Can swap route maps and navigate to the same path',
(tester) async {
final routeMap1 = RouteMap(routes: {'/': (_) => const MaterialPageOne()});
final routeMap2 = RouteMap(routes: {'/': (_) => const MaterialPageTwo()});

final delegate = RoutemasterDelegate(routesBuilder: (context) {
final state = StateProvider.of(context).state;
return state.someValue == '1' ? routeMap1 : routeMap2;
});
final state = AppState()..someValue = '1';

await tester.pumpWidget(
StateProvider(
state: state,
child: MaterialApp.router(
routeInformationParser: const RoutemasterParser(),
routerDelegate: delegate,
),
),
);

expect(find.byType(PageOne), findsOneWidget);

// Change state to swap to routeMap2
state.someValue = '2';
delegate.push('/');

await tester.pump();
await tester.pump();
expect(find.byType(PageTwo), findsOneWidget);
});
}

class AppState extends ChangeNotifier {
Expand Down

0 comments on commit 8a7e37e

Please sign in to comment.