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:
2026-11-11 03:48:41 +00:00
parent baac6eca9a
commit 9bdabb32d9
33 changed files with 1646 additions and 2326 deletions
+10 -41
View File
@@ -1,13 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
/// The Runs tab mirrors the attention count in every mount of both hosts:
/// the floating tab bar at full width on a phone and right-aligned on a wide
/// window. Zero draws the
/// bare icon with no count and no attention semantics.
/// The Runs tab mirrors the attention count in every mount: the floating tab
/// bar at full width on a phone and right-aligned on a wide window. Zero draws
/// the bare icon with no count and no attention semantics.
void main() {
final needingAttention = RegExp('Notifications, 3 needing attention');
final anyAttention = RegExp('needing attention');
@@ -15,27 +13,22 @@ void main() {
Future<void> pumpShell(
WidgetTester tester, {
required double width,
required bool cupertino,
required int count,
}) async {
tester.view.physicalSize = Size(width, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final shell = AdaptiveShell(cupertino: cupertino, attentionCount: count);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
);
final shell = AdaptiveShell(attentionCount: count);
await tester.pumpWidget(MaterialApp(home: shell));
}
for (final width in [390.0, 1000.0]) {
final mount = width < 600 ? 'bottom bar' : 'wide bar';
testWidgets('Material $mount shows the count on the Runs tab', (
tester,
) async {
testWidgets('$mount shows the count on the Runs tab', (tester) async {
final semantics = tester.ensureSemantics();
await pumpShell(tester, width: width, cupertino: false, count: 3);
await pumpShell(tester, width: width, count: 3);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing);
final badge = find.byType(Badge);
@@ -49,9 +42,9 @@ void main() {
semantics.dispose();
});
testWidgets('Material $mount hides the badge at zero', (tester) async {
testWidgets('$mount hides the badge at zero', (tester) async {
final semantics = tester.ensureSemantics();
await pumpShell(tester, width: width, cupertino: false, count: 0);
await pumpShell(tester, width: width, count: 0);
final badge = find.byType(Badge);
expect(badge, findsOneWidget);
expect(tester.widget<Badge>(badge).isLabelVisible, isFalse);
@@ -67,32 +60,8 @@ void main() {
});
}
for (final width in [390.0, 1280.0]) {
final mount = width < 600 ? 'tab bar' : 'wide tab bar';
testWidgets('Cupertino $mount shows the count on the Runs item', (
tester,
) async {
final semantics = tester.ensureSemantics();
await pumpShell(tester, width: width, cupertino: true, count: 3);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(Badge), findsNothing, reason: 'no Material badge');
expect(find.text('3'), findsOneWidget);
expect(find.bySemanticsLabel(needingAttention), findsOneWidget);
semantics.dispose();
});
testWidgets('Cupertino $mount hides the count at zero', (tester) async {
final semantics = tester.ensureSemantics();
await pumpShell(tester, width: width, cupertino: true, count: 0);
expect(find.text('0'), findsNothing);
expect(find.bySemanticsLabel(anyAttention), findsNothing);
semantics.dispose();
});
}
testWidgets('the badge stays visible from every destination', (tester) async {
await pumpShell(tester, width: 1000, cupertino: false, count: 2);
await pumpShell(tester, width: 1000, count: 2);
for (final name in ['runs', 'chat', 'search']) {
await tester.tap(find.byKey(ValueKey('shell.destination.$name')));
await tester.pumpAndSettle();
+62 -79
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -6,89 +5,73 @@ import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets(
'$host Ctrl+Tab and Ctrl+Shift+Tab leave destinations unchanged',
(tester) async {
final app = AdaptiveShell(
cupertino: cupertino,
destinationBodies: {
for (final destination in shellTabDestinations)
destination: (_) => Focus(
autofocus: destination == AppDestination.pipelines,
child: Text(destination.name),
),
},
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
);
Future<void> press({required bool shift}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
if (shift) {
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
}
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
if (shift) {
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
}
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
}
expect(find.text('pipelines'), findsOneWidget);
await press(shift: true);
expect(find.text('pipelines'), findsOneWidget);
await press(shift: false);
expect(find.text('pipelines'), findsOneWidget);
testWidgets('Ctrl+Tab and Ctrl+Shift+Tab leave destinations unchanged', (
tester,
) async {
final app = AdaptiveShell(
destinationBodies: {
for (final destination in shellTabDestinations)
destination: (_) => Focus(
autofocus: destination == AppDestination.pipelines,
child: Text(destination.name),
),
},
);
await tester.pumpWidget(MaterialApp(home: app));
testWidgets(
'$host plain Tab traverses and Ctrl+Tab does not change destinations',
(tester) async {
final first = FocusNode();
final second = FocusNode();
addTearDown(first.dispose);
addTearDown(second.dispose);
final app = AdaptiveShell(
cupertino: cupertino,
destinationBodies: {
AppDestination.pipelines: (_) => Column(
children: [
cupertino
? CupertinoTextField(focusNode: first)
: TextField(focusNode: first),
cupertino
? CupertinoTextField(focusNode: second)
: TextField(focusNode: second),
],
),
AppDestination.runs: (_) => const Text('runs'),
},
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
);
first.requestFocus();
await tester.pump();
Future<void> press({required bool shift}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
if (shift) {
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
}
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
if (shift) {
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
}
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
}
// Plain Tab retains normal traversal semantics and does not select a tab.
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pump();
expect(second.hasFocus, isTrue);
expect(find.text('pipelines'), findsOneWidget);
await press(shift: true);
expect(find.text('pipelines'), findsOneWidget);
await press(shift: false);
expect(find.text('pipelines'), findsOneWidget);
});
first.requestFocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
expect(find.text('runs'), findsNothing);
testWidgets('plain Tab traverses and Ctrl+Tab does not change destinations', (
tester,
) async {
final first = FocusNode();
final second = FocusNode();
addTearDown(first.dispose);
addTearDown(second.dispose);
final app = AdaptiveShell(
destinationBodies: {
AppDestination.pipelines: (_) => Column(
children: [
TextField(focusNode: first),
TextField(focusNode: second),
],
),
AppDestination.runs: (_) => const Text('runs'),
},
);
}
await tester.pumpWidget(MaterialApp(home: app));
first.requestFocus();
await tester.pump();
// Plain Tab retains normal traversal semantics and does not select a tab.
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pump();
expect(second.hasFocus, isTrue);
first.requestFocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
expect(find.text('runs'), findsNothing);
});
}
+51 -56
View File
@@ -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/adaptive_shell.dart';
@@ -9,66 +8,62 @@ import 'package:pipelines_app/shell/list_detail.dart';
/// page) closes when another item is selected, so the pane shows the newly
/// selected item instead of the old item's page.
void main() {
for (final cupertino in [false, true]) {
testWidgets('selecting another item closes the previous item\'s page '
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
tester.view.physicalSize = const Size(1200, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final selected = ValueNotifier<int>(1);
addTearDown(selected.dispose);
testWidgets("selecting another item closes the previous item's page", (
tester,
) async {
tester.view.physicalSize = const Size(1200, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final selected = ValueNotifier<int>(1);
addTearDown(selected.dispose);
Widget detail(int id) => Builder(
builder: (context) => Center(
child: GestureDetector(
key: const Key('open-page'),
onTap: () => Navigator.of(context).push(
PageRouteBuilder<void>(
pageBuilder: (_, _, _) => Text('page of item $id'),
),
Widget detail(int id) => Builder(
builder: (context) => Center(
child: GestureDetector(
key: const Key('open-page'),
onTap: () => Navigator.of(context).push(
PageRouteBuilder<void>(
pageBuilder: (_, _, _) => Text('page of item $id'),
),
child: Text('item $id'),
),
child: Text('item $id'),
),
),
);
final shell = AdaptiveShell(
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => ValueListenableBuilder<int>(
valueListenable: selected,
builder: (_, id, _) => ListDetailPanes(
list: const Text('list'),
detailIdentity: id,
detail: detail(id),
),
),
);
},
);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: shell,
),
);
await tester.pumpAndSettle();
final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => ValueListenableBuilder<int>(
valueListenable: selected,
builder: (_, id, _) => ListDetailPanes(
list: const Text('list'),
detailIdentity: id,
detail: detail(id),
),
),
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: shell)
: MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: shell,
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('open-page')));
await tester.pumpAndSettle();
expect(find.text('page of item 1'), findsOneWidget);
await tester.tap(find.byKey(const Key('open-page')));
await tester.pumpAndSettle();
expect(find.text('page of item 1'), findsOneWidget);
// The same item rebuilt keeps its page open.
selected.value = 1;
await tester.pumpAndSettle();
expect(find.text('page of item 1'), findsOneWidget);
// The same item rebuilt keeps its page open.
selected.value = 1;
await tester.pumpAndSettle();
expect(find.text('page of item 1'), findsOneWidget);
selected.value = 2;
await tester.pumpAndSettle();
expect(find.text('page of item 1'), findsNothing);
expect(find.text('item 2'), findsOneWidget);
});
}
selected.value = 2;
await tester.pumpAndSettle();
expect(find.text('page of item 1'), findsNothing);
expect(find.text('item 2'), findsOneWidget);
});
}
+28 -43
View File
@@ -1,52 +1,37 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/empty_detail_pane.dart';
/// One placeholder for an empty detail pane: the destination's icon above a
/// short muted line, centred, on both hosts.
/// short muted line, centred.
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
for (final destination in [
AppDestination.runs,
AppDestination.chat,
AppDestination.pipelines,
]) {
testWidgets('$host ${destination.name}: icon over a muted line', (
tester,
) async {
final content = EmptyDetailPane(
destination: destination,
message: 'Select one to open it here.',
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: content))
: MaterialApp(home: Scaffold(body: content)),
);
final details = destinationDetails(destination);
final icon = find.byIcon(
cupertino ? details.cupertinoIcon : details.icon,
);
expect(icon, findsOneWidget);
final text = find.text('Select one to open it here.');
expect(
tester.getTopLeft(text).dy,
greaterThan(tester.getRect(icon).bottom),
);
// Centred in the pane.
final size = tester.view.physicalSize / tester.view.devicePixelRatio;
expect(tester.getCenter(text).dx, closeTo(size.width / 2, 1));
// Muted: the same secondary colour on the icon and the line.
final context = tester.element(text);
final muted = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
expect(tester.widget<Icon>(icon).color, muted);
expect(tester.widget<Text>(text).style?.color, muted);
});
}
for (final destination in [
AppDestination.runs,
AppDestination.chat,
AppDestination.pipelines,
]) {
testWidgets('${destination.name}: icon over a muted line', (tester) async {
final content = EmptyDetailPane(
destination: destination,
message: 'Select one to open it here.',
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: content)));
final icon = find.byIcon(destinationDetails(destination).icon);
expect(icon, findsOneWidget);
final text = find.text('Select one to open it here.');
expect(
tester.getTopLeft(text).dy,
greaterThan(tester.getRect(icon).bottom),
);
// Centred in the pane.
final size = tester.view.physicalSize / tester.view.devicePixelRatio;
expect(tester.getCenter(text).dx, closeTo(size.width / 2, 1));
// Muted: the same secondary colour on the icon and the line.
final context = tester.element(text);
final muted = Theme.of(context).colorScheme.onSurfaceVariant;
expect(tester.widget<Icon>(icon).color, muted);
expect(tester.widget<Text>(text).style?.color, muted);
});
}
}
+141 -171
View File
@@ -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);
});
}
+138 -155
View File
@@ -1,6 +1,5 @@
import 'dart:ui' show SemanticsAction;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -27,12 +26,10 @@ void main() {
);
Widget shell({
required bool cupertino,
required ListPaneWidthStore store,
AppDestination destination = AppDestination.runs,
}) {
final app = AdaptiveShell(
cupertino: cupertino,
destination: destination,
listPaneWidthStore: store,
destinationBodies: {
@@ -40,7 +37,7 @@ void main() {
AppDestination.chat: (_) => panes('chat'),
},
);
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app);
return MaterialApp(home: app);
}
Future<void> settle(WidgetTester tester) async {
@@ -66,172 +63,158 @@ void main() {
.width;
final divider = find.byKey(const ValueKey('list-detail-divider'));
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('dragging resizes the list live, the shell bar '
'follows, and the width clamps', (tester) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore();
await tester.pumpWidget(shell(store: store));
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
expect(shellBarWidth(tester), kListPaneMaxWidth);
testWidgets('$host: dragging resizes the list live, the shell bar '
'follows, and the width clamps', (tester) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore();
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
expect(shellBarWidth(tester), kListPaneMaxWidth);
final gesture = await tester.startGesture(tester.getCenter(divider));
await gesture.moveBy(const Offset(-50, 0));
await gesture.moveBy(const Offset(-50, 0));
await tester.pump();
// Live, before the drag ends; nothing saved yet.
expect(listWidth(tester), closeTo(340, 0.5));
expect(shellBarWidth(tester), closeTo(340, 0.5));
expect(bodyWidth(tester), closeTo(1200 - 1 - 340, 0.5));
expect(store.values, isEmpty);
await gesture.up();
await tester.pump();
expect(store.values['runs'], closeTo(340, 0.5));
final gesture = await tester.startGesture(tester.getCenter(divider));
await gesture.moveBy(const Offset(-50, 0));
await gesture.moveBy(const Offset(-50, 0));
await tester.pump();
// Live, before the drag ends; nothing saved yet.
expect(listWidth(tester), closeTo(340, 0.5));
expect(shellBarWidth(tester), closeTo(340, 0.5));
expect(bodyWidth(tester), closeTo(1200 - 1 - 340, 0.5));
expect(store.values, isEmpty);
await gesture.up();
await tester.pump();
expect(store.values['runs'], closeTo(340, 0.5));
// Never narrower than the minimum...
await tester.drag(divider, const Offset(-400, 0));
await settle(tester);
expect(listWidth(tester), kListPaneMinWidth);
// ...nor wider than leaves the open item half the window.
await tester.drag(divider, const Offset(900, 0));
await settle(tester);
expect(listWidth(tester), closeTo(1200 - 1 - 600, 0.5));
expect(shellBarWidth(tester), closeTo(599, 0.5));
expect(store.values['runs'], closeTo(599, 0.5));
});
// Never narrower than the minimum...
await tester.drag(divider, const Offset(-400, 0));
await settle(tester);
expect(listWidth(tester), kListPaneMinWidth);
// ...nor wider than leaves the open item half the window.
await tester.drag(divider, const Offset(900, 0));
await settle(tester);
expect(listWidth(tester), closeTo(1200 - 1 - 600, 0.5));
expect(shellBarWidth(tester), closeTo(599, 0.5));
expect(store.values['runs'], closeTo(599, 0.5));
});
testWidgets('a double tap returns to the default policy', (tester) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore({'runs': 300});
await tester.pumpWidget(shell(store: store));
await settle(tester);
expect(listWidth(tester), 300);
testWidgets('$host: a double tap returns to the default policy', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore({'runs': 300});
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
expect(listWidth(tester), 300);
await tester.tap(divider);
await tester.pump(const Duration(milliseconds: 50));
await tester.tap(divider);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
expect(shellBarWidth(tester), kListPaneMaxWidth);
expect(store.values, isEmpty);
});
await tester.tap(divider);
await tester.pump(const Duration(milliseconds: 50));
await tester.tap(divider);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
expect(shellBarWidth(tester), kListPaneMaxWidth);
expect(store.values, isEmpty);
});
testWidgets('widths are kept per destination and restored', (tester) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore({'runs': 300, 'chat': 500});
await tester.pumpWidget(shell(store: store));
await settle(tester);
expect(listWidth(tester), 300);
expect(shellBarWidth(tester), 300);
testWidgets('$host: widths are kept per destination and restored', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore({'runs': 300, 'chat': 500});
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
expect(listWidth(tester), 300);
expect(shellBarWidth(tester), 300);
await tester.pumpWidget(
shell(store: store, destination: AppDestination.chat),
);
await settle(tester);
final chatList = find.byKey(const ValueKey('list-detail-list')).last;
expect(tester.getSize(chatList).width, 500);
expect(shellBarWidth(tester), 500);
await tester.pumpWidget(
shell(
cupertino: cupertino,
store: store,
destination: AppDestination.chat,
),
);
await settle(tester);
final chatList = find.byKey(const ValueKey('list-detail-list')).last;
expect(tester.getSize(chatList).width, 500);
expect(shellBarWidth(tester), 500);
// A destination nobody resized keeps the default policy.
final fresh = MemoryListPaneWidthStore({'chat': 500});
await tester.pumpWidget(const SizedBox());
await tester.pumpWidget(shell(store: fresh));
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
});
// A destination nobody resized keeps the default policy.
final fresh = MemoryListPaneWidthStore({'chat': 500});
await tester.pumpWidget(const SizedBox());
await tester.pumpWidget(shell(cupertino: cupertino, store: fresh));
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
});
testWidgets('a small window clamps the saved width without '
'overwriting it', (tester) async {
await setSize(tester, const Size(1000, 800));
final store = MemoryListPaneWidthStore({'runs': 600});
await tester.pumpWidget(shell(store: store));
await settle(tester);
expect(listWidth(tester), closeTo(1000 - 1 - 500, 0.5));
expect(shellBarWidth(tester), closeTo(499, 0.5));
expect(store.values['runs'], 600);
testWidgets('$host: a small window clamps the saved width without '
'overwriting it', (tester) async {
await setSize(tester, const Size(1000, 800));
final store = MemoryListPaneWidthStore({'runs': 600});
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
expect(listWidth(tester), closeTo(1000 - 1 - 500, 0.5));
expect(shellBarWidth(tester), closeTo(499, 0.5));
expect(store.values['runs'], 600);
await setSize(tester, const Size(1600, 800));
await settle(tester);
expect(listWidth(tester), 600);
expect(shellBarWidth(tester), 600);
});
await setSize(tester, const Size(1600, 800));
await settle(tester);
expect(listWidth(tester), 600);
expect(shellBarWidth(tester), 600);
});
testWidgets('arrow keys move the divider and it reads as a '
'slider', (tester) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore();
final semantics = tester.ensureSemantics();
await tester.pumpWidget(shell(store: store));
await settle(tester);
Focus.of(tester.element(divider)).requestFocus();
await tester.pump();
testWidgets('$host: arrow keys move the divider and it reads as a '
'slider', (tester) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore();
final semantics = tester.ensureSemantics();
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
Focus.of(tester.element(divider)).requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth - kListPaneDividerKeyStep);
expect(store.values['runs'], kListPaneMaxWidth - kListPaneDividerKeyStep);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth + kListPaneDividerKeyStep);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth - kListPaneDividerKeyStep);
expect(store.values['runs'], kListPaneMaxWidth - kListPaneDividerKeyStep);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth + kListPaneDividerKeyStep);
expect(
tester.getSemantics(divider),
matchesSemantics(
label: 'List width',
hint: 'Drag, or use the arrow keys, to resize the list',
value: '456 pixels',
increasedValue: '472 pixels',
decreasedValue: '440 pixels',
isSlider: true,
isFocusable: true,
isFocused: true,
hasIncreaseAction: true,
hasDecreaseAction: true,
hasFocusAction: true,
),
);
tester.semantics.performAction(
find.semantics.byLabel('List width'),
SemanticsAction.decrease,
);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
semantics.dispose();
});
expect(
tester.getSemantics(divider),
matchesSemantics(
label: 'List width',
hint: 'Drag, or use the arrow keys, to resize the list',
value: '456 pixels',
increasedValue: '472 pixels',
decreasedValue: '440 pixels',
isSlider: true,
isFocusable: true,
isFocused: true,
hasIncreaseAction: true,
hasDecreaseAction: true,
hasFocusAction: true,
),
);
tester.semantics.performAction(
find.semantics.byLabel('List width'),
SemanticsAction.decrease,
);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
semantics.dispose();
});
testWidgets('the native resize grip is visible at rest and gains '
'emphasis on focus', (tester) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell(store: MemoryListPaneWidthStore()));
await settle(tester);
testWidgets('$host: the native resize grip is visible at rest and gains '
'emphasis on focus', (tester) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(
shell(cupertino: cupertino, store: MemoryListPaneWidthStore()),
);
await settle(tester);
AdaptiveResizeGrip grip() => tester.widget<AdaptiveResizeGrip>(
find.descendant(
of: find.byType(ListPaneDivider),
matching: find.byType(AdaptiveResizeGrip),
),
);
expect(grip().emphasized, isFalse);
AdaptiveResizeGrip grip() => tester.widget<AdaptiveResizeGrip>(
find.descendant(
of: find.byType(ListPaneDivider),
matching: find.byType(AdaptiveResizeGrip),
),
);
expect(grip().emphasized, isFalse);
Focus.of(tester.element(divider)).requestFocus();
await tester.pump();
expect(grip().emphasized, isTrue);
});
}
Focus.of(tester.element(divider)).requestFocus();
await tester.pump();
expect(grip().emphasized, isTrue);
});
test('bounds: list at least 240, open item at least half the window', () {
expect(listPaneWidthBounds(1200, 1200), (min: 240.0, max: 599.0));
+84 -98
View File
@@ -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/adaptive_shell.dart';
@@ -28,7 +27,7 @@ void main() {
/// An open item: its title published to the pane's bar, its own tabs
/// floating where the pane says, and a list padded clear of both bars.
Widget item({bool cupertino = false}) => ShellBar(
Widget item() => ShellBar(
title: 'Open item',
subtitle: 'Its context',
actions: const [Icon(Icons.more_vert, semanticLabel: 'More')],
@@ -40,7 +39,7 @@ void main() {
bar: KeyedSubtree(
key: const Key('item-tabs'),
child: FloatingDestinationBar(
cupertino: cupertino,
cupertino: false,
edge: edge,
currentIndex: 0,
onTap: (_) {},
@@ -68,9 +67,8 @@ void main() {
),
);
Widget shell({bool cupertino = false, int attention = 0}) {
Widget shell({int attention = 0}) {
final app = AdaptiveShell(
cupertino: cupertino,
attentionCount: attention,
destinationBodies: {
AppDestination.runs: (_) => ShellBadge(
@@ -89,14 +87,14 @@ void main() {
detail: DetailPane(
destination: AppDestination.runs,
implyBack: false,
builder: (_) => item(cupertino: cupertino),
builder: (_) => item(),
),
),
),
},
destination: AppDestination.runs,
);
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app);
return MaterialApp(home: app);
}
Finder shellBar() => find.byWidgetPredicate(
@@ -107,100 +105,88 @@ void main() {
matching: find.byType(SegmentedBar),
);
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('1200: the shell bar covers the list pane and the '
'item\'s bar shares its row', (tester) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell());
await tester.pump();
await tester.pump();
testWidgets('$host 1200: the shell bar covers the list pane and the '
'item\'s bar shares its row', (tester) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell(cupertino: cupertino));
await tester.pump();
await tester.pump();
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final shellPills = find.descendant(
of: shellBar(),
matching: find.byType(GlassPill),
);
for (final element in shellPills.evaluate()) {
expect(
rectOf(element).right,
lessThanOrEqualTo(list.right),
reason: 'no shell piece sits over the open item',
);
}
// Both titles on the same top row.
final shellTitle = tester.getRect(
find.descendant(of: shellBar(), matching: find.text('Runs')),
);
final paneTitle = tester.getRect(find.text('Open item'));
expect(paneTitle.left, greaterThanOrEqualTo(body.left));
final paneTop = tester.getRect(
find.descendant(of: paneBar(), matching: find.byType(GlassPill)).first,
);
final shellTop = tester.getRect(shellPills.first);
expect(paneTop.top, shellTop.top);
expect(paneTitle.top, lessThan(shellTitle.bottom));
// The title pill carries the item's context too.
expect(find.text('Its context'), findsOneWidget);
});
testWidgets('$host 1200: the item\'s tabs float at the bottom of its '
'pane, the shell\'s tab bar under the list', (tester) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell(cupertino: cupertino));
await tester.pump();
await tester.pump();
final shellTabs = tester.getRect(
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.runs')).first,
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
final itemTabs = tester.getRect(
find.descendant(
of: find.byKey(const Key('item-tabs')),
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
// The shell's tabs sit at the bottom of the list pane; the item's at
// the bottom right of the detail pane, never on them.
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
expect(shellTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(shellTabs.right, lessThanOrEqualTo(list.right));
expect(itemTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(itemTabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(itemTabs.left, greaterThanOrEqualTo(body.left));
expect(itemTabs.overlaps(shellTabs), isFalse);
// The item's list starts below its bar and clears its tabs at rest.
final paneBarPill = tester.getRect(
find.descendant(of: paneBar(), matching: find.byType(GlassPill)).first,
);
final list = tester.getRect(find.byKey(const ValueKey('list-detail-list')));
final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
final shellPills = find.descendant(
of: shellBar(),
matching: find.byType(GlassPill),
);
for (final element in shellPills.evaluate()) {
expect(
tester.getTopLeft(find.text('item row 0')).dy,
greaterThanOrEqualTo(paneBarPill.bottom),
rectOf(element).right,
lessThanOrEqualTo(list.right),
reason: 'no shell piece sits over the open item',
);
expect(
MediaQuery.paddingOf(
tester.element(find.byKey(const Key('item-list'))),
).bottom,
greaterThanOrEqualTo(800 - itemTabs.top),
);
});
}
}
// Both titles on the same top row.
final shellTitle = tester.getRect(
find.descendant(of: shellBar(), matching: find.text('Runs')),
);
final paneTitle = tester.getRect(find.text('Open item'));
expect(paneTitle.left, greaterThanOrEqualTo(body.left));
final paneTop = tester.getRect(
find.descendant(of: paneBar(), matching: find.byType(GlassPill)).first,
);
final shellTop = tester.getRect(shellPills.first);
expect(paneTop.top, shellTop.top);
expect(paneTitle.top, lessThan(shellTitle.bottom));
// The title pill carries the item's context too.
expect(find.text('Its context'), findsOneWidget);
});
testWidgets('1200: the item\'s tabs float at the bottom of its '
'pane, the shell\'s tab bar under the list', (tester) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell());
await tester.pump();
await tester.pump();
final shellTabs = tester.getRect(
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.runs')).first,
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
final itemTabs = tester.getRect(
find.descendant(
of: find.byKey(const Key('item-tabs')),
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
// The shell's tabs sit at the bottom of the list pane; the item's at
// the bottom right of the detail pane, never on them.
final list = tester.getRect(find.byKey(const ValueKey('list-detail-list')));
expect(shellTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(shellTabs.right, lessThanOrEqualTo(list.right));
expect(itemTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(itemTabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(itemTabs.left, greaterThanOrEqualTo(body.left));
expect(itemTabs.overlaps(shellTabs), isFalse);
// The item's list starts below its bar and clears its tabs at rest.
final paneBarPill = tester.getRect(
find.descendant(of: paneBar(), matching: find.byType(GlassPill)).first,
);
expect(
tester.getTopLeft(find.text('item row 0')).dy,
greaterThanOrEqualTo(paneBarPill.bottom),
);
expect(
MediaQuery.paddingOf(
tester.element(find.byKey(const Key('item-list'))),
).bottom,
greaterThanOrEqualTo(800 - itemTabs.top),
);
});
testWidgets('390: an open item is its own page with its tabs at the bottom', (
tester,
+2 -28
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -35,16 +34,11 @@ Future<void> _search(WidgetTester tester) async {
await tester.pumpAndSettle();
}
Future<void> _pump(
WidgetTester tester,
AppDestination from, {
bool cupertino = false,
}) async {
Future<void> _pump(WidgetTester tester, AppDestination from) async {
tester.view.physicalSize = const Size(1200, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final shell = AdaptiveShell(
cupertino: cupertino,
destination: from,
destinationBodies: {
for (final destination in AppDestination.values)
@@ -53,9 +47,7 @@ Future<void> _pump(
SearchScreen(gateway: _Gateway(), onOpen: (_) {}, embedded: true),
},
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
);
await tester.pumpWidget(MaterialApp(home: shell));
await tester.pumpAndSettle();
}
@@ -87,24 +79,6 @@ void main() {
);
}
testWidgets(
'Cupertino Escape preserves native Search focus handoff and previous tab',
(tester) async {
await _pump(tester, AppDestination.runs, cupertino: true);
await _search(tester);
await tester.enterText(find.byKey(searchFieldKey), 'query');
await tester.pumpAndSettle();
_field(tester).focusNode.unfocus();
await tester.pumpAndSettle();
await _press(tester, LogicalKeyboardKey.escape);
expect(_field(tester).focusNode.hasPrimaryFocus, isTrue);
expect(_field(tester).controller.text, 'query');
await _press(tester, LogicalKeyboardKey.escape);
expect(find.text('Body runs'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
},
);
testWidgets('Escape dismisses a Search dialog before changing tabs', (
tester,
) async {
-55
View File
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -130,58 +129,4 @@ void main() {
variant: TargetPlatformVariant.only(platform),
);
}
testWidgets(
'Cupertino Command slash retains primary focus after query updates',
(tester) async {
final composer = TextEditingController(text: 'draft');
final focus = FocusNode();
addTearDown(composer.dispose);
addTearDown(focus.dispose);
await tester.pumpWidget(
CupertinoApp(
home: AdaptiveShell(
cupertino: true,
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
CupertinoTextField(controller: composer, focusNode: focus),
AppDestination.search: (_) => SearchScreen(
gateway: _Gateway(),
onOpen: (_) {},
embedded: true,
),
},
),
),
);
await tester.pumpAndSettle();
focus.requestFocus();
await tester.pump();
await _chord(tester, [
LogicalKeyboardKey.metaLeft,
], LogicalKeyboardKey.slash);
EditableText field() => tester.widget<EditableText>(
find.descendant(
of: find.byKey(searchFieldKey),
matching: find.byType(EditableText),
),
);
expect(field().focusNode.hasPrimaryFocus, isTrue);
await tester.enterText(find.byKey(searchFieldKey), 'release');
await tester.pumpAndSettle(const Duration(milliseconds: 300));
await tester.pump(const Duration(seconds: 1));
expect(field().controller.text, 'release');
expect(field().focusNode.hasPrimaryFocus, isTrue);
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
await tester.pumpAndSettle();
focus.requestFocus();
await tester.pump();
await _chord(tester, [
LogicalKeyboardKey.metaLeft,
], LogicalKeyboardKey.slash);
expect(field().controller.text, 'release');
expect(field().focusNode.hasPrimaryFocus, isTrue);
},
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
);
}
+81 -88
View File
@@ -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/adaptive_shell.dart';
@@ -6,9 +5,8 @@ import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/shell_bar.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
Widget _app({required bool cupertino, required bool open, VoidCallback? back}) {
Widget _app({required bool open, VoidCallback? back}) {
final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => open
@@ -21,102 +19,97 @@ Widget _app({required bool cupertino, required bool open, VoidCallback? back}) {
: const Text('list'),
},
);
return cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell);
return MaterialApp(home: shell);
}
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'cupertino' : 'material';
testWidgets('$host: an open screen takes over the bar and gives it back', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
var backs = 0;
await tester.pumpWidget(
_app(cupertino: cupertino, open: true, back: () => backs++),
);
await tester.pump();
testWidgets('an open screen takes over the bar and gives it back', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
var backs = 0;
await tester.pumpWidget(_app(open: true, back: () => backs++));
await tester.pump();
expect(find.text('Run 7'), findsOneWidget);
expect(find.byKey(const Key('run-more')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back')));
expect(backs, 1);
expect(find.text('Run 7'), findsOneWidget);
expect(find.byKey(const Key('run-more')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back')));
expect(backs, 1);
await tester.pumpWidget(_app(cupertino: cupertino, open: false));
await tester.pump();
expect(find.text('Run 7'), findsNothing);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
expect(find.byKey(const Key('run-more')), findsNothing);
});
await tester.pumpWidget(_app(open: false));
await tester.pump();
expect(find.text('Run 7'), findsNothing);
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
expect(find.byKey(const Key('run-more')), findsNothing);
});
testWidgets('$host: Search is the fourth tab; Settings is not a tab', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(_app(cupertino: cupertino, open: false));
expect(AppDestination.values, hasLength(5));
expect(shellTabDestinations, [
AppDestination.pipelines,
AppDestination.runs,
AppDestination.chat,
AppDestination.search,
]);
expect(
find.byKey(const ValueKey('shell.destination.search')),
findsOneWidget,
);
expect(
find.byKey(const ValueKey('shell.destination.settings')),
findsNothing,
);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
});
testWidgets('Search is the fourth tab; Settings is not a tab', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(_app(open: false));
expect(AppDestination.values, hasLength(5));
expect(shellTabDestinations, [
AppDestination.pipelines,
AppDestination.runs,
AppDestination.chat,
AppDestination.search,
]);
expect(
find.byKey(const ValueKey('shell.destination.search')),
findsOneWidget,
);
expect(
find.byKey(const ValueKey('shell.destination.settings')),
findsNothing,
);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
});
testWidgets('$host: floating tabs stay inset and select destinations', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(_app(cupertino: cupertino, open: false));
testWidgets('floating tabs stay inset and select destinations', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(_app(open: false));
final destinationPill = find.descendant(
final destinationPill = find.descendant(
of: find.byType(FloatingDestinationBar),
matching: find.byKey(FloatingDestinationBar.rowKey),
);
// 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
.widget<FloatingDestinationBar>(find.byType(FloatingDestinationBar))
.showLabels,
isTrue,
);
for (final destination in shellTabDestinations) {
final caption = find.descendant(
of: find.byType(FloatingDestinationBar),
matching: find.byKey(FloatingDestinationBar.rowKey),
matching: find.text(destinationDetails(destination).label),
);
// 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
.widget<FloatingDestinationBar>(find.byType(FloatingDestinationBar))
.showLabels,
isTrue,
expect(caption, findsOneWidget);
expect(rect.contains(tester.getRect(caption).center), isTrue);
final target = tester.getSize(
find.byKey(ValueKey('shell.destination.${destination.name}')),
);
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();
expect(find.text('Chat — Not implemented'), findsOneWidget);
});
}
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();
expect(find.text('Chat — Not implemented'), findsOneWidget);
});
testWidgets('tabs show the running and unread counts their screens publish', (
tester,
+18 -27
View File
@@ -1,34 +1,25 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/shell_destination_menu.dart';
import 'package:pipelines_app/shell/destination.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets('compact menu exposes all named destinations ($cupertino)', (
tester,
) async {
AppDestination? selected;
final menu = ShellDestinationMenu(
cupertino: cupertino,
current: AppDestination.chat,
onSelected: (value) => selected = value,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: menu))
: MaterialApp(home: Scaffold(body: menu)),
);
await tester.tap(find.text('Menu'));
await tester.pumpAndSettle();
for (final name in ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings']) {
expect(find.text(name), findsOneWidget);
}
await tester.tap(find.text('Runs'));
await tester.pumpAndSettle();
expect(selected, AppDestination.runs);
expect(tester.takeException(), isNull);
});
}
testWidgets('compact menu exposes all named destinations', (tester) async {
AppDestination? selected;
final menu = ShellDestinationMenu(
cupertino: false,
current: AppDestination.chat,
onSelected: (value) => selected = value,
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: menu)));
await tester.tap(find.text('Menu'));
await tester.pumpAndSettle();
for (final name in ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings']) {
expect(find.text(name), findsOneWidget);
}
await tester.tap(find.text('Runs'));
await tester.pumpAndSettle();
expect(selected, AppDestination.runs);
expect(tester.takeException(), isNull);
});
}
+176 -192
View File
@@ -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/adaptive_shell.dart';
@@ -46,11 +45,11 @@ void main() {
);
/// A detail with its own floating tabs over a list, like run detail.
Widget tabsDetail(bool cupertino) => FloatingBarOverlay(
Widget tabsDetail() => FloatingBarOverlay(
bar: KeyedSubtree(
key: const Key('detail-tabs'),
child: FloatingDestinationBar(
cupertino: cupertino,
cupertino: false,
currentIndex: 0,
onTap: (_) {},
items: const [
@@ -72,7 +71,6 @@ void main() {
);
Widget shell({
required bool cupertino,
bool split = true,
bool tabs = false,
double textScale = 1,
@@ -80,7 +78,6 @@ void main() {
AppDestination destination = AppDestination.chat,
}) {
final app = AdaptiveShell(
cupertino: cupertino,
listPaneWidthStore: store ?? MemoryListPaneWidthStore(),
destination: destination,
destinationBodies: {
@@ -88,7 +85,7 @@ void main() {
AppDestination.chat: (_) => split
? ListDetailPanes(
list: listBody(),
detail: tabs ? tabsDetail(cupertino) : composerDetail(),
detail: tabs ? tabsDetail() : composerDetail(),
)
: listBody(),
},
@@ -97,7 +94,7 @@ void main() {
data: MediaQueryData.fromView(
WidgetsBinding.instance.platformDispatcher.views.first,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
child: MaterialApp(home: app),
);
}
@@ -110,204 +107,191 @@ void main() {
.first,
);
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
for (final width in [1200.0, 1600.0]) {
testWidgets('$width split: the destination bar sits under the '
'list and the composer at the detail\'s bottom edge', (tester) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(shell());
await tester.pump();
await tester.pump();
for (final width in [1200.0, 1600.0]) {
testWidgets('$host $width split: the destination bar sits under the '
'list and the composer at the detail\'s bottom edge', (tester) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(shell(cupertino: cupertino));
await tester.pump();
await tester.pump();
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final pill = destinationPill(tester);
// Leading at the bottom of the list pane, never over the detail.
expect(pill.left, closeTo(list.left + kFloatingBarMargin, 0.5));
expect(pill.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(pill.right, lessThanOrEqualTo(list.right));
expect(pill.overlaps(body), isFalse, reason: 'never over the detail');
expect(
pill.width,
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);
}
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final pill = destinationPill(tester);
// Leading at the bottom of the list pane, never over the detail.
expect(pill.left, closeTo(list.left + kFloatingBarMargin, 0.5));
expect(pill.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(pill.right, lessThanOrEqualTo(list.right));
expect(pill.overlaps(body), isFalse, reason: 'never over the detail');
// The composer reaches the detail's bottom edge: nothing is reserved
// there for the shell's bar any more.
final composer = tester.getRect(find.byKey(const Key('composer')));
expect(composer.left, body.left);
expect(composer.bottom, closeTo(800, 0.5));
expect(composer.overlaps(pill), isFalse);
// The list clears the bar, so its last rows scroll out from under it.
final listContext = tester.element(find.byKey(const Key('list')));
expect(
MediaQuery.paddingOf(listContext).bottom,
greaterThanOrEqualTo(800 - pill.top),
);
await tester.drag(find.byKey(const Key('list')), const Offset(0, -4000));
await tester.pumpAndSettle();
final last = tester.getRect(find.text('row 39'));
expect(last.bottom, lessThanOrEqualTo(pill.top));
});
testWidgets('$width split: the item tabs sit at the bottom right '
'of the detail, and its content clears only them', (tester) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(shell(tabs: true));
await tester.pump();
await tester.pump();
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final pill = destinationPill(tester);
final tabs = tester.getRect(
find
.descendant(
of: find.byKey(const Key('detail-tabs')),
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
expect(tabs.right, closeTo(width - kFloatingBarMargin, 0.5));
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(
pill.width,
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.
final composer = tester.getRect(find.byKey(const Key('composer')));
expect(composer.left, body.left);
expect(composer.bottom, closeTo(800, 0.5));
expect(composer.overlaps(pill), isFalse);
// The list clears the bar, so its last rows scroll out from under it.
final listContext = tester.element(find.byKey(const Key('list')));
expect(
MediaQuery.paddingOf(listContext).bottom,
greaterThanOrEqualTo(800 - pill.top),
);
await tester.drag(
find.byKey(const Key('list')),
const Offset(0, -4000),
);
await tester.pumpAndSettle();
final last = tester.getRect(find.text('row 39'));
expect(last.bottom, lessThanOrEqualTo(pill.top));
});
testWidgets('$host $width split: the item tabs sit at the bottom right '
'of the detail, and its content clears only them', (tester) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(shell(cupertino: cupertino, tabs: true));
await tester.pump();
await tester.pump();
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final pill = destinationPill(tester);
final tabs = tester.getRect(
find
.descendant(
of: find.byKey(const Key('detail-tabs')),
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
expect(tabs.right, closeTo(width - kFloatingBarMargin, 0.5));
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),
matching: find.text(label),
),
findsNothing,
);
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.
final listContext = tester.element(
find.byKey(const Key('detail-list')),
);
expect(
MediaQuery.paddingOf(listContext).bottom,
closeTo(800 - tabs.top, 0.5),
);
});
}
testWidgets('$host 1200 split: the bar follows a dragged list width', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
for (final width in [300.0, 520.0]) {
final store = MemoryListPaneWidthStore({'chat': width});
await tester.pumpWidget(
KeyedSubtree(
key: ValueKey(width),
child: shell(cupertino: cupertino, store: store),
),
);
await tester.pumpAndSettle();
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
expect(list.width, closeTo(width, 0.5));
final pill = destinationPill(tester);
expect(pill.left, closeTo(list.left + kFloatingBarMargin, 0.5));
expect(pill.left, greaterThanOrEqualTo(kFloatingBarMargin - 0.5));
expect(pill.right, lessThanOrEqualTo(list.right - kFloatingBarMargin));
}
});
expect(pill.right, lessThan(body.left));
testWidgets('$host 1200 Settings: a page without a list keeps the bar '
'at the right edge', (tester) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(
shell(cupertino: cupertino, destination: AppDestination.settings),
// The item's list pads its end clear of its own tabs.
final listContext = tester.element(find.byKey(const Key('detail-list')));
expect(
MediaQuery.paddingOf(listContext).bottom,
closeTo(800 - tabs.top, 0.5),
);
await tester.pump();
final pill = destinationPill(tester);
expect(pill.right, closeTo(1200 - kFloatingBarMargin, 0.5));
});
}
testWidgets('$host 1200 unsplit: the bar stays under the list column', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
await tester.pump();
testWidgets('1200 split: the bar follows a dragged list width', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
for (final width in [300.0, 520.0]) {
final store = MemoryListPaneWidthStore({'chat': width});
await tester.pumpWidget(
KeyedSubtree(
key: ValueKey(width),
child: shell(store: store),
),
);
await tester.pumpAndSettle();
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
expect(list.width, closeTo(width, 0.5));
final pill = destinationPill(tester);
// Same place as beside an open item (Search has no split), so opening
// or closing an item never moves the bar across the window.
expect(pill.left, closeTo(kFloatingBarMargin, 0.5));
expect(pill.width, lessThan(1200 * 0.6));
});
testWidgets('$host 390: the bar hugs its tabs at the phone\'s bottom '
'right', (tester) async {
await setSize(tester, const Size(390, 844));
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
await tester.pump();
final pill = destinationPill(tester);
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));
});
for (final width in [600.0, 840.0]) {
testWidgets('$host $width split at 2x: the bar fits the list pane and '
'the item tabs the detail, without overflow', (tester) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(
shell(cupertino: cupertino, tabs: true, textScale: 2),
);
await tester.pump();
await tester.pump();
expect(tester.takeException(), isNull);
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
final pill = destinationPill(tester);
expect(pill.left, greaterThanOrEqualTo(list.left));
expect(pill.right, lessThanOrEqualTo(list.right));
});
expect(pill.left, closeTo(list.left + kFloatingBarMargin, 0.5));
expect(pill.left, greaterThanOrEqualTo(kFloatingBarMargin - 0.5));
expect(pill.right, lessThanOrEqualTo(list.right - kFloatingBarMargin));
}
});
testWidgets('1200 Settings: a page without a list keeps the bar '
'at the right edge', (tester) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell(destination: AppDestination.settings));
await tester.pump();
final pill = destinationPill(tester);
expect(pill.right, closeTo(1200 - kFloatingBarMargin, 0.5));
});
testWidgets('1200 unsplit: the bar stays under the list column', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell(split: false));
await tester.pump();
final pill = destinationPill(tester);
// Same place as beside an open item (Search has no split), so opening
// or closing an item never moves the bar across the window.
expect(pill.left, closeTo(kFloatingBarMargin, 0.5));
expect(pill.width, lessThan(1200 * 0.6));
});
testWidgets('390: the bar hugs its tabs at the phone\'s bottom '
'right', (tester) async {
await setSize(tester, const Size(390, 844));
await tester.pumpWidget(shell(split: false));
await tester.pump();
final pill = destinationPill(tester);
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));
});
for (final width in [600.0, 840.0]) {
testWidgets('$width split at 2x: the bar fits the list pane and '
'the item tabs the detail, without overflow', (tester) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(shell(tabs: true, textScale: 2));
await tester.pump();
await tester.pump();
expect(tester.takeException(), isNull);
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
final pill = destinationPill(tester);
expect(pill.left, greaterThanOrEqualTo(list.left));
expect(pill.right, lessThanOrEqualTo(list.right));
});
}
}
+57 -69
View File
@@ -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/features/runs/data/runs_repository.dart';
@@ -36,7 +35,7 @@ void main() {
.first,
);
Future<void> pumpSplitRun(WidgetTester tester, bool cupertino) async {
Future<void> pumpSplitRun(WidgetTester tester) async {
tester.view.physicalSize = const Size(1200, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
@@ -45,7 +44,6 @@ void main() {
addTearDown(controller.dispose);
await controller.select(77);
final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => ListDetailPanes(
@@ -65,78 +63,68 @@ void main() {
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: shell)
: MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: shell,
),
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: shell,
),
);
await tester.pumpAndSettle();
}
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('1200: run tabs float at the pane\'s bottom beside the '
'shell bar under the list, and the stage page opens in the pane', (
tester,
) async {
await pumpSplitRun(tester);
final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
final list = tester.getRect(find.byKey(const ValueKey('list-detail-list')));
var main = shellPill(tester);
expect(main.left, closeTo(list.left + kFloatingBarMargin, 0.5));
expect(main.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
testWidgets('$host 1200: run tabs float at the pane\'s bottom beside the '
'shell bar under the list, and the stage page opens in the pane', (
final runTabs = pillOf(tester, find.byKey(const Key('run-detail-tabs')));
expect(runTabs.left, greaterThanOrEqualTo(body.left));
expect(runTabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(runTabs.overlaps(main), isFalse);
expect(runTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
// Open the stage page from the timeline.
await openRunDetailTab(tester, RunDetailTab.timeline);
final row = find.byKey(const ValueKey('run-timeline-visit-1'));
await tester.ensureVisible(row);
await tester.pumpAndSettle();
await tester.tap(row);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-back')), findsOneWidget);
// The page covers only the detail pane: the root navigator has nothing
// pushed, and the list and the shell's tab bar stay in place.
expect(
tester.state<NavigatorState>(find.byType(Navigator).first).canPop(),
isFalse,
);
expect(find.text('run row 0'), findsOneWidget);
final back = tester.getRect(find.byKey(const Key('run-visit-back')));
expect(back.left, greaterThanOrEqualTo(body.left));
main = shellPill(tester);
expect(main.left, closeTo(list.left + kFloatingBarMargin, 0.5));
final visitTabs = pillOf(
tester,
) async {
await pumpSplitRun(tester, cupertino);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
var main = shellPill(tester);
expect(main.left, closeTo(list.left + kFloatingBarMargin, 0.5));
expect(main.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
find.byKey(const Key('run-visit-tabs')).last,
);
expect(visitTabs.left, greaterThanOrEqualTo(body.left));
expect(visitTabs.overlaps(main), isFalse);
expect(visitTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(tester.takeException(), isNull);
final runTabs = pillOf(tester, find.byKey(const Key('run-detail-tabs')));
expect(runTabs.left, greaterThanOrEqualTo(body.left));
expect(runTabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(runTabs.overlaps(main), isFalse);
expect(runTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
// The shell's tabs still work over the open stage page.
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
await tester.pumpAndSettle();
// Open the stage page from the timeline.
await openRunDetailTab(tester, RunDetailTab.timeline);
final row = find.byKey(const ValueKey('run-timeline-visit-1'));
await tester.ensureVisible(row);
await tester.pumpAndSettle();
await tester.tap(row);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-back')), findsOneWidget);
// The page covers only the detail pane: the root navigator has nothing
// pushed, and the list and the shell's tab bar stay in place.
expect(
tester.state<NavigatorState>(find.byType(Navigator).first).canPop(),
isFalse,
);
expect(find.text('run row 0'), findsOneWidget);
final back = tester.getRect(find.byKey(const Key('run-visit-back')));
expect(back.left, greaterThanOrEqualTo(body.left));
main = shellPill(tester);
expect(main.left, closeTo(list.left + kFloatingBarMargin, 0.5));
final visitTabs = pillOf(
tester,
find.byKey(const Key('run-visit-tabs')).last,
);
expect(visitTabs.left, greaterThanOrEqualTo(body.left));
expect(visitTabs.overlaps(main), isFalse);
expect(visitTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(tester.takeException(), isNull);
// The shell's tabs still work over the open stage page.
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
await tester.pumpAndSettle();
// Back closes the page inside the pane, back to the run.
await tester.tap(find.byKey(const Key('run-visit-back')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-back')), findsNothing);
expect(find.byKey(const Key('run-detail-tabs')), findsOneWidget);
});
}
// Back closes the page inside the pane, back to the run.
await tester.tap(find.byKey(const Key('run-visit-back')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-back')), findsNothing);
expect(find.byKey(const Key('run-detail-tabs')), findsOneWidget);
});
}
+45 -56
View File
@@ -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/features/runs/data/runs_repository.dart';
@@ -18,11 +17,7 @@ import '../features/runs/ui/run_detail_visit_support.dart';
/// edge at an unfolded foldable's width and on a wide window: its content
/// spans the pane minus the page's own padding, with no reading-width cap.
void main() {
Future<void> openStagePage(
WidgetTester tester, {
required bool cupertino,
required Size size,
}) async {
Future<void> openStagePage(WidgetTester tester, {required Size size}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
@@ -31,7 +26,6 @@ void main() {
addTearDown(controller.dispose);
await controller.select(77);
final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => ListDetailPanes(
@@ -49,12 +43,10 @@ void main() {
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: shell)
: MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: shell,
),
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: shell,
),
);
await tester.pumpAndSettle();
await openRunDetailTab(tester, RunDetailTab.timeline);
@@ -65,48 +57,45 @@ void main() {
await tester.pumpAndSettle();
}
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
for (final size in const [Size(880, 1000), Size(1400, 900)]) {
testWidgets('$host ${size.width.toInt()}: the stage page spans the '
'detail pane edge to edge', (tester) async {
await openStagePage(tester, cupertino: cupertino, size: size);
expect(find.byKey(const Key('run-visit-back')), findsOneWidget);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
// The pane is the detail's whole share of the window, up to its
// right edge.
expect(body.right, size.width);
final pane = tester.getRect(find.byKey(const Key('run-visit-pane')));
expect(pane.left, body.left);
expect(pane.right, body.right);
// The facts block and the Input and Output sections span the whole
// pane; only the page's own padding insets their content.
final facts = tester.getRect(find.byKey(const Key('run-visit-facts')));
expect(facts.left, body.left);
expect(facts.right, body.right);
final titles = find.descendant(
of: find.byKey(const Key('run-visit-pane')),
matching: find.byType(StickySectionTitle),
);
expect(titles, findsNWidgets(2));
for (final title in tester.widgetList(titles)) {
final rect = tester.getRect(find.byWidget(title));
expect(rect.left, body.left);
expect(rect.right, body.right);
}
// The heading starts at the page padding and the chevron ends at it.
final input = tester.getRect(
find.descendant(of: titles.first, matching: find.text('Input')),
);
expect(input.left, body.left + 16);
final chevron = tester.getRect(
find.descendant(of: titles.first, matching: find.byType(Icon)).last,
);
expect(chevron.right, closeTo(body.right - 8, 0.5));
expect(tester.takeException(), isNull);
});
}
for (final size in const [Size(880, 1000), Size(1400, 900)]) {
testWidgets('${size.width.toInt()}: the stage page spans the '
'detail pane edge to edge', (tester) async {
await openStagePage(tester, size: size);
expect(find.byKey(const Key('run-visit-back')), findsOneWidget);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
// The pane is the detail's whole share of the window, up to its
// right edge.
expect(body.right, size.width);
final pane = tester.getRect(find.byKey(const Key('run-visit-pane')));
expect(pane.left, body.left);
expect(pane.right, body.right);
// The facts block and the Input and Output sections span the whole
// pane; only the page's own padding insets their content.
final facts = tester.getRect(find.byKey(const Key('run-visit-facts')));
expect(facts.left, body.left);
expect(facts.right, body.right);
final titles = find.descendant(
of: find.byKey(const Key('run-visit-pane')),
matching: find.byType(StickySectionTitle),
);
expect(titles, findsNWidgets(2));
for (final title in tester.widgetList(titles)) {
final rect = tester.getRect(find.byWidget(title));
expect(rect.left, body.left);
expect(rect.right, body.right);
}
// The heading starts at the page padding and the chevron ends at it.
final input = tester.getRect(
find.descendant(of: titles.first, matching: find.text('Input')),
);
expect(input.left, body.left + 16);
final chevron = tester.getRect(
find.descendant(of: titles.first, matching: find.byType(Icon)).last,
);
expect(chevron.right, closeTo(body.right - 8, 0.5));
expect(tester.takeException(), isNull);
});
}
}
+89 -97
View File
@@ -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/adaptive_shell.dart';
@@ -38,7 +37,7 @@ void main() {
/// An item publishing its bar to the pane, with its own floating tabs
/// placed where the pane says (like run and pipeline detail).
Widget tabbedItem(bool cupertino) => ShellBar(
Widget tabbedItem() => ShellBar(
title: 'Open item',
child: Builder(
builder: (context) {
@@ -48,7 +47,7 @@ void main() {
bar: KeyedSubtree(
key: const Key('item-tabs'),
child: FloatingDestinationBar(
cupertino: cupertino,
cupertino: false,
edge: edge,
currentIndex: 0,
onTap: (_) {},
@@ -71,12 +70,12 @@ void main() {
);
/// An item drawing its own header over itself (like the chat thread).
Widget overlayItem(bool cupertino) => ShellBar(
Widget overlayItem() => ShellBar(
barless: true,
child: SegmentedBarOverlay(
bar: SegmentedBar(
key: const Key('own-header'),
cupertino: cupertino,
cupertino: false,
automaticallyImplyLeading: false,
title: 'Own header',
),
@@ -84,9 +83,8 @@ void main() {
),
);
Widget shell(bool cupertino, Widget Function(bool) item) {
Widget shell(Widget item) {
final app = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs,
destinationBodies: {
AppDestination.runs: (_) => ListDetailPanes(
@@ -96,12 +94,12 @@ void main() {
detail: DetailPane(
destination: AppDestination.runs,
implyBack: false,
builder: (_) => item(cupertino),
builder: (_) => item,
),
),
},
);
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app);
return MaterialApp(home: app);
}
Iterable<Rect> pillsOf(WidgetTester tester, Finder bar) => find
@@ -112,99 +110,93 @@ void main() {
return box.localToGlobal(Offset.zero) & box.size;
});
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('split under a status bar: list and pane bars sit '
'below it, content reaches the top edge', (tester) async {
await setUp(tester, const Size(1200, 800));
await tester.pumpWidget(shell(tabbedItem()));
await tester.pump();
await tester.pump();
testWidgets('$host split under a status bar: list and pane bars sit '
'below it, content reaches the top edge', (tester) async {
await setUp(tester, const Size(1200, 800));
await tester.pumpWidget(shell(cupertino, tabbedItem));
await tester.pump();
await tester.pump();
final listBar = find.byWidgetPredicate(
(widget) => widget is SegmentedBar && widget.title == 'Runs',
);
final paneBar = find.byWidgetPredicate(
(widget) => widget is SegmentedBar && widget.title == 'Open item',
);
for (final bar in [listBar, paneBar]) {
final pills = pillsOf(tester, bar);
expect(pills, isNotEmpty);
for (final pill in pills) {
expect(pill.top, greaterThanOrEqualTo(statusBar));
}
}
// Content may still extend under the bars and the status bar.
expect(tester.getTopLeft(find.byKey(const Key('list'))).dy, 0);
expect(tester.getTopLeft(find.byKey(const Key('item-list'))).dy, 0);
// At rest (the bars' pieces have popped in) the first rows start
// below the bars.
await tester.pump(const Duration(seconds: 1));
final paneBottom = pillsOf(tester, paneBar).first.bottom;
expect(
tester.getTopLeft(find.text('item 0')).dy,
greaterThanOrEqualTo(paneBottom),
);
});
testWidgets('$host split under a status bar: a self-drawn header (chat) '
'sits below it', (tester) async {
await setUp(tester, const Size(1200, 800));
await tester.pumpWidget(shell(cupertino, overlayItem));
await tester.pump();
await tester.pump();
final pills = pillsOf(tester, find.byKey(const Key('own-header')));
final listBar = find.byWidgetPredicate(
(widget) => widget is SegmentedBar && widget.title == 'Runs',
);
final paneBar = find.byWidgetPredicate(
(widget) => widget is SegmentedBar && widget.title == 'Open item',
);
for (final bar in [listBar, paneBar]) {
final pills = pillsOf(tester, bar);
expect(pills, isNotEmpty);
for (final pill in pills) {
expect(pill.top, greaterThanOrEqualTo(statusBar));
}
expect(tester.getTopLeft(find.byKey(const Key('item-list'))).dy, 0);
});
}
// Content may still extend under the bars and the status bar.
expect(tester.getTopLeft(find.byKey(const Key('list'))).dy, 0);
expect(tester.getTopLeft(find.byKey(const Key('item-list'))).dy, 0);
// At rest (the bars' pieces have popped in) the first rows start
// below the bars.
await tester.pump(const Duration(seconds: 1));
final paneBottom = pillsOf(tester, paneBar).first.bottom;
expect(
tester.getTopLeft(find.text('item 0')).dy,
greaterThanOrEqualTo(paneBottom),
);
});
testWidgets('$host split: the item tabs sit at the bottom right of the '
'detail pane, the shell tab bar under the list', (tester) async {
// A gesture-navigation inset as on the unfolded foldable.
await setUp(tester, const Size(1200, 800), bottom: 24);
await tester.pumpWidget(shell(cupertino, tabbedItem));
await tester.pump();
await tester.pump();
testWidgets('split under a status bar: a self-drawn header (chat) '
'sits below it', (tester) async {
await setUp(tester, const Size(1200, 800));
await tester.pumpWidget(shell(overlayItem()));
await tester.pump();
await tester.pump();
final pills = pillsOf(tester, find.byKey(const Key('own-header')));
expect(pills, isNotEmpty);
for (final pill in pills) {
expect(pill.top, greaterThanOrEqualTo(statusBar));
}
expect(tester.getTopLeft(find.byKey(const Key('item-list'))).dy, 0);
});
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final tabs = tester.getRect(
find.descendant(
of: find.byKey(const Key('item-tabs')),
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
expect(tabs.left, greaterThanOrEqualTo(body.left));
expect(tabs.right, lessThanOrEqualTo(body.right));
final shellTabs = tester.getRect(
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.runs')).first,
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
// Both bars sit above the system inset: the shell's under the list
// pane, the item's at the detail pane's trailing edge.
final listPane = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
expect(shellTabs.bottom, closeTo(800 - 24, 0.5));
expect(shellTabs.right, lessThanOrEqualTo(listPane.right));
expect(tabs.bottom, closeTo(800 - 24, 0.5));
expect(tabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(shellTabs.overlaps(tabs), isFalse);
// The item's list clears its tabs at rest.
final list = tester.element(find.byKey(const Key('item-list')));
expect(
MediaQuery.paddingOf(list).bottom,
greaterThanOrEqualTo(800 - tabs.top),
);
});
}
testWidgets('split: the item tabs sit at the bottom right of the '
'detail pane, the shell tab bar under the list', (tester) async {
// A gesture-navigation inset as on the unfolded foldable.
await setUp(tester, const Size(1200, 800), bottom: 24);
await tester.pumpWidget(shell(tabbedItem()));
await tester.pump();
await tester.pump();
final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
final tabs = tester.getRect(
find.descendant(
of: find.byKey(const Key('item-tabs')),
matching: find.byKey(FloatingDestinationBar.rowKey),
),
);
expect(tabs.left, greaterThanOrEqualTo(body.left));
expect(tabs.right, lessThanOrEqualTo(body.right));
final shellTabs = tester.getRect(
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.runs')).first,
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
// Both bars sit above the system inset: the shell's under the list
// pane, the item's at the detail pane's trailing edge.
final listPane = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
expect(shellTabs.bottom, closeTo(800 - 24, 0.5));
expect(shellTabs.right, lessThanOrEqualTo(listPane.right));
expect(tabs.bottom, closeTo(800 - 24, 0.5));
expect(tabs.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(shellTabs.overlaps(tabs), isFalse);
// The item's list clears its tabs at rest.
final list = tester.element(find.byKey(const Key('item-list')));
expect(
MediaQuery.paddingOf(list).bottom,
greaterThanOrEqualTo(800 - tabs.top),
);
});
}
+84 -103
View File
@@ -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/adaptive_shell.dart';
@@ -50,9 +49,8 @@ void main() {
),
);
Widget app({required bool cupertino, required bool split}) {
Widget app({required bool split}) {
final shell = AdaptiveShell(
cupertino: cupertino,
destinationBodies: {
AppDestination.runs: (_) => split
? ListDetailPanes(
@@ -69,9 +67,7 @@ void main() {
);
Widget margins(BuildContext context, Widget? child) =>
WindowMargins(child: child!);
return cupertino
? CupertinoApp(builder: margins, home: shell)
: MaterialApp(builder: margins, home: shell);
return MaterialApp(builder: margins, home: shell);
}
Finder pills(Finder bar) =>
@@ -94,107 +90,92 @@ void main() {
return rects.reduce((a, b) => a.expandToInclude(b));
}
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('1280: list and detail bars keep 16 px from the top '
'and every side', (tester) async {
await setSize(tester, const Size(1280, 800));
await tester.pumpWidget(app(split: true));
await tester.pump();
// The pieces pop in; measure them at rest.
await tester.pump(const Duration(seconds: 2));
testWidgets('$host 1280: list and detail bars keep 16 px from the top '
'and every side', (tester) async {
await setSize(tester, const Size(1280, 800));
await tester.pumpWidget(app(cupertino: cupertino, split: true));
await tester.pump();
// The pieces pop in; measure them at rest.
await tester.pump(const Duration(seconds: 2));
final listPane = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
final listBar = span(tester, shellBar);
final itemBar = span(tester, paneBar);
expect(listBar.top, closeTo(16, 0.5));
expect(listBar.left, closeTo(listPane.left + 16, 0.5));
expect(listBar.right, closeTo(listPane.right - 16, 0.5));
expect(itemBar.top, closeTo(16, 0.5));
expect(itemBar.left, closeTo(body.left + 16, 0.5));
expect(itemBar.right, closeTo(body.right - 16, 0.5));
final listPane = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final listBar = span(tester, shellBar);
final itemBar = span(tester, paneBar);
expect(listBar.top, closeTo(16, 0.5));
expect(listBar.left, closeTo(listPane.left + 16, 0.5));
expect(listBar.right, closeTo(listPane.right - 16, 0.5));
expect(itemBar.top, closeTo(16, 0.5));
expect(itemBar.left, closeTo(body.left + 16, 0.5));
expect(itemBar.right, closeTo(body.right - 16, 0.5));
// Each pane's content still starts below its bar (and its 8 px gap)
// at rest, so nothing hides behind the taller margin.
expect(
tester.getTopLeft(find.text('list row 0')).dy,
greaterThanOrEqualTo(listBar.bottom + 8 - 0.5),
);
expect(
tester.getTopLeft(find.text('item row 0')).dy,
greaterThanOrEqualTo(itemBar.bottom + 8 - 0.5),
);
expect(tester.takeException(), isNull);
});
// Each pane's content still starts below its bar (and its 8 px gap)
// at rest, so nothing hides behind the taller margin.
expect(
tester.getTopLeft(find.text('list row 0')).dy,
greaterThanOrEqualTo(listBar.bottom + 8 - 0.5),
);
expect(
tester.getTopLeft(find.text('item row 0')).dy,
greaterThanOrEqualTo(itemBar.bottom + 8 - 0.5),
);
expect(tester.takeException(), isNull);
});
testWidgets('390: the phone keeps the bar at 8 px from the top and '
'12 px from the sides', (tester) async {
await setSize(tester, const Size(390, 844));
await tester.pumpWidget(app(split: false));
await tester.pump();
// The pieces pop in; measure them at rest.
await tester.pump(const Duration(seconds: 2));
testWidgets('$host 390: the phone keeps the bar at 8 px from the top and '
'12 px from the sides', (tester) async {
await setSize(tester, const Size(390, 844));
await tester.pumpWidget(app(cupertino: cupertino, split: false));
await tester.pump();
// The pieces pop in; measure them at rest.
await tester.pump(const Duration(seconds: 2));
final bar = span(tester, shellBar);
expect(bar.top, closeTo(8, 0.5));
expect(bar.left, closeTo(12, 0.5));
expect(bar.right, closeTo(390 - 12, 0.5));
expect(
tester.getTopLeft(find.text('list row 0')).dy,
greaterThanOrEqualTo(bar.bottom + 8 - 0.5),
);
expect(tester.takeException(), isNull);
});
final bar = span(tester, shellBar);
expect(bar.top, closeTo(8, 0.5));
expect(bar.left, closeTo(12, 0.5));
expect(bar.right, closeTo(390 - 12, 0.5));
expect(
tester.getTopLeft(find.text('list row 0')).dy,
greaterThanOrEqualTo(bar.bottom + 8 - 0.5),
);
expect(tester.takeException(), isNull);
});
testWidgets('1280: a pushed page\'s bar keeps the wide margins', (
tester,
) async {
await setSize(tester, const Size(1280, 800));
final bar = SegmentedBar(
cupertino: false,
title: 'Settings',
actions: const [Icon(Icons.more_vert, semanticLabel: 'More')],
);
final body = Builder(
builder: (context) => ListView(
padding: withTopBarClearance(context, EdgeInsets.zero),
children: const [SizedBox(height: 40, child: Text('first row'))],
),
);
Widget margins(BuildContext context, Widget? child) =>
WindowMargins(child: child!);
await tester.pumpWidget(
MaterialApp(
builder: margins,
home: Scaffold(extendBodyBehindAppBar: true, appBar: bar, body: body),
),
);
await tester.pump(const Duration(seconds: 2));
testWidgets('$host 1280: a pushed page\'s bar keeps the wide margins', (
tester,
) async {
await setSize(tester, const Size(1280, 800));
final bar = SegmentedBar(
cupertino: cupertino,
title: 'Settings',
actions: const [Icon(Icons.more_vert, semanticLabel: 'More')],
);
final body = Builder(
builder: (context) => ListView(
padding: withTopBarClearance(context, EdgeInsets.zero),
children: const [SizedBox(height: 40, child: Text('first row'))],
),
);
Widget margins(BuildContext context, Widget? child) =>
WindowMargins(child: child!);
await tester.pumpWidget(
cupertino
? CupertinoApp(
builder: margins,
home: CupertinoPageScaffold(navigationBar: bar, child: body),
)
: MaterialApp(
builder: margins,
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: bar,
body: body,
),
),
);
await tester.pump(const Duration(seconds: 2));
final pieces = span(tester, find.byType(SegmentedBar));
expect(pieces.top, closeTo(16, 0.5));
expect(pieces.left, closeTo(16, 0.5));
expect(pieces.right, closeTo(1280 - 16, 0.5));
expect(
tester.getTopLeft(find.text('first row')).dy,
closeTo(pieces.bottom + 8, 0.5),
);
expect(tester.takeException(), isNull);
});
}
final pieces = span(tester, find.byType(SegmentedBar));
expect(pieces.top, closeTo(16, 0.5));
expect(pieces.left, closeTo(16, 0.5));
expect(pieces.right, closeTo(1280 - 16, 0.5));
expect(
tester.getTopLeft(find.text('first row')).dy,
closeTo(pieces.bottom + 8, 0.5),
);
expect(tester.takeException(), isNull);
});
}