08b2540ec2
Use the phone NavigationBar as a real Scaffold bottom slot so destination content ends at the bar rather than scrolling beneath it. Update shell regression coverage and document the focused verification.
250 lines
9.7 KiB
Dart
250 lines
9.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/shell/list_detail_policy.dart';
|
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
|
import 'package:pipelines_app/shell/destination.dart';
|
|
import 'package:pipelines_app/shell/shell_navigation_bar.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_destination_labels.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
|
|
|
|
/// Main navigation keeps visible captions and full-size targets: a full-width
|
|
/// navigation bar on a phone, and on a wide window a floating bar at the
|
|
/// leading edge under the list.
|
|
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> expectNoSharedBackdrop(WidgetTester tester) async {
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(FloatingDestinationLabels),
|
|
matching: find.byWidgetPredicate(
|
|
(widget) =>
|
|
widget is DecoratedBox &&
|
|
widget.decoration is BoxDecoration &&
|
|
(widget.decoration as BoxDecoration).borderRadius ==
|
|
BorderRadius.circular(16),
|
|
),
|
|
),
|
|
findsNothing,
|
|
);
|
|
}
|
|
|
|
Future<void> setSize(WidgetTester tester, Size size) async {
|
|
tester.view.physicalSize = size;
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
}
|
|
|
|
var taps = 0;
|
|
double? contentBottomPadding;
|
|
|
|
Widget shell() {
|
|
final app = AdaptiveShell(
|
|
destinationBodies: {
|
|
AppDestination.pipelines: (_) => Builder(
|
|
builder: (context) {
|
|
contentBottomPadding = MediaQuery.paddingOf(context).bottom;
|
|
return StatefulBuilder(
|
|
builder: (context, setState) => GestureDetector(
|
|
key: const Key('content'),
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () => setState(() => taps++),
|
|
child: SizedBox.expand(child: Text('taps $taps')),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
},
|
|
);
|
|
return MaterialApp(home: app);
|
|
}
|
|
|
|
testWidgets('a phone shows a full-width navigation bar, and taps above it '
|
|
'reach the content', (tester) async {
|
|
taps = 0;
|
|
await setSize(tester, const Size(390, 844));
|
|
await tester.pumpWidget(shell());
|
|
await tester.pumpAndSettle();
|
|
final bar = tester.getRect(find.byType(NavigationBar));
|
|
expect(bar.left, 0);
|
|
expect(bar.right, 390);
|
|
expect(find.byType(FloatingDestinationBar), findsNothing);
|
|
expect(find.byType(NavigationRail), findsNothing);
|
|
await tester.tapAt(Offset(195, bar.top - 40));
|
|
await tester.pump();
|
|
expect(taps, 1);
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Chat — Not implemented'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('wide leading bar under the list, content '
|
|
'keeps the width and taps beside the bar reach it', (tester) async {
|
|
taps = 0;
|
|
await setSize(tester, const Size(640, 800));
|
|
await tester.pumpWidget(shell());
|
|
final rect = tester.getRect(pill());
|
|
// With no item open the bar still sits under the list column, where it
|
|
// sits beside an open item, so it never jumps sides.
|
|
expect(rect.left, moreOrLessEquals(kFloatingBarMargin, epsilon: 0.5));
|
|
expect(rect.bottom, 800 - 16);
|
|
expect(rect.width, lessThan(640 * 0.6));
|
|
// Captions participate in the bar's content-driven width.
|
|
await expectLabeledTargets(tester, rect);
|
|
await expectNoSharedBackdrop(tester);
|
|
expect(
|
|
rect.width,
|
|
lessThanOrEqualTo(listDetailListWidth(640, 640, null) - 2 * 16),
|
|
);
|
|
// Below the rail's window width (see kNavigationRailMinWindowWidth) the
|
|
// floating bar still sits under the list: no rail, content at the left edge.
|
|
expect(find.byType(NavigationRail), findsNothing);
|
|
expect(tester.getRect(find.byKey(const Key('content'))).left, 0);
|
|
// Beside the bar, at the bar's height, the content takes the tap.
|
|
await tester.tapAt(Offset(rect.right + 40, rect.center.dy));
|
|
await tester.pump();
|
|
expect(taps, 1);
|
|
// On the bar, the tab takes it.
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Chat — Not implemented'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets(
|
|
'phone content has no floating-bar padding; tablet content does',
|
|
(tester) async {
|
|
for (final size in const [Size(390, 844), Size(640, 800)]) {
|
|
await setSize(tester, size);
|
|
await tester.pumpWidget(shell());
|
|
await tester.pump();
|
|
final rect = size.width < 600
|
|
? tester.getRect(find.byType(NavigationBar))
|
|
: tester.getRect(pill());
|
|
expect(
|
|
contentBottomPadding,
|
|
size.width < 600 ? 0 : size.height - rect.top,
|
|
reason: '$size',
|
|
);
|
|
}
|
|
},
|
|
);
|
|
|
|
testWidgets('resizing moves the bar without remounting content', (
|
|
tester,
|
|
) async {
|
|
taps = 0;
|
|
await setSize(tester, const Size(390, 844));
|
|
await tester.pumpWidget(shell());
|
|
await tester.tap(find.byKey(const Key('content')));
|
|
await tester.pump();
|
|
expect(find.text('taps 1'), findsOneWidget);
|
|
final state = tester.state(find.byType(StatefulBuilder));
|
|
|
|
tester.view.physicalSize = const Size(640, 800);
|
|
await tester.pump();
|
|
expect(find.byType(NavigationBar), findsNothing);
|
|
expect(
|
|
tester.getRect(pill()).left,
|
|
moreOrLessEquals(kFloatingBarMargin, epsilon: 0.5),
|
|
);
|
|
expect(tester.getRect(pill()).width, lessThan(640 * 0.6));
|
|
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
|
|
|
tester.view.physicalSize = const Size(390, 844);
|
|
await tester.pump();
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(FloatingDestinationBar), findsNothing);
|
|
expect(tester.getRect(find.byType(NavigationBar)).width, 390);
|
|
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
|
});
|
|
|
|
testWidgets('the navigation bar respects the bottom safe area', (
|
|
tester,
|
|
) async {
|
|
await setSize(tester, const Size(390, 844));
|
|
tester.view.padding = const FakeViewPadding(bottom: 34);
|
|
await tester.pumpWidget(shell());
|
|
await tester.pumpAndSettle();
|
|
// The bar sits above the gesture inset, its own surface ending there.
|
|
expect(tester.getRect(find.byType(NavigationBar)).bottom, 844 - 34);
|
|
});
|
|
|
|
testWidgets('the selected tab is marked selected for assistive '
|
|
'technology', (tester) async {
|
|
final semantics = tester.ensureSemantics();
|
|
await setSize(tester, const Size(1200, 800));
|
|
await tester.pumpWidget(shell());
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
|
|
await tester.pumpAndSettle();
|
|
final runs = tester.getSemantics(
|
|
find.byKey(const ValueKey('shell.destination.runs')),
|
|
);
|
|
expect(runs, isSemantics(isSelected: true));
|
|
// Captions do not duplicate the tab name for assistive technology.
|
|
expect(runs.label, startsWith('Runs'));
|
|
expect(
|
|
tester.getSemantics(find.byKey(const ValueKey('shell.destination.chat'))),
|
|
isNot(isSemantics(isSelected: true)),
|
|
);
|
|
semantics.dispose();
|
|
});
|
|
|
|
testWidgets('phone at 320 with 2x text does not overflow', (tester) async {
|
|
await setSize(tester, const Size(320, 568));
|
|
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
|
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
|
await tester.pumpWidget(shell());
|
|
await tester.pumpAndSettle();
|
|
expect(tester.takeException(), isNull);
|
|
final bar = find.byType(NavigationBar);
|
|
expect(tester.getRect(bar).width, 320);
|
|
// Every destination keeps its label and a full-size target at 2x text.
|
|
for (final destination in shellBarDestinations) {
|
|
final label = destinationDetails(destination).label;
|
|
final caption = find.descendant(of: bar, matching: find.text(label));
|
|
expect(caption, findsOneWidget);
|
|
expect(
|
|
tester.getRect(caption).overlaps(tester.getRect(bar)),
|
|
isTrue,
|
|
reason: label,
|
|
);
|
|
final target = tester.getSize(
|
|
find.byType(NavigationDestination).at(
|
|
shellBarDestinations.indexOf(destination),
|
|
),
|
|
);
|
|
expect(target.width, greaterThanOrEqualTo(44), reason: label);
|
|
expect(target.height, greaterThanOrEqualTo(44), reason: label);
|
|
}
|
|
});
|
|
}
|