Remove Cupertino folder picker branches

Keep the Material-only folder picker implementation while preserving public cupertino parameters for callers. Narrow the matching tests to the supported Material host.
This commit is contained in:
2026-11-11 10:56:54 +00:00
parent a3fdecbbcb
commit 1c2bb8733a
7 changed files with 185 additions and 401 deletions
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/folder_picker/folder_picker_route.dart';
@@ -22,7 +21,7 @@ class _Launcher extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: CupertinoButton(
child: TextButton(
child: const Text('Open picker'),
onPressed: () async => onResult(
await showFolderPicker(
@@ -37,11 +36,8 @@ class _Launcher extends StatelessWidget {
}
}
enum _Host { material, cupertino }
Future<void> _pump(
WidgetTester tester,
_Host host,
Widget launcher, {
Size size = const Size(420, 900),
}) async {
@@ -49,12 +45,10 @@ Future<void> _pump(
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
host == _Host.material
? MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(body: launcher),
)
: CupertinoApp(home: CupertinoPageScaffold(child: launcher)),
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(body: launcher),
),
);
await tester.tap(find.text('Open picker'));
await tester.pumpAndSettle();
@@ -63,123 +57,114 @@ Future<void> _pump(
Finder _crumb(String path) => find.byKey(ValueKey('folder-crumb-$path'));
void main() {
for (final host in _Host.values) {
testWidgets('${host.name}: opens at home, navigates, jumps up and returns '
'the folder', (tester) async {
final gateway = FakeDirectoryGateway();
String? result = 'unset';
await _pump(
tester,
host,
_Launcher(gateway: gateway, onResult: (value) => result = value),
);
expect(gateway.requests, [null]);
expect(find.text('Choose folder'), findsOneWidget);
expect(find.text('projects'), findsOneWidget);
expect(find.text('src'), findsOneWidget);
expect(find.text('git'), findsOneWidget);
expect(find.text('notes.txt'), findsOneWidget);
expect(find.text('Start in ~'), findsOneWidget);
testWidgets('opens at home, navigates, jumps up and returns the folder', (
tester,
) async {
final gateway = FakeDirectoryGateway();
String? result = 'unset';
await _pump(
tester,
_Launcher(gateway: gateway, onResult: (value) => result = value),
);
expect(gateway.requests, [null]);
expect(find.text('Choose folder'), findsOneWidget);
expect(find.text('projects'), findsOneWidget);
expect(find.text('src'), findsOneWidget);
expect(find.text('git'), findsOneWidget);
expect(find.text('notes.txt'), findsOneWidget);
expect(find.text('Start in ~'), findsOneWidget);
await tester.tap(find.text('projects'));
await tester.pumpAndSettle();
expect(gateway.requests.last, '$fakeHome/projects');
expect(find.text('app'), findsOneWidget);
expect(find.text('README.md'), findsOneWidget);
expect(find.text('Start in ~/projects'), findsOneWidget);
await tester.tap(find.text('projects'));
await tester.pumpAndSettle();
expect(gateway.requests.last, '$fakeHome/projects');
expect(find.text('app'), findsOneWidget);
expect(find.text('README.md'), findsOneWidget);
expect(find.text('Start in ~/projects'), findsOneWidget);
await tester.tap(find.text('app'));
await tester.pumpAndSettle();
expect(find.text('lib'), findsOneWidget);
// The home crumb jumps straight back up two levels.
await tester.tap(_crumb(fakeHome));
await tester.pumpAndSettle();
expect(gateway.requests.last, fakeHome);
expect(find.text('Start in ~'), findsOneWidget);
await tester.tap(find.text('app'));
await tester.pumpAndSettle();
expect(find.text('lib'), findsOneWidget);
// The home crumb jumps straight back up two levels.
await tester.tap(_crumb(fakeHome));
await tester.pumpAndSettle();
expect(gateway.requests.last, fakeHome);
expect(find.text('Start in ~'), findsOneWidget);
// Back climbs one folder instead of leaving the picker.
await tester.tap(find.text('projects'));
await tester.pumpAndSettle();
await tester.tap(find.text('web'));
await tester.pumpAndSettle();
expect(find.text('This folder is empty.'), findsOneWidget);
await tester.tap(
host == _Host.material
? find.byType(BackButton)
: find.byType(CupertinoNavigationBarBackButton),
);
await tester.pumpAndSettle();
expect(find.text('Start in ~/projects'), findsOneWidget);
expect(result, 'unset');
// Back climbs one folder instead of leaving the picker.
await tester.tap(find.text('projects'));
await tester.pumpAndSettle();
await tester.tap(find.text('web'));
await tester.pumpAndSettle();
expect(find.text('This folder is empty.'), findsOneWidget);
await tester.tap(find.byType(BackButton));
await tester.pumpAndSettle();
expect(find.text('Start in ~/projects'), findsOneWidget);
expect(result, 'unset');
await tester.tap(find.byKey(const Key('folder-picker-start')));
await tester.pumpAndSettle();
expect(result, '$fakeHome/projects');
expect(find.text('Choose folder'), findsNothing);
});
await tester.tap(find.byKey(const Key('folder-picker-start')));
await tester.pumpAndSettle();
expect(result, '$fakeHome/projects');
expect(find.text('Choose folder'), findsNothing);
});
testWidgets('${host.name}: hidden toggle and filter', (tester) async {
final gateway = FakeDirectoryGateway();
await _pump(tester, host, _Launcher(gateway: gateway, onResult: (_) {}));
expect(find.text('.config'), findsNothing);
expect(find.text('.zshrc'), findsNothing);
expect(find.text('Show hidden (2)'), findsOneWidget);
await tester.tap(find.byKey(const Key('folder-picker-hidden')));
await tester.pumpAndSettle();
expect(find.text('.config'), findsOneWidget);
expect(find.text('.zshrc'), findsOneWidget);
testWidgets('hidden toggle and filter', (tester) async {
final gateway = FakeDirectoryGateway();
await _pump(tester, _Launcher(gateway: gateway, onResult: (_) {}));
expect(find.text('.config'), findsNothing);
expect(find.text('.zshrc'), findsNothing);
expect(find.text('Show hidden (2)'), findsOneWidget);
await tester.tap(find.byKey(const Key('folder-picker-hidden')));
await tester.pumpAndSettle();
expect(find.text('.config'), findsOneWidget);
expect(find.text('.zshrc'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('folder-picker-filter')),
'PRO',
);
await tester.pumpAndSettle();
expect(find.text('projects'), findsOneWidget);
expect(find.text('src'), findsNothing);
await tester.enterText(
find.byKey(const Key('folder-picker-filter')),
'zzz',
);
await tester.pumpAndSettle();
expect(find.textContaining('Nothing here matches'), findsOneWidget);
});
await tester.enterText(
find.byKey(const Key('folder-picker-filter')),
'PRO',
);
await tester.pumpAndSettle();
expect(find.text('projects'), findsOneWidget);
expect(find.text('src'), findsNothing);
await tester.enterText(
find.byKey(const Key('folder-picker-filter')),
'zzz',
);
await tester.pumpAndSettle();
expect(find.textContaining('Nothing here matches'), findsOneWidget);
});
testWidgets('${host.name}: a refused folder is shown inline and home '
'recovers', (tester) async {
final gateway = FakeDirectoryGateway();
String? result = 'unset';
await _pump(
tester,
host,
_Launcher(
gateway: gateway,
initialPath: '/etc',
onResult: (value) => result = value,
),
);
expect(find.textContaining('outside the home directory'), findsOneWidget);
expect(find.text('No folder selected'), findsOneWidget);
await tester.tap(find.byKey(const Key('folder-picker-start')));
await tester.pumpAndSettle();
expect(result, 'unset');
testWidgets('a refused folder is shown inline and home recovers', (
tester,
) async {
final gateway = FakeDirectoryGateway();
String? result = 'unset';
await _pump(
tester,
_Launcher(
gateway: gateway,
initialPath: '/etc',
onResult: (value) => result = value,
),
);
expect(find.textContaining('outside the home directory'), findsOneWidget);
expect(find.text('No folder selected'), findsOneWidget);
await tester.tap(find.byKey(const Key('folder-picker-start')));
await tester.pumpAndSettle();
expect(result, 'unset');
await tester.tap(find.text('Go to home'));
await tester.pumpAndSettle();
expect(find.text('projects'), findsOneWidget);
await tester.tap(find.text('Go to home'));
await tester.pumpAndSettle();
expect(find.text('projects'), findsOneWidget);
gateway.denied.add('$fakeHome/projects');
await tester.tap(find.text('projects'));
await tester.pumpAndSettle();
expect(
find.text('permission denied: $fakeHome/projects'),
findsOneWidget,
);
await tester.tap(find.text('Back to ~'));
await tester.pumpAndSettle();
expect(find.text('projects'), findsOneWidget);
expect(find.text('Start in ~'), findsOneWidget);
});
}
gateway.denied.add('$fakeHome/projects');
await tester.tap(find.text('projects'));
await tester.pumpAndSettle();
expect(find.text('permission denied: $fakeHome/projects'), findsOneWidget);
await tester.tap(find.text('Back to ~'));
await tester.pumpAndSettle();
expect(find.text('projects'), findsOneWidget);
expect(find.text('Start in ~'), findsOneWidget);
});
testWidgets('opens at an initial folder and offers recents at home', (
tester,
@@ -187,7 +172,6 @@ void main() {
final gateway = FakeDirectoryGateway();
await _pump(
tester,
_Host.material,
_Launcher(
gateway: gateway,
initialPath: '$fakeHome/projects',
@@ -207,31 +191,20 @@ void main() {
expect(find.text('lib'), findsOneWidget);
});
for (final host in _Host.values) {
testWidgets('${host.name}: wide windows get a dialog, phones a page', (
testWidgets('wide windows get a dialog, phones a page', (tester) async {
final gateway = FakeDirectoryGateway();
await _pump(
tester,
) async {
final gateway = FakeDirectoryGateway();
await _pump(
tester,
host,
_Launcher(gateway: gateway, onResult: (_) {}),
size: const Size(1000, 900),
);
final page = tester.getSize(find.text('Choose folder'));
expect(page.width, greaterThan(0));
final scaffoldType = host == _Host.material
? Scaffold
: CupertinoPageScaffold;
final picker = find.ancestor(
of: find.text('Choose folder'),
matching: find.byType(scaffoldType),
);
expect(tester.getSize(picker.first).width, lessThan(1000));
expect(
host == _Host.material ? find.byType(Dialog) : find.byType(ClipRRect),
findsWidgets,
);
});
}
_Launcher(gateway: gateway, onResult: (_) {}),
size: const Size(1000, 900),
);
final page = tester.getSize(find.text('Choose folder'));
expect(page.width, greaterThan(0));
final picker = find.ancestor(
of: find.text('Choose folder'),
matching: find.byType(Scaffold),
);
expect(tester.getSize(picker.first).width, lessThan(1000));
expect(find.byType(Dialog), findsWidgets);
});
}
@@ -19,7 +19,6 @@ FakeChatGateway _gateway(FakeDirectoryGateway directories) {
void main() {
final hosts = <String, Future<void> Function(WidgetTester, FakeChatGateway)>{
'material': (tester, gateway) => pumpMaterialChat(tester, gateway),
'cupertino': (tester, gateway) => pumpCupertinoChat(tester, gateway),
'ios material': (tester, gateway) => pumpIosMaterialChat(tester, gateway),
};
for (final MapEntry(key: name, value: pump) in hosts.entries) {