fix(detail): auto-dismiss "Load remote images" snack bar #548
@@ -239,6 +239,10 @@ class _EmailDetailScreenState extends ConsumerState<EmailDetailScreen> {
|
||||
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.',
|
||||
),
|
||||
|
||||
@@ -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.',
|
||||
),
|
||||
|
||||
@@ -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: '<p>Hello <img src="https://example.com/x.png"/></p>',
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
'<p>Hi <img src="https://example.com/x.png"/></p>',
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user