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);
|
||||
}
|
||||
|
||||
@@ -89,11 +89,28 @@ void main() {
|
||||
of: find.byType(FloatingDestinationBar),
|
||||
matching: find.byKey(FloatingDestinationBar.rowKey),
|
||||
);
|
||||
// Sized to its four tabs at the bottom right.
|
||||
// Visible captions determine the width while full-size targets stay inset.
|
||||
final rect = tester.getRect(destinationPill);
|
||||
expect(rect.width, lessThanOrEqualTo(390 - 2 * 16));
|
||||
expect(
|
||||
tester.getSize(destinationPill).width,
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||
tester
|
||||
.widget<FloatingDestinationBar>(find.byType(FloatingDestinationBar))
|
||||
.showLabels,
|
||||
isTrue,
|
||||
);
|
||||
for (final destination in shellTabDestinations) {
|
||||
final caption = find.descendant(
|
||||
of: find.byType(FloatingDestinationBar),
|
||||
matching: find.text(destinationDetails(destination).label),
|
||||
);
|
||||
expect(caption, findsOneWidget);
|
||||
expect(rect.contains(tester.getRect(caption).center), isTrue);
|
||||
final target = tester.getSize(
|
||||
find.byKey(ValueKey('shell.destination.${destination.name}')),
|
||||
);
|
||||
expect(target.width, greaterThanOrEqualTo(44));
|
||||
expect(target.height, greaterThanOrEqualTo(44));
|
||||
}
|
||||
expect(tester.getRect(destinationPill).right, 390 - 16);
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||
await tester.pump();
|
||||
|
||||
@@ -135,8 +135,17 @@ void main() {
|
||||
expect(pill.overlaps(body), isFalse, reason: 'never over the detail');
|
||||
expect(
|
||||
pill.width,
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||
lessThanOrEqualTo(list.width - 2 * kFloatingBarMargin),
|
||||
);
|
||||
for (final destination in shellTabDestinations) {
|
||||
final caption = find.byKey(
|
||||
ValueKey(
|
||||
'destination-label-${destinationDetails(destination).label}',
|
||||
),
|
||||
);
|
||||
expect(caption, findsOneWidget);
|
||||
expect(pill.contains(tester.getRect(caption).center), isTrue);
|
||||
}
|
||||
|
||||
// The composer reaches the detail's bottom edge: nothing is reserved
|
||||
// there for the shell's bar any more.
|
||||
@@ -183,6 +192,24 @@ void main() {
|
||||
expect(tabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
|
||||
expect(tabs.left, greaterThan(body.left));
|
||||
expect(tabs.overlaps(pill), isFalse);
|
||||
// Page tabs retain their dense icon-only presentation; only app
|
||||
// destinations gain visible captions.
|
||||
final detailBar = tester.widget<FloatingDestinationBar>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('detail-tabs')),
|
||||
matching: find.byType(FloatingDestinationBar),
|
||||
),
|
||||
);
|
||||
expect(detailBar.showLabels, isFalse);
|
||||
for (final label in ['One', 'Two', 'Three']) {
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('detail-tabs')),
|
||||
matching: find.text(label),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
}
|
||||
expect(pill.right, lessThan(body.left));
|
||||
|
||||
// The item's list pads its end clear of its own tabs.
|
||||
@@ -246,10 +273,17 @@ void main() {
|
||||
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
|
||||
await tester.pump();
|
||||
final pill = destinationPill(tester);
|
||||
expect(
|
||||
pill.width,
|
||||
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
||||
);
|
||||
expect(pill.width, lessThanOrEqualTo(390 - 2 * kFloatingBarMargin));
|
||||
for (final destination in shellTabDestinations) {
|
||||
expect(
|
||||
find.byKey(
|
||||
ValueKey(
|
||||
'destination-label-${destinationDetails(destination).label}',
|
||||
),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user