Files
IKAR/test/undo_notification_test.dart

75 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ikar/frontend/widgets/undo_notification.dart';
import 'package:ikar/l10n/app_localizations.dart';
void main() {
Future<void> pump(
WidgetTester tester,
void Function(BuildContext) show,
) async {
await tester.pumpWidget(
MaterialApp(
locale: const Locale('ru'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: Builder(
builder: (context) => TextButton(
onPressed: () => show(context),
child: const Text('delete'),
),
),
),
),
);
await tester.tap(find.text('delete'));
await tester.pump();
}
testWidgets('undo cancels deletion and cannot later commit', (tester) async {
var committed = 0;
var cancelled = 0;
late PendingUndo pending;
await pump(tester, (context) {
pending = showUndoNotification(
context,
'pending',
onCommit: () {
committed++;
},
onUndo: () {
cancelled++;
},
);
});
pending.undo();
pending.commit();
await tester.pumpAndSettle();
expect(committed, 0);
expect(cancelled, 1);
});
testWidgets('expiration commits once despite repeated callbacks', (
tester,
) async {
var committed = 0;
late PendingUndo pending;
await pump(tester, (context) {
pending = showUndoNotification(
context,
'pending',
duration: const Duration(seconds: 1),
onCommit: () {
committed++;
},
onUndo: () {},
);
});
await tester.pump(const Duration(seconds: 2));
pending.commit();
await tester.pumpAndSettle();
expect(committed, 1);
});
}