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/material.dart';
import '../../data/directory_listing.dart'; import '../../data/directory_listing.dart';
@@ -36,7 +35,6 @@ class FolderPickerList extends StatelessWidget {
FolderSectionHeader(cupertino: cupertino, text: 'Recent folders'), FolderSectionHeader(cupertino: cupertino, text: 'Recent folders'),
for (final path in recents) for (final path in recents)
_RecentRow( _RecentRow(
cupertino: cupertino,
label: homeRelativeLabel(listing.home, path), label: homeRelativeLabel(listing.home, path),
onTap: () => controller.open(path), onTap: () => controller.open(path),
), ),
@@ -47,7 +45,6 @@ class FolderPickerList extends StatelessWidget {
], ],
for (final entry in entries) for (final entry in entries)
_EntryRow( _EntryRow(
cupertino: cupertino,
entry: entry, entry: entry,
onTap: controller.canEnter(entry) onTap: controller.canEnter(entry)
? () => controller.open(entry.path) ? () => controller.open(entry.path)
@@ -78,26 +75,13 @@ class FolderPickerList extends StatelessWidget {
} }
class _RecentRow extends StatelessWidget { class _RecentRow extends StatelessWidget {
const _RecentRow({ const _RecentRow({required this.label, required this.onTap});
required this.cupertino,
required this.label,
required this.onTap,
});
final bool cupertino;
final String label; final String label;
final VoidCallback onTap; final VoidCallback onTap;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (cupertino) {
return CupertinoListTile(
leading: const Icon(CupertinoIcons.clock),
title: Text(label),
trailing: const CupertinoListTileChevron(),
onTap: onTap,
);
}
return ListTile( return ListTile(
leading: const Icon(Icons.history), leading: const Icon(Icons.history),
title: Text(label), title: Text(label),
@@ -108,13 +92,8 @@ class _RecentRow extends StatelessWidget {
} }
class _EntryRow extends StatelessWidget { class _EntryRow extends StatelessWidget {
const _EntryRow({ const _EntryRow({required this.entry, required this.onTap});
required this.cupertino,
required this.entry,
required this.onTap,
});
final bool cupertino;
final DirectoryEntry entry; final DirectoryEntry entry;
final VoidCallback? onTap; final VoidCallback? onTap;
@@ -128,27 +107,12 @@ class _EntryRow extends StatelessWidget {
? Row( ? Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
if (entry.isGitRepo) FolderGitBadge(cupertino: cupertino), if (entry.isGitRepo) const FolderGitBadge(cupertino: false),
const SizedBox(width: 4), const SizedBox(width: 4),
cupertino const Icon(Icons.chevron_right),
? const CupertinoListTileChevron()
: const Icon(Icons.chevron_right),
], ],
) )
: null; : null;
if (cupertino) {
final dim = CupertinoColors.tertiaryLabel.resolveFrom(context);
return CupertinoListTile(
key: ValueKey('folder-entry-${entry.path}'),
leading: Icon(
folder ? CupertinoIcons.folder_fill : CupertinoIcons.doc,
color: enabled ? null : dim,
),
title: Text(entry.name, style: enabled ? null : TextStyle(color: dim)),
trailing: trailing,
onTap: onTap,
);
}
return ListTile( return ListTile(
key: ValueKey('folder-entry-${entry.path}'), key: ValueKey('folder-entry-${entry.path}'),
enabled: enabled, enabled: enabled,
@@ -171,29 +135,11 @@ class FolderGitBadge extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (!cupertino) { final scheme = Theme.of(context).colorScheme;
final scheme = Theme.of(context).colorScheme; return Badge(
return Badge( label: const Text('git'),
label: const Text('git'), backgroundColor: scheme.secondaryContainer,
backgroundColor: scheme.secondaryContainer, textColor: scheme.onSecondaryContainer,
textColor: scheme.onSecondaryContainer,
);
}
return DecoratedBox(
decoration: BoxDecoration(
color: CupertinoColors.systemGrey5.resolveFrom(context),
borderRadius: BorderRadius.circular(6),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
child: Text(
'git',
style: TextStyle(
fontSize: 12,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
),
),
),
); );
} }
} }
@@ -1,9 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../../../../ui/adaptive/segmented_bar.dart'; import '../../../../ui/adaptive/segmented_bar.dart';
import '../sessions/chat_adaptive.dart';
import 'folder_picker_controller.dart'; import 'folder_picker_controller.dart';
import 'folder_picker_list.dart'; import 'folder_picker_list.dart';
import 'folder_picker_parts.dart'; import 'folder_picker_parts.dart';
@@ -79,25 +77,20 @@ class _FolderPickerPageState extends State<FolderPickerPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final body = Column( final body = Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
FolderBreadcrumbs(cupertino: cupertino, controller: _controller), FolderBreadcrumbs(cupertino: false, controller: _controller),
FolderPickerToolbar( FolderPickerToolbar(
cupertino: cupertino, cupertino: false,
controller: _controller, controller: _controller,
filter: _filter, filter: _filter,
), ),
Expanded( Expanded(
child: FolderPickerList( child: FolderPickerList(cupertino: false, controller: _controller),
cupertino: cupertino,
controller: _controller,
),
), ),
FolderStartBar( FolderStartBar(
cupertino: cupertino, cupertino: false,
path: _controller.selectable, path: _controller.selectable,
home: _controller.home, home: _controller.home,
onStart: _start, onStart: _start,
@@ -110,48 +103,31 @@ class _FolderPickerPageState extends State<FolderPickerPage> {
onPopInvokedWithResult: (didPop, _) { onPopInvokedWithResult: (didPop, _) {
if (!didPop) _back(); if (!didPop) _back();
}, },
child: cupertino ? _cupertino(context, body) : _material(body), child: _material(body),
); );
} }
/// The app's segmented bar: Back (climbing one folder), the title, and /// The app's segmented bar: Back (climbing one folder), the title, and
/// Cancel in the actions pill, each popping in like every other bar. /// Cancel in the actions pill, each popping in like every other bar.
SegmentedBar _bar(bool cupertino) => SegmentedBar( SegmentedBar _bar() => SegmentedBar(
cupertino: cupertino, cupertino: false,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
leading: SegmentedBackButton(cupertino: cupertino, onPressed: _back), leading: SegmentedBackButton(cupertino: false, onPressed: _back),
title: widget.purpose.title, title: widget.purpose.title,
actions: [ actions: [
if (cupertino) TextButton(
CupertinoButton( onPressed: () => Navigator.pop(context),
padding: const EdgeInsets.symmetric(horizontal: 16), child: const Text('Cancel'),
onPressed: () => Navigator.pop(context), ),
child: const Text('Cancel'),
)
else
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
], ],
); );
Widget _material(Widget body) { Widget _material(Widget body) {
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
appBar: _bar(false), appBar: _bar(),
// Inset below the floating bar, which the scaffold reports as padding. // Inset below the floating bar, which the scaffold reports as padding.
body: SafeArea(child: body), body: SafeArea(child: body),
); );
} }
Widget _cupertino(BuildContext context, Widget body) {
return CupertinoPageScaffold(
navigationBar: _bar(true),
child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: SafeArea(child: body),
),
);
}
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../data/directory_listing.dart'; import '../../data/directory_listing.dart';
@@ -27,12 +26,7 @@ class FolderBreadcrumbs extends StatelessWidget {
final crumb = crumbs[i]; final crumb = crumbs[i];
final last = i == crumbs.length - 1; final last = i == crumbs.length - 1;
if (i > 0) { if (i > 0) {
children.add( children.add(Icon(Icons.chevron_right, size: 16));
Icon(
cupertino ? CupertinoIcons.chevron_right : Icons.chevron_right,
size: 16,
),
);
} }
children.add( children.add(
Semantics( Semantics(
@@ -70,29 +64,13 @@ class FolderBreadcrumbs extends StatelessWidget {
? Row( ? Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(cupertino ? CupertinoIcons.house : Icons.home_outlined), const Icon(Icons.home_outlined),
const SizedBox(width: 4), const SizedBox(width: 4),
text, text,
], ],
) )
: text; : text;
final onPressed = last ? null : () => controller.open(crumb.path); final onPressed = last ? null : () => controller.open(crumb.path);
if (cupertino) {
return CupertinoButton(
key: ValueKey('folder-crumb-${crumb.path}'),
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 8),
onPressed: onPressed,
disabledColor: CupertinoColors.transparent,
child: last
? DefaultTextStyle.merge(
style: TextStyle(
color: CupertinoColors.label.resolveFrom(context),
),
child: label,
)
: label,
);
}
return TextButton( return TextButton(
key: ValueKey('folder-crumb-${crumb.path}'), key: ValueKey('folder-crumb-${crumb.path}'),
onPressed: onPressed, onPressed: onPressed,
@@ -124,61 +102,33 @@ class FolderPickerToolbar extends StatelessWidget {
final hiddenLabel = controller.hiddenCount > 0 final hiddenLabel = controller.hiddenCount > 0
? 'Show hidden (${controller.hiddenCount})' ? 'Show hidden (${controller.hiddenCount})'
: 'Show hidden'; : 'Show hidden';
final field = cupertino final field = TextField(
? CupertinoSearchTextField( key: const Key('folder-picker-filter'),
key: const Key('folder-picker-filter'), controller: filter,
controller: filter, onChanged: controller.setFilter,
placeholder: 'Filter this folder', decoration: InputDecoration(
onChanged: controller.setFilter, isDense: true,
) prefixIcon: const Icon(Icons.search),
: TextField( hintText: 'Filter this folder',
key: const Key('folder-picker-filter'), border: const OutlineInputBorder(),
controller: filter, suffixIcon: filter.text.isEmpty
onChanged: controller.setFilter, ? null
decoration: InputDecoration( : IconButton(
isDense: true, tooltip: 'Clear filter',
prefixIcon: const Icon(Icons.search), icon: const Icon(Icons.clear),
hintText: 'Filter this folder', onPressed: () {
border: const OutlineInputBorder(), filter.clear();
suffixIcon: filter.text.isEmpty controller.setFilter('');
? null },
: IconButton(
tooltip: 'Clear filter',
icon: const Icon(Icons.clear),
onPressed: () {
filter.clear();
controller.setFilter('');
},
),
),
);
final toggle = cupertino
? Semantics(
label: 'Show hidden',
toggled: controller.showHidden,
excludeSemantics: true,
child: GestureDetector(
onTap: () => controller.setShowHidden(!controller.showHidden),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(hiddenLabel),
const SizedBox(width: 6),
CupertinoSwitch(
key: const Key('folder-picker-hidden'),
value: controller.showHidden,
onChanged: controller.setShowHidden,
),
],
), ),
), ),
) );
: FilterChip( final toggle = FilterChip(
key: const Key('folder-picker-hidden'), key: const Key('folder-picker-hidden'),
label: Text(hiddenLabel), label: Text(hiddenLabel),
selected: controller.showHidden, selected: controller.showHidden,
onSelected: controller.setShowHidden, onSelected: controller.setShowHidden,
); );
return Padding( return Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 8), padding: const EdgeInsets.fromLTRB(16, 4, 16, 8),
child: Wrap( child: Wrap(
@@ -222,18 +172,12 @@ class FolderStartBar extends StatelessWidget {
? 'No folder selected' ? 'No folder selected'
: purpose.describe(homeRelativeLabel(home!, path!)); : purpose.describe(homeRelativeLabel(home!, path!));
final onPressed = path == null ? null : onStart; final onPressed = path == null ? null : onStart;
final button = cupertino final button = FilledButton.icon(
? CupertinoButton.filled( key: const Key('folder-picker-start'),
key: const Key('folder-picker-start'), onPressed: onPressed,
onPressed: onPressed, icon: Icon(purpose.icon),
child: Text(purpose.confirmLabel), label: Text(purpose.confirmLabel),
) );
: FilledButton.icon(
key: const Key('folder-picker-start'),
onPressed: onPressed,
icon: Icon(purpose.icon),
label: Text(purpose.confirmLabel),
);
final content = Padding( final content = Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12), padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
child: Column( child: Column(
@@ -251,19 +195,6 @@ class FolderStartBar extends StatelessWidget {
], ],
), ),
); );
if (cupertino) {
return DecoratedBox(
decoration: BoxDecoration(
border: Border(
top: BorderSide(
color: CupertinoColors.separator.resolveFrom(context),
width: 0,
),
),
),
child: content,
);
}
return Material( return Material(
color: Theme.of(context).colorScheme.surfaceContainer, color: Theme.of(context).colorScheme.surfaceContainer,
child: content, child: content,
@@ -1,10 +1,8 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../sessions/chat_adaptive.dart';
import 'folder_picker_page.dart'; import 'folder_picker_page.dart';
import 'folder_picker_purpose.dart'; import 'folder_picker_purpose.dart';
@@ -27,7 +25,6 @@ Future<String?> showFolderPicker(
List<String> recents = const [], List<String> recents = const [],
FolderPickerPurpose purpose = FolderPickerPurpose.startChat, FolderPickerPurpose purpose = FolderPickerPurpose.startChat,
}) { }) {
final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final size = MediaQuery.sizeOf(context); final size = MediaQuery.sizeOf(context);
final wide = size.width >= folderPickerDialogBreakpoint; final wide = size.width >= folderPickerDialogBreakpoint;
final navigator = Navigator.of(context, rootNavigator: true); final navigator = Navigator.of(context, rootNavigator: true);
@@ -39,9 +36,7 @@ Future<String?> showFolderPicker(
); );
if (!wide) { if (!wide) {
return navigator.push<String>( return navigator.push<String>(
cupertino MaterialPageRoute(fullscreenDialog: true, builder: page),
? CupertinoPageRoute(fullscreenDialog: true, builder: page)
: MaterialPageRoute(fullscreenDialog: true, builder: page),
); );
} }
Widget bounded(BuildContext context) { Widget bounded(BuildContext context) {
@@ -53,18 +48,6 @@ Future<String?> showFolderPicker(
); );
} }
if (cupertino) {
return showCupertinoDialog<String>(
context: context,
useRootNavigator: true,
builder: (context) => Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(14),
child: bounded(context),
),
),
);
}
return showDialog<String>( return showDialog<String>(
context: context, context: context,
useRootNavigator: true, useRootNavigator: true,
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../data/directory_listing.dart'; import '../../data/directory_listing.dart';
@@ -15,9 +14,7 @@ class FolderPickerLoading extends StatelessWidget {
return Center( return Center(
child: Semantics( child: Semantics(
label: 'Loading folder', label: 'Loading folder',
child: cupertino child: const CircularProgressIndicator(),
? const CupertinoActivityIndicator()
: const CircularProgressIndicator(),
), ),
); );
} }
@@ -33,12 +30,7 @@ class FolderPickerLoadingBar extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Semantics( return Semantics(
label: 'Loading folder', label: 'Loading folder',
child: cupertino child: const LinearProgressIndicator(),
? const Padding(
padding: EdgeInsets.all(8),
child: CupertinoActivityIndicator(),
)
: const LinearProgressIndicator(),
); );
} }
} }
@@ -57,9 +49,7 @@ class FolderPickerError extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final color = cupertino final color = Theme.of(context).colorScheme.error;
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error;
final listing = controller.listing; final listing = controller.listing;
final actions = <(String, VoidCallback)>[ final actions = <(String, VoidCallback)>[
('Retry', controller.retry), ('Retry', controller.retry),
@@ -76,12 +66,7 @@ class FolderPickerError extends StatelessWidget {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Icon( Icon(Icons.error_outline, color: color),
cupertino
? CupertinoIcons.exclamationmark_triangle
: Icons.error_outline,
color: color,
),
const SizedBox(height: 8), const SizedBox(height: 8),
Text( Text(
"Can't open this folder", "Can't open this folder",
@@ -101,9 +86,7 @@ class FolderPickerError extends StatelessWidget {
alignment: WrapAlignment.center, alignment: WrapAlignment.center,
children: [ children: [
for (final (label, onPressed) in actions) for (final (label, onPressed) in actions)
cupertino TextButton(onPressed: onPressed, child: Text(label)),
? CupertinoButton(onPressed: onPressed, child: Text(label))
: TextButton(onPressed: onPressed, child: Text(label)),
], ],
), ),
], ],
@@ -125,14 +108,9 @@ class FolderSectionHeader extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final style = cupertino final style = Theme.of(context).textTheme.labelLarge?.copyWith(
? TextStyle( color: Theme.of(context).colorScheme.primary,
fontSize: 13, );
color: CupertinoColors.secondaryLabel.resolveFrom(context),
)
: Theme.of(context).textTheme.labelLarge?.copyWith(
color: Theme.of(context).colorScheme.primary,
);
return Padding( return Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4), padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
child: Text(text, style: style), child: Text(text, style: style),
@@ -153,9 +131,7 @@ class FolderPickerNote extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final color = cupertino final color = Theme.of(context).colorScheme.onSurfaceVariant;
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
return Padding( return Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Text(text, style: TextStyle(color: color)), child: Text(text, style: TextStyle(color: color)),
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/folder_picker/folder_picker_route.dart'; import 'package:pipelines_app/features/chat/ui/folder_picker/folder_picker_route.dart';
@@ -22,7 +21,7 @@ class _Launcher extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return Center(
child: CupertinoButton( child: TextButton(
child: const Text('Open picker'), child: const Text('Open picker'),
onPressed: () async => onResult( onPressed: () async => onResult(
await showFolderPicker( await showFolderPicker(
@@ -37,11 +36,8 @@ class _Launcher extends StatelessWidget {
} }
} }
enum _Host { material, cupertino }
Future<void> _pump( Future<void> _pump(
WidgetTester tester, WidgetTester tester,
_Host host,
Widget launcher, { Widget launcher, {
Size size = const Size(420, 900), Size size = const Size(420, 900),
}) async { }) async {
@@ -49,12 +45,10 @@ Future<void> _pump(
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset); addTearDown(tester.view.reset);
await tester.pumpWidget( await tester.pumpWidget(
host == _Host.material MaterialApp(
? MaterialApp( theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android), home: Scaffold(body: launcher),
home: Scaffold(body: launcher), ),
)
: CupertinoApp(home: CupertinoPageScaffold(child: launcher)),
); );
await tester.tap(find.text('Open picker')); await tester.tap(find.text('Open picker'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
@@ -63,123 +57,114 @@ Future<void> _pump(
Finder _crumb(String path) => find.byKey(ValueKey('folder-crumb-$path')); Finder _crumb(String path) => find.byKey(ValueKey('folder-crumb-$path'));
void main() { void main() {
for (final host in _Host.values) { testWidgets('opens at home, navigates, jumps up and returns the folder', (
testWidgets('${host.name}: opens at home, navigates, jumps up and returns ' tester,
'the folder', (tester) async { ) async {
final gateway = FakeDirectoryGateway(); final gateway = FakeDirectoryGateway();
String? result = 'unset'; String? result = 'unset';
await _pump( await _pump(
tester, tester,
host, _Launcher(gateway: gateway, onResult: (value) => result = value),
_Launcher(gateway: gateway, onResult: (value) => result = value), );
); expect(gateway.requests, [null]);
expect(gateway.requests, [null]); expect(find.text('Choose folder'), findsOneWidget);
expect(find.text('Choose folder'), findsOneWidget); expect(find.text('projects'), findsOneWidget);
expect(find.text('projects'), findsOneWidget); expect(find.text('src'), findsOneWidget);
expect(find.text('src'), findsOneWidget); expect(find.text('git'), findsOneWidget);
expect(find.text('git'), findsOneWidget); expect(find.text('notes.txt'), findsOneWidget);
expect(find.text('notes.txt'), findsOneWidget); expect(find.text('Start in ~'), findsOneWidget);
expect(find.text('Start in ~'), findsOneWidget);
await tester.tap(find.text('projects')); await tester.tap(find.text('projects'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(gateway.requests.last, '$fakeHome/projects'); expect(gateway.requests.last, '$fakeHome/projects');
expect(find.text('app'), findsOneWidget); expect(find.text('app'), findsOneWidget);
expect(find.text('README.md'), findsOneWidget); expect(find.text('README.md'), findsOneWidget);
expect(find.text('Start in ~/projects'), findsOneWidget); expect(find.text('Start in ~/projects'), findsOneWidget);
await tester.tap(find.text('app')); await tester.tap(find.text('app'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('lib'), findsOneWidget); expect(find.text('lib'), findsOneWidget);
// The home crumb jumps straight back up two levels. // The home crumb jumps straight back up two levels.
await tester.tap(_crumb(fakeHome)); await tester.tap(_crumb(fakeHome));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(gateway.requests.last, fakeHome); expect(gateway.requests.last, fakeHome);
expect(find.text('Start in ~'), findsOneWidget); expect(find.text('Start in ~'), findsOneWidget);
// Back climbs one folder instead of leaving the picker. // Back climbs one folder instead of leaving the picker.
await tester.tap(find.text('projects')); await tester.tap(find.text('projects'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.text('web')); await tester.tap(find.text('web'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('This folder is empty.'), findsOneWidget); expect(find.text('This folder is empty.'), findsOneWidget);
await tester.tap( await tester.tap(find.byType(BackButton));
host == _Host.material await tester.pumpAndSettle();
? find.byType(BackButton) expect(find.text('Start in ~/projects'), findsOneWidget);
: find.byType(CupertinoNavigationBarBackButton), expect(result, 'unset');
);
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.tap(find.byKey(const Key('folder-picker-start')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(result, '$fakeHome/projects'); expect(result, '$fakeHome/projects');
expect(find.text('Choose folder'), findsNothing); expect(find.text('Choose folder'), findsNothing);
}); });
testWidgets('${host.name}: hidden toggle and filter', (tester) async { testWidgets('hidden toggle and filter', (tester) async {
final gateway = FakeDirectoryGateway(); final gateway = FakeDirectoryGateway();
await _pump(tester, host, _Launcher(gateway: gateway, onResult: (_) {})); await _pump(tester, _Launcher(gateway: gateway, onResult: (_) {}));
expect(find.text('.config'), findsNothing); expect(find.text('.config'), findsNothing);
expect(find.text('.zshrc'), findsNothing); expect(find.text('.zshrc'), findsNothing);
expect(find.text('Show hidden (2)'), findsOneWidget); expect(find.text('Show hidden (2)'), findsOneWidget);
await tester.tap(find.byKey(const Key('folder-picker-hidden'))); await tester.tap(find.byKey(const Key('folder-picker-hidden')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('.config'), findsOneWidget); expect(find.text('.config'), findsOneWidget);
expect(find.text('.zshrc'), findsOneWidget); expect(find.text('.zshrc'), findsOneWidget);
await tester.enterText( await tester.enterText(
find.byKey(const Key('folder-picker-filter')), find.byKey(const Key('folder-picker-filter')),
'PRO', 'PRO',
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('projects'), findsOneWidget); expect(find.text('projects'), findsOneWidget);
expect(find.text('src'), findsNothing); expect(find.text('src'), findsNothing);
await tester.enterText( await tester.enterText(
find.byKey(const Key('folder-picker-filter')), find.byKey(const Key('folder-picker-filter')),
'zzz', 'zzz',
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.textContaining('Nothing here matches'), findsOneWidget); expect(find.textContaining('Nothing here matches'), findsOneWidget);
}); });
testWidgets('${host.name}: a refused folder is shown inline and home ' testWidgets('a refused folder is shown inline and home recovers', (
'recovers', (tester) async { tester,
final gateway = FakeDirectoryGateway(); ) async {
String? result = 'unset'; final gateway = FakeDirectoryGateway();
await _pump( String? result = 'unset';
tester, await _pump(
host, tester,
_Launcher( _Launcher(
gateway: gateway, gateway: gateway,
initialPath: '/etc', initialPath: '/etc',
onResult: (value) => result = value, onResult: (value) => result = value,
), ),
); );
expect(find.textContaining('outside the home directory'), findsOneWidget); expect(find.textContaining('outside the home directory'), findsOneWidget);
expect(find.text('No folder selected'), findsOneWidget); expect(find.text('No folder selected'), findsOneWidget);
await tester.tap(find.byKey(const Key('folder-picker-start'))); await tester.tap(find.byKey(const Key('folder-picker-start')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(result, 'unset'); expect(result, 'unset');
await tester.tap(find.text('Go to home')); await tester.tap(find.text('Go to home'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('projects'), findsOneWidget); expect(find.text('projects'), findsOneWidget);
gateway.denied.add('$fakeHome/projects'); gateway.denied.add('$fakeHome/projects');
await tester.tap(find.text('projects')); await tester.tap(find.text('projects'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect( expect(find.text('permission denied: $fakeHome/projects'), findsOneWidget);
find.text('permission denied: $fakeHome/projects'), await tester.tap(find.text('Back to ~'));
findsOneWidget, await tester.pumpAndSettle();
); expect(find.text('projects'), findsOneWidget);
await tester.tap(find.text('Back to ~')); expect(find.text('Start in ~'), findsOneWidget);
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', ( testWidgets('opens at an initial folder and offers recents at home', (
tester, tester,
@@ -187,7 +172,6 @@ void main() {
final gateway = FakeDirectoryGateway(); final gateway = FakeDirectoryGateway();
await _pump( await _pump(
tester, tester,
_Host.material,
_Launcher( _Launcher(
gateway: gateway, gateway: gateway,
initialPath: '$fakeHome/projects', initialPath: '$fakeHome/projects',
@@ -207,31 +191,20 @@ void main() {
expect(find.text('lib'), findsOneWidget); expect(find.text('lib'), findsOneWidget);
}); });
for (final host in _Host.values) { testWidgets('wide windows get a dialog, phones a page', (tester) async {
testWidgets('${host.name}: wide windows get a dialog, phones a page', ( final gateway = FakeDirectoryGateway();
await _pump(
tester, tester,
) async { _Launcher(gateway: gateway, onResult: (_) {}),
final gateway = FakeDirectoryGateway(); size: const Size(1000, 900),
await _pump( );
tester, final page = tester.getSize(find.text('Choose folder'));
host, expect(page.width, greaterThan(0));
_Launcher(gateway: gateway, onResult: (_) {}), final picker = find.ancestor(
size: const Size(1000, 900), of: find.text('Choose folder'),
); matching: find.byType(Scaffold),
final page = tester.getSize(find.text('Choose folder')); );
expect(page.width, greaterThan(0)); expect(tester.getSize(picker.first).width, lessThan(1000));
final scaffoldType = host == _Host.material expect(find.byType(Dialog), findsWidgets);
? 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,
);
});
}
} }
@@ -19,7 +19,6 @@ FakeChatGateway _gateway(FakeDirectoryGateway directories) {
void main() { void main() {
final hosts = <String, Future<void> Function(WidgetTester, FakeChatGateway)>{ final hosts = <String, Future<void> Function(WidgetTester, FakeChatGateway)>{
'material': (tester, gateway) => pumpMaterialChat(tester, gateway), 'material': (tester, gateway) => pumpMaterialChat(tester, gateway),
'cupertino': (tester, gateway) => pumpCupertinoChat(tester, gateway),
'ios material': (tester, gateway) => pumpIosMaterialChat(tester, gateway), 'ios material': (tester, gateway) => pumpIosMaterialChat(tester, gateway),
}; };
for (final MapEntry(key: name, value: pump) in hosts.entries) { for (final MapEntry(key: name, value: pump) in hosts.entries) {