From c5fa66cbf15f948bfcc229f9b7d4a8a5a0428943 Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 6 Aug 2024 09:00:26 +0700 Subject: [PATCH] fixup! TF-3023 Write widget test for SMimeSignatureStatus icon --- .../presentation_email_extension.dart | 5 +- .../utils/smime_signature_constant.dart | 5 + ...nder_and_receiver_builder_widget_test.dart | 112 ++++++++++++++++++ 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 lib/features/email/presentation/utils/smime_signature_constant.dart diff --git a/lib/features/email/presentation/extensions/presentation_email_extension.dart b/lib/features/email/presentation/extensions/presentation_email_extension.dart index 4dd642f5de..d1385cd9b8 100644 --- a/lib/features/email/presentation/extensions/presentation_email_extension.dart +++ b/lib/features/email/presentation/extensions/presentation_email_extension.dart @@ -2,14 +2,15 @@ import 'package:model/email/presentation_email.dart'; import 'package:model/extensions/list_email_header_extension.dart'; import 'package:tmail_ui_user/features/email/presentation/model/smime_signature_status.dart'; +import 'package:tmail_ui_user/features/email/presentation/utils/smime_signature_constant.dart'; extension PresentationEmailExtension on PresentationEmail { SMimeSignatureStatus get sMimeStatus { final status = emailHeader?.toSet().sMimeStatus; - if (status == 'Good signature') { + if (status == SMimeSignatureConstant.GOOD_SIGNATURE) { return SMimeSignatureStatus.goodSignature; - } else if (status == 'Bad signature') { + } else if (status == SMimeSignatureConstant.BAD_SIGNATURE) { return SMimeSignatureStatus.badSignature; } else { return SMimeSignatureStatus.notSigned; diff --git a/lib/features/email/presentation/utils/smime_signature_constant.dart b/lib/features/email/presentation/utils/smime_signature_constant.dart new file mode 100644 index 0000000000..167718e752 --- /dev/null +++ b/lib/features/email/presentation/utils/smime_signature_constant.dart @@ -0,0 +1,5 @@ + +class SMimeSignatureConstant { + static const String GOOD_SIGNATURE = 'Good signature'; + static const String BAD_SIGNATURE = 'Bad signature'; +} \ No newline at end of file diff --git a/test/features/email/presentation/information_sender_and_receiver_builder_widget_test.dart b/test/features/email/presentation/information_sender_and_receiver_builder_widget_test.dart index e4a0525452..60d358c669 100644 --- a/test/features/email/presentation/information_sender_and_receiver_builder_widget_test.dart +++ b/test/features/email/presentation/information_sender_and_receiver_builder_widget_test.dart @@ -160,6 +160,118 @@ void main() { find.byKey(const Key('smime_signature_status_icon')), findsNothing); }); + + testWidgets('should not be displayed when email header have X-SMIME-Status = "Good Signatures"', (tester) async { + final presentationEmail = PresentationEmail( + id: EmailId(Id('a123')), + from: { + EmailAddress('example', 'example@linagora.com') + }, + emailHeader: [ + EmailHeader(EmailProperty.headerSMimeStatusKey, 'Good Signatures') + ] + ); + final widget = makeTestableWidget( + child: InformationSenderAndReceiverBuilder( + emailSelected: presentationEmail, + responsiveUtils: responsiveUtils, + imagePaths: imagePaths, + emailUnsubscribe: null, + ), + ); + + await tester.pumpWidget(widget); + + await tester.pumpAndSettle(); + + expect( + find.byKey(const Key('smime_signature_status_icon')), + findsNothing); + }); + + testWidgets('should not be displayed when email header have X-SMIME-Status = "Good signatures"', (tester) async { + final presentationEmail = PresentationEmail( + id: EmailId(Id('a123')), + from: { + EmailAddress('example', 'example@linagora.com') + }, + emailHeader: [ + EmailHeader(EmailProperty.headerSMimeStatusKey, 'Good signatures') + ] + ); + final widget = makeTestableWidget( + child: InformationSenderAndReceiverBuilder( + emailSelected: presentationEmail, + responsiveUtils: responsiveUtils, + imagePaths: imagePaths, + emailUnsubscribe: null, + ), + ); + + await tester.pumpWidget(widget); + + await tester.pumpAndSettle(); + + expect( + find.byKey(const Key('smime_signature_status_icon')), + findsNothing); + }); + + testWidgets('should not be displayed when email header have X-SMIME-Status = "Bad Signatures"', (tester) async { + final presentationEmail = PresentationEmail( + id: EmailId(Id('a123')), + from: { + EmailAddress('example', 'example@linagora.com') + }, + emailHeader: [ + EmailHeader(EmailProperty.headerSMimeStatusKey, 'Bad Signatures') + ] + ); + final widget = makeTestableWidget( + child: InformationSenderAndReceiverBuilder( + emailSelected: presentationEmail, + responsiveUtils: responsiveUtils, + imagePaths: imagePaths, + emailUnsubscribe: null, + ), + ); + + await tester.pumpWidget(widget); + + await tester.pumpAndSettle(); + + expect( + find.byKey(const Key('smime_signature_status_icon')), + findsNothing); + }); + + testWidgets('should not be displayed when email header have X-SMIME-Status = "Bad signatures"', (tester) async { + final presentationEmail = PresentationEmail( + id: EmailId(Id('a123')), + from: { + EmailAddress('example', 'example@linagora.com') + }, + emailHeader: [ + EmailHeader(EmailProperty.headerSMimeStatusKey, 'Bad signatures') + ] + ); + final widget = makeTestableWidget( + child: InformationSenderAndReceiverBuilder( + emailSelected: presentationEmail, + responsiveUtils: responsiveUtils, + imagePaths: imagePaths, + emailUnsubscribe: null, + ), + ); + + await tester.pumpWidget(widget); + + await tester.pumpAndSettle(); + + expect( + find.byKey(const Key('smime_signature_status_icon')), + findsNothing); + }); }); }); } \ No newline at end of file