Fit long Files breadcrumb labels to the panel
Each folder in the path gets a maximum width (the current folder the whole row) and its label is shortened in the middle to what actually fits, measured with the label's style, so a long name never pushes the current folder out of a narrow panel.
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_preview.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_kind.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_header.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_file_bridge.dart';
|
||||
@@ -159,18 +160,67 @@ void main() {
|
||||
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',
|
||||
testWidgets('a long current folder is shortened in the middle to fit a '
|
||||
'narrow panel and stays fully visible', (tester) async {
|
||||
const name = 'a-folder-name-that-is-long-enough-to-ellipsize-in-the-middle';
|
||||
final controller = FilesController(
|
||||
gateway: Gateway(),
|
||||
initialPath: '/home/projects/$name',
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
// The narrowest Files panel.
|
||||
child: SizedBox(
|
||||
width: 280,
|
||||
child: FilesPanel(
|
||||
controller: controller,
|
||||
viewer: const FilesViewer(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
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,
|
||||
final viewport = tester.getRect(
|
||||
find.byKey(const Key('files-breadcrumb-scroll')),
|
||||
);
|
||||
final leaf = find.descendant(
|
||||
of: find.byKey(const Key('files-breadcrumb-scroll')),
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Text &&
|
||||
(widget.data ?? '').startsWith('a-folder') &&
|
||||
(widget.data ?? '').endsWith('middle'),
|
||||
),
|
||||
);
|
||||
expect(leaf, findsOneWidget);
|
||||
final label = tester.widget<Text>(leaf).data!;
|
||||
expect(label, contains('…'));
|
||||
expect(label.length, lessThan(name.length));
|
||||
final rect = tester.getRect(leaf);
|
||||
expect(rect.left, greaterThanOrEqualTo(viewport.left - 0.5));
|
||||
expect(rect.right, lessThanOrEqualTo(viewport.right + 0.5));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
test('middleEllipsis keeps a label that fits and shortens one that does '
|
||||
'not', () {
|
||||
const style = TextStyle(fontSize: 10);
|
||||
expect(middleEllipsis('short', maxWidth: 500, style: style), 'short');
|
||||
final cut = middleEllipsis(
|
||||
'abcdefghijklmnopqrstuvwxyz',
|
||||
maxWidth: 100,
|
||||
style: style,
|
||||
);
|
||||
expect(cut, contains('…'));
|
||||
expect(cut.startsWith('a'), isTrue);
|
||||
expect(cut.endsWith('z'), isTrue);
|
||||
});
|
||||
|
||||
testWidgets('file sorting uses a sort icon and preserves direction', (
|
||||
|
||||
Reference in New Issue
Block a user