import 'package:flutter_test/flutter_test.dart'; import 'package:halkyon_ui/halkyon_ui.dart'; import 'package:material_ui/material_ui.dart'; void main() { late int undos; late int kept; setUp(() { undos = 0; kept = 0; }); /// Shows "Studyset archived" with a way to undo it. Future archive(WidgetTester tester) async { await tester.pumpWidget( MaterialApp( localizationsDelegates: HalkyonUiLocalizations.localizationsDelegates, supportedLocales: HalkyonUiLocalizations.supportedLocales, home: Scaffold( body: Builder( builder: (context) => TextButton( onPressed: () => showUndoSnackBar( context, message: 'Studyset archived', onUndo: () => undos++, onKept: () => kept++, ), child: const Text('Archive'), ), ), ), ), ); await tester.tap(find.text('Archive')); await tester.pumpAndSettle(); } testWidgets('offers to undo', (tester) async { await archive(tester); expect(find.text('Studyset archived'), findsOneWidget); await tester.tap(find.text('Undo')); await tester.pumpAndSettle(); expect(undos, 1); expect(find.text('Studyset archived'), findsNothing); }); testWidgets('goes by itself after three seconds', (tester) async { await archive(tester); await tester.pump(const Duration(seconds: 3)); await tester.pumpAndSettle(); expect(find.text('Studyset archived'), findsNothing); expect(undos, 0); }); testWidgets('tells once it went without Undo, so what waited for it ' 'happens then', (tester) async { await archive(tester); expect(kept, 0, reason: 'not while it shows'); await tester.pump(const Duration(seconds: 3)); await tester.pumpAndSettle(); expect(kept, 1); }); testWidgets('never tells it was kept once undone', (tester) async { await archive(tester); await tester.tap(find.text('Undo')); await tester.pumpAndSettle(); await tester.pump(const Duration(seconds: 5)); expect(kept, 0); }); }