Learn's DelayedDeletions, unchanged, with its test, so that Train's workouts can be deleted with an undo as Learn's items are. Learn's deletions import it from halkyon_app now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
49 lines
1.4 KiB
Dart
49 lines
1.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:halkyon_app/halkyon_app.dart';
|
|
|
|
import '../support/eventually.dart';
|
|
|
|
void main() {
|
|
late List<String> deleted;
|
|
late DelayedDeletions deletions;
|
|
|
|
setUp(() {
|
|
deleted = [];
|
|
deletions = DelayedDeletions(
|
|
(id) async => deleted.add(id),
|
|
undoWindow: const Duration(milliseconds: 10),
|
|
);
|
|
});
|
|
tearDown(() => deletions.dispose());
|
|
|
|
test('a held deletion waits past the time to undo, until it is let go: '
|
|
'then it takes its time to undo', () async {
|
|
deletions.hold('a');
|
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
|
expect(deletions.pending, {'a'});
|
|
expect(deleted, isEmpty);
|
|
|
|
deletions.delete('a');
|
|
expect(deletions.pending, {'a'});
|
|
await eventually(() => deletions.pending.isEmpty);
|
|
expect(deleted, ['a']);
|
|
});
|
|
|
|
test('a held deletion can be undone', () async {
|
|
deletions
|
|
..hold('a')
|
|
..undo('a');
|
|
expect(deletions.pending, isEmpty);
|
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
|
expect(deleted, isEmpty);
|
|
});
|
|
|
|
test('closing drops a held deletion: the item stays', () async {
|
|
deletions.hold('a');
|
|
await deletions.dispose();
|
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
|
|
|
expect(deleted, isEmpty);
|
|
deletions = DelayedDeletions((id) async {});
|
|
});
|
|
}
|