Keep Files breadcrumbs aligned to the current folder
Pin the horizontally scrolling breadcrumb to its trailing edge so deep paths keep the current folder visible. Preserve tappable navigation, middle-ellipsize long labels, and cover the behavior with focused widget tests and the rendered fixture.
This commit is contained in:
@@ -21,14 +21,20 @@ class Gateway extends PipelinesClient {
|
||||
@override
|
||||
Uri get endpoint => Uri.parse('ws://example.test/connect');
|
||||
bool fail = false;
|
||||
final requestedPaths = <String>[];
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (fail) throw StateError('internal transport secret');
|
||||
final request = fields['list_directory'];
|
||||
final path = request is Map && request['path'] is String
|
||||
? request['path'] as String
|
||||
: '/home/demo';
|
||||
requestedPaths.add(path);
|
||||
return {
|
||||
'directory_listing': {
|
||||
'path': '/home/demo',
|
||||
'path': path,
|
||||
'home': '/home',
|
||||
'entries': [
|
||||
for (final name in [
|
||||
@@ -55,10 +61,11 @@ void main() {
|
||||
WidgetTester tester, {
|
||||
Gateway? gateway,
|
||||
FilesViewer? viewer,
|
||||
String initialPath = '/home/demo',
|
||||
}) async {
|
||||
final controller = FilesController(
|
||||
gateway: gateway ?? Gateway(),
|
||||
initialPath: '/home/demo',
|
||||
initialPath: initialPath,
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(
|
||||
@@ -93,6 +100,79 @@ void main() {
|
||||
expect(find.widgetWithText(TextButton, 'demo'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'deep breadcrumbs keep the leaf fully visible at the trailing edge',
|
||||
(tester) async {
|
||||
final gateway = Gateway();
|
||||
await pump(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
initialPath:
|
||||
'/home/alpha/beta/gamma/delta/epsilon/zeta/eta/theta/iota/omega',
|
||||
);
|
||||
|
||||
final scroll = tester.widget<SingleChildScrollView>(
|
||||
find.byKey(const Key('files-breadcrumb-scroll')),
|
||||
);
|
||||
expect(find.text('omega'), findsOneWidget);
|
||||
expect(
|
||||
scroll.controller!.position.pixels,
|
||||
scroll.controller!.position.maxScrollExtent,
|
||||
);
|
||||
final viewport = tester.getRect(
|
||||
find.byKey(const Key('files-breadcrumb-scroll')),
|
||||
);
|
||||
final leaf = tester.getRect(find.text('omega'));
|
||||
final leafButton = tester.getRect(
|
||||
find.widgetWithText(TextButton, 'omega'),
|
||||
);
|
||||
expect(leaf.right, lessThanOrEqualTo(viewport.right));
|
||||
expect(leafButton.right, closeTo(viewport.right, 1));
|
||||
|
||||
scroll.controller!.jumpTo(0);
|
||||
await tester.pump();
|
||||
await tester.tap(find.widgetWithText(TextButton, 'alpha'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.requestedPaths.last, '/home/alpha');
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('navigating deeper pins the new breadcrumb leaf', (tester) async {
|
||||
final gateway = Gateway();
|
||||
final controller = await pump(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
initialPath: '/home/alpha/beta',
|
||||
);
|
||||
|
||||
await controller.open('/home/alpha/beta/gamma/delta/leaf');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final scroll = tester.widget<SingleChildScrollView>(
|
||||
find.byKey(const Key('files-breadcrumb-scroll')),
|
||||
);
|
||||
expect(find.text('leaf'), findsOneWidget);
|
||||
expect(
|
||||
scroll.controller!.position.pixels,
|
||||
scroll.controller!.position.maxScrollExtent,
|
||||
);
|
||||
expect(gateway.requestedPaths.last, '/home/alpha/beta/gamma/delta/leaf');
|
||||
});
|
||||
|
||||
testWidgets('long breadcrumb labels use middle ellipsis', (tester) async {
|
||||
await pump(
|
||||
tester,
|
||||
initialPath:
|
||||
'/home/a-folder-name-that-is-long-enough-to-ellipsize-in-the-middle',
|
||||
);
|
||||
|
||||
expect(find.text('a-folder-name-that…ize-in-the-middle'), findsOneWidget);
|
||||
expect(
|
||||
find.text('a-folder-name-that-is-long-enough-to-ellipsize-in-the-middle'),
|
||||
findsNothing,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('file sorting uses a sort icon and preserves direction', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user