From 38fc79d8e5ba07ff46c6e196d64e00c9dd943ffa Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 27 Mar 2026 18:42:15 +0700 Subject: [PATCH] fixup! fixup! TF-4385 Fix spam banner show it once per day --- ...t_spam_mailbox_cached_interactor_test.dart | 34 ++++++++++++++++++- .../spam_report_controller_test.dart | 10 +++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/test/features/mailbox_dashboard/domain/usecases/get_spam_mailbox_cached_interactor_test.dart b/test/features/mailbox_dashboard/domain/usecases/get_spam_mailbox_cached_interactor_test.dart index b0755a40a..b25f73725 100644 --- a/test/features/mailbox_dashboard/domain/usecases/get_spam_mailbox_cached_interactor_test.dart +++ b/test/features/mailbox_dashboard/domain/usecases/get_spam_mailbox_cached_interactor_test.dart @@ -86,6 +86,20 @@ void main() { }); group('cooldown active (dismissed less than 24h ago)', () { + test('does not show banner when dismissed 13 hours ago', () { + when(spamReportRepository + .getLastTimeDismissedSpamReportedMilliseconds()) + .thenAnswer((_) async => msAgo(13)); + + expect( + interactor.execute(accountId, userName), + emitsInOrder([ + Right(GetSpamMailboxCachedLoading()), + leftWithException(), + ]), + ); + }); + test('does not show banner when dismissed 1 hour ago', () { when(spamReportRepository .getLastTimeDismissedSpamReportedMilliseconds()) @@ -101,7 +115,25 @@ void main() { }); }); - group('cooldown expired (dismissed 24h+ ago)', () { + group('cooldown expired (dismissed 24h ago)', () { + test('shows banner when dismissed exactly 24 hours ago and unread > 0', + () { + final spamMailbox = makeSpamMailbox(unreadCount: 3); + when(spamReportRepository + .getLastTimeDismissedSpamReportedMilliseconds()) + .thenAnswer((_) async => msAgo(24)); + when(spamReportRepository.getSpamMailboxCached(accountId, userName)) + .thenAnswer((_) async => spamMailbox); + + expect( + interactor.execute(accountId, userName), + emitsInOrder([ + Right(GetSpamMailboxCachedLoading()), + Right(GetSpamMailboxCachedSuccess(spamMailbox)), + ]), + ); + }); + test('shows banner when dismissed 25 hours ago and unread > 0', () { final spamMailbox = makeSpamMailbox(unreadCount: 3); when(spamReportRepository diff --git a/test/features/mailbox_dashboard/presentation/controller/spam_report_controller_test.dart b/test/features/mailbox_dashboard/presentation/controller/spam_report_controller_test.dart index 1e6a28fb1..6cac50d73 100644 --- a/test/features/mailbox_dashboard/presentation/controller/spam_report_controller_test.dart +++ b/test/features/mailbox_dashboard/presentation/controller/spam_report_controller_test.dart @@ -126,7 +126,7 @@ void main() { .thenAnswer((_) => failureStream(NoUnreadSpamEmailsException())); controller.getSpamMailboxCached(testAccountId, testUserName); - await Future.delayed(const Duration(milliseconds: 100)); + await untilCalled(storeSpamReportInteractor.execute(any)); verify(storeSpamReportInteractor.execute(any)).called(1); expect(controller.presentationSpamMailbox.value, isNull); @@ -139,7 +139,7 @@ void main() { .thenAnswer((_) => failureStream(NoUnreadSpamEmailsException())); controller.getSpamMailboxCached(testAccountId, testUserName); - await Future.delayed(const Duration(milliseconds: 100)); + await pumpEventQueue(); verifyNever(storeSpamReportInteractor.execute(any)); expect(controller.presentationSpamMailbox.value, isNull); @@ -152,7 +152,7 @@ void main() { .thenAnswer((_) => failureStream(NoUnreadSpamEmailsException())); controller.getSpamMailboxCached(testAccountId, testUserName); - await Future.delayed(const Duration(milliseconds: 100)); + await pumpEventQueue(); verifyNever(storeSpamReportInteractor.execute(any)); expect(controller.presentationSpamMailbox.value, isNull); @@ -167,7 +167,7 @@ void main() { .thenAnswer((_) => failureStream(SpamDismissCooldownActiveException())); controller.getSpamMailboxCached(testAccountId, testUserName); - await Future.delayed(const Duration(milliseconds: 100)); + await pumpEventQueue(); verifyNever(storeSpamReportInteractor.execute(any)); expect(controller.presentationSpamMailbox.value, isNull); @@ -187,7 +187,7 @@ void main() { ])); controller.getSpamMailboxCached(testAccountId, testUserName); - await Future.delayed(const Duration(milliseconds: 100)); + await pumpEventQueue(); expect(controller.presentationSpamMailbox.value, isNotNull); });