-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cca7de
commit 0f4c556
Showing
4 changed files
with
107 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; | ||
|
||
void main() { | ||
testWidgets('Should update pages when notifier changes', | ||
(WidgetTester tester) async { | ||
final pageListBuilderNotifier = ValueNotifier((BuildContext _) => [ | ||
WoltModalSheetPage( | ||
child: const Text('Initial Page'), | ||
), | ||
]); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Builder(builder: (context) { | ||
final NavigatorState navigator = Navigator.of(context); | ||
return WoltModalSheet( | ||
pageListBuilderNotifier: pageListBuilderNotifier, | ||
pageIndexNotifier: ValueNotifier(0), | ||
onModalDismissedWithBarrierTap: () {}, | ||
onModalDismissedWithDrag: () {}, | ||
pageContentDecorator: null, | ||
modalDecorator: null, | ||
modalTypeBuilder: (_) => WoltModalType.bottomSheet(), | ||
transitionAnimationController: null, | ||
route: WoltModalSheetRoute<void>( | ||
pageListBuilderNotifier: pageListBuilderNotifier, | ||
transitionAnimationController: | ||
AnimationController(vsync: navigator), | ||
barrierDismissible: true, | ||
), | ||
enableDrag: null, | ||
showDragHandle: null, | ||
useSafeArea: false, | ||
); | ||
}), | ||
), | ||
); | ||
|
||
// Initial state check. | ||
expect(find.text('Initial Page'), findsOneWidget); | ||
|
||
// Update the notifier. | ||
pageListBuilderNotifier.value = (_) => [ | ||
WoltModalSheetPage(child: const Text('Updated Page')), | ||
]; | ||
|
||
// Trigger the listener. | ||
pageListBuilderNotifier.notifyListeners(); | ||
await tester.pumpAndSettle(); | ||
|
||
// Check if the UI is updated. | ||
expect(find.text('Updated Page'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('Listener should be removed on dispose', | ||
(WidgetTester tester) async { | ||
final pageListBuilderNotifier = ValueNotifier((_) => [ | ||
WoltModalSheetPage(child: const Text('Initial Page')), | ||
]); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Builder(builder: (context) { | ||
final NavigatorState navigator = Navigator.of(context); | ||
return WoltModalSheet( | ||
pageListBuilderNotifier: pageListBuilderNotifier, | ||
pageIndexNotifier: ValueNotifier(0), | ||
onModalDismissedWithBarrierTap: () {}, | ||
onModalDismissedWithDrag: () {}, | ||
pageContentDecorator: null, | ||
modalDecorator: null, | ||
modalTypeBuilder: (_) => WoltModalType.bottomSheet(), | ||
transitionAnimationController: null, | ||
route: WoltModalSheetRoute<void>( | ||
pageListBuilderNotifier: pageListBuilderNotifier, | ||
transitionAnimationController: | ||
AnimationController(vsync: navigator), | ||
barrierDismissible: true, | ||
), | ||
enableDrag: null, | ||
showDragHandle: null, | ||
useSafeArea: false, | ||
); | ||
}), | ||
), | ||
); | ||
|
||
// Update the notifier after the widget is disposed. | ||
await tester.pumpWidget(Container()); // Dispose the widget. | ||
pageListBuilderNotifier.value = (_) => [ | ||
WoltModalSheetPage(child: const Text('Should Not Update')), | ||
]; | ||
|
||
// Trigger the listener. | ||
pageListBuilderNotifier.notifyListeners(); | ||
await tester.pumpAndSettle(); | ||
|
||
// Since the widget is disposed, this text should not be found. | ||
expect(find.text('Should Not Update'), findsNothing); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters