Remove Cupertino shell branches
Keep the Material-only shell path while preserving public cupertino parameters for callers. Narrow matching tests to Material hosts and behavior because the app always runs under MaterialApp.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/list_detail_policy.dart';
|
||||
@@ -67,9 +66,8 @@ void main() {
|
||||
var taps = 0;
|
||||
double? contentBottomPadding;
|
||||
|
||||
Widget shell({required bool cupertino}) {
|
||||
Widget shell() {
|
||||
final app = AdaptiveShell(
|
||||
cupertino: cupertino,
|
||||
destinationBodies: {
|
||||
AppDestination.pipelines: (_) => Builder(
|
||||
builder: (context) {
|
||||
@@ -86,184 +84,156 @@ void main() {
|
||||
),
|
||||
},
|
||||
);
|
||||
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app);
|
||||
return MaterialApp(home: app);
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
testWidgets('phone bar hugs its tabs at the bottom right too, and '
|
||||
'taps beside it reach the content', (tester) async {
|
||||
taps = 0;
|
||||
await setSize(tester, const Size(390, 844));
|
||||
await tester.pumpWidget(shell());
|
||||
final rect = tester.getRect(pill());
|
||||
await expectLabeledTargets(tester, rect);
|
||||
await expectNoSharedBackdrop(tester);
|
||||
expect(rect.width, lessThanOrEqualTo(390 - 2 * 16));
|
||||
expect(rect.right, 390 - 16);
|
||||
expect(rect.bottom, 844 - 16);
|
||||
expect(find.byType(NavigationRail), findsNothing);
|
||||
await tester.tapAt(Offset(rect.left - 40, rect.center.dy));
|
||||
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('$host: phone bar hugs its tabs at the bottom right too, and '
|
||||
'taps beside it reach the content', (tester) async {
|
||||
taps = 0;
|
||||
await setSize(tester, const Size(390, 844));
|
||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||
final rect = tester.getRect(pill());
|
||||
await expectLabeledTargets(tester, rect);
|
||||
await expectNoSharedBackdrop(tester);
|
||||
expect(rect.width, lessThanOrEqualTo(390 - 2 * 16));
|
||||
expect(rect.right, 390 - 16);
|
||||
expect(rect.bottom, 844 - 16);
|
||||
expect(find.byType(NavigationRail), findsNothing);
|
||||
await tester.tapAt(Offset(rect.left - 40, rect.center.dy));
|
||||
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('$host: 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(1200, 800));
|
||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||
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(1200 * 0.6));
|
||||
// Captions participate in the bar's content-driven width.
|
||||
await expectLabeledTargets(tester, rect);
|
||||
await expectNoSharedBackdrop(tester);
|
||||
expect(
|
||||
rect.width,
|
||||
lessThanOrEqualTo(listDetailListWidth(1200, 1200, null) - 2 * 16),
|
||||
);
|
||||
// No rail or sidebar: the content starts at the left edge.
|
||||
expect(find.byType(NavigationRail), findsNothing);
|
||||
expect(find.byType(CupertinoListTile), 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('$host: content learns the bar height as bottom padding', (
|
||||
tester,
|
||||
) async {
|
||||
for (final size in const [Size(390, 844), Size(1200, 800)]) {
|
||||
await setSize(tester, size);
|
||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||
await tester.pump();
|
||||
final rect = tester.getRect(pill());
|
||||
// The content's bottom padding clears the whole bar and its margin.
|
||||
expect(
|
||||
contentBottomPadding,
|
||||
moreOrLessEquals(size.height - rect.top, epsilon: 0.5),
|
||||
reason: '$size',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('$host: resizing moves the bar without remounting content', (
|
||||
tester,
|
||||
) async {
|
||||
taps = 0;
|
||||
await setSize(tester, const Size(390, 844));
|
||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||
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(1200, 800);
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getRect(pill()).left,
|
||||
moreOrLessEquals(kFloatingBarMargin, epsilon: 0.5),
|
||||
);
|
||||
expect(tester.getRect(pill()).width, lessThan(1200 * 0.6));
|
||||
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
||||
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
await tester.pump();
|
||||
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));
|
||||
});
|
||||
|
||||
testWidgets('$host: the 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(cupertino: cupertino));
|
||||
expect(tester.getRect(pill()).bottom, 844 - 34);
|
||||
});
|
||||
|
||||
testWidgets('$host: 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(cupertino: cupertino));
|
||||
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('Cupertino bar builds no Material widget', (tester) async {
|
||||
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(1200, 800));
|
||||
await tester.pumpWidget(shell(cupertino: true));
|
||||
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(1200 * 0.6));
|
||||
// Captions participate in the bar's content-driven width.
|
||||
await expectLabeledTargets(tester, rect);
|
||||
await expectNoSharedBackdrop(tester);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(FloatingDestinationBar),
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Material ||
|
||||
widget is NavigationBar ||
|
||||
widget is InkWell,
|
||||
),
|
||||
),
|
||||
findsNothing,
|
||||
rect.width,
|
||||
lessThanOrEqualTo(listDetailListWidth(1200, 1200, null) - 2 * 16),
|
||||
);
|
||||
// No rail or sidebar: the content starts 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('content learns the bar height as bottom padding', (
|
||||
tester,
|
||||
) async {
|
||||
for (final size in const [Size(390, 844), Size(1200, 800)]) {
|
||||
await setSize(tester, size);
|
||||
await tester.pumpWidget(shell());
|
||||
await tester.pump();
|
||||
final rect = tester.getRect(pill());
|
||||
// The content's bottom padding clears the whole bar and its margin.
|
||||
expect(
|
||||
contentBottomPadding,
|
||||
moreOrLessEquals(size.height - rect.top, epsilon: 0.5),
|
||||
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(1200, 800);
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getRect(pill()).left,
|
||||
moreOrLessEquals(kFloatingBarMargin, epsilon: 0.5),
|
||||
);
|
||||
expect(tester.getRect(pill()).width, lessThan(1200 * 0.6));
|
||||
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
||||
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
await tester.pump();
|
||||
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));
|
||||
});
|
||||
|
||||
testWidgets('the 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());
|
||||
expect(tester.getRect(pill()).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 {
|
||||
for (final cupertino in [false, true]) {
|
||||
await setSize(tester, const Size(320, 568));
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
await tester.pumpWidget(shell(cupertino: cupertino));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
// 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(
|
||||
bounds.height,
|
||||
greaterThan(
|
||||
FloatingDestinationBar.selectedButtonSize(cupertino: cupertino),
|
||||
),
|
||||
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);
|
||||
// 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),
|
||||
);
|
||||
expect(tester.getRect(pill()).right, 320 - 16);
|
||||
final text = tester.widget<Text>(caption);
|
||||
final size = text.style!.fontSize!;
|
||||
expect(tester.getSize(caption).height, greaterThanOrEqualTo(size * 2));
|
||||
}
|
||||
expect(
|
||||
bounds.height,
|
||||
greaterThan(FloatingDestinationBar.selectedButtonSize(cupertino: false)),
|
||||
);
|
||||
expect(tester.getRect(pill()).right, 320 - 16);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user