Skip to content

Commit

Permalink
add Unittests for lib/widgets/event_card.dart (#2669)
Browse files Browse the repository at this point in the history
* add Unittests for lib/widgets/event_card.dart

* add Unittests for lib/widgets/event_card.dart
  • Loading branch information
sayyad-asifbasha authored Dec 28, 2024
1 parent b6ddb72 commit 0e8b559
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/widget_tests/widgets/event_card_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ void main() {
testSetupLocator();
});

tearDown(() {
userConfig.currentUser.id = null;
});

group("Test for EventCard widget", () {
testWidgets('Check if Event Card shows up', (tester) async {
mockNetworkImages(() async {
Expand Down Expand Up @@ -195,5 +199,37 @@ void main() {
expect(find.text("1"), findsOneWidget);
});
});

testWidgets('Check for Created Row visibility', (tester) async {
mockNetworkImages(() async {
final event = getEvent();
userConfig.currentUser.id = event.creator!.id;
await tester.pumpWidget(createCustomEventCard(event));
await tester.pump();
final BuildContext ctx = tester.element(find.byType(EventCard));
expect(find.byIcon(Icons.verified), findsOneWidget);
expect(
find.text(AppLocalizations.of(ctx)!.strictTranslate('Created')),
findsOneWidget,
);
});
});

testWidgets(
'should not show Created row and verified icon when current user is not the event creator',
(tester) async {
mockNetworkImages(() async {
final event = getEvent();
userConfig.currentUser.id = "nonCreatorId";
await tester.pumpWidget(createCustomEventCard(event));
await tester.pump();
final BuildContext ctx = tester.element(find.byType(EventCard));
expect(find.byIcon(Icons.verified), findsNothing);
expect(
find.text(AppLocalizations.of(ctx)!.strictTranslate('Created')),
findsNothing,
);
});
});
});
}

0 comments on commit 0e8b559

Please sign in to comment.