From 6858aef8fc165ba54125f4af8159812934ba47c4 Mon Sep 17 00:00:00 2001 From: Ravi Dev Pandey <62198564+literalEval@users.noreply.github.com> Date: Tue, 7 Feb 2023 22:17:13 +0530 Subject: [PATCH 1/3] Add tests for UserTasksPage (#1468) --- test/helpers/test_locator.dart | 2 + .../tasks/user_tasks_page_test.dart | 91 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 test/views/after_auth_screens/tasks/user_tasks_page_test.dart diff --git a/test/helpers/test_locator.dart b/test/helpers/test_locator.dart index e303d1730..9cc79db39 100644 --- a/test/helpers/test_locator.dart +++ b/test/helpers/test_locator.dart @@ -21,6 +21,7 @@ import 'package:talawa/view_model/after_auth_view_models/event_view_models/explo import 'package:talawa/view_model/after_auth_view_models/feed_view_models/organization_feed_view_model.dart'; import 'package:talawa/view_model/after_auth_view_models/profile_view_models/edit_profile_view_model.dart'; import 'package:talawa/view_model/after_auth_view_models/profile_view_models/profile_page_view_model.dart'; +import 'package:talawa/view_model/after_auth_view_models/task_view_models/explore_tasks_view_model.dart'; import 'package:talawa/view_model/lang_view_model.dart'; import 'package:talawa/view_model/main_screen_view_model.dart'; import 'package:talawa/view_model/pre_auth_view_models/login_view_model.dart'; @@ -93,6 +94,7 @@ void testSetupLocator() { locator.registerFactory(() => EditEventViewModel()); locator.registerFactory(() => AddPostViewModel()); locator.registerFactory(() => EventInfoViewModel()); + locator.registerFactory(() => ExploreTasksViewModel()); //Widgets viewModels locator.registerFactory(() => ProgressDialogViewModel()); diff --git a/test/views/after_auth_screens/tasks/user_tasks_page_test.dart b/test/views/after_auth_screens/tasks/user_tasks_page_test.dart new file mode 100644 index 000000000..afc095169 --- /dev/null +++ b/test/views/after_auth_screens/tasks/user_tasks_page_test.dart @@ -0,0 +1,91 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:talawa/services/graphql_config.dart'; +import 'package:talawa/services/size_config.dart'; +import 'package:talawa/services/task_service.dart'; +import 'package:talawa/utils/app_localization.dart'; +import 'package:talawa/view_model/lang_view_model.dart'; +import 'package:talawa/views/after_auth_screens/tasks/user_tasks_page.dart'; +import 'package:talawa/views/base_view.dart'; +import 'package:talawa/widgets/task_schedule.dart'; + +import '../../../helpers/test_helpers.dart'; +import '../../../helpers/test_locator.dart'; + +Widget createUserTasksPage() { + return BaseView( + onModelReady: (model) => model.initialize(), + builder: (context, langModel, child) { + return const MaterialApp( + locale: Locale('en'), + localizationsDelegates: [ + AppLocalizationsDelegate(isTest: true), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + home: UserTasksPage(), + ); + }, + ); +} + +void main() { + testSetupLocator(); + locator().test(); + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() { + registerServices(); + locator().test(); + }); + + tearDown(() { + unregisterServices(); + }); + + group("Test for UserTasksPage", () { + testWidgets("Check if UserTasksPage shows up", (tester) async { + await tester.pumpWidget(createUserTasksPage()); + await tester.pumpAndSettle(); + + expect(find.byType(UserTasksPage), findsOneWidget); + }); + + testWidgets("Check if all children show up correctly", (tester) async { + await tester.pumpWidget(createUserTasksPage()); + await tester.pumpAndSettle(); + + expect(find.byType(RefreshIndicator), findsOneWidget); + expect(find.byType(Scaffold), findsOneWidget); + expect(find.byType(TaskSchedule), findsOneWidget); + expect( + find.byWidgetPredicate( + (widget) => widget is Scaffold && widget.appBar is AppBar, + ), + findsOneWidget, + ); + expect(find.text("User Tasks"), findsOneWidget); + }); + + testWidgets("Check if refreshing works", (tester) async { + await tester.pumpWidget(createUserTasksPage()); + await tester.pumpAndSettle(); + + bool _isRefreshed = false; + + when(locator().getTasksByUser()).thenAnswer((_) async { + _isRefreshed = true; + }); + + await tester.drag( + find.byType(RefreshIndicator), + const Offset(0, 200), + ); + await tester.pumpAndSettle(); + + expect(_isRefreshed, true); + }); + }); +} From 311b205a8371eee891e5bef1a794f904295cd6cb Mon Sep 17 00:00:00 2001 From: Md Noman Khan <54404474+noman2002@users.noreply.github.com> Date: Tue, 7 Feb 2023 22:17:40 +0530 Subject: [PATCH 2/3] navigation-fix (#1469) --- lib/views/main_screen.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/views/main_screen.dart b/lib/views/main_screen.dart index c32dd8dca..b1c58aa7f 100644 --- a/lib/views/main_screen.dart +++ b/lib/views/main_screen.dart @@ -133,6 +133,18 @@ class _MainScreenState extends State { icon: const Icon(Icons.home), label: AppLocalizations.of(context)!.strictTranslate('Home'), ), + BottomNavigationBarItem( + icon: const Icon(Icons.event_note), + label: AppLocalizations.of(context)!.strictTranslate('Events'), + ), + BottomNavigationBarItem( + icon: const Icon(Icons.add_box), + label: AppLocalizations.of(context)!.strictTranslate('Add'), + ), + BottomNavigationBarItem( + icon: const Icon(Icons.chat_outlined), + label: AppLocalizations.of(context)!.strictTranslate('Chat'), + ), BottomNavigationBarItem( icon: const Icon(Icons.account_circle), label: AppLocalizations.of(context)!.strictTranslate('Profile'), @@ -183,6 +195,13 @@ class _MainScreenState extends State { /// When talawa app receives the plugins data is will dynamically render more components from the construtor. navBarClasses = [ OrganizationFeed(key: const Key("HomeView"), homeModel: model), + ExploreEvents(key: const Key('ExploreEvents'), homeModel: model), + AddPost( + key: const Key('AddPost'), + drawerKey: MainScreenViewModel.scaffoldKey), + const ChatPage( + key: Key('Chats'), + ), ProfilePage(key: model.keySPEditProfile, homeModel: model), ]; // ignore_for_file: unused_local_variable From 1b09ba4097543dd7e5feb62b013ffd3b959fe74e Mon Sep 17 00:00:00 2001 From: Ayush Chaudhary <95746190+Ayush0Chaudhary@users.noreply.github.com> Date: Wed, 8 Feb 2023 22:58:46 +0530 Subject: [PATCH 3/3] Fixes #1242 Create tests for create_event_page.dart (#1472) --- .../create_event_view_model.dart | 2 - .../events/create_event_page.dart | 4 + lib/widgets/add_members_bottom_sheet.dart | 1 + test/helpers/test_helpers.dart | 17 + test/helpers/test_helpers.mocks.dart | 11 + .../events/create_event_page_test.dart | 480 ++++++++++++++++++ 6 files changed, 513 insertions(+), 2 deletions(-) create mode 100644 test/views/after_auth_screens/events/create_event_page_test.dart diff --git a/lib/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart b/lib/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart index ff345c8bc..e3b1da412 100644 --- a/lib/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart +++ b/lib/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart @@ -111,7 +111,6 @@ class CreateEventViewModel extends BaseModel { variables: variables, ); navigationService.pop(); - print('Result is : $result'); if (result != null) { navigationService.pop(); @@ -153,7 +152,6 @@ class CreateEventViewModel extends BaseModel { void buildUserList({required bool isAdmin}) { isAdmin ? _selectedAdmins.clear() : _selectedMembers.clear(); - orgMembersList.forEach((orgMember) { if (_adminCheckedMap[orgMember.id] == true && isAdmin) { _selectedAdmins.add(orgMember); diff --git a/lib/views/after_auth_screens/events/create_event_page.dart b/lib/views/after_auth_screens/events/create_event_page.dart index d9b4e1e27..5422fa19b 100644 --- a/lib/views/after_auth_screens/events/create_event_page.dart +++ b/lib/views/after_auth_screens/events/create_event_page.dart @@ -75,6 +75,7 @@ class _CreateEventPageState extends State { width: SizeConfig.screenWidth! * 0.036, ), TextButton( + key: const Key('txt_btn_cep'), onPressed: () => model.getImageFromGallery(), child: Text( AppLocalizations.of(context)! @@ -162,6 +163,7 @@ class _CreateEventPageState extends State { height: SizeConfig.screenHeight! * 0.013, ), DateTimeTile( + key: const Key('key for test cep'), date: "${model.eventEndDate.toLocal()}".split(' ')[0], time: model.eventEndTime.format(context), setDate: () async { @@ -259,6 +261,7 @@ class _CreateEventPageState extends State { SizedBox(height: SizeConfig.screenHeight! * 0.026), const Divider(), InkWell( + key: const Key('inwell_cep1'), onTap: () { EventBottomSheet().addUserBottomSheet( context: context, @@ -297,6 +300,7 @@ class _CreateEventPageState extends State { SizedBox(height: SizeConfig.screenHeight! * 0.026), const Divider(), InkWell( + key: const Key('inwell_cep2'), onTap: () { EventBottomSheet().addUserBottomSheet( context: context, diff --git a/lib/widgets/add_members_bottom_sheet.dart b/lib/widgets/add_members_bottom_sheet.dart index 8f57d43a1..e623d57c3 100644 --- a/lib/widgets/add_members_bottom_sheet.dart +++ b/lib/widgets/add_members_bottom_sheet.dart @@ -39,6 +39,7 @@ class EventBottomSheet { style: const TextStyle(fontSize: 16), ), TextButton( + key: const Key('text_btn_ambs1'), onPressed: () { model.buildUserList(isAdmin: isAdmin); Navigator.pop(context); diff --git a/test/helpers/test_helpers.dart b/test/helpers/test_helpers.dart index 99c2a4652..2b730c7ff 100644 --- a/test/helpers/test_helpers.dart +++ b/test/helpers/test_helpers.dart @@ -95,6 +95,23 @@ OrganizationService getAndRegisterOrganizationService() { _removeRegistrationIfExists(); final service = MockOrganizationService(); locator.registerSingleton(service); + + final User user1 = User( + id: "fakeUser1", + firstName: 'ayush', + lastName: 'chaudhary', + image: 'www.image.com', + ); + final User user2 = User( + id: "fakeUser2", + firstName: 'ayush', + lastName: 'chaudhary', + image: 'www.image.com', + ); + final List users = [user1, user2]; + when(service.getOrgMembersList('XYZ')).thenAnswer((realInvocation) async { + return users; + }); return service; } diff --git a/test/helpers/test_helpers.mocks.dart b/test/helpers/test_helpers.mocks.dart index cff124de5..29ecfe610 100644 --- a/test/helpers/test_helpers.mocks.dart +++ b/test/helpers/test_helpers.mocks.dart @@ -148,6 +148,17 @@ class MockNavigationService extends _i2.Mock implements _i7.NavigationService { Invocation.method(#showSnackBar, [message], {#duration: duration}), returnValueForMissingStub: null); @override + void showTalawaErrorWidget(String? errorMessage, + {Duration? duration = const Duration(seconds: 2)}) => + super.noSuchMethod( + Invocation.method( + #showTalawaErrorWidget, [errorMessage], {#duration: duration}), + returnValueForMissingStub: null); + @override + void showTalawaErrorDialog(String? errorMessage) => super.noSuchMethod( + Invocation.method(#showTalawaErrorDialog, [errorMessage]), + returnValueForMissingStub: null); + @override void pop() => super.noSuchMethod(Invocation.method(#pop, []), returnValueForMissingStub: null); } diff --git a/test/views/after_auth_screens/events/create_event_page_test.dart b/test/views/after_auth_screens/events/create_event_page_test.dart new file mode 100644 index 000000000..5e0df90ca --- /dev/null +++ b/test/views/after_auth_screens/events/create_event_page_test.dart @@ -0,0 +1,480 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:intl/intl.dart'; +import 'package:mockito/mockito.dart'; +import 'package:talawa/constants/custom_theme.dart'; +import 'package:talawa/services/org_service.dart'; +import 'package:talawa/services/size_config.dart'; +import 'package:talawa/services/third_party_service/multi_media_pick_service.dart'; +import 'package:talawa/utils/app_localization.dart'; +import 'package:talawa/view_model/lang_view_model.dart'; +import 'package:talawa/views/after_auth_screens/events/create_event_page.dart'; +import 'package:talawa/views/base_view.dart'; + +import '../../../helpers/test_helpers.dart'; +import '../../../helpers/test_locator.dart'; + +class MockCallbackFunction extends Mock { + call(); +} + +final setDateCallback = MockCallbackFunction(); +final setTimeCallback = MockCallbackFunction(); + +Widget createEventScreen( + {ThemeMode themeMode = ThemeMode.light, required ThemeData theme}) => + BaseView( + onModelReady: (model) => model.initialize(), + builder: (context, langModel, child) { + return MaterialApp( + locale: const Locale('en'), + localizationsDelegates: [ + const AppLocalizationsDelegate(isTest: true), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + key: const Key('Root'), + themeMode: themeMode, + theme: theme, + home: Scaffold( + key: navigationService.navigatorKey, + body: const CreateEventPage( + key: Key('CreateEventScreen'), + ), + ), + // navigatorKey: navigationService.navigatorKey, + // onGenerateRoute: router.generateRoute, + ); + }); + +void main() { + SizeConfig().test(); + testSetupLocator(); + locator.unregister(); + locator.unregister(); + locator.registerSingleton(OrganizationService()); + // locator.registerSingleton(LikeButtonViewModel()); + + setUp(() { + registerServices(); + }); + + testWidgets("Checking tap Inkwell for setDate 1 datetime", (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + final inkwellFinder = find.byType(InkWell); + expect(inkwellFinder, findsNWidgets(8)); + // tester.allElements.forEach((element) { + // print(element); + // }); + + ///returning the file variable to the + ///result of function multimediaPickerService.getPhotoFromGallery + ///when this function is called in the + ///view model of add_post_page. + final file = File('fakePath'); + + /// using the new instance of multimediaPickerService + /// so that when statement can be used again, + /// else it gives null point exception + final multimediaPickerService = locator(); + + /// when is function provided by mockito lib + when(multimediaPickerService.getPhotoFromGallery(camera: false)) + .thenAnswer((_) async { + return file; + }); + + await tester.tap(inkwellFinder.at(1)); + await tester.pump(); + }); + + testWidgets("Checking tap Inkwell for setTime 1 datetime", (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + final inkwellFinder = find.byType(InkWell); + expect(inkwellFinder, findsNWidgets(8)); + + ///returning the file variable to the + ///result of function multimediaPickerService.getPhotoFromGallery + ///when this function is called in the + ///view model of add_post_page. + final file = File('fakePath'); + + /// using the new instance of multimediaPickerService + /// so that when statement can be used again, + /// else it gives null point exception + final multimediaPickerService = locator(); + + /// when is function provided by mockito lib + when(multimediaPickerService.getPhotoFromGallery(camera: false)) + .thenAnswer((_) async { + return file; + }); + + await tester.tap(inkwellFinder.at(2)); + await tester.pump(); + }); + testWidgets("Checking tap Inkwell for setDate 2 datetime", (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + final inkwellFinder = find.byType(InkWell); + expect(inkwellFinder, findsNWidgets(8)); + + ///returning the file variable to the + ///result of function multimediaPickerService.getPhotoFromGallery + ///when this function is called in the + ///view model of add_post_page. + final file = File('fakePath'); + + /// using the new instance of multimediaPickerService + /// so that when statement can be used again, + /// else it gives null point exception + final multimediaPickerService = locator(); + + /// when is function provided by mockito lib + when(multimediaPickerService.getPhotoFromGallery(camera: false)) + .thenAnswer((_) async { + return file; + }); + + await tester.tap(inkwellFinder.at(3)); + await tester.pump(); + }); + + testWidgets("Checking tap Inkwell for set time 2 datetime", (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + final inkwellFinder = find.byType(InkWell); + expect(inkwellFinder, findsNWidgets(8)); + // tester.allElements.forEach((element) { + // print(element); + // }); + + ///returning the file variable to the + ///result of function multimediaPickerService.getPhotoFromGallery + ///when this function is called in the + ///view model of add_post_page. + final file = File('fakePath'); + + /// using the new instance of multimediaPickerService + /// so that when statement can be used again, + /// else it gives null point exception + final multimediaPickerService = locator(); + + /// when is function provided by mockito lib + when(multimediaPickerService.getPhotoFromGallery(camera: false)) + .thenAnswer((_) async { + return file; + }); + + await tester.tap(inkwellFinder.at(4)); + await tester.pump(); + }); + + testWidgets('checks if the upload photo from button shows correct icon', + (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + + /// using the key of icon button + /// because their are many icon button + + final finder = find.byKey(const Key('txt_btn_cep')); + + expect(finder, findsOneWidget); + + ///returning the file variable to the + ///result of function multimediaPickerService.getPhotoFromGallery + ///when this function is called in the + ///view model of add_post_page. + final file = File('fakePath'); + + /// using the new instance of multimediaPickerService + /// so that when statement can be used again, + /// else it gives null point exception + final multimediaPickerServices = locator(); + + /// when is function provided by mockito lib + when(multimediaPickerServices.getPhotoFromGallery()).thenAnswer((_) async { + return file; + }); + + await tester.tap(finder); + await tester.pump(); + + expect(finder, findsOneWidget); + }); + + testWidgets( + 'checks if the uploaded photo from gallery button is removed after pressing remove button', + (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + + /// using the key of icon button + /// because their are many icon button + + final finder = find.byKey(const Key('txt_btn_cep')); + + final cancelBtn = find.byIcon(Icons.cancel); + + expect(finder, findsOneWidget); + + ///returning the file variable to the + ///result of function multimediaPickerService.getPhotoFromGallery + ///when this function is called in the + ///view model of add_post_page. + final file = File('fakePath'); + + /// using the new instance of multimediaPickerService + /// so that when statement can be used again, + /// else it gives null point exception + final multimediaPickerService = locator(); + + /// when is function provided by mockito lib + when(multimediaPickerService.getPhotoFromGallery(camera: false)) + .thenAnswer((_) async { + return file; + }); + + await tester.tap(finder); + await tester.pump(); + + await tester.tap(cancelBtn); + await tester.pump(); + }); + + testWidgets("Testing Keep public section", (tester) async { + await tester.pumpWidget(createEventScreen( + theme: TalawaTheme.lightTheme, + )); + await tester.pumpAndSettle(); + final appLocalization = AppLocalizations.of( + navigationService.navigatorKey.currentContext!, + ); + final keepPublicText = find.descendant( + of: find.byType(Row), + matching: find.text( + appLocalization!.strictTranslate('Keep Public'), + ), + ); + final switches = find.descendant( + of: find.byType(Row), + matching: find.byType(Switch), + ); + expect(keepPublicText, findsOneWidget); + expect(switches, findsNWidgets(2)); + expect( + (tester.widget(keepPublicText) as Text?)?.style!.fontSize, + 16, + ); + expect((tester.firstWidget(switches) as Switch).value, true); + await tester.tap(switches.first); + await tester.pumpAndSettle(); + expect((tester.firstWidget(switches) as Switch).value, false); + }); + + testWidgets("Testing Keep Registerable section", (tester) async { + await tester.pumpWidget(createEventScreen( + theme: TalawaTheme.lightTheme, + )); + await tester.pumpAndSettle(); + final appLocalization = AppLocalizations.of( + navigationService.navigatorKey.currentContext!, + ); + final keepRegisterableText = find.descendant( + of: find.byType(Row), + matching: find.text( + appLocalization!.strictTranslate('Keep Registerable'), + ), + ); + final switches = find.descendant( + of: find.byType(Row), + matching: find.byType(Switch), + ); + expect(keepRegisterableText, findsOneWidget); + expect(switches, findsNWidgets(2)); + expect( + (tester.widget(keepRegisterableText) as Text?)?.style!.fontSize, + 16, + ); + expect((tester.widgetList(switches).toList()[1] as Switch).value, true); + await tester.ensureVisible(switches.at(1)); + await tester.tap(switches.at(1)); + await tester.pumpAndSettle(); + expect((tester.widgetList(switches).toList()[1] as Switch).value, false); + }); + + testWidgets("Checking tap Inkwell work for admin list", (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + final inkwellFinder = find.byType(InkWell); + expect(inkwellFinder, findsNWidgets(8)); + + ///returning the file variable to the + ///result of function multimediaPickerService.getPhotoFromGallery + ///when this function is called in the + ///view model of add_post_page. + final file = File('fakePath'); + + /// using the new instance of multimediaPickerService + /// so that when statement can be used again, + /// else it gives null point exception + final multimediaPickerService = locator(); + + /// when is function provided by mockito lib + when(multimediaPickerService.getPhotoFromGallery(camera: false)) + .thenAnswer((_) async { + return file; + }); + + await tester.ensureVisible(find.byKey(const Key('inwell_cep1'))); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('inwell_cep1'))); + await tester.pump(); + + //TODO: implement Rest of the test when the _adminCheckedMap or _memberCheckedMap return true for some id + //TODO: for not it return false for all the ordMember.id + // + // orgMembersList.forEach((orgMember) { + // if (isAdmin) { + // _adminCheckedMap.putIfAbsent(orgMember.id!, () => false); + // } else { + // _memberCheckedMap.putIfAbsent(orgMember.id!, () => false); + // } + // _memberCheckedMap.putIfAbsent(orgMember.id!, () => false); + // }); + }); + + testWidgets("Checking tap Inkwell for second add to bottom sheet", + (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + final inkwellFinder = find.byType(InkWell); + expect(inkwellFinder, findsNWidgets(8)); + + await tester.ensureVisible(find.byKey(const Key('inwell_cep2'))); + await tester.pump(); + + // await tester.tap(find.byKey(const Key('text_btn_ambs'))); + await tester.tap(find.byKey( + const Key('inwell_cep2'), + )); + await tester.pump(); + + await tester.pump(); + await tester.ensureVisible(find.byKey(const Key('text_btn_ambs1'))); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('text_btn_ambs1'))); + await tester.pump(); + }); + group('setState Coverage completion', () { + testWidgets('Tap on DataTimeTile date', (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + + await tester.tap(find.byKey(const Key('EventDateTimeTileDate')).first); + await tester.pump(); + + await tester.ensureVisible(find.byKey(const Key('key for test cep'))); + await tester.pump(); + + expect(find.byType(DatePickerDialog), findsOneWidget); + expect(find.byType(CalendarDatePicker), findsOneWidget); + + await tester.tap(find.text('OK')); + await tester.pumpAndSettle(); + + expect(find.text(DateTime.now().toString().split(' ').first), + findsNWidgets(2)); + }); + testWidgets('Tap on DataTimeTile time', (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('EventDateTimeTileTime')).first); + await tester.pump(); + + expect(find.byType(TimePickerDialog), findsOneWidget); + + await tester.tap(find.text('OK')); + await tester.pump(); + expect(find.text(DateFormat.jm().format(DateTime.now()).toString()), + findsNWidgets(2)); + }); + testWidgets('Tap on DataTimeTile date', (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pump(); + + await tester.tap(find.byKey(const Key('EventDateTimeTileDate')).last); + await tester.pump(); + + await tester.ensureVisible(find.byKey(const Key('key for test cep'))); + await tester.pump(); + + expect(find.byType(DatePickerDialog), findsOneWidget); + expect(find.byType(CalendarDatePicker), findsOneWidget); + + await tester.tap(find.text('OK')); + await tester.pumpAndSettle(); + expect(find.text(DateTime.now().toString().split(' ').first), + findsNWidgets(2)); + }); + testWidgets('Tap on DataTimeTile time', (tester) async { + await tester.pumpWidget(createEventScreen( + themeMode: ThemeMode.dark, + theme: TalawaTheme.darkTheme, + )); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('EventDateTimeTileTime')).last); + await tester.pump(); + + expect(find.byType(TimePickerDialog), findsOneWidget); + + await tester.tap(find.text('OK')); + await tester.pump(); + expect(find.text(DateFormat.jm().format(DateTime.now()).toString()), + findsNWidgets(2)); + }); + }); +}