From 077d8232514b03ed35e98af21f737a77ee793ee5 Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 20 Jun 2025 15:39:30 +0700 Subject: [PATCH] TF-3793 Write unit test to cover the display the warning message in calendar event Signed-off-by: dab246 --- ...alendar_event_information_widget_test.dart | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 test/features/email/presentation/widgets/calendar_event/calendar_event_information_widget_test.dart diff --git a/test/features/email/presentation/widgets/calendar_event/calendar_event_information_widget_test.dart b/test/features/email/presentation/widgets/calendar_event/calendar_event_information_widget_test.dart new file mode 100644 index 000000000..e98f02470 --- /dev/null +++ b/test/features/email/presentation/widgets/calendar_event/calendar_event_information_widget_test.dart @@ -0,0 +1,139 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/properties/attendee/calendar_attendee.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/properties/attendee/calendar_attendee_mail_to.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/properties/calendar_organizer.dart'; +import 'package:jmap_dart_client/jmap/mail/calendar/properties/mail_address.dart'; +import 'package:tmail_ui_user/features/email/presentation/widgets/calendar_event/calendar_event_information_widget.dart'; +import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; + +import '../../../../../fixtures/widget_fixtures.dart'; + +void main() { + group('CalendarEventInformationWidget::', () { + testWidgets( + 'Should show warning message\n' + 'when user is not in the participants\n' + 'and is not the organizer', + (tester) async { + // Arrange + const ownEmail = 'user@example.com'; + final calendarEvent = CalendarEvent( + organizer: CalendarOrganizer( + mailto: MailAddress('organizer@example.com'), + ), + participants: [ + CalendarAttendee( + mailto: CalendarAttendeeMailTo(MailAddress('participant@example.com')), + ) + ], + ); + + // Act + await tester.pumpWidget( + WidgetFixtures.makeTestableWidget( + child: Scaffold( + body: CalendarEventInformationWidget( + calendarEvent: calendarEvent, + onCalendarEventReplyActionClick: (_) {}, + calendarEventReplying: false, + isFree: false, + ownEmailAddress: ownEmail, + ), + ), + ), + ); + await tester.pumpAndSettle(); + + // Assert + expect( + find.text(AppLocalizations().youAreNotInvitedToThisEventPleaseContactTheOrganizer), + findsOneWidget, + ); + }); + + testWidgets( + 'Should NOT show warning message\n' + 'when user is in participants', + (tester) async { + // Arrange + const ownEmail = 'user@example.com'; + final calendarEvent = CalendarEvent( + organizer: CalendarOrganizer( + mailto: MailAddress('organizer@example.com'), + ), + participants: [ + CalendarAttendee( + mailto: CalendarAttendeeMailTo(MailAddress('participant@example.com')), + ), + CalendarAttendee( + mailto: CalendarAttendeeMailTo(MailAddress(ownEmail)), + ), + ], + ); + + // Act + await tester.pumpWidget( + WidgetFixtures.makeTestableWidget( + child: Scaffold( + body: CalendarEventInformationWidget( + calendarEvent: calendarEvent, + onCalendarEventReplyActionClick: (_) {}, + calendarEventReplying: false, + isFree: false, + ownEmailAddress: ownEmail, + ), + ), + ), + ); + await tester.pumpAndSettle(); + + // Assert + expect( + find.text(AppLocalizations().youAreNotInvitedToThisEventPleaseContactTheOrganizer), + findsNothing, + ); + }); + + testWidgets( + 'Should NOT show warning message\n' + 'when user is the organizer', + (tester) async { + // Arrange + const ownEmail = 'user@example.com'; + final calendarEvent = CalendarEvent( + organizer: CalendarOrganizer( + mailto: MailAddress(ownEmail), + ), + participants: [ + CalendarAttendee( + mailto: CalendarAttendeeMailTo(MailAddress('participant@example.com')), + ), + ], + ); + + // Act + await tester.pumpWidget( + WidgetFixtures.makeTestableWidget( + child: Scaffold( + body: CalendarEventInformationWidget( + calendarEvent: calendarEvent, + onCalendarEventReplyActionClick: (_) {}, + calendarEventReplying: false, + isFree: false, + ownEmailAddress: ownEmail, + ), + ), + ), + ); + await tester.pumpAndSettle(); + + // Assert + expect( + find.text(AppLocalizations().youAreNotInvitedToThisEventPleaseContactTheOrganizer), + findsNothing, + ); + }); + }); +}