diff --git a/lib/ui/screens/email_detail_screen.dart b/lib/ui/screens/email_detail_screen.dart index 59097be..5a2d3b2 100644 --- a/lib/ui/screens/email_detail_screen.dart +++ b/lib/ui/screens/email_detail_screen.dart @@ -239,6 +239,10 @@ class _EmailDetailScreenState extends ConsumerState { ScaffoldMessenger.of(ctx).showSnackBar( SnackBar( duration: const Duration(seconds: 3), + // SnackBar defaults to persist=true when an action + // is set, which disables the auto-dismiss timer. + // Explicitly opt back into duration-based dismiss. + persist: false, content: const Text( 'Images will be loaded automatically for this sender.', ), diff --git a/lib/ui/screens/thread_detail_screen.dart b/lib/ui/screens/thread_detail_screen.dart index 9c0351f..6058aa0 100644 --- a/lib/ui/screens/thread_detail_screen.dart +++ b/lib/ui/screens/thread_detail_screen.dart @@ -214,6 +214,10 @@ class _EmailMessageCardState extends ConsumerState<_EmailMessageCard> { ScaffoldMessenger.of(context).showSnackBar( SnackBar( duration: const Duration(seconds: 3), + // SnackBar defaults to persist=true when an + // action is set, which disables auto-dismiss. + // Explicitly opt into duration-based dismiss. + persist: false, content: const Text( 'Images will be loaded automatically for this sender.', ), diff --git a/test/widget/email_detail_screen_test.dart b/test/widget/email_detail_screen_test.dart index b7237bd..677ff0a 100644 --- a/test/widget/email_detail_screen_test.dart +++ b/test/widget/email_detail_screen_test.dart @@ -582,6 +582,54 @@ void main() { expect(find.textContaining('Structure not available'), findsOneWidget); }); + + testWidgets( + 'Load remote images snack bar auto-dismisses after 3 seconds', + (tester) async { + const body = EmailBody( + emailId: 'acc-1:42', + htmlBody: '

Hello

', + attachments: [], + ); + await tester.pumpWidget( + buildApp( + initialLocation: + '/accounts/acc-1/mailboxes/INBOX/emails/acc-1%3A42', + overrides: _overrides(body: body), + ), + ); + await tester.pumpAndSettle(); + + // The "Load remote images" button is visible because the sender is + // not yet trusted. + expect(find.text('Load remote images'), findsOneWidget); + + await tester.tap(find.text('Load remote images')); + // Settle the snack bar enter animation and the setState rebuild + // that swaps in the image-loading WebView. + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + // Snack bar must be visible. + expect( + find.text('Images will be loaded automatically for this sender.'), + findsOneWidget, + ); + + // After 3 seconds (the snack bar's duration) plus the reverse + // animation, the snack bar must be gone. + // Regression test for #484: SnackBar with an action defaults to + // persist=true, which disables auto-dismiss — explicit persist:false + // restores duration-based dismissal. + await tester.pump(const Duration(seconds: 4)); + await tester.pumpAndSettle(); + + expect( + find.text('Images will be loaded automatically for this sender.'), + findsNothing, + ); + }, + ); }); } diff --git a/test/widget/thread_detail_screen_test.dart b/test/widget/thread_detail_screen_test.dart index e61f19d..63b6e61 100644 --- a/test/widget/thread_detail_screen_test.dart +++ b/test/widget/thread_detail_screen_test.dart @@ -249,5 +249,59 @@ void main() { expect(find.text('Body content here'), findsOneWidget); }); + + testWidgets( + 'Load remote images snack bar auto-dismisses after 3 seconds', + (tester) async { + final email = _threadEmail(); + await tester.pumpWidget( + buildApp( + initialLocation: '/accounts/acc-1/mailboxes/INBOX/threads/thread-1', + overrides: [ + accountRepositoryProvider.overrideWithValue( + FakeAccountRepository([kTestAccount]), + ), + mailboxRepositoryProvider.overrideWithValue( + FakeMailboxRepository(), + ), + emailRepositoryProvider.overrideWithValue( + FakeEmailRepository( + emails: [email], + emailBody: const EmailBody( + emailId: 'acc-1:10', + htmlBody: + '

Hi

', + attachments: [], + ), + ), + ), + ], + ), + ); + await tester.pumpAndSettle(); + + expect(find.text('Load remote images'), findsOneWidget); + + await tester.tap(find.text('Load remote images')); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + expect( + find.text('Images will be loaded automatically for this sender.'), + findsOneWidget, + ); + + // Regression test for #484: SnackBar with an action defaults to + // persist=true, which disables auto-dismiss — explicit persist:false + // restores duration-based dismissal. + await tester.pump(const Duration(seconds: 4)); + await tester.pumpAndSettle(); + + expect( + find.text('Images will be loaded automatically for this sender.'), + findsNothing, + ); + }, + ); }); }