Verify labeled navigation bounds and scalable targets
This commit is contained in:
@@ -6,14 +6,39 @@ import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||
|
||||
/// The shell's one floating glass tab bar: full width on a phone, sized to its
|
||||
/// tabs at the right edge on a phone and under the list column on a wide window, with content behind it.
|
||||
/// Main navigation keeps visible captions and full-size targets, floating at
|
||||
/// the trailing edge on a phone and centered under the list on a wide window.
|
||||
void main() {
|
||||
Finder pill() => find.descendant(
|
||||
of: find.byType(FloatingDestinationBar),
|
||||
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||
);
|
||||
|
||||
Future<void> expectLabeledTargets(WidgetTester tester, Rect bounds) async {
|
||||
// Measure settled hit targets, not their brief entrance scale.
|
||||
await tester.pumpAndSettle();
|
||||
final bar = find.byType(FloatingDestinationBar);
|
||||
expect(tester.widget<FloatingDestinationBar>(bar).showLabels, isTrue);
|
||||
Rect? contentBounds;
|
||||
for (final destination in shellTabDestinations) {
|
||||
final label = destinationDetails(destination).label;
|
||||
final caption = find.descendant(of: bar, matching: find.text(label));
|
||||
expect(caption, findsOneWidget);
|
||||
final captionRect = tester.getRect(caption);
|
||||
expect(bounds.contains(captionRect.center), isTrue, reason: label);
|
||||
final target = tester.getRect(
|
||||
find.byKey(ValueKey('shell.destination.${destination.name}')),
|
||||
);
|
||||
expect(target.width, greaterThanOrEqualTo(44), reason: label);
|
||||
expect(target.height, greaterThanOrEqualTo(44), reason: label);
|
||||
final itemBounds = captionRect.expandToInclude(target);
|
||||
contentBounds = contentBounds?.expandToInclude(itemBounds) ?? itemBounds;
|
||||
}
|
||||
// The plate hugs the actual labels/targets, with only a modest inset;
|
||||
// no fixed width or font-metric formula is assumed.
|
||||
expect(bounds.width - contentBounds!.width, inInclusiveRange(0, 32));
|
||||
}
|
||||
|
||||
Future<void> setSize(WidgetTester tester, Size size) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -54,10 +79,8 @@ void main() {
|
||||
await setSize(tester, const Size(390, 844));
|
||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||
final rect = tester.getRect(pill());
|
||||
expect(
|
||||
rect.width,
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||
);
|
||||
await expectLabeledTargets(tester, rect);
|
||||
expect(rect.width, lessThanOrEqualTo(390 - 2 * 16));
|
||||
expect(rect.right, 390 - 16);
|
||||
expect(rect.bottom, 844 - 16);
|
||||
expect(find.byType(NavigationRail), findsNothing);
|
||||
@@ -86,10 +109,11 @@ void main() {
|
||||
);
|
||||
expect(rect.bottom, 800 - 16);
|
||||
expect(rect.width, lessThan(1200 * 0.6));
|
||||
// Four icon-only tabs, with the wider neighbour gaps derived by the bar.
|
||||
// Captions participate in the bar's content-driven width.
|
||||
await expectLabeledTargets(tester, rect);
|
||||
expect(
|
||||
rect.width,
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||
lessThanOrEqualTo(listDetailListWidth(1200, 1200, null) - 2 * 16),
|
||||
);
|
||||
// No rail or sidebar: the content starts at the left edge.
|
||||
expect(find.byType(NavigationRail), findsNothing);
|
||||
@@ -147,10 +171,8 @@ void main() {
|
||||
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getRect(pill()).width,
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||
);
|
||||
await expectLabeledTargets(tester, tester.getRect(pill()));
|
||||
expect(tester.getRect(pill()).width, lessThanOrEqualTo(390 - 2 * 16));
|
||||
expect(tester.getRect(pill()).right, 390 - 16);
|
||||
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
||||
});
|
||||
@@ -173,7 +195,7 @@ void main() {
|
||||
find.byKey(const ValueKey('shell.destination.runs')),
|
||||
);
|
||||
expect(runs, isSemantics(isSelected: true));
|
||||
// Icon-only, yet the tab keeps its name for assistive technology.
|
||||
// Captions do not duplicate the tab name for assistive technology.
|
||||
expect(runs.label, startsWith('Runs'));
|
||||
expect(
|
||||
tester.getSemantics(
|
||||
@@ -210,10 +232,24 @@ void main() {
|
||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
// Sized to its four tabs at the right, as on any width.
|
||||
// Large captions wrap rather than shrinking the tap targets.
|
||||
final bounds = tester.getRect(pill());
|
||||
await expectLabeledTargets(tester, bounds);
|
||||
expect(bounds.width, lessThanOrEqualTo(320 - 2 * 16));
|
||||
for (final destination in shellTabDestinations) {
|
||||
final caption = find.descendant(
|
||||
of: find.byType(FloatingDestinationBar),
|
||||
matching: find.text(destinationDetails(destination).label),
|
||||
);
|
||||
final text = tester.widget<Text>(caption);
|
||||
final size = text.style!.fontSize!;
|
||||
expect(tester.getSize(caption).height, greaterThanOrEqualTo(size * 2));
|
||||
}
|
||||
expect(
|
||||
tester.getRect(pill()).width,
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||
bounds.height,
|
||||
greaterThan(
|
||||
FloatingDestinationBar.selectedButtonSize(cupertino: cupertino),
|
||||
),
|
||||
);
|
||||
expect(tester.getRect(pill()).right, 320 - 16);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user