2020// CURRENTLY RED: lib/files exports no FilesView. HAND-OFF:
2121// lib/files/files_view.dart -> app-files-engineer.
2222
23+ import 'dart:async' ;
2324import 'dart:convert' ;
24- import 'dart:typed_data' ;
2525
2626import 'package:flutter/material.dart' ;
2727import 'package:flutter/services.dart' ;
2828import 'package:flutter_test/flutter_test.dart' ;
2929
30+ import 'package:pyble/app/providers.dart' ;
3031import 'package:pyble/editor/editor.dart' ;
3132import 'package:pyble/files/files.dart' ;
3233import 'package:pyble/localization/localization.dart' ;
33- import 'package:pyble/app/providers.dart' ;
3434import 'package:pyble/pble/pble.dart' ;
3535
3636import '../support/feature_harness.dart' ;
@@ -55,6 +55,34 @@ class _FailingDeleteConnection extends RecordingConnection {
5555 }
5656}
5757
58+ /// Holds one delete so the shell navigation provider can change while the
59+ /// non-cancellable PBLE/1 mutation remains in flight.
60+ class _HeldDeleteConnection extends RecordingConnection {
61+ _HeldDeleteConnection () : super (initial: ConnState .ready);
62+
63+ final Completer <void > started = Completer <void >();
64+ final Completer <void > release = Completer <void >();
65+
66+ @override
67+ Future <void > delete (String path) async {
68+ if (! started.isCompleted) started.complete ();
69+ await release.future;
70+ await super .delete (path);
71+ }
72+ }
73+
74+ /// Simulates a file disappearing before the board reports ENOENT. Reconciliation
75+ /// must not leave that absent row counted as a selected, retryable ghost.
76+ class _DisappearingDeleteConnection extends RecordingConnection {
77+ _DisappearingDeleteConnection () : super (initial: ConnState .ready);
78+
79+ @override
80+ Future <void > delete (String path) async {
81+ await super .delete (path);
82+ throw const ENoEnt ('scripted file disappeared before delete' );
83+ }
84+ }
85+
5886void main () {
5987 Uint8List b (String s) => Uint8List .fromList (utf8.encode (s));
6088 Key entryKey (String n) => ValueKey <String >('fileEntry_$n ' );
@@ -885,6 +913,162 @@ void main() {
885913 },
886914 );
887915
916+ testWidgets (
917+ 'editing selection clears the prior partial-result accounting' ,
918+ (WidgetTester tester) async {
919+ final _FailingDeleteConnection rec = _FailingDeleteConnection (
920+ failPath: '/beta.py' ,
921+ );
922+ addTearDown (rec.dispose);
923+ for (final String name in < String > ['alpha.py' , 'beta.py' , 'gamma.py' ]) {
924+ await rec.putFile ('/$name ' , b ('$name \n ' ));
925+ }
926+ await pumpSurface (tester, const FilesView (), connection: rec);
927+ await tester.pumpAndSettle ();
928+ final AppLocalizations l10n = l10nOf (tester);
929+
930+ await enterSelection (tester);
931+ await selectAllShown (tester);
932+ await tester.tap (find.byKey (kFilesBulkDeleteActionKey));
933+ await tester.pumpAndSettle ();
934+ await tester.tap (
935+ find.descendant (
936+ of: find.byType (AlertDialog ),
937+ matching: find.widgetWithText (FilledButton , l10n.commonDelete),
938+ ),
939+ );
940+ await tester.pumpAndSettle ();
941+
942+ final String stopped = l10n.filesDeleteSelectedStopped (1 , 2 );
943+ expect (find.text (stopped), findsOneWidget);
944+ await tester.tap (find.byKey (entryKey ('gamma.py' )));
945+ await tester.pump ();
946+
947+ expect (
948+ find.text (stopped),
949+ findsNothing,
950+ reason:
951+ 'a terminal result cannot be rewritten by later selection edits' ,
952+ );
953+ expect (
954+ find.text (l10n.filesDeleteSelectedStopped (1 , 1 )),
955+ findsNothing,
956+ reason:
957+ 'a later selection edit dismisses rather than mutates the result' ,
958+ );
959+ expect (find.text (l10n.filesSelectionSelectedCount (1 )), findsOneWidget);
960+ },
961+ );
962+
963+ testWidgets (
964+ 'reconciliation removes an absent failed row from retry selection' ,
965+ (WidgetTester tester) async {
966+ final _DisappearingDeleteConnection rec =
967+ _DisappearingDeleteConnection ();
968+ addTearDown (rec.dispose);
969+ await rec.putFile ('/alpha.py' , b ('alpha\n ' ));
970+ await rec.putFile ('/beta.py' , b ('beta\n ' ));
971+ await pumpSurface (tester, const FilesView (), connection: rec);
972+ await tester.pumpAndSettle ();
973+ final AppLocalizations l10n = l10nOf (tester);
974+
975+ await enterSelection (tester);
976+ await selectAllShown (tester);
977+ await tester.tap (find.byKey (kFilesBulkDeleteActionKey));
978+ await tester.pumpAndSettle ();
979+ await tester.tap (
980+ find.descendant (
981+ of: find.byType (AlertDialog ),
982+ matching: find.widgetWithText (FilledButton , l10n.commonDelete),
983+ ),
984+ );
985+ await tester.pumpAndSettle ();
986+
987+ expect (find.byKey (entryKey ('alpha.py' )), findsNothing);
988+ expect (find.byKey (selectKey ('alpha.py' )), findsNothing);
989+ expect (find.byKey (selectKey ('beta.py' )), findsOneWidget);
990+ expect (
991+ tester.widget <Checkbox >(find.byKey (selectKey ('beta.py' ))).value,
992+ isTrue,
993+ );
994+ expect (find.text (l10n.filesSelectionSelectedCount (1 )), findsOneWidget);
995+ expect (
996+ find.text (l10n.filesDeleteSelectedStopped (0 , 1 )),
997+ findsOneWidget,
998+ );
999+ },
1000+ );
1001+
1002+ testWidgets (
1003+ 'navigation during a running delete clears selection without hidden focus' ,
1004+ (WidgetTester tester) async {
1005+ final _HeldDeleteConnection rec = _HeldDeleteConnection ();
1006+ addTearDown (rec.dispose);
1007+ await rec.putFile ('/alpha.py' , b ('alpha\n ' ));
1008+ await pumpSurface (tester, const FilesView (), connection: rec);
1009+ await tester.pumpAndSettle ();
1010+ final AppLocalizations l10n = l10nOf (tester);
1011+
1012+ await enterSelection (tester);
1013+ await tester.tap (find.byKey (entryKey ('alpha.py' )));
1014+ await tester.pump ();
1015+ await tester.tap (find.byKey (kFilesBulkDeleteActionKey));
1016+ await tester.pumpAndSettle ();
1017+ await tester.tap (
1018+ find.descendant (
1019+ of: find.byType (AlertDialog ),
1020+ matching: find.widgetWithText (FilledButton , l10n.commonDelete),
1021+ ),
1022+ );
1023+ await tester.pump ();
1024+ expect (rec.started.isCompleted, isTrue);
1025+
1026+ containerOf (tester).read (selectedSurfaceProvider.notifier).state =
1027+ AppSurface .editor;
1028+ await tester.pump ();
1029+ rec.release.complete ();
1030+ await tester.pumpAndSettle ();
1031+
1032+ expect (find.byKey (kFilesSelectionBarKey), findsNothing);
1033+ final Finder selectAction = find.byKey (kFilesSelectActionKey);
1034+ expect (selectAction, findsOneWidget);
1035+ expect (
1036+ primaryFocusIsWithin (tester, selectAction),
1037+ isFalse,
1038+ reason: 'completion must not move focus into an offstage Files tree' ,
1039+ );
1040+ expect (find.text (l10n.filesDeleteSelectedComplete (1 )), findsOneWidget);
1041+ },
1042+ );
1043+
1044+ testWidgets ('a replaced listing dismisses a stale confirmation safely' , (
1045+ WidgetTester tester,
1046+ ) async {
1047+ final RecordingConnection rec = RecordingConnection (
1048+ initial: ConnState .ready,
1049+ );
1050+ addTearDown (rec.dispose);
1051+ await rec.putFile ('/alpha.py' , b ('alpha\n ' ));
1052+ await pumpSurface (tester, const FilesView (), connection: rec);
1053+ await tester.pumpAndSettle ();
1054+
1055+ await enterSelection (tester);
1056+ await tester.tap (find.byKey (entryKey ('alpha.py' )));
1057+ await tester.pump ();
1058+ await tester.tap (find.byKey (kFilesBulkDeleteActionKey));
1059+ await tester.pumpAndSettle ();
1060+ expect (find.byType (AlertDialog ), findsOneWidget);
1061+
1062+ await containerOf (tester).read (fileExplorerProvider.notifier).refresh ();
1063+ await tester.pumpAndSettle ();
1064+
1065+ expect (find.byType (AlertDialog ), findsNothing);
1066+ expect (find.byKey (kFilesSelectionBarKey), findsNothing);
1067+ expect (rec.deleteCalls, isEmpty);
1068+ final Finder selectAction = find.byKey (kFilesSelectActionKey);
1069+ expect (primaryFocusIsWithin (tester, selectAction), isTrue);
1070+ });
1071+
8881072 testWidgets (
8891073 'selection and exact confirmation do not overflow narrow 2x UI' ,
8901074 (WidgetTester tester) async {
0 commit comments