From 1e93d91bfc68a49344406ce04e05893481b15bf9 Mon Sep 17 00:00:00 2001 From: Jonathan Daniels Date: Thu, 28 Apr 2022 10:37:53 -0700 Subject: [PATCH] test: added test for barrier dismiss on tap --- .../view/character_selection_page_test.dart | 65 ++++++++++++++----- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/test/select_character/view/character_selection_page_test.dart b/test/select_character/view/character_selection_page_test.dart index 48179f34..90ac509d 100644 --- a/test/select_character/view/character_selection_page_test.dart +++ b/test/select_character/view/character_selection_page_test.dart @@ -86,22 +86,55 @@ void main() { .called(1); }); - testWidgets( - 'displays how to play dialog for 3 seconds when start is tapped', - (tester) async { - await tester.pumpApp( - CharacterSelectionView(), - characterThemeCubit: characterThemeCubit, - ); - await tester.ensureVisible(find.byType(TextButton)); - await tester.tap(find.byType(TextButton)); - await tester.pumpAndSettle(); - expect(find.byType(HowToPlayDialog), findsOneWidget); - await tester.pump(Duration(seconds: 3)); - await tester.pumpAndSettle(); - expect(find.byType(HowToPlayDialog), findsNothing); - }, - ); + group('HowToPlayDialog', () { + testWidgets( + 'is displayed for 3 seconds when start is tapped', + (tester) async { + await tester.pumpApp( + CharacterSelectionView(), + characterThemeCubit: characterThemeCubit, + ); + await tester.ensureVisible(find.byType(TextButton)); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + expect(find.byType(HowToPlayDialog), findsOneWidget); + await tester.pump(Duration(seconds: 3)); + await tester.pumpAndSettle(); + expect(find.byType(HowToPlayDialog), findsNothing); + }, + ); + + testWidgets( + 'can be dismissed manually before 3 seconds have passed', + (tester) async { + await tester.pumpApp( + Scaffold( + body: Builder( + builder: (context) { + return ElevatedButton( + onPressed: () { + Navigator.of(context) + .push(CharacterSelectionDialog.route()); + }, + child: Text('Tap me'), + ); + }, + ), + ), + characterThemeCubit: characterThemeCubit, + ); + await tester.tap(find.text('Tap me')); + await tester.pumpAndSettle(); + await tester.ensureVisible(find.byType(TextButton)); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + expect(find.byType(HowToPlayDialog), findsOneWidget); + await tester.tapAt(Offset(1, 1)); + await tester.pumpAndSettle(); + expect(find.byType(HowToPlayDialog), findsNothing); + }, + ); + }); }); testWidgets('CharacterImageButton renders correctly', (tester) async {