Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test pr #2139

Closed
wants to merge 6 commits into from
Closed

Test pr #2139

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Modified the event edit test and made the code coverage of file edit_…
…event_page to 100%
Azad99-9 committed Nov 22, 2023
commit 36ac99f80f3bef28a7ed2675b50b50ed4523a78b
894 changes: 447 additions & 447 deletions test/widget_tests/after_auth_screens/events/edit_event_page_test.dart
Original file line number Diff line number Diff line change
@@ -70,477 +70,477 @@ Widget editEventScreen({
},
);

Future<void> main() async {
// SizeConfig().test();
// setupLocator();
// graphqlConfig.test();
void main() {
SizeConfig().test();
setupLocator();
graphqlConfig.test();

// setupFirebaseMocks();
setupFirebaseMocks();
// await Firebase.initializeApp();

// group("Edit Event Screen Widget Test in dark mode", () {
// testWidgets("Testing if dark mode is applied", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// themeMode: ThemeMode.dark,
// theme: TalawaTheme.darkTheme,
// ),
// );
// await tester.pumpAndSettle();
// expect(
// (tester.firstWidget(find.byKey(const Key('Root'))) as MaterialApp)
// .theme
// ?.scaffoldBackgroundColor,
// TalawaTheme.darkTheme.scaffoldBackgroundColor,
// );
// });
// testWidgets("Testing if tapping on Done works", (tester) async {
// getAndRegisterUserConfig();
// final service = getAndRegisterEventService();
// locator<DataBaseMutationFunctions>().init();
group("Edit Event Screen Widget Test in dark mode", () {
testWidgets("Testing if dark mode is applied", (tester) async {
await tester.pumpWidget(
editEventScreen(
themeMode: ThemeMode.dark,
theme: TalawaTheme.darkTheme,
),
);
await tester.pumpAndSettle();
expect(
(tester.firstWidget(find.byKey(const Key('Root'))) as MaterialApp)
.theme
?.scaffoldBackgroundColor,
TalawaTheme.darkTheme.scaffoldBackgroundColor,
);
});
testWidgets("Testing if tapping on Done works", (tester) async {
getAndRegisterUserConfig();
final service = getAndRegisterEventService();
locator<DataBaseMutationFunctions>().init();

// await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
// await tester.pumpAndSettle();
await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
await tester.pumpAndSettle();

// await tester.tap(find.text('Done'));
// await tester.pump();
await tester.tap(find.text('Done'));
await tester.pump();

// verify(
// (service as MockEventService)
// .editEvent(eventId: '1', variables: anyNamed('variables')),
// );
// });
// testWidgets('Tap on Add Image', (tester) async {
// await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
// await tester.pumpAndSettle();
verify(
(service as MockEventService)
.editEvent(eventId: '1', variables: anyNamed('variables')),
);
});
testWidgets('Tap on Add Image', (tester) async {
await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
await tester.pumpAndSettle();

// await tester.tap(find.text('Add Image'));
// await tester.pump();
// });
// testWidgets('Tap on DataTimeTile date', (tester) async {
// await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
// await tester.pumpAndSettle();
await tester.tap(find.text('Add Image'));
await tester.pump();
});
testWidgets('Tap on DataTimeTile date', (tester) async {
await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
await tester.pumpAndSettle();

// await tester.tap(find.byKey(const Key('EventDateTimeTileDate')).first);
// await tester.pump();
await tester.tap(find.byKey(const Key('EventDateTimeTileDate')).first);
await tester.pump();

// expect(find.byType(DatePickerDialog), findsOneWidget);
expect(find.byType(DatePickerDialog), findsOneWidget);

// await tester.tap(find.text('31'));
// await tester.tap(find.text('OK'));
// await tester.pumpAndSettle();
await tester.tap(find.text('31'));
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();

// expect(find.text('2021-01-31'), findsOneWidget);
// });
// testWidgets('Tap on DataTimeTile time', (tester) async {
// await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
// await tester.pumpAndSettle();
expect(find.text('2021-01-31'), findsOneWidget);
});
testWidgets('Tap on DataTimeTile time', (tester) async {
await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
await tester.pumpAndSettle();

// await tester.tap(find.byKey(const Key('EventDateTimeTileTime')).first);
// await tester.pump();
await tester.tap(find.byKey(const Key('EventDateTimeTileTime')).first);
await tester.pump();

// expect(find.byType(TimePickerDialog), findsOneWidget);
expect(find.byType(TimePickerDialog), findsOneWidget);

// final center = tester
// .getCenter(find.byKey(const ValueKey<String>('time-picker-dial')));
// await tester.tapAt(Offset(center.dx - 10, center.dy));
// await tester.pump();
// await tester.tapAt(Offset(center.dx, center.dy + 10));
// await tester.tap(find.text('OK'));
// await tester.pump();
final center = tester
.getCenter(find.byKey(const ValueKey<String>('time-picker-dial')));
await tester.tapAt(Offset(center.dx - 10, center.dy));
await tester.pump();
await tester.tapAt(Offset(center.dx, center.dy + 10));
await tester.tap(find.text('OK'));
await tester.pump();

// expect(find.text('9:30 AM'), findsOneWidget);
// });
// testWidgets('Tap on DataTimeTile date for end', (tester) async {
// await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
// await tester.pumpAndSettle();
expect(find.text('9:30 AM'), findsOneWidget);
});
testWidgets('Tap on DataTimeTile date for end', (tester) async {
await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
await tester.pumpAndSettle();

// await tester.tap(find.byKey(const Key('EventDateTimeTileDate')).last);
// await tester.pump();
await tester.tap(find.byKey(const Key('EventDateTimeTileDate')).last);
await tester.pump();

// expect(find.byType(DatePickerDialog), findsOneWidget);
expect(find.byType(DatePickerDialog), findsOneWidget);

// await tester.tap(find.text('31'));
// await tester.tap(find.text('OK'));
// await tester.pumpAndSettle();
await tester.tap(find.text('31'));
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();

// expect(find.text('2022-01-31'), findsOneWidget);
// });
// testWidgets('Tap on DataTimeTile time for end', (tester) async {
// await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
// await tester.pumpAndSettle();
expect(find.text('2022-01-31'), findsOneWidget);
});
testWidgets('Tap on DataTimeTile time for end', (tester) async {
await tester.pumpWidget(editEventScreen(theme: TalawaTheme.darkTheme));
await tester.pumpAndSettle();

// await tester.tap(find.byKey(const Key('EventDateTimeTileTime')).last);
// await tester.pump();
await tester.tap(find.byKey(const Key('EventDateTimeTileTime')).last);
await tester.pump();

// expect(find.byType(TimePickerDialog), findsOneWidget);
expect(find.byType(TimePickerDialog), findsOneWidget);

// await tester.tap(find.text('PM'));
// await tester.tap(find.text('OK'));
// await tester.pump();
await tester.tap(find.text('PM'));
await tester.tap(find.text('OK'));
await tester.pump();

// expect(find.text('12:00 PM'), findsOneWidget);
// });
// });
expect(find.text('12:00 PM'), findsOneWidget);
});
});

// group("Edit Event Screen Widget Test in light mode", () {
// testWidgets("Testing if light mode is applied", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// themeMode: ThemeMode.light,
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// expect(
// (tester.firstWidget(find.byKey(const Key('Root'))) as MaterialApp)
// .theme
// ?.scaffoldBackgroundColor,
// TalawaTheme.lightTheme.scaffoldBackgroundColor,
// );
// });
// });
// group('Edit Event Screen Widget Test', () {
// testWidgets("Testing if Edit Event Screen shows up", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final screenScaffoldWidget = find.byKey(const Key('EditEventScreen'));
// expect(screenScaffoldWidget, findsOneWidget);
// });
group("Edit Event Screen Widget Test in light mode", () {
testWidgets("Testing if light mode is applied", (tester) async {
await tester.pumpWidget(
editEventScreen(
themeMode: ThemeMode.light,
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
expect(
(tester.firstWidget(find.byKey(const Key('Root'))) as MaterialApp)
.theme
?.scaffoldBackgroundColor,
TalawaTheme.lightTheme.scaffoldBackgroundColor,
);
});
});
group('Edit Event Screen Widget Test', () {
testWidgets("Testing if Edit Event Screen shows up", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final screenScaffoldWidget = find.byKey(const Key('EditEventScreen'));
expect(screenScaffoldWidget, findsOneWidget);
});

// group("Testing app bar properties and contents", () {
// testWidgets("Testing if app bar shows up", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appBar = find.byType(AppBar);
// final appBarWidget = tester.firstWidget(appBar) as AppBar;
// expect(appBar, findsOneWidget);
// expect(appBarWidget.elevation, 1);
// });
// testWidgets("Testing close button in app bar", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appBar = find.byType(AppBar);
// final appBarWidget = tester.firstWidget(appBar) as AppBar;
// final closeBtn = find.descendant(
// of: find.byType(AppBar),
// matching: find.byType(GestureDetector),
// );
// final closeIcon = find.descendant(
// of: closeBtn.first,
// matching: find.byIcon(Icons.close),
// );
// expect(appBarWidget.leading, tester.firstWidget(closeBtn));
// expect(
// (appBarWidget.leading as GestureDetector?)?.child,
// tester.firstWidget(closeIcon),
// );
// });
// testWidgets("Testing title in app bar", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appBar = find.byType(AppBar);
// final appBarWidget = tester.firstWidget(appBar) as AppBar;
// final title = find.descendant(
// of: find.byType(AppBar),
// matching: find.byType(Text),
// );
// expect(appBarWidget.title, tester.firstWidget<Text>(title));
// expect(appBarWidget.centerTitle, true);
// expect(
// (appBarWidget.title as Text?)?.data,
// 'Edit Event',
// );
// expect(
// (appBarWidget.title as Text?)?.style!.fontFamily,
// TalawaTheme.lightTheme.textTheme.titleLarge!.fontFamily,
// );
// expect(
// (appBarWidget.title as Text?)?.style!.fontSize,
// 20,
// );
// });
// testWidgets("Testing done button in app bar", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appBar = find.byType(AppBar);
// final appBarWidget = tester.firstWidget(appBar) as AppBar;
// final doneBtn = find.descendant(
// of: find.byType(AppBar),
// matching: find.byType(TextButton),
// );
// final doneText =
// find.descendant(of: doneBtn, matching: find.byType(Text));
// expect(appBarWidget.actions?.length, 1);
// expect(appBarWidget.actions?.first, tester.firstWidget(doneBtn));
// expect(
// (appBarWidget.actions?.first as TextButton?)?.child,
// tester.firstWidget<Text>(doneText),
// );
// expect(
// ((appBarWidget.actions?.first as TextButton?)?.child as Text?)?.data,
// 'Done',
// );
// expect(
// ((appBarWidget.actions?.first as TextButton?)?.child as Text?)
// ?.style!
// .fontSize,
// 16,
// );
// expect(
// ((appBarWidget.actions?.first as TextButton?)?.child as Text?)
// ?.style!
// .color,
// TalawaTheme.lightTheme.colorScheme.secondary,
// );
// });
// });
group("Testing app bar properties and contents", () {
testWidgets("Testing if app bar shows up", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appBar = find.byType(AppBar);
final appBarWidget = tester.firstWidget(appBar) as AppBar;
expect(appBar, findsOneWidget);
expect(appBarWidget.elevation, 1);
});
testWidgets("Testing close button in app bar", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appBar = find.byType(AppBar);
final appBarWidget = tester.firstWidget(appBar) as AppBar;
final closeBtn = find.descendant(
of: find.byType(AppBar),
matching: find.byType(GestureDetector),
);
final closeIcon = find.descendant(
of: closeBtn.first,
matching: find.byIcon(Icons.close),
);
expect(appBarWidget.leading, tester.firstWidget(closeBtn));
expect(
(appBarWidget.leading as GestureDetector?)?.child,
tester.firstWidget(closeIcon),
);
});
testWidgets("Testing title in app bar", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appBar = find.byType(AppBar);
final appBarWidget = tester.firstWidget(appBar) as AppBar;
final title = find.descendant(
of: find.byType(AppBar),
matching: find.byType(Text),
);
expect(appBarWidget.title, tester.firstWidget<Text>(title));
expect(appBarWidget.centerTitle, true);
expect(
(appBarWidget.title as Text?)?.data,
'Edit Event',
);
expect(
(appBarWidget.title as Text?)?.style!.fontFamily,
TalawaTheme.lightTheme.textTheme.titleLarge!.fontFamily,
);
expect(
(appBarWidget.title as Text?)?.style!.fontSize,
20,
);
});
testWidgets("Testing done button in app bar", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appBar = find.byType(AppBar);
final appBarWidget = tester.firstWidget(appBar) as AppBar;
final doneBtn = find.descendant(
of: find.byType(AppBar),
matching: find.byType(TextButton),
);
final doneText =
find.descendant(of: doneBtn, matching: find.byType(Text));
expect(appBarWidget.actions?.length, 1);
expect(appBarWidget.actions?.first, tester.firstWidget(doneBtn));
expect(
(appBarWidget.actions?.first as TextButton?)?.child,
tester.firstWidget<Text>(doneText),
);
expect(
((appBarWidget.actions?.first as TextButton?)?.child as Text?)?.data,
'Done',
);
expect(
((appBarWidget.actions?.first as TextButton?)?.child as Text?)
?.style!
.fontSize,
16,
);
expect(
((appBarWidget.actions?.first as TextButton?)?.child as Text?)
?.style!
.color,
TalawaTheme.lightTheme.colorScheme.secondary,
);
});
});

// group("Testing body properties and contents", () {
// testWidgets("Testing Add Image section", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appLocalization = AppLocalizations.of(
// navigationService.navigatorKey.currentContext!,
// );
// final imageIcon = find.descendant(
// of: find.byType(Row),
// matching: find.byIcon(Icons.image),
// );
// final addImageBtn = find.descendant(
// of: find.byType(Row),
// matching: find.byType(TextButton),
// );
// final addImageText = find.descendant(
// of: addImageBtn.first,
// matching: find.byType(Text),
// );
// final imageShowWidget = find.byType(Image);
// expect(imageIcon, findsOneWidget);
// expect(addImageText, findsOneWidget);
// expect(
// (tester.widget(addImageText) as Text?)?.data,
// appLocalization!.strictTranslate("Add Image"),
// );
// expect(
// (tester.widget(addImageText) as Text?)?.style!.fontSize,
// 16,
// );
// expect(imageShowWidget, findsNothing);
// });
// testWidgets("Testing if Edit Event Form widget shows", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final editEventForm = find.byType(EditEventForm);
// expect(editEventForm, findsOneWidget);
// });
// testWidgets("Testing Select Start Date and Time section", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appLocalization = AppLocalizations.of(
// navigationService.navigatorKey.currentContext!,
// );
// final textDesc = find.text(
// appLocalization!.strictTranslate('Select Start Date and Time'),
// );
// final dateTimeTiles = find.byType(DateTimeTile);
// expect(textDesc, findsOneWidget);
// expect(dateTimeTiles, findsNWidgets(2));
// expect(
// (tester.firstWidget(dateTimeTiles) as DateTimeTile).date,
// DateTime(2021, 1, 1).toString().split(' ')[0],
// );
// expect(
// (tester.firstWidget(dateTimeTiles) as DateTimeTile).time,
// TimeOfDay.fromDateTime(DateTime(2021, 1, 1)).format(
// navigationService.navigatorKey.currentContext!,
// ),
// );
// expect(
// (tester.widget(textDesc) as Text?)?.style!.fontSize,
// 16,
// );
// });
// testWidgets("Testing Select End Date and Time section", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appLocalization = AppLocalizations.of(
// navigationService.navigatorKey.currentContext!,
// );
// final textDesc = find.text(
// appLocalization!.strictTranslate('Select End Date and Time'),
// );
// final dateTimeTiles = find.byType(DateTimeTile);
// expect(textDesc, findsOneWidget);
// expect(dateTimeTiles, findsNWidgets(2));
// expect(
// (tester.widgetList(dateTimeTiles).toList()[1] as DateTimeTile).date,
// DateTime(2022, 1, 1).toString().split(' ')[0],
// );
// expect(
// (tester.widgetList(dateTimeTiles).toList()[1] as DateTimeTile).time,
// TimeOfDay.fromDateTime(DateTime(2022, 1, 1)).format(
// navigationService.navigatorKey.currentContext!,
// ),
// );
// expect(
// (tester.widgetList(dateTimeTiles).toList()[1] as DateTimeTile).time,
// TimeOfDay.fromDateTime(DateTime(2022, 1, 1)).format(
// navigationService.navigatorKey.currentContext!,
// ),
// );
// expect(
// (tester.widget(textDesc) as Text?)?.style!.fontSize,
// 16,
// );
// });
// testWidgets("Testing Does not repeat section", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appLocalization = AppLocalizations.of(
// navigationService.navigatorKey.currentContext!,
// );
// final restoreIcon = find.descendant(
// of: find.byType(Row),
// matching: find.byIcon(Icons.restore),
// );
// final doesNotRepeatText = find.descendant(
// of: find.byType(Row),
// matching: find.text(
// appLocalization!.strictTranslate('Does not repeat'),
// ),
// );
// expect(restoreIcon, findsOneWidget);
// expect(doesNotRepeatText, findsOneWidget);
// expect(
// (tester.widget(doesNotRepeatText) as Text?)?.style!.fontSize,
// 16,
// );
// });
// testWidgets("Testing Keep public section", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// 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(
// editEventScreen(
// 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),
// skipOffstage: false,
// );
// 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("Testing if cancel button in app bar works", (tester) async {
// await tester.pumpWidget(
// editEventScreen(
// theme: TalawaTheme.lightTheme,
// ),
// );
// await tester.pumpAndSettle();
// final appBar = find.byType(AppBar);
// final closeBtn = find.descendant(
// of: appBar,
// matching: find.byType(GestureDetector),
// );
// await tester.tap(closeBtn.first);
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
// final createEventScreenPage = find.byKey(const Key('EditEventScreen'));
// expect(createEventScreenPage, findsNothing);
// });
// });
// });
group("Testing body properties and contents", () {
testWidgets("Testing Add Image section", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appLocalization = AppLocalizations.of(
navigationService.navigatorKey.currentContext!,
);
final imageIcon = find.descendant(
of: find.byType(Row),
matching: find.byIcon(Icons.image),
);
final addImageBtn = find.descendant(
of: find.byType(Row),
matching: find.byType(TextButton),
);
final addImageText = find.descendant(
of: addImageBtn.first,
matching: find.byType(Text),
);
final imageShowWidget = find.byType(Image);
expect(imageIcon, findsOneWidget);
expect(addImageText, findsOneWidget);
expect(
(tester.widget(addImageText) as Text?)?.data,
appLocalization!.strictTranslate("Add Image"),
);
expect(
(tester.widget(addImageText) as Text?)?.style!.fontSize,
16,
);
expect(imageShowWidget, findsNothing);
});
testWidgets("Testing if Edit Event Form widget shows", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final editEventForm = find.byType(EditEventForm);
expect(editEventForm, findsOneWidget);
});
testWidgets("Testing Select Start Date and Time section", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appLocalization = AppLocalizations.of(
navigationService.navigatorKey.currentContext!,
);
final textDesc = find.text(
appLocalization!.strictTranslate('Select Start Date and Time'),
);
final dateTimeTiles = find.byType(DateTimeTile);
expect(textDesc, findsOneWidget);
expect(dateTimeTiles, findsNWidgets(2));
expect(
(tester.firstWidget(dateTimeTiles) as DateTimeTile).date,
DateTime(2021, 1, 1).toString().split(' ')[0],
);
expect(
(tester.firstWidget(dateTimeTiles) as DateTimeTile).time,
TimeOfDay.fromDateTime(DateTime(2021, 1, 1)).format(
navigationService.navigatorKey.currentContext!,
),
);
expect(
(tester.widget(textDesc) as Text?)?.style!.fontSize,
16,
);
});
testWidgets("Testing Select End Date and Time section", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appLocalization = AppLocalizations.of(
navigationService.navigatorKey.currentContext!,
);
final textDesc = find.text(
appLocalization!.strictTranslate('Select End Date and Time'),
);
final dateTimeTiles = find.byType(DateTimeTile);
expect(textDesc, findsOneWidget);
expect(dateTimeTiles, findsNWidgets(2));
expect(
(tester.widgetList(dateTimeTiles).toList()[1] as DateTimeTile).date,
DateTime(2022, 1, 1).toString().split(' ')[0],
);
expect(
(tester.widgetList(dateTimeTiles).toList()[1] as DateTimeTile).time,
TimeOfDay.fromDateTime(DateTime(2022, 1, 1)).format(
navigationService.navigatorKey.currentContext!,
),
);
expect(
(tester.widgetList(dateTimeTiles).toList()[1] as DateTimeTile).time,
TimeOfDay.fromDateTime(DateTime(2022, 1, 1)).format(
navigationService.navigatorKey.currentContext!,
),
);
expect(
(tester.widget(textDesc) as Text?)?.style!.fontSize,
16,
);
});
testWidgets("Testing Does not repeat section", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appLocalization = AppLocalizations.of(
navigationService.navigatorKey.currentContext!,
);
final restoreIcon = find.descendant(
of: find.byType(Row),
matching: find.byIcon(Icons.restore),
);
final doesNotRepeatText = find.descendant(
of: find.byType(Row),
matching: find.text(
appLocalization!.strictTranslate('Does not repeat'),
),
);
expect(restoreIcon, findsOneWidget);
expect(doesNotRepeatText, findsOneWidget);
expect(
(tester.widget(doesNotRepeatText) as Text?)?.style!.fontSize,
16,
);
});
testWidgets("Testing Keep public section", (tester) async {
await tester.pumpWidget(
editEventScreen(
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(
editEventScreen(
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),
skipOffstage: false,
);
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("Testing if cancel button in app bar works", (tester) async {
await tester.pumpWidget(
editEventScreen(
theme: TalawaTheme.lightTheme,
),
);
await tester.pumpAndSettle();
final appBar = find.byType(AppBar);
final closeBtn = find.descendant(
of: appBar,
matching: find.byType(GestureDetector),
);
await tester.tap(closeBtn.first);
await tester.pumpAndSettle(const Duration(milliseconds: 500));
final createEventScreenPage = find.byKey(const Key('EditEventScreen'));
expect(createEventScreenPage, findsNothing);
});
});
});
}