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
+19 -55
View File
@@ -1,10 +1,8 @@
import '../ui/motion/fade_through_stack.dart'; import '../ui/motion/fade_through_stack.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import '../ui/adaptive/segmented_bar.dart'; import '../ui/adaptive/segmented_bar.dart';
import '../ui/adaptive/floating_bar_layout.dart';
import '../ui/adaptive/floating_destination_bar.dart'; import '../ui/adaptive/floating_destination_bar.dart';
import 'attention_badge.dart'; import 'attention_badge.dart';
import 'destination.dart'; import 'destination.dart';
@@ -37,6 +35,9 @@ class AdaptiveShell extends StatefulWidget {
final ListPaneWidthStore listPaneWidthStore; final ListPaneWidthStore listPaneWidthStore;
final Map<AppDestination, WidgetBuilder> destinationBodies; final Map<AppDestination, WidgetBuilder> destinationBodies;
/// Retained for callers that still pass it; the shell always draws the
/// Material controls and scaffold whether this is set or not.
final bool cupertino; final bool cupertino;
/// The destination a route owner selected. When null the shell keeps its own /// The destination a route owner selected. When null the shell keeps its own
@@ -120,7 +121,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
key: const ValueKey('shell.badge.chat.unread'), key: const ValueKey('shell.badge.chat.unread'),
count: _bar.badge(destination, ShellBadgeKind.unread), count: _bar.badge(destination, ShellBadgeKind.unread),
label: 'unread chats', label: 'unread chats',
cupertino: widget.cupertino, cupertino: false,
child: icon, child: icon,
); );
} }
@@ -130,12 +131,12 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
final attention = widget.attentionCount > 0; final attention = widget.attentionCount > 0;
return AttentionDestinationIcon( return AttentionDestinationIcon(
count: widget.attentionCount, count: widget.attentionCount,
cupertino: widget.cupertino, cupertino: false,
child: ActivityBadge( child: ActivityBadge(
key: const ValueKey('shell.badge.runs.running'), key: const ValueKey('shell.badge.runs.running'),
count: attention ? 0 : _bar.badge(destination, ShellBadgeKind.running), count: attention ? 0 : _bar.badge(destination, ShellBadgeKind.running),
label: 'runs in progress', label: 'runs in progress',
cupertino: widget.cupertino, cupertino: false,
child: icon, child: icon,
), ),
); );
@@ -202,7 +203,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
alignment: AlignmentDirectional.bottomStart, alignment: AlignmentDirectional.bottomStart,
child: FloatingDestinationBar( child: FloatingDestinationBar(
showLabels: true, showLabels: true,
cupertino: widget.cupertino, cupertino: false,
currentIndex: index, currentIndex: index,
onTap: (value) => _select(shellTabDestinations[value]), onTap: (value) => _select(shellTabDestinations[value]),
items: _destinationItems(), items: _destinationItems(),
@@ -240,24 +241,6 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
}, },
child: child, child: child,
); );
if (widget.cupertino) {
return backable(
ShellSystemInsets(
padding: system,
child: CupertinoPageScaffold(
navigationBar: topBar,
child: SafeArea(
top: false,
bottom: false,
child: FloatingBarOverlay(
bar: bar,
child: _destinationStack(contents),
),
),
),
),
);
}
return backable( return backable(
ShellSystemInsets( ShellSystemInsets(
padding: system, padding: system,
@@ -352,10 +335,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
final item = destinationDetails(destination); final item = destinationDetails(destination);
return FloatingDestinationItem( return FloatingDestinationItem(
key: ValueKey('shell.destination.${destination.name}'), key: ValueKey('shell.destination.${destination.name}'),
icon: _icon( icon: _icon(destination, item.icon),
destination,
widget.cupertino ? item.cupertinoIcon : item.icon,
),
label: item.label, label: item.label,
); );
}).toList(); }).toList();
@@ -367,18 +347,17 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
String label, { String label, {
required bool page, required bool page,
}) { }) {
final cupertino = widget.cupertino;
final onBack = spec?.onBack ?? (page ? _closePage : null); final onBack = spec?.onBack ?? (page ? _closePage : null);
final published = spec?.actions ?? const <Widget>[]; final published = spec?.actions ?? const <Widget>[];
final onSearch = widget.onSearch; final onSearch = widget.onSearch;
return SegmentedBar( return SegmentedBar(
cupertino: cupertino, cupertino: false,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
leading: onBack == null leading: onBack == null
? null ? null
: SegmentedBackButton( : SegmentedBackButton(
key: const ValueKey('shell.back'), key: const ValueKey('shell.back'),
cupertino: cupertino, cupertino: false,
onPressed: onBack, onPressed: onBack,
), ),
title: spec?.title ?? label, title: spec?.title ?? label,
@@ -401,22 +380,12 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
// A screen whose main pill is its own field (Search) needs no // A screen whose main pill is its own field (Search) needs no
// separate Search action. // separate Search action.
else if (onSearch != null && spec?.titleWidget == null && !page) else if (onSearch != null && spec?.titleWidget == null && !page)
cupertino IconButton(
? CupertinoButton( key: const ValueKey('shell.search'),
key: const ValueKey('shell.search'), onPressed: onSearch,
padding: EdgeInsets.zero, tooltip: 'Search',
onPressed: onSearch, icon: const Icon(Icons.search),
child: const Icon( ),
CupertinoIcons.search,
semanticLabel: 'Search',
),
)
: IconButton(
key: const ValueKey('shell.search'),
onPressed: onSearch,
tooltip: 'Search',
icon: const Icon(Icons.search),
),
...widget.barActions, ...widget.barActions,
], ],
); );
@@ -438,10 +407,9 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
/// split never remounts it. /// split never remounts it.
/// ///
/// It rebuilds itself when [listenable] (the focused destination's published /// It rebuilds itself when [listenable] (the focused destination's published
/// bar) changes; [initial] supplies the size and obstruction, which do not /// bar) changes; [initial] supplies the size, which does not depend on the
/// depend on the published contents. /// published contents.
class _ListPaneBar extends StatelessWidget class _ListPaneBar extends StatelessWidget implements PreferredSizeWidget {
implements ObstructingPreferredSizeWidget {
const _ListPaneBar({ const _ListPaneBar({
required this.listenable, required this.listenable,
required this.initial, required this.initial,
@@ -461,10 +429,6 @@ class _ListPaneBar extends StatelessWidget
@override @override
Size get preferredSize => initial.preferredSize; Size get preferredSize => initial.preferredSize;
@override
bool shouldFullyObstruct(BuildContext context) =>
initial.shouldFullyObstruct(context);
@override @override
Widget build(BuildContext context) => ListenableBuilder( Widget build(BuildContext context) => ListenableBuilder(
listenable: listenable, listenable: listenable,
+20 -67
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../features/attention/domain/attention_models.dart'; import '../features/attention/domain/attention_models.dart';
@@ -8,9 +7,8 @@ import '../ui/motion/motion.dart';
/// ///
/// The bell itself lives in the Runs heading, so without this the count would /// The bell itself lives in the Runs heading, so without this the count would
/// be visible only on that destination; the web mirrors it on the rail and /// be visible only on that destination; the web mirrors it on the rail and
/// dock tab. Material hosts use the framework [Badge]; Cupertino has no badge /// dock tab. Material hosts use the framework [Badge]. Zero draws the bare
/// control, so its tab bar and sidebar get the host's red count overlay. Zero /// icon, and a count labels the item exactly like the bell:
/// draws the bare icon, and a count labels the item exactly like the bell:
/// `Notifications, {n} needing attention`. /// `Notifications, {n} needing attention`.
class AttentionDestinationIcon extends StatelessWidget { class AttentionDestinationIcon extends StatelessWidget {
const AttentionDestinationIcon({ const AttentionDestinationIcon({
@@ -21,24 +19,25 @@ class AttentionDestinationIcon extends StatelessWidget {
}); });
final int count; final int count;
/// Retained for callers that still pass it; the icon is always the Material
/// [Badge] whether this is set or not.
final bool cupertino; final bool cupertino;
final Widget child; final Widget child;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final visible = count > 0; final visible = count > 0;
final Widget icon = cupertino final Widget icon = Badge(
? _CupertinoCountOverlay(count: count, visible: visible, child: child) label: visible
: Badge( ? MotionSwitcher(
label: visible scale: true,
? MotionSwitcher( child: Text('$count', key: ValueKey(count)),
scale: true, )
child: Text('$count', key: ValueKey(count)), : null,
) isLabelVisible: visible,
: null, child: child,
isLabelVisible: visible, );
child: child,
);
if (!visible) return icon; if (!visible) return icon;
// The number alone would read as a stray "3"; the item carries the bell's // The number alone would read as a stray "3"; the item carries the bell's
// full label instead. // full label instead.
@@ -49,51 +48,6 @@ class AttentionDestinationIcon extends StatelessWidget {
} }
} }
/// The iOS tab-badge idiom: a red stadium with the count over the icon's
/// trailing corner. Content-driven size; only the overlap offset is fixed.
class _CupertinoCountOverlay extends StatelessWidget {
const _CupertinoCountOverlay({
required this.count,
required this.visible,
required this.child,
});
final int count;
final bool visible;
final Widget child;
@override
Widget build(BuildContext context) {
if (!visible) return child;
final style = CupertinoTheme.of(
context,
).textTheme.tabLabelTextStyle.copyWith(color: CupertinoColors.white);
return Stack(
clipBehavior: Clip.none,
children: [
child,
PositionedDirectional(
top: -6,
end: -10,
child: DecoratedBox(
decoration: ShapeDecoration(
color: CupertinoColors.systemRed.resolveFrom(context),
shape: const StadiumBorder(),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
child: MotionSwitcher(
scale: true,
child: Text('$count', key: ValueKey(count), style: style),
),
),
),
),
],
);
}
}
/// A small count on a tab icon: blue for activity (runs in progress, unread /// A small count on a tab icon: blue for activity (runs in progress, unread
/// chats), so it reads apart from the red needs-you count. /// chats), so it reads apart from the red needs-you count.
class ActivityBadge extends StatelessWidget { class ActivityBadge extends StatelessWidget {
@@ -108,6 +62,9 @@ class ActivityBadge extends StatelessWidget {
final int count; final int count;
final String label; final String label;
/// Retained for callers that still pass it; the badge uses the Material
/// theme colours whether this is set or not.
final bool cupertino; final bool cupertino;
final bool bottom; final bool bottom;
final Widget child; final Widget child;
@@ -115,12 +72,8 @@ class ActivityBadge extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final visible = count > 0; final visible = count > 0;
final color = cupertino final color = Theme.of(context).colorScheme.primary;
? CupertinoColors.systemBlue.resolveFrom(context) final text = Theme.of(context).colorScheme.onPrimary;
: Theme.of(context).colorScheme.primary;
final text = cupertino
? CupertinoColors.white
: Theme.of(context).colorScheme.onPrimary;
final stack = Stack( final stack = Stack(
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
+5 -1
View File
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
enum AppDestination { pipelines, runs, chat, search, settings } enum AppDestination { pipelines, runs, chat, search, settings }
@@ -20,6 +20,10 @@ AppDestination shellTabFor(AppDestination destination) =>
? destination ? destination
: AppDestination.pipelines; : AppDestination.pipelines;
/// The label and icons for [value].
///
/// [cupertinoIcon] is retained in the record for callers that still read it;
/// the shell itself draws [icon] on its Material path.
({String label, IconData icon, IconData cupertinoIcon}) destinationDetails( ({String label, IconData icon, IconData cupertinoIcon}) destinationDetails(
AppDestination value, AppDestination value,
) => switch (value) { ) => switch (value) {
+3 -12
View File
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../ui/adaptive/host.dart';
import '../ui/adaptive/segmented_bar.dart'; import '../ui/adaptive/segmented_bar.dart';
import '../ui/motion/container_transform_route.dart'; import '../ui/motion/container_transform_route.dart';
import '../ui/motion/container_transform_source.dart'; import '../ui/motion/container_transform_source.dart';
@@ -93,17 +91,14 @@ PageRoute<void> detailPageRoute(
ContainerTransformLink? growFrom, ContainerTransformLink? growFrom,
}) { }) {
final page = DetailPane(destination: destination, builder: builder); final page = DetailPane(destination: destination, builder: builder);
final cupertino = usesCupertinoHost(context);
if (growFrom != null) { if (growFrom != null) {
return ContainerTransformPageRoute<void>( return ContainerTransformPageRoute<void>(
link: growFrom, link: growFrom,
cupertino: cupertino, cupertino: false,
builder: (_) => page, builder: (_) => page,
); );
} }
return cupertino return MaterialPageRoute<void>(builder: (_) => page);
? CupertinoPageRoute<void>(builder: (_) => page)
: MaterialPageRoute<void>(builder: (_) => page);
} }
/// An open item's own bar over its content: what the content publishes /// An open item's own bar over its content: what the content publishes
@@ -151,11 +146,10 @@ class _DetailPaneState extends State<DetailPane> {
// status-bar inset itself. The scaffold and the body's place in it stay // status-bar inset itself. The scaffold and the body's place in it stay
// the same either way, so switching never remounts the content. // the same either way, so switching never remounts the content.
final barless = spec?.barless ?? false; final barless = spec?.barless ?? false;
final cupertino = usesCupertinoHost(context);
final bar = barless final bar = barless
? null ? null
: SegmentedBar( : SegmentedBar(
cupertino: cupertino, cupertino: false,
automaticallyImplyLeading: widget.implyBack, automaticallyImplyLeading: widget.implyBack,
title: title, title: title,
subtitle: spec?.subtitle, subtitle: spec?.subtitle,
@@ -171,9 +165,6 @@ class _DetailPaneState extends State<DetailPane> {
// pads its lists by the bar's height (top) and by the system's or a // pads its lists by the bar's height (top) and by the system's or a
// floating tab bar's (bottom), floating its own tabs clear of them. // floating tab bar's (bottom), floating its own tabs clear of them.
final content = SafeArea(top: false, bottom: false, child: body); final content = SafeArea(top: false, bottom: false, child: body);
if (cupertino) {
return CupertinoPageScaffold(navigationBar: bar, child: content);
}
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
appBar: bar, appBar: bar,
+4 -5
View File
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../ui/adaptive/host.dart';
import '../ui/motion/surface_visibility.dart'; import '../ui/motion/surface_visibility.dart';
/// The open item's own navigator beside a list on a wide window. /// The open item's own navigator beside a list on a wide window.
@@ -43,9 +41,10 @@ class _DetailPaneNavigatorState extends State<DetailPaneNavigator> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Page<void> root = usesCupertinoHost(context) final Page<void> root = MaterialPage<void>(
? CupertinoPage<void>(key: _rootKey, child: widget.child) key: _rootKey,
: MaterialPage<void>(key: _rootKey, child: widget.child); child: widget.child,
);
// Only the shown tab's pane answers the system Back: a page left open in // Only the shown tab's pane answers the system Back: a page left open in
// another tab's pane stays there while Back acts on the current tab. The // another tab's pane stays there while Back acts on the current tab. The
// route asks every handler on it, so a hidden pane also ignores the call. // route asks every handler on it, so a hidden pane also ignores the call.
+2 -11
View File
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../ui/adaptive/host.dart';
import 'destination.dart'; import 'destination.dart';
/// The detail pane beside a list before anything is chosen: the /// The detail pane beside a list before anything is chosen: the
@@ -19,22 +17,15 @@ class EmptyDetailPane extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final details = destinationDetails(destination); final details = destinationDetails(destination);
final color = cupertino final color = Theme.of(context).colorScheme.onSurfaceVariant;
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
return Center( return Center(
child: Padding( child: Padding(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon( Icon(details.icon, size: 32, color: color),
cupertino ? details.cupertinoIcon : details.icon,
size: 32,
color: color,
),
const SizedBox(height: 12), const SizedBox(height: 12),
Text( Text(
message, message,
+1 -8
View File
@@ -1,9 +1,7 @@
import 'package:flutter/gestures.dart' show DragStartBehavior; import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import '../ui/adaptive/host.dart';
import '../ui/adaptive/resize_grip.dart'; import '../ui/adaptive/resize_grip.dart';
/// How wide the divider's invisible grab area is, centred on its line. /// How wide the divider's invisible grab area is, centred on its line.
@@ -17,12 +15,7 @@ class ListPaneDividerLine extends StatelessWidget {
const ListPaneDividerLine({super.key}); const ListPaneDividerLine({super.key});
@override @override
Widget build(BuildContext context) => usesCupertinoHost(context) Widget build(BuildContext context) => const VerticalDivider(width: 1);
? Container(
width: 1,
color: CupertinoColors.separator.resolveFrom(context),
)
: const VerticalDivider(width: 1);
} }
/// The grab area over [ListPaneDividerLine]: dragging it (mouse or touch) /// The grab area over [ListPaneDividerLine]: dragging it (mouse or touch)
+4 -34
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'destination.dart'; import 'destination.dart';
@@ -10,48 +9,19 @@ class ShellDestinationMenu extends StatelessWidget {
required this.current, required this.current,
required this.onSelected, required this.onSelected,
}); });
/// Retained for callers that still pass it; the menu is always the Material
/// popup whether this is set or not.
final bool cupertino; final bool cupertino;
final AppDestination current; final AppDestination current;
final ValueChanged<AppDestination> onSelected; final ValueChanged<AppDestination> onSelected;
Future<void> _choose(BuildContext context) async {
final value = await showCupertinoModalPopup<AppDestination>(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('Main navigation'),
actions: [
for (final destination in AppDestination.values)
CupertinoActionSheetAction(
isDefaultAction: destination == current,
onPressed: () => Navigator.pop(context, destination),
child: Text(destinationDetails(destination).label),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
if (value != null && context.mounted) onSelected(value);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final child = Column( final child = Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: const [Icon(Icons.apps), Text('Menu')],
Icon(cupertino ? CupertinoIcons.square_grid_2x2 : Icons.apps),
const Text('Menu'),
],
); );
if (cupertino) {
return Semantics(
button: true,
label: 'Main navigation',
child: CupertinoButton(onPressed: () => _choose(context), child: child),
);
}
return PopupMenuButton<AppDestination>( return PopupMenuButton<AppDestination>(
tooltip: 'Main navigation', tooltip: 'Main navigation',
onSelected: onSelected, onSelected: onSelected,
@@ -2,7 +2,6 @@ import 'dart:math' as math;
import 'dart:ui' show Tristate; import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/list_detail.dart'; import 'package:pipelines_app/shell/list_detail.dart';
@@ -18,266 +17,247 @@ import 'package:pipelines_app/ui/theme/app_theme.dart';
import '../features/pipelines/fixtures.dart'; import '../features/pipelines/fixtures.dart';
void main() { void main() {
for (final cupertino in [false, true]) { for (final brightness in Brightness.values) {
for (final brightness in Brightness.values) { for (final width in [640.0, 840.0, 1280.0]) {
for (final width in [640.0, 840.0, 1280.0]) { for (final scale in [1.0, 2.0]) {
for (final scale in [1.0, 2.0]) { testWidgets('shared body-priority panes and selected rows: '
testWidgets('shared body-priority panes and selected rows: $cupertino ' '$brightness at $width @${scale}x', (tester) async {
'$brightness at $width @${scale}x', (tester) async { SharedPreferences.setMockInitialValues({});
SharedPreferences.setMockInitialValues({}); tester.view.physicalSize = Size(width, 900);
tester.view.physicalSize = Size(width, 900); tester.view.devicePixelRatio = 1;
tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset);
addTearDown(tester.view.reset); tester.platformDispatcher.textScaleFactorTestValue = scale;
tester.platformDispatcher.textScaleFactorTestValue = scale; addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
addTearDown( final fixture = PipelineFixture();
tester.platformDispatcher.clearTextScaleFactorTestValue, final gateway = FakeGateway(
); (type, fields) => switch (type) {
final fixture = PipelineFixture(); 'list_pipelines' => pipelineListReply(fixture.summaries),
final gateway = FakeGateway( 'get_pipeline' => pipelineDetailReply(
(type, fields) => switch (type) { fixture.detailFor(
'list_pipelines' => pipelineListReply(fixture.summaries), fields['pipeline_id'] as int,
'get_pipeline' => pipelineDetailReply( fields['version'] as int,
fixture.detailFor( )!,
fields['pipeline_id'] as int, ),
fields['version'] as int, 'list_runs' => {
)!, 'runs': [
), for (final id in [1, 2])
'list_runs' => { {'id': id, 'title': 'Run item $id', 'status': 'succeeded'},
'runs': [ ],
for (final id in [1, 2]) },
{ 'get_run' => {
'id': id, 'run_detail': {
'title': 'Run item $id', 'id': fields['run_id'],
'status': 'succeeded', 'title': 'Run item ${fields['run_id']}',
}, 'status': 'succeeded',
], 'input': {'prompt': 'Recorded input'},
}, },
'get_run' => { },
'run_detail': { 'chat_sessions' => {
'id': fields['run_id'], 'chat_sessions': [
'title': 'Run item ${fields['run_id']}', {
'status': 'succeeded', 'id': 'a',
'input': {'prompt': 'Recorded input'}, 'title': 'Chat item a',
'backend': 'claude',
'model': 'claude-opus',
'mode': 'auto',
'mode_name': 'Auto',
}, },
}, {
'chat_sessions' => { 'id': 'b',
'chat_sessions': [ 'title': 'Chat item b',
{ 'backend': 'claude',
'id': 'a', 'model': 'claude-opus',
'title': 'Chat item a', 'mode': 'auto',
'backend': 'claude', 'mode_name': 'Auto',
'model': 'claude-opus', },
'mode': 'auto', ],
'mode_name': 'Auto',
},
{
'id': 'b',
'title': 'Chat item b',
'backend': 'claude',
'model': 'claude-opus',
'mode': 'auto',
'mode_name': 'Auto',
},
],
},
'chat_messages' => {
'chat_history': {'messages': []},
},
_ => {},
}, },
); 'chat_messages' => {
final shell = AdaptiveShell( 'chat_history': {'messages': []},
cupertino: cupertino,
destinationBodies: {
AppDestination.pipelines: (_) =>
PipelinesScreen(gateway: gateway, embedded: true),
AppDestination.runs: (_) => RunsScreen(gateway: gateway),
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
}, },
); _ => {},
await tester.pumpWidget( },
cupertino );
? CupertinoApp( final shell = AdaptiveShell(
theme: CupertinoThemeData(brightness: brightness), destinationBodies: {
home: shell, AppDestination.pipelines: (_) =>
) PipelinesScreen(gateway: gateway, embedded: true),
: MaterialApp( AppDestination.runs: (_) => RunsScreen(gateway: gateway),
theme: brightness == Brightness.dark AppDestination.chat: (_) => ChatScreen(gateway: gateway),
? appDarkTheme() },
: appLightTheme(), );
home: shell, await tester.pumpWidget(
), MaterialApp(
); theme: brightness == Brightness.dark
await tester.pumpAndSettle(); ? appDarkTheme()
final paneWidths = <double>[]; : appLightTheme(),
final bodyWidths = <double>[]; home: shell,
for (final destination in ['Pipelines', 'Runs', 'Chat']) { ),
if (destination != 'Pipelines') { );
await tester.tap( await tester.pumpAndSettle();
find.byKey( final paneWidths = <double>[];
ValueKey('shell.destination.${destination.toLowerCase()}'), final bodyWidths = <double>[];
), for (final destination in ['Pipelines', 'Runs', 'Chat']) {
); if (destination != 'Pipelines') {
await tester.pumpAndSettle(); await tester.tap(
expect( find.byKey(
tester.takeException(), ValueKey('shell.destination.${destination.toLowerCase()}'),
isNull,
reason: '$destination list',
);
}
final list = find.byKey(const ValueKey('list-detail-list'));
final detail = find.byKey(const ValueKey('list-detail-body'));
expect(list, findsOneWidget);
expect(detail, findsOneWidget);
final before = tester.getSize(list).width;
final bodyBefore = tester.getSize(detail).width;
paneWidths.add(before);
bodyWidths.add(bodyBefore);
expect(bodyBefore, greaterThanOrEqualTo(width * 0.5));
// 60% of the window, or more once the list reaches its cap.
expect(
bodyBefore,
lessThanOrEqualTo(
math.max(width * 0.6, width - 1 - kListPaneMaxWidth) + 0.5,
), ),
); );
expect(bodyBefore, greaterThan(before));
final rowKeys = switch (destination) {
'Pipelines' => ['pipeline-row-1', 'pipeline-row-2'],
'Runs' => ['run-row-1', 'run-row-2'],
_ => ['chat-row-a', 'chat-row-b'],
};
for (final key in rowKeys) {
final target = find.byKey(ValueKey(key));
// In a narrow Cupertino list the row center can be a star/menu
// control. Open the chat through its title, not a trailing action.
final opener = destination == 'Chat'
? find.descendant(
of: target,
matching: find.text('Chat item ${key.split('-').last}'),
)
: target;
await tester.ensureVisible(opener);
await tester.tap(opener);
await tester.pumpAndSettle();
expect(
tester.takeException(),
isNull,
reason: '$destination after opening $key',
);
expect(tester.getSize(list).width, closeTo(before, 0.01));
expect(tester.getSize(detail).width, closeTo(bodyBefore, 0.01));
expect(
tester
.state<NavigatorState>(find.byType(Navigator).first)
.canPop(),
isFalse,
);
for (final rowKey in rowKeys) {
final row = find.byKey(ValueKey(rowKey));
expect(
row,
findsOneWidget,
reason: 'the list must remain visible',
);
final selected = rowKey == key;
expect(
tester.getSemantics(row).flagsCollection.isSelected ==
Tristate.isTrue,
selected,
reason: '$destination: $rowKey after opening $key',
);
// Every list retains shared row semantics; features may supply their own fill.
final context = tester.element(row);
expect(tester.widget<AppListRow>(row).selected, selected);
final surface = find.descendant(
of: row,
matching: find.byKey(appListRowSurfaceKey),
);
expect(
cupertino
? tester.widget<ColoredBox>(surface).color
: tester.widget<Material>(surface).color,
selected
? tester.widget<AppListRow>(row).selectedFill ??
AppListRow.selectedColor(
context,
cupertino: cupertino,
)
: const Color(0x00000000),
);
}
}
if (destination == 'Chat') {
// Starring lives in the row's actions menu.
final menu = find.byKey(const Key('chat-actions-b'));
await tester.ensureVisible(menu);
await tester.tap(menu);
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(
gateway
.callsOf('chat_star')
.last
.fields['chat_query']['session_id'],
'b',
);
final actions = find.byKey(const Key('chat-actions-b'));
await tester.ensureVisible(actions);
await tester.tap(actions);
await tester.pumpAndSettle();
expect(find.text('Rename…'), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
}
// A phone still uses stock page navigation; returning to a wide
// window must keep the selected item without clearing its route.
tester.view.physicalSize = const Size(390, 900);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect( expect(
tester tester.takeException(),
.state<NavigatorState>(find.byType(Navigator).first) isNull,
.canPop(), reason: '$destination list',
isTrue,
reason: '$destination should push its selected item on a phone',
); );
expect( }
find.byKey(const ValueKey('list-detail-list')), final list = find.byKey(const ValueKey('list-detail-list'));
findsNothing, final detail = find.byKey(const ValueKey('list-detail-body'));
); expect(list, findsOneWidget);
tester.view.physicalSize = Size(width, 900); expect(detail, findsOneWidget);
final before = tester.getSize(list).width;
final bodyBefore = tester.getSize(detail).width;
paneWidths.add(before);
bodyWidths.add(bodyBefore);
expect(bodyBefore, greaterThanOrEqualTo(width * 0.5));
// 60% of the window, or more once the list reaches its cap.
expect(
bodyBefore,
lessThanOrEqualTo(
math.max(width * 0.6, width - 1 - kListPaneMaxWidth) + 0.5,
),
);
expect(bodyBefore, greaterThan(before));
final rowKeys = switch (destination) {
'Pipelines' => ['pipeline-row-1', 'pipeline-row-2'],
'Runs' => ['run-row-1', 'run-row-2'],
_ => ['chat-row-a', 'chat-row-b'],
};
for (final key in rowKeys) {
final target = find.byKey(ValueKey(key));
// The row center can be a star/menu control. Open the chat
// through its title, not a trailing action.
final opener = destination == 'Chat'
? find.descendant(
of: target,
matching: find.text('Chat item ${key.split('-').last}'),
)
: target;
await tester.ensureVisible(opener);
await tester.tap(opener);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(
tester.takeException(),
isNull,
reason: '$destination after opening $key',
);
expect(tester.getSize(list).width, closeTo(before, 0.01));
expect(tester.getSize(detail).width, closeTo(bodyBefore, 0.01));
expect( expect(
tester tester
.state<NavigatorState>(find.byType(Navigator).first) .state<NavigatorState>(find.byType(Navigator).first)
.canPop(), .canPop(),
isFalse, isFalse,
); );
expect(tester.getSize(list).width, closeTo(before, 0.01)); for (final rowKey in rowKeys) {
expect( final row = find.byKey(ValueKey(rowKey));
tester expect(
.getSemantics(find.byKey(ValueKey(rowKeys.last))) row,
.flagsCollection findsOneWidget,
.isSelected, reason: 'the list must remain visible',
Tristate.isTrue, );
); final selected = rowKey == key;
expect(
tester.getSemantics(row).flagsCollection.isSelected ==
Tristate.isTrue,
selected,
reason: '$destination: $rowKey after opening $key',
);
// Every list retains shared row semantics; features may supply their own fill.
final context = tester.element(row);
expect(tester.widget<AppListRow>(row).selected, selected);
final surface = find.descendant(
of: row,
matching: find.byKey(appListRowSurfaceKey),
);
expect(
tester.widget<Material>(surface).color,
selected
? tester.widget<AppListRow>(row).selectedFill ??
AppListRow.selectedColor(context, cupertino: false)
: const Color(0x00000000),
);
}
} }
if (destination == 'Chat') {
// Starring lives in the row's actions menu.
final menu = find.byKey(const Key('chat-actions-b'));
await tester.ensureVisible(menu);
await tester.tap(menu);
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(
gateway
.callsOf('chat_star')
.last
.fields['chat_query']['session_id'],
'b',
);
final actions = find.byKey(const Key('chat-actions-b'));
await tester.ensureVisible(actions);
await tester.tap(actions);
await tester.pumpAndSettle();
expect(find.text('Rename…'), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
}
// A phone still uses stock page navigation; returning to a wide
// window must keep the selected item without clearing its route.
tester.view.physicalSize = const Size(390, 900);
await tester.pumpAndSettle();
expect( expect(
paneWidths, tester
everyElement(closeTo(paneWidths.first, 0.01)), .state<NavigatorState>(find.byType(Navigator).first)
reason: 'Pipelines, Runs and Chat must use identical pane widths', .canPop(),
isTrue,
reason: '$destination should push its selected item on a phone',
); );
expect(tester.takeException(), isNull);
expect( expect(
bodyWidths, find.byKey(const ValueKey('list-detail-list')),
everyElement(closeTo(bodyWidths.first, 0.01)), findsNothing,
reason:
'Every destination must share the body-priority sizing policy',
); );
await tester.pumpWidget(const SizedBox.shrink()); tester.view.physicalSize = Size(width, 900);
}); await tester.pumpAndSettle();
} expect(
tester
.state<NavigatorState>(find.byType(Navigator).first)
.canPop(),
isFalse,
);
expect(tester.getSize(list).width, closeTo(before, 0.01));
expect(
tester
.getSemantics(find.byKey(ValueKey(rowKeys.last)))
.flagsCollection
.isSelected,
Tristate.isTrue,
);
}
expect(
paneWidths,
everyElement(closeTo(paneWidths.first, 0.01)),
reason: 'Pipelines, Runs and Chat must use identical pane widths',
);
expect(tester.takeException(), isNull);
expect(
bodyWidths,
everyElement(closeTo(bodyWidths.first, 0.01)),
reason:
'Every destination must share the body-priority sizing policy',
);
await tester.pumpWidget(const SizedBox.shrink());
});
} }
} }
} }
@@ -26,9 +26,8 @@ import 'search_wiring_test.dart'
void main() { void main() {
Future<PlatformRouteInformationProvider> openPhoneApp( Future<PlatformRouteInformationProvider> openPhoneApp(
WidgetTester tester, WidgetTester tester,
FakeChannel channel, { FakeChannel channel,
required bool cupertino, ) async {
}) async {
tester.view.physicalSize = const Size(390, 844); tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetPhysicalSize);
@@ -42,77 +41,65 @@ void main() {
channel: channel, channel: channel,
client: PipelinesClient(channelFactory: (_) => channel), client: PipelinesClient(channelFactory: (_) => channel),
provider: provider, provider: provider,
cupertino: cupertino,
); );
await replyRunList(tester, channel); await replyRunList(tester, channel);
return provider; return provider;
} }
for (final cupertino in [false, true]) { testWidgets('phone: an artifact hit opens that artifact in the '
final platform = cupertino ? 'Cupertino' : 'Material'; 'viewer, and Back shows it on the run Artifacts tab', (tester) async {
final channel = FakeChannel()..readyCompleter.complete();
final provider = await openPhoneApp(tester, channel);
testWidgets('$platform phone: an artifact hit opens that artifact in the ' await openArtifactHit(tester, channel);
'viewer, and Back shows it on the run Artifacts tab', (tester) async { expect(provider.value.uri.path, '/runs/7');
final channel = FakeChannel()..readyCompleter.complete(); await replyRunDetailFor(tester, channel, searchSelectionDetail());
final provider = await openPhoneApp( await tester.pumpAndSettle();
tester,
channel,
cupertino: cupertino,
);
await openArtifactHit(tester, channel); expect(find.byType(SearchScreen), findsNothing);
expect(provider.value.uri.path, '/runs/7'); final viewer = tester.widget<ArtifactViewerPage>(
await replyRunDetailFor(tester, channel, searchSelectionDetail()); find.byType(ArtifactViewerPage),
await tester.pumpAndSettle(); );
expect(viewer.selectedIdentity, contains('report.txt'));
expect(find.text('report.txt'), findsWidgets);
expect(find.byType(SearchScreen), findsNothing); await closeViewer(tester);
final viewer = tester.widget<ArtifactViewerPage>( expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt');
find.byType(ArtifactViewerPage),
);
expect(viewer.selectedIdentity, contains('report.txt'));
expect(find.text('report.txt'), findsWidgets);
await closeViewer(tester); await tester.pumpWidget(const SizedBox.shrink());
expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt'); await tester.pump();
});
await tester.pumpWidget(const SizedBox.shrink()); testWidgets('phone: an artifact the run no longer lists opens '
await tester.pump(); 'its Artifacts tab with a notice', (tester) async {
}); final channel = FakeChannel()..readyCompleter.complete();
await openPhoneApp(tester, channel);
testWidgets('$platform phone: an artifact the run no longer lists opens ' await openArtifactHit(tester, channel);
'its Artifacts tab with a notice', (tester) async { final detail = searchSelectionDetail();
final channel = FakeChannel()..readyCompleter.complete(); final steps = [
await openPhoneApp(tester, channel, cupertino: cupertino); for (final step in detail['steps'] as List)
Map<String, dynamic>.from(step as Map),
];
steps[1]['artifacts'] = <JsonMap>[
{
'name': 'other.txt',
'content_type': 'text/plain',
'size_bytes': 3,
'url': '/artifacts/7/2/other.txt',
},
];
await replyRunDetailFor(tester, channel, {...detail, 'steps': steps});
await tester.pumpAndSettle();
await openArtifactHit(tester, channel); expect(find.byType(ArtifactViewerPage), findsNothing);
final detail = searchSelectionDetail(); expect(
final steps = [ find.byKey(const ValueKey('run-detail-artifacts-7')),
for (final step in detail['steps'] as List) findsOneWidget,
Map<String, dynamic>.from(step as Map), );
]; expect(find.text('That artifact is no longer available.'), findsOneWidget);
steps[1]['artifacts'] = <JsonMap>[
{
'name': 'other.txt',
'content_type': 'text/plain',
'size_bytes': 3,
'url': '/artifacts/7/2/other.txt',
},
];
await replyRunDetailFor(tester, channel, {...detail, 'steps': steps});
await tester.pumpAndSettle();
expect(find.byType(ArtifactViewerPage), findsNothing); await tester.pumpWidget(const SizedBox.shrink());
expect( await tester.pump();
find.byKey(const ValueKey('run-detail-artifacts-7')), });
findsOneWidget,
);
expect(
find.text('That artifact is no longer available.'),
findsOneWidget,
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
} }
+84 -91
View File
@@ -30,102 +30,95 @@ Map<String, dynamic> _results(String kind, List<Map<String, dynamic>> hits) => {
/// chat search the app sends after it, then a tap on the chat hit opens that /// chat search the app sends after it, then a tap on the chat hit opens that
/// chat in the Chat tab with its session selected. /// chat in the Chat tab with its session selected.
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('a chat hit opens its chat in the Chat tab', (tester) async {
testWidgets('${cupertino ? 'Cupertino' : 'Material'}: a chat hit opens ' tester.view.physicalSize = const Size(900, 1000);
'its chat in the Chat tab', (tester) async { tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(900, 1000); addTearDown(tester.view.resetPhysicalSize);
tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.view.resetPhysicalSize); final channel = FakeChannel()..readyCompleter.complete();
addTearDown(tester.view.resetDevicePixelRatio); final provider = PlatformRouteInformationProvider(
final channel = FakeChannel()..readyCompleter.complete(); initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
final provider = PlatformRouteInformationProvider( );
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')), addTearDown(provider.dispose);
); await pumpApp(
addTearDown(provider.dispose); tester,
await pumpApp( channel: channel,
tester, client: PipelinesClient(channelFactory: (_) => channel),
channel: channel, provider: provider,
client: PipelinesClient(channelFactory: (_) => channel), );
provider: provider, await replyRunList(tester, channel);
cupertino: cupertino,
);
await replyRunList(tester, channel);
await tapTab(tester, 'Search'); await tapTab(tester, 'Search');
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 600)); await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
await tester.enterText( await tester.enterText(find.byKey(const ValueKey('search.field')), 'flaky');
find.byKey(const ValueKey('search.field')), await tester.pump(const Duration(milliseconds: 300));
'flaky',
);
await tester.pump(const Duration(milliseconds: 300));
final runs = await waitForSearch(tester, channel); final runs = await waitForSearch(tester, channel);
channel.incoming.add(jsonEncode({'id': runs['id'], ..._results('', [])})); channel.incoming.add(jsonEncode({'id': runs['id'], ..._results('', [])}));
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
final chats = await waitForSearch(tester, channel, chats: true); final chats = await waitForSearch(tester, channel, chats: true);
expect(chats['search'], {'query': 'flaky', 'kind': 'chat', 'limit': 0}); expect(chats['search'], {'query': 'flaky', 'kind': 'chat', 'limit': 0});
channel.incoming.add( channel.incoming.add(
jsonEncode({ jsonEncode({
'id': chats['id'], 'id': chats['id'],
..._results('chat', [ ..._results('chat', [
{ {
'kind': 'chat', 'kind': 'chat',
'target': 'chat:$_session', 'target': 'chat:$_session',
'score': 1, 'score': 1,
'matched_field': 'message', 'matched_field': 'message',
'chat': { 'chat': {
'session_id': _session, 'session_id': _session,
'title': 'Fix CI',
'directory': '/work/api',
'backend': 'claude',
'message_id': 'm2',
'snippet': 'the flaky retry loop',
},
},
]),
}),
);
await tester.pump();
await tester.pump();
expect(find.text('Chats (1)'), findsOneWidget);
expect(find.textContaining('the flaky retry loop'), findsOneWidget);
await tester.tap(
find.byKey(const ValueKey('search.result.chat:$_session')),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400));
expect(provider.value.uri.path, '/chat/$_session');
expect(find.byType(SearchScreen), findsNothing);
final screen = tester.widget<ChatScreen>(find.byType(ChatScreen));
expect(screen.initialSessionId, _session);
await reply(
tester,
channel,
'chat_sessions',
body: {
'type': 'chat_sessions',
'chat_sessions': [
{
'id': _session,
'title': 'Fix CI', 'title': 'Fix CI',
'directory': '/work/api', 'directory': '/work/api',
'backend': 'claude', 'backend': 'claude',
'message_id': 'm2',
'snippet': 'the flaky retry loop',
}, },
], },
}, ]),
); }),
await tester.pump(const Duration(milliseconds: 400)); );
expect(find.text('Fix CI'), findsWidgets); await tester.pump();
await tester.pump();
expect(find.text('Chats (1)'), findsOneWidget);
expect(find.textContaining('the flaky retry loop'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink()); await tester.tap(
await tester.pump(); find.byKey(const ValueKey('search.result.chat:$_session')),
}); );
} await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400));
expect(provider.value.uri.path, '/chat/$_session');
expect(find.byType(SearchScreen), findsNothing);
final screen = tester.widget<ChatScreen>(find.byType(ChatScreen));
expect(screen.initialSessionId, _session);
await reply(
tester,
channel,
'chat_sessions',
body: {
'type': 'chat_sessions',
'chat_sessions': [
{
'id': _session,
'title': 'Fix CI',
'directory': '/work/api',
'backend': 'claude',
},
],
},
);
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Fix CI'), findsWidgets);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
} }
+5 -99
View File
@@ -332,14 +332,12 @@ Future<void> pumpApp(
required FakeChannel channel, required FakeChannel channel,
required PipelinesClient client, required PipelinesClient client,
required PlatformRouteInformationProvider provider, required PlatformRouteInformationProvider provider,
required bool cupertino,
}) async { }) async {
await tester.pumpWidget( await tester.pumpWidget(
PipelinesApp( PipelinesApp(
androidSupported: false, androidSupported: false,
server: webServer(), server: webServer(),
client: client, client: client,
cupertino: cupertino,
routeInformationProvider: provider, routeInformationProvider: provider,
), ),
); );
@@ -373,7 +371,6 @@ void main() {
channel: channel, channel: channel,
client: client, client: client,
provider: provider, provider: provider,
cupertino: false,
); );
await replyRunList(tester, channel); await replyRunList(tester, channel);
await replyRunDetail(tester, channel, 2); await replyRunDetail(tester, channel, 2);
@@ -439,13 +436,7 @@ void main() {
); );
addTearDown(provider.dispose); addTearDown(provider.dispose);
await pumpApp( await pumpApp(tester, channel: channel, client: client, provider: provider);
tester,
channel: channel,
client: client,
provider: provider,
cupertino: false,
);
await replyRunList(tester, channel); await replyRunList(tester, channel);
await replyRunDetail(tester, channel, 2); await replyRunDetail(tester, channel, 2);
@@ -519,13 +510,7 @@ void main() {
); );
addTearDown(provider.dispose); addTearDown(provider.dispose);
await pumpApp( await pumpApp(tester, channel: channel, client: client, provider: provider);
tester,
channel: channel,
client: client,
provider: provider,
cupertino: false,
);
await replyRunList(tester, channel); await replyRunList(tester, channel);
await replyRunDetailFor(tester, channel, searchSelectionDetail()); await replyRunDetailFor(tester, channel, searchSelectionDetail());
expect(find.text('Run 7'), findsWidgets); expect(find.text('Run 7'), findsWidgets);
@@ -631,13 +616,7 @@ void main() {
); );
addTearDown(provider.dispose); addTearDown(provider.dispose);
await pumpApp( await pumpApp(tester, channel: channel, client: client, provider: provider);
tester,
channel: channel,
client: client,
provider: provider,
cupertino: false,
);
await replyRunList(tester, channel); await replyRunList(tester, channel);
await tapTab(tester, 'Search'); await tapTab(tester, 'Search');
@@ -706,13 +685,7 @@ void main() {
); );
addTearDown(provider.dispose); addTearDown(provider.dispose);
await pumpApp( await pumpApp(tester, channel: channel, client: client, provider: provider);
tester,
channel: channel,
client: client,
provider: provider,
cupertino: false,
);
await replyRun7List(tester, channel); await replyRun7List(tester, channel);
// The hit navigates to run 7, but its detail is never loaded: the operator // The hit navigates to run 7, but its detail is never loaded: the operator
@@ -763,13 +736,7 @@ void main() {
); );
addTearDown(provider.dispose); addTearDown(provider.dispose);
await pumpApp( await pumpApp(tester, channel: channel, client: client, provider: provider);
tester,
channel: channel,
client: client,
provider: provider,
cupertino: false,
);
await replyRun7List(tester, channel); await replyRun7List(tester, channel);
await openArtifactHit(tester, channel); await openArtifactHit(tester, channel);
@@ -801,67 +768,6 @@ void main() {
await tester.pump(); await tester.pump();
}); });
testWidgets('Cupertino Search is a native tab', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
final channel = FakeChannel()..readyCompleter.complete();
var sockets = 0;
final client = PipelinesClient(
channelFactory: (_) {
sockets++;
return channel;
},
);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
);
addTearDown(provider.dispose);
await pumpApp(
tester,
channel: channel,
client: client,
provider: provider,
cupertino: true,
);
await replyRunList(tester, channel);
expect(find.text('Preserved run'), findsWidgets);
await tapTab(tester, 'Search');
await tester.pump();
await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100));
expect(provider.value.uri.path, '/search');
expect(find.byKey(const ValueKey('search.field')), findsOneWidget);
expect(find.byType(Material), findsNothing);
final cupertinoField = tester.widget<EditableText>(
find.descendant(
of: find.byKey(const ValueKey('search.field')),
matching: find.byType(EditableText),
),
);
expect(cupertinoField.focusNode.hasFocus, isTrue);
await tapTab(tester, 'Runs');
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400));
expect(provider.value.uri.path, '/runs');
expect(find.byKey(const ValueKey('search.field')), findsNothing);
expect(find.text('Preserved run'), findsWidgets);
expect(sockets, 1);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
test( test(
'the hit helper never guesses a route for pipeline or malformed hits', 'the hit helper never guesses a route for pipeline or malformed hits',
() { () {
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/destination.dart';
@@ -9,114 +7,88 @@ import 'package:pipelines_app/shell/list_detail.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
void main() { void main() {
for (final cupertino in [false, true]) { for (final scale in [1.0, 2.0]) {
for (final scale in [1.0, 2.0]) { testWidgets('chat list stays above labeled navigation ($scale)', (
testWidgets( tester,
'chat list stays above labeled navigation ($cupertino, $scale)', ) async {
(tester) async { tester.view.physicalSize = const Size(1200, 900);
tester.view.physicalSize = const Size(1200, 900); tester.view.devicePixelRatio = 1;
tester.view.devicePixelRatio = 1; tester.platformDispatcher.textScaleFactorTestValue = scale;
tester.platformDispatcher.textScaleFactorTestValue = scale; addTearDown(tester.view.reset);
addTearDown(tester.view.reset); addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); String? opened;
String? opened; final sessions = [
final sessions = [ for (var i = 0; i < 14; i++)
for (var i = 0; i < 14; i++) {
{ 'id': 's$i',
'id': 's$i', 'title': 'Chat item $i',
'title': 'Chat item $i', 'model': 'model',
'model': 'model', 'directory': '/work/project-$i',
'directory': '/work/project-$i', },
}, ];
]; Widget list() => MaterialSessionList(
Widget list() => cupertino sections: [(title: 'Chats', sessions: sessions)],
? CupertinoSessionList( emptyMessage: null,
sections: [(title: 'Chats', sessions: sessions)], duplicateTitles: const {},
emptyMessage: null, onOpen: (row) => opened = row['id'] as String,
duplicateTitles: const {}, onRename: (_) {},
onOpen: (row) => opened = row['id'] as String, onClose: (_) {},
onRename: (_) {}, onReopen: (_) {},
onClose: (_) {}, onStar: (_) {},
onReopen: (_) {}, onHide: (_) {},
onStar: (_) {}, onClearSearch: null,
onHide: (_) {}, isUnseen: (_) => false,
onClearSearch: null, errorFor: (_) => null,
isUnseen: (_) => false, );
errorFor: (_) => null, final shell = AdaptiveShell(
) destination: AppDestination.chat,
: MaterialSessionList( destinationBodies: {
sections: [(title: 'Chats', sessions: sessions)], AppDestination.chat: (_) =>
emptyMessage: null, ListDetailPanes(list: list(), detail: const SizedBox.expand()),
duplicateTitles: const {},
onOpen: (row) => opened = row['id'] as String,
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: (_) {},
onHide: (_) {},
onClearSearch: null,
isUnseen: (_) => false,
errorFor: (_) => null,
);
final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ListDetailPanes(
list: list(),
detail: const SizedBox.expand(),
),
},
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
);
await tester.pumpAndSettle();
final navigation = tester.getRect(
find.byKey(FloatingDestinationBar.rowKey),
);
final scrollView = find.byType(CustomScrollView);
final viewport = tester.getRect(scrollView);
expect(viewport.bottom, lessThanOrEqualTo(navigation.top + .5));
expect(viewport.width, greaterThan(0));
final scrollable = tester.state<ScrollableState>(
find.descendant(of: scrollView, matching: find.byType(Scrollable)),
);
scrollable.position.jumpTo(scrollable.position.maxScrollExtent);
await tester.pumpAndSettle();
final last = find.byKey(const Key('chat-row-s13'));
expect(
tester.getRect(last).bottom,
lessThanOrEqualTo(navigation.top + .5),
);
final metadata = find.descendant(
of: last,
matching: find.text('model · /work/project-13'),
);
expect(metadata, findsOneWidget);
expect(
tester.getRect(metadata).bottom,
lessThanOrEqualTo(navigation.top + .5),
);
await tester.tap(find.text('Chat item 13'));
await tester.pump();
expect(opened, 's13');
final retainedOffset = scrollable.position.pixels;
tester.view.physicalSize = const Size(1440, 900);
await tester.pumpAndSettle();
expect(
tester.state<ScrollableState>(
find.descendant(
of: scrollView,
matching: find.byType(Scrollable),
),
),
same(scrollable),
);
expect(scrollable.position.pixels, closeTo(retainedOffset, .5));
expect(tester.takeException(), isNull);
}, },
); );
} await tester.pumpWidget(MaterialApp(home: shell));
await tester.pumpAndSettle();
final navigation = tester.getRect(
find.byKey(FloatingDestinationBar.rowKey),
);
final scrollView = find.byType(CustomScrollView);
final viewport = tester.getRect(scrollView);
expect(viewport.bottom, lessThanOrEqualTo(navigation.top + .5));
expect(viewport.width, greaterThan(0));
final scrollable = tester.state<ScrollableState>(
find.descendant(of: scrollView, matching: find.byType(Scrollable)),
);
scrollable.position.jumpTo(scrollable.position.maxScrollExtent);
await tester.pumpAndSettle();
final last = find.byKey(const Key('chat-row-s13'));
expect(
tester.getRect(last).bottom,
lessThanOrEqualTo(navigation.top + .5),
);
final metadata = find.descendant(
of: last,
matching: find.text('model · /work/project-13'),
);
expect(metadata, findsOneWidget);
expect(
tester.getRect(metadata).bottom,
lessThanOrEqualTo(navigation.top + .5),
);
await tester.tap(find.text('Chat item 13'));
await tester.pump();
expect(opened, 's13');
final retainedOffset = scrollable.position.pixels;
tester.view.physicalSize = const Size(1440, 900);
await tester.pumpAndSettle();
expect(
tester.state<ScrollableState>(
find.descendant(of: scrollView, matching: find.byType(Scrollable)),
),
same(scrollable),
);
expect(scrollable.position.pixels, closeTo(retainedOffset, .5));
expect(tester.takeException(), isNull);
});
} }
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart' import 'package:pipelines_app/core/transport/pipelines_client.dart'
@@ -9,22 +8,18 @@ import 'package:pipelines_app/features/settings/settings_store.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
import 'fake_channel.dart'; import 'fake_channel.dart';
/// Settings as the shell's tab: the page runs behind the shell's bar, and on /// Settings as the shell's tab: the page runs behind the shell's bar.
/// Cupertino the grouped background reaches the top edge with the bar's
/// scrim in the same colour, so no white band or seam shows under the bar.
void main() { void main() {
Future<void> pump(WidgetTester tester, {required bool cupertino}) async { Future<void> pump(WidgetTester tester) async {
await tester.binding.setSurfaceSize(const Size(560, 1000)); await tester.binding.setSurfaceSize(const Size(560, 1000));
addTearDown(() => tester.binding.setSurfaceSize(null)); addTearDown(() => tester.binding.setSurfaceSize(null));
final factory = FakeChannelFactory(); final factory = FakeChannelFactory();
final client = transport.PipelinesClient(channelFactory: factory.call); final client = transport.PipelinesClient(channelFactory: factory.call);
addTearDown(client.dispose); addTearDown(client.dispose);
final shell = AdaptiveShell( final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.settings, destination: AppDestination.settings,
destinationBodies: { destinationBodies: {
AppDestination.settings: (_) => SettingsScreen( AppDestination.settings: (_) => SettingsScreen(
@@ -34,9 +29,7 @@ void main() {
), ),
}, },
); );
await tester.pumpWidget( await tester.pumpWidget(MaterialApp(home: shell));
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
);
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
} }
@@ -52,34 +45,8 @@ void main() {
) )
.color; .color;
testWidgets('Cupertino: the grouped background runs under the bar', ( testWidgets('the bar keeps the shell page background', (tester) async {
tester, await pump(tester);
) async {
await pump(tester, cupertino: true);
final grouped = AppColors.groupedBackground.color.toARGB32();
expect(scrimOf(tester).toARGB32(), grouped);
// The page's background starts at the top edge, behind the bar.
final page = find.ancestor(
of: find.byKey(const ValueKey<String>('settings.scroll')),
matching: find.byWidgetPredicate(
(widget) => widget is ColoredBox && widget.color.toARGB32() == grouped,
),
);
expect(page, findsWidgets);
expect(tester.getTopLeft(page.last).dy, 0);
// The groups start below the bar and persistent category selector.
final bar = tester.getRect(find.byType(SegmentedBar));
expect(
tester.getTopLeft(find.byType(SettingsGroup).first).dy,
greaterThanOrEqualTo(bar.bottom - 8),
);
});
testWidgets('Material: the bar keeps the shell page background', (
tester,
) async {
await pump(tester, cupertino: false);
final context = tester.element(find.byType(SettingsGroup).first); final context = tester.element(find.byType(SettingsGroup).first);
expect( expect(
+10 -41
View File
@@ -1,13 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.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 Runs tab mirrors the attention count in every mount: the floating tab
/// the floating tab bar at full width on a phone and right-aligned on a wide /// bar at full width on a phone and right-aligned on a wide window. Zero draws
/// window. Zero draws the /// the bare icon with no count and no attention semantics.
/// bare icon with no count and no attention semantics.
void main() { void main() {
final needingAttention = RegExp('Notifications, 3 needing attention'); final needingAttention = RegExp('Notifications, 3 needing attention');
final anyAttention = RegExp('needing attention'); final anyAttention = RegExp('needing attention');
@@ -15,27 +13,22 @@ void main() {
Future<void> pumpShell( Future<void> pumpShell(
WidgetTester tester, { WidgetTester tester, {
required double width, required double width,
required bool cupertino,
required int count, required int count,
}) async { }) async {
tester.view.physicalSize = Size(width, 900); tester.view.physicalSize = Size(width, 900);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio); addTearDown(tester.view.resetDevicePixelRatio);
final shell = AdaptiveShell(cupertino: cupertino, attentionCount: count); final shell = AdaptiveShell(attentionCount: count);
await tester.pumpWidget( await tester.pumpWidget(MaterialApp(home: shell));
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
);
} }
for (final width in [390.0, 1000.0]) { for (final width in [390.0, 1000.0]) {
final mount = width < 600 ? 'bottom bar' : 'wide bar'; final mount = width < 600 ? 'bottom bar' : 'wide bar';
testWidgets('Material $mount shows the count on the Runs tab', ( testWidgets('$mount shows the count on the Runs tab', (tester) async {
tester,
) async {
final semantics = tester.ensureSemantics(); 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(FloatingDestinationBar), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing); expect(find.byType(NavigationRail), findsNothing);
final badge = find.byType(Badge); final badge = find.byType(Badge);
@@ -49,9 +42,9 @@ void main() {
semantics.dispose(); 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(); 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); final badge = find.byType(Badge);
expect(badge, findsOneWidget); expect(badge, findsOneWidget);
expect(tester.widget<Badge>(badge).isLabelVisible, isFalse); 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 { 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']) { for (final name in ['runs', 'chat', 'search']) {
await tester.tap(find.byKey(ValueKey('shell.destination.$name'))); await tester.tap(find.byKey(ValueKey('shell.destination.$name')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
+62 -79
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.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'; import 'package:pipelines_app/shell/destination.dart';
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('Ctrl+Tab and Ctrl+Shift+Tab leave destinations unchanged', (
final host = cupertino ? 'Cupertino' : 'Material'; tester,
) async {
testWidgets( final app = AdaptiveShell(
'$host Ctrl+Tab and Ctrl+Shift+Tab leave destinations unchanged', destinationBodies: {
(tester) async { for (final destination in shellTabDestinations)
final app = AdaptiveShell( destination: (_) => Focus(
cupertino: cupertino, autofocus: destination == AppDestination.pipelines,
destinationBodies: { child: Text(destination.name),
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);
}, },
); );
await tester.pumpWidget(MaterialApp(home: app));
testWidgets( Future<void> press({required bool shift}) async {
'$host plain Tab traverses and Ctrl+Tab does not change destinations', await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
(tester) async { if (shift) {
final first = FocusNode(); await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
final second = FocusNode(); }
addTearDown(first.dispose); await tester.sendKeyEvent(LogicalKeyboardKey.tab);
addTearDown(second.dispose); if (shift) {
final app = AdaptiveShell( await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
cupertino: cupertino, }
destinationBodies: { await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
AppDestination.pipelines: (_) => Column( await tester.pump();
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();
// Plain Tab retains normal traversal semantics and does not select a tab. expect(find.text('pipelines'), findsOneWidget);
await tester.sendKeyEvent(LogicalKeyboardKey.tab); await press(shift: true);
await tester.pump(); expect(find.text('pipelines'), findsOneWidget);
expect(second.hasFocus, isTrue); await press(shift: false);
expect(find.text('pipelines'), findsOneWidget);
});
first.requestFocus(); testWidgets('plain Tab traverses and Ctrl+Tab does not change destinations', (
await tester.pump(); tester,
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft); ) async {
await tester.sendKeyEvent(LogicalKeyboardKey.tab); final first = FocusNode();
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft); final second = FocusNode();
await tester.pump(); addTearDown(first.dispose);
expect(find.text('runs'), findsNothing); 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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.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 /// page) closes when another item is selected, so the pane shows the newly
/// selected item instead of the old item's page. /// selected item instead of the old item's page.
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets("selecting another item closes the previous item's page", (
testWidgets('selecting another item closes the previous item\'s page ' tester,
'(${cupertino ? 'cupertino' : 'material'})', (tester) async { ) async {
tester.view.physicalSize = const Size(1200, 800); tester.view.physicalSize = const Size(1200, 800);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset); addTearDown(tester.view.reset);
final selected = ValueNotifier<int>(1); final selected = ValueNotifier<int>(1);
addTearDown(selected.dispose); addTearDown(selected.dispose);
Widget detail(int id) => Builder( Widget detail(int id) => Builder(
builder: (context) => Center( builder: (context) => Center(
child: GestureDetector( child: GestureDetector(
key: const Key('open-page'), key: const Key('open-page'),
onTap: () => Navigator.of(context).push( onTap: () => Navigator.of(context).push(
PageRouteBuilder<void>( PageRouteBuilder<void>(
pageBuilder: (_, _, _) => Text('page of item $id'), 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( await tester.tap(find.byKey(const Key('open-page')));
cupertino: cupertino, await tester.pumpAndSettle();
destination: AppDestination.runs, expect(find.text('page of item 1'), findsOneWidget);
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'))); // The same item rebuilt keeps its page open.
await tester.pumpAndSettle(); selected.value = 1;
expect(find.text('page of item 1'), findsOneWidget); await tester.pumpAndSettle();
expect(find.text('page of item 1'), findsOneWidget);
// The same item rebuilt keeps its page open. selected.value = 2;
selected.value = 1; await tester.pumpAndSettle();
await tester.pumpAndSettle(); expect(find.text('page of item 1'), findsNothing);
expect(find.text('page of item 1'), findsOneWidget); 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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/empty_detail_pane.dart'; import 'package:pipelines_app/shell/empty_detail_pane.dart';
/// One placeholder for an empty detail pane: the destination's icon above a /// 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() { void main() {
for (final cupertino in [false, true]) { for (final destination in [
final host = cupertino ? 'Cupertino' : 'Material'; AppDestination.runs,
for (final destination in [ AppDestination.chat,
AppDestination.runs, AppDestination.pipelines,
AppDestination.chat, ]) {
AppDestination.pipelines, testWidgets('${destination.name}: icon over a muted line', (tester) async {
]) { final content = EmptyDetailPane(
testWidgets('$host ${destination.name}: icon over a muted line', ( destination: destination,
tester, message: 'Select one to open it here.',
) async { );
final content = EmptyDetailPane( await tester.pumpWidget(MaterialApp(home: Scaffold(body: content)));
destination: destination, final icon = find.byIcon(destinationDetails(destination).icon);
message: 'Select one to open it here.', expect(icon, findsOneWidget);
); final text = find.text('Select one to open it here.');
await tester.pumpWidget( expect(
cupertino tester.getTopLeft(text).dy,
? CupertinoApp(home: CupertinoPageScaffold(child: content)) greaterThan(tester.getRect(icon).bottom),
: MaterialApp(home: Scaffold(body: content)), );
); // Centred in the pane.
final details = destinationDetails(destination); final size = tester.view.physicalSize / tester.view.devicePixelRatio;
final icon = find.byIcon( expect(tester.getCenter(text).dx, closeTo(size.width / 2, 1));
cupertino ? details.cupertinoIcon : details.icon, // Muted: the same secondary colour on the icon and the line.
); final context = tester.element(text);
expect(icon, findsOneWidget); final muted = Theme.of(context).colorScheme.onSurfaceVariant;
final text = find.text('Select one to open it here.'); expect(tester.widget<Icon>(icon).color, muted);
expect( expect(tester.widget<Text>(text).style?.color, muted);
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);
});
}
} }
} }
+141 -171
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/list_detail_policy.dart'; import 'package:pipelines_app/shell/list_detail_policy.dart';
@@ -67,9 +66,8 @@ void main() {
var taps = 0; var taps = 0;
double? contentBottomPadding; double? contentBottomPadding;
Widget shell({required bool cupertino}) { Widget shell() {
final app = AdaptiveShell( final app = AdaptiveShell(
cupertino: cupertino,
destinationBodies: { destinationBodies: {
AppDestination.pipelines: (_) => Builder( AppDestination.pipelines: (_) => Builder(
builder: (context) { 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]) { testWidgets('phone bar hugs its tabs at the bottom right too, and '
final host = cupertino ? 'Cupertino' : 'Material'; '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 ' testWidgets('wide leading bar under the list, content '
'taps beside it reach the content', (tester) async { 'keeps the width and taps beside the bar reach it', (tester) async {
taps = 0; 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 {
await setSize(tester, const Size(1200, 800)); 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( expect(
find.descendant( rect.width,
of: find.byType(FloatingDestinationBar), lessThanOrEqualTo(listDetailListWidth(1200, 1200, null) - 2 * 16),
matching: find.byWidgetPredicate(
(widget) =>
widget is Material ||
widget is NavigationBar ||
widget is InkWell,
),
),
findsNothing,
); );
// 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 { 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));
await setSize(tester, const Size(320, 568)); tester.platformDispatcher.textScaleFactorTestValue = 2;
tester.platformDispatcher.textScaleFactorTestValue = 2; addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); await tester.pumpWidget(shell());
await tester.pumpWidget(shell(cupertino: cupertino)); await tester.pumpAndSettle();
await tester.pumpAndSettle(); expect(tester.takeException(), isNull);
expect(tester.takeException(), isNull); // Large captions wrap rather than shrinking the tap targets.
// Large captions wrap rather than shrinking the tap targets. final bounds = tester.getRect(pill());
final bounds = tester.getRect(pill()); await expectLabeledTargets(tester, bounds);
await expectLabeledTargets(tester, bounds); expect(bounds.width, lessThanOrEqualTo(320 - 2 * 16));
expect(bounds.width, lessThanOrEqualTo(320 - 2 * 16)); for (final destination in shellTabDestinations) {
for (final destination in shellTabDestinations) { final caption = find.descendant(
final caption = find.descendant( of: find.byType(FloatingDestinationBar),
of: find.byType(FloatingDestinationBar), matching: find.text(destinationDetails(destination).label),
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),
),
); );
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 'dart:ui' show SemanticsAction;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -27,12 +26,10 @@ void main() {
); );
Widget shell({ Widget shell({
required bool cupertino,
required ListPaneWidthStore store, required ListPaneWidthStore store,
AppDestination destination = AppDestination.runs, AppDestination destination = AppDestination.runs,
}) { }) {
final app = AdaptiveShell( final app = AdaptiveShell(
cupertino: cupertino,
destination: destination, destination: destination,
listPaneWidthStore: store, listPaneWidthStore: store,
destinationBodies: { destinationBodies: {
@@ -40,7 +37,7 @@ void main() {
AppDestination.chat: (_) => panes('chat'), AppDestination.chat: (_) => panes('chat'),
}, },
); );
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app); return MaterialApp(home: app);
} }
Future<void> settle(WidgetTester tester) async { Future<void> settle(WidgetTester tester) async {
@@ -66,172 +63,158 @@ void main() {
.width; .width;
final divider = find.byKey(const ValueKey('list-detail-divider')); final divider = find.byKey(const ValueKey('list-detail-divider'));
for (final cupertino in [false, true]) { testWidgets('dragging resizes the list live, the shell bar '
final host = cupertino ? 'Cupertino' : 'Material'; '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 ' final gesture = await tester.startGesture(tester.getCenter(divider));
'follows, and the width clamps', (tester) async { await gesture.moveBy(const Offset(-50, 0));
await setSize(tester, const Size(1200, 800)); await gesture.moveBy(const Offset(-50, 0));
final store = MemoryListPaneWidthStore(); await tester.pump();
await tester.pumpWidget(shell(cupertino: cupertino, store: store)); // Live, before the drag ends; nothing saved yet.
await settle(tester); expect(listWidth(tester), closeTo(340, 0.5));
expect(listWidth(tester), kListPaneMaxWidth); expect(shellBarWidth(tester), closeTo(340, 0.5));
expect(shellBarWidth(tester), kListPaneMaxWidth); 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)); // Never narrower than the minimum...
await gesture.moveBy(const Offset(-50, 0)); await tester.drag(divider, const Offset(-400, 0));
await gesture.moveBy(const Offset(-50, 0)); await settle(tester);
await tester.pump(); expect(listWidth(tester), kListPaneMinWidth);
// Live, before the drag ends; nothing saved yet. // ...nor wider than leaves the open item half the window.
expect(listWidth(tester), closeTo(340, 0.5)); await tester.drag(divider, const Offset(900, 0));
expect(shellBarWidth(tester), closeTo(340, 0.5)); await settle(tester);
expect(bodyWidth(tester), closeTo(1200 - 1 - 340, 0.5)); expect(listWidth(tester), closeTo(1200 - 1 - 600, 0.5));
expect(store.values, isEmpty); expect(shellBarWidth(tester), closeTo(599, 0.5));
await gesture.up(); expect(store.values['runs'], closeTo(599, 0.5));
await tester.pump(); });
expect(store.values['runs'], closeTo(340, 0.5));
// Never narrower than the minimum... testWidgets('a double tap returns to the default policy', (tester) async {
await tester.drag(divider, const Offset(-400, 0)); await setSize(tester, const Size(1200, 800));
await settle(tester); final store = MemoryListPaneWidthStore({'runs': 300});
expect(listWidth(tester), kListPaneMinWidth); await tester.pumpWidget(shell(store: store));
// ...nor wider than leaves the open item half the window. await settle(tester);
await tester.drag(divider, const Offset(900, 0)); expect(listWidth(tester), 300);
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('$host: a double tap returns to the default policy', ( await tester.tap(divider);
tester, await tester.pump(const Duration(milliseconds: 50));
) async { await tester.tap(divider);
await setSize(tester, const Size(1200, 800)); await settle(tester);
final store = MemoryListPaneWidthStore({'runs': 300}); expect(listWidth(tester), kListPaneMaxWidth);
await tester.pumpWidget(shell(cupertino: cupertino, store: store)); expect(shellBarWidth(tester), kListPaneMaxWidth);
await settle(tester); expect(store.values, isEmpty);
expect(listWidth(tester), 300); });
await tester.tap(divider); testWidgets('widths are kept per destination and restored', (tester) async {
await tester.pump(const Duration(milliseconds: 50)); await setSize(tester, const Size(1200, 800));
await tester.tap(divider); final store = MemoryListPaneWidthStore({'runs': 300, 'chat': 500});
await settle(tester); await tester.pumpWidget(shell(store: store));
expect(listWidth(tester), kListPaneMaxWidth); await settle(tester);
expect(shellBarWidth(tester), kListPaneMaxWidth); expect(listWidth(tester), 300);
expect(store.values, isEmpty); expect(shellBarWidth(tester), 300);
});
testWidgets('$host: widths are kept per destination and restored', ( await tester.pumpWidget(
tester, shell(store: store, destination: AppDestination.chat),
) async { );
await setSize(tester, const Size(1200, 800)); await settle(tester);
final store = MemoryListPaneWidthStore({'runs': 300, 'chat': 500}); final chatList = find.byKey(const ValueKey('list-detail-list')).last;
await tester.pumpWidget(shell(cupertino: cupertino, store: store)); expect(tester.getSize(chatList).width, 500);
await settle(tester); expect(shellBarWidth(tester), 500);
expect(listWidth(tester), 300);
expect(shellBarWidth(tester), 300);
await tester.pumpWidget( // A destination nobody resized keeps the default policy.
shell( final fresh = MemoryListPaneWidthStore({'chat': 500});
cupertino: cupertino, await tester.pumpWidget(const SizedBox());
store: store, await tester.pumpWidget(shell(store: fresh));
destination: AppDestination.chat, await settle(tester);
), expect(listWidth(tester), kListPaneMaxWidth);
); });
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. testWidgets('a small window clamps the saved width without '
final fresh = MemoryListPaneWidthStore({'chat': 500}); 'overwriting it', (tester) async {
await tester.pumpWidget(const SizedBox()); await setSize(tester, const Size(1000, 800));
await tester.pumpWidget(shell(cupertino: cupertino, store: fresh)); final store = MemoryListPaneWidthStore({'runs': 600});
await settle(tester); await tester.pumpWidget(shell(store: store));
expect(listWidth(tester), kListPaneMaxWidth); 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 ' await setSize(tester, const Size(1600, 800));
'overwriting it', (tester) async { await settle(tester);
await setSize(tester, const Size(1000, 800)); expect(listWidth(tester), 600);
final store = MemoryListPaneWidthStore({'runs': 600}); expect(shellBarWidth(tester), 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)); testWidgets('arrow keys move the divider and it reads as a '
await settle(tester); 'slider', (tester) async {
expect(listWidth(tester), 600); await setSize(tester, const Size(1200, 800));
expect(shellBarWidth(tester), 600); 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 ' await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
'slider', (tester) async { await settle(tester);
await setSize(tester, const Size(1200, 800)); expect(listWidth(tester), kListPaneMaxWidth - kListPaneDividerKeyStep);
final store = MemoryListPaneWidthStore(); expect(store.values['runs'], kListPaneMaxWidth - kListPaneDividerKeyStep);
final semantics = tester.ensureSemantics(); await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpWidget(shell(cupertino: cupertino, store: store)); await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await settle(tester); await settle(tester);
Focus.of(tester.element(divider)).requestFocus(); expect(listWidth(tester), kListPaneMaxWidth + kListPaneDividerKeyStep);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft); expect(
await settle(tester); tester.getSemantics(divider),
expect(listWidth(tester), kListPaneMaxWidth - kListPaneDividerKeyStep); matchesSemantics(
expect(store.values['runs'], kListPaneMaxWidth - kListPaneDividerKeyStep); label: 'List width',
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); hint: 'Drag, or use the arrow keys, to resize the list',
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); value: '456 pixels',
await settle(tester); increasedValue: '472 pixels',
expect(listWidth(tester), kListPaneMaxWidth + kListPaneDividerKeyStep); 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( testWidgets('the native resize grip is visible at rest and gains '
tester.getSemantics(divider), 'emphasis on focus', (tester) async {
matchesSemantics( await setSize(tester, const Size(1200, 800));
label: 'List width', await tester.pumpWidget(shell(store: MemoryListPaneWidthStore()));
hint: 'Drag, or use the arrow keys, to resize the list', await settle(tester);
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('$host: the native resize grip is visible at rest and gains ' AdaptiveResizeGrip grip() => tester.widget<AdaptiveResizeGrip>(
'emphasis on focus', (tester) async { find.descendant(
await setSize(tester, const Size(1200, 800)); of: find.byType(ListPaneDivider),
await tester.pumpWidget( matching: find.byType(AdaptiveResizeGrip),
shell(cupertino: cupertino, store: MemoryListPaneWidthStore()), ),
); );
await settle(tester); expect(grip().emphasized, isFalse);
AdaptiveResizeGrip grip() => tester.widget<AdaptiveResizeGrip>( Focus.of(tester.element(divider)).requestFocus();
find.descendant( await tester.pump();
of: find.byType(ListPaneDivider), expect(grip().emphasized, isTrue);
matching: find.byType(AdaptiveResizeGrip), });
),
);
expect(grip().emphasized, isFalse);
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', () { test('bounds: list at least 240, open item at least half the window', () {
expect(listPaneWidthBounds(1200, 1200), (min: 240.0, max: 599.0)); 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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.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 /// 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. /// 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', title: 'Open item',
subtitle: 'Its context', subtitle: 'Its context',
actions: const [Icon(Icons.more_vert, semanticLabel: 'More')], actions: const [Icon(Icons.more_vert, semanticLabel: 'More')],
@@ -40,7 +39,7 @@ void main() {
bar: KeyedSubtree( bar: KeyedSubtree(
key: const Key('item-tabs'), key: const Key('item-tabs'),
child: FloatingDestinationBar( child: FloatingDestinationBar(
cupertino: cupertino, cupertino: false,
edge: edge, edge: edge,
currentIndex: 0, currentIndex: 0,
onTap: (_) {}, onTap: (_) {},
@@ -68,9 +67,8 @@ void main() {
), ),
); );
Widget shell({bool cupertino = false, int attention = 0}) { Widget shell({int attention = 0}) {
final app = AdaptiveShell( final app = AdaptiveShell(
cupertino: cupertino,
attentionCount: attention, attentionCount: attention,
destinationBodies: { destinationBodies: {
AppDestination.runs: (_) => ShellBadge( AppDestination.runs: (_) => ShellBadge(
@@ -89,14 +87,14 @@ void main() {
detail: DetailPane( detail: DetailPane(
destination: AppDestination.runs, destination: AppDestination.runs,
implyBack: false, implyBack: false,
builder: (_) => item(cupertino: cupertino), builder: (_) => item(),
), ),
), ),
), ),
}, },
destination: AppDestination.runs, destination: AppDestination.runs,
); );
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app); return MaterialApp(home: app);
} }
Finder shellBar() => find.byWidgetPredicate( Finder shellBar() => find.byWidgetPredicate(
@@ -107,100 +105,88 @@ void main() {
matching: find.byType(SegmentedBar), matching: find.byType(SegmentedBar),
); );
for (final cupertino in [false, true]) { testWidgets('1200: the shell bar covers the list pane and the '
final host = cupertino ? 'Cupertino' : 'Material'; '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 ' final list = tester.getRect(find.byKey(const ValueKey('list-detail-list')));
'item\'s bar shares its row', (tester) async { final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
await setSize(tester, const Size(1200, 800)); final shellPills = find.descendant(
await tester.pumpWidget(shell(cupertino: cupertino)); of: shellBar(),
await tester.pump(); matching: find.byType(GlassPill),
await tester.pump(); );
for (final element in shellPills.evaluate()) {
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,
);
expect( expect(
tester.getTopLeft(find.text('item row 0')).dy, rectOf(element).right,
greaterThanOrEqualTo(paneBarPill.bottom), lessThanOrEqualTo(list.right),
reason: 'no shell piece sits over the open item',
); );
expect( }
MediaQuery.paddingOf( // Both titles on the same top row.
tester.element(find.byKey(const Key('item-list'))), final shellTitle = tester.getRect(
).bottom, find.descendant(of: shellBar(), matching: find.text('Runs')),
greaterThanOrEqualTo(800 - itemTabs.top), );
); 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', ( testWidgets('390: an open item is its own page with its tabs at the bottom', (
tester, tester,
+2 -28
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -35,16 +34,11 @@ Future<void> _search(WidgetTester tester) async {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
Future<void> _pump( Future<void> _pump(WidgetTester tester, AppDestination from) async {
WidgetTester tester,
AppDestination from, {
bool cupertino = false,
}) async {
tester.view.physicalSize = const Size(1200, 900); tester.view.physicalSize = const Size(1200, 900);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset); addTearDown(tester.view.reset);
final shell = AdaptiveShell( final shell = AdaptiveShell(
cupertino: cupertino,
destination: from, destination: from,
destinationBodies: { destinationBodies: {
for (final destination in AppDestination.values) for (final destination in AppDestination.values)
@@ -53,9 +47,7 @@ Future<void> _pump(
SearchScreen(gateway: _Gateway(), onOpen: (_) {}, embedded: true), SearchScreen(gateway: _Gateway(), onOpen: (_) {}, embedded: true),
}, },
); );
await tester.pumpWidget( await tester.pumpWidget(MaterialApp(home: shell));
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
);
await tester.pumpAndSettle(); 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', ( testWidgets('Escape dismisses a Search dialog before changing tabs', (
tester, tester,
) async { ) async {
-55
View File
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -130,58 +129,4 @@ void main() {
variant: TargetPlatformVariant.only(platform), 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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.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/shell/shell_bar.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_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( final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs, destination: AppDestination.runs,
destinationBodies: { destinationBodies: {
AppDestination.runs: (_) => open AppDestination.runs: (_) => open
@@ -21,102 +19,97 @@ Widget _app({required bool cupertino, required bool open, VoidCallback? back}) {
: const Text('list'), : const Text('list'),
}, },
); );
return cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell); return MaterialApp(home: shell);
} }
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('an open screen takes over the bar and gives it back', (
final host = cupertino ? 'cupertino' : 'material'; tester,
testWidgets('$host: an open screen takes over the bar and gives it back', ( ) async {
tester, tester.view.physicalSize = const Size(390, 844);
) async { tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(390, 844); addTearDown(tester.view.reset);
tester.view.devicePixelRatio = 1; var backs = 0;
addTearDown(tester.view.reset); await tester.pumpWidget(_app(open: true, back: () => backs++));
var backs = 0; await tester.pump();
await tester.pumpWidget(
_app(cupertino: cupertino, open: true, back: () => backs++),
);
await tester.pump();
expect(find.text('Run 7'), findsOneWidget); expect(find.text('Run 7'), findsOneWidget);
expect(find.byKey(const Key('run-more')), findsOneWidget); expect(find.byKey(const Key('run-more')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back'))); await tester.tap(find.byKey(const ValueKey('shell.back')));
expect(backs, 1); expect(backs, 1);
await tester.pumpWidget(_app(cupertino: cupertino, open: false)); await tester.pumpWidget(_app(open: false));
await tester.pump(); await tester.pump();
expect(find.text('Run 7'), findsNothing); expect(find.text('Run 7'), findsNothing);
expect(find.byKey(const ValueKey('shell.back')), findsNothing); expect(find.byKey(const ValueKey('shell.back')), findsNothing);
expect(find.byKey(const Key('run-more')), findsNothing); expect(find.byKey(const Key('run-more')), findsNothing);
}); });
testWidgets('$host: Search is the fourth tab; Settings is not a tab', ( testWidgets('Search is the fourth tab; Settings is not a tab', (
tester, tester,
) async { ) async {
tester.view.physicalSize = const Size(390, 844); tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset); addTearDown(tester.view.reset);
await tester.pumpWidget(_app(cupertino: cupertino, open: false)); await tester.pumpWidget(_app(open: false));
expect(AppDestination.values, hasLength(5)); expect(AppDestination.values, hasLength(5));
expect(shellTabDestinations, [ expect(shellTabDestinations, [
AppDestination.pipelines, AppDestination.pipelines,
AppDestination.runs, AppDestination.runs,
AppDestination.chat, AppDestination.chat,
AppDestination.search, AppDestination.search,
]); ]);
expect( expect(
find.byKey(const ValueKey('shell.destination.search')), find.byKey(const ValueKey('shell.destination.search')),
findsOneWidget, findsOneWidget,
); );
expect( expect(
find.byKey(const ValueKey('shell.destination.settings')), find.byKey(const ValueKey('shell.destination.settings')),
findsNothing, findsNothing,
); );
expect(find.byKey(const ValueKey('shell.search')), findsNothing); expect(find.byKey(const ValueKey('shell.search')), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget); expect(find.byType(FloatingDestinationBar), findsOneWidget);
}); });
testWidgets('$host: floating tabs stay inset and select destinations', ( testWidgets('floating tabs stay inset and select destinations', (
tester, tester,
) async { ) async {
tester.view.physicalSize = const Size(390, 844); tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset); addTearDown(tester.view.reset);
await tester.pumpWidget(_app(cupertino: cupertino, open: false)); 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), 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. expect(caption, findsOneWidget);
final rect = tester.getRect(destinationPill); expect(rect.contains(tester.getRect(caption).center), isTrue);
expect(rect.width, lessThanOrEqualTo(390 - 2 * 16)); final target = tester.getSize(
expect( find.byKey(ValueKey('shell.destination.${destination.name}')),
tester
.widget<FloatingDestinationBar>(find.byType(FloatingDestinationBar))
.showLabels,
isTrue,
); );
for (final destination in shellTabDestinations) { expect(target.width, greaterThanOrEqualTo(44));
final caption = find.descendant( expect(target.height, greaterThanOrEqualTo(44));
of: find.byType(FloatingDestinationBar), }
matching: find.text(destinationDetails(destination).label), expect(tester.getRect(destinationPill).right, 390 - 16);
); await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
expect(caption, findsOneWidget); await tester.pump();
expect(rect.contains(tester.getRect(caption).center), isTrue); expect(find.text('Chat — Not implemented'), findsOneWidget);
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);
});
}
testWidgets('tabs show the running and unread counts their screens publish', ( testWidgets('tabs show the running and unread counts their screens publish', (
tester, tester,
+18 -27
View File
@@ -1,34 +1,25 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/shell_destination_menu.dart'; import 'package:pipelines_app/shell/shell_destination_menu.dart';
import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/destination.dart';
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('compact menu exposes all named destinations', (tester) async {
testWidgets('compact menu exposes all named destinations ($cupertino)', ( AppDestination? selected;
tester, final menu = ShellDestinationMenu(
) async { cupertino: false,
AppDestination? selected; current: AppDestination.chat,
final menu = ShellDestinationMenu( onSelected: (value) => selected = value,
cupertino: cupertino, );
current: AppDestination.chat, await tester.pumpWidget(MaterialApp(home: Scaffold(body: menu)));
onSelected: (value) => selected = value, await tester.tap(find.text('Menu'));
); await tester.pumpAndSettle();
await tester.pumpWidget( for (final name in ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings']) {
cupertino expect(find.text(name), findsOneWidget);
? CupertinoApp(home: CupertinoPageScaffold(child: menu)) }
: MaterialApp(home: Scaffold(body: menu)), await tester.tap(find.text('Runs'));
); await tester.pumpAndSettle();
await tester.tap(find.text('Menu')); expect(selected, AppDestination.runs);
await tester.pumpAndSettle(); expect(tester.takeException(), isNull);
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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.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. /// A detail with its own floating tabs over a list, like run detail.
Widget tabsDetail(bool cupertino) => FloatingBarOverlay( Widget tabsDetail() => FloatingBarOverlay(
bar: KeyedSubtree( bar: KeyedSubtree(
key: const Key('detail-tabs'), key: const Key('detail-tabs'),
child: FloatingDestinationBar( child: FloatingDestinationBar(
cupertino: cupertino, cupertino: false,
currentIndex: 0, currentIndex: 0,
onTap: (_) {}, onTap: (_) {},
items: const [ items: const [
@@ -72,7 +71,6 @@ void main() {
); );
Widget shell({ Widget shell({
required bool cupertino,
bool split = true, bool split = true,
bool tabs = false, bool tabs = false,
double textScale = 1, double textScale = 1,
@@ -80,7 +78,6 @@ void main() {
AppDestination destination = AppDestination.chat, AppDestination destination = AppDestination.chat,
}) { }) {
final app = AdaptiveShell( final app = AdaptiveShell(
cupertino: cupertino,
listPaneWidthStore: store ?? MemoryListPaneWidthStore(), listPaneWidthStore: store ?? MemoryListPaneWidthStore(),
destination: destination, destination: destination,
destinationBodies: { destinationBodies: {
@@ -88,7 +85,7 @@ void main() {
AppDestination.chat: (_) => split AppDestination.chat: (_) => split
? ListDetailPanes( ? ListDetailPanes(
list: listBody(), list: listBody(),
detail: tabs ? tabsDetail(cupertino) : composerDetail(), detail: tabs ? tabsDetail() : composerDetail(),
) )
: listBody(), : listBody(),
}, },
@@ -97,7 +94,7 @@ void main() {
data: MediaQueryData.fromView( data: MediaQueryData.fromView(
WidgetsBinding.instance.platformDispatcher.views.first, WidgetsBinding.instance.platformDispatcher.views.first,
).copyWith(textScaler: TextScaler.linear(textScale)), ).copyWith(textScaler: TextScaler.linear(textScale)),
child: cupertino ? CupertinoApp(home: app) : MaterialApp(home: app), child: MaterialApp(home: app),
); );
} }
@@ -110,204 +107,191 @@ void main() {
.first, .first,
); );
for (final cupertino in [false, true]) { for (final width in [1200.0, 1600.0]) {
final host = cupertino ? 'Cupertino' : 'Material'; 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]) { final list = tester.getRect(
testWidgets('$host $width split: the destination bar sits under the ' find.byKey(const ValueKey('list-detail-list')),
'list and the composer at the detail\'s bottom edge', (tester) async { );
await setSize(tester, Size(width, 800)); final body = tester.getRect(
await tester.pumpWidget(shell(cupertino: cupertino)); find.byKey(const ValueKey('list-detail-body')),
await tester.pump(); );
await tester.pump(); 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( // The composer reaches the detail's bottom edge: nothing is reserved
find.byKey(const ValueKey('list-detail-list')), // there for the shell's bar any more.
); final composer = tester.getRect(find.byKey(const Key('composer')));
final body = tester.getRect( expect(composer.left, body.left);
find.byKey(const ValueKey('list-detail-body')), expect(composer.bottom, closeTo(800, 0.5));
); expect(composer.overlaps(pill), isFalse);
final pill = destinationPill(tester);
// Leading at the bottom of the list pane, never over the detail. // The list clears the bar, so its last rows scroll out from under it.
expect(pill.left, closeTo(list.left + kFloatingBarMargin, 0.5)); final listContext = tester.element(find.byKey(const Key('list')));
expect(pill.bottom, closeTo(800 - kFloatingBarMargin, 0.5)); expect(
expect(pill.right, lessThanOrEqualTo(list.right)); MediaQuery.paddingOf(listContext).bottom,
expect(pill.overlaps(body), isFalse, reason: 'never over the detail'); 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( 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( find.descendant(
of: find.byKey(const Key('detail-tabs')), 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 ' // The item's list pads its end clear of its own tabs.
'at the right edge', (tester) async { final listContext = tester.element(find.byKey(const Key('detail-list')));
await setSize(tester, const Size(1200, 800)); expect(
await tester.pumpWidget( MediaQuery.paddingOf(listContext).bottom,
shell(cupertino: cupertino, destination: AppDestination.settings), 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', ( testWidgets('1200 split: the bar follows a dragged list width', (
tester, tester,
) async { ) async {
await setSize(tester, const Size(1200, 800)); await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell(cupertino: cupertino, split: false)); for (final width in [300.0, 520.0]) {
await tester.pump(); 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); final pill = destinationPill(tester);
// Same place as beside an open item (Search has no split), so opening expect(pill.left, closeTo(list.left + kFloatingBarMargin, 0.5));
// or closing an item never moves the bar across the window. expect(pill.left, greaterThanOrEqualTo(kFloatingBarMargin - 0.5));
expect(pill.left, closeTo(kFloatingBarMargin, 0.5)); expect(pill.right, lessThanOrEqualTo(list.right - kFloatingBarMargin));
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));
});
} }
});
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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart'; import 'package:pipelines_app/features/runs/data/runs_repository.dart';
@@ -36,7 +35,7 @@ void main() {
.first, .first,
); );
Future<void> pumpSplitRun(WidgetTester tester, bool cupertino) async { Future<void> pumpSplitRun(WidgetTester tester) async {
tester.view.physicalSize = const Size(1200, 800); tester.view.physicalSize = const Size(1200, 800);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset); addTearDown(tester.view.reset);
@@ -45,7 +44,6 @@ void main() {
addTearDown(controller.dispose); addTearDown(controller.dispose);
await controller.select(77); await controller.select(77);
final shell = AdaptiveShell( final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs, destination: AppDestination.runs,
destinationBodies: { destinationBodies: {
AppDestination.runs: (_) => ListDetailPanes( AppDestination.runs: (_) => ListDetailPanes(
@@ -65,78 +63,68 @@ void main() {
}, },
); );
await tester.pumpWidget( await tester.pumpWidget(
cupertino MaterialApp(
? CupertinoApp(home: shell) theme: ThemeData(platform: TargetPlatform.android),
: MaterialApp( home: shell,
theme: ThemeData(platform: TargetPlatform.android), ),
home: shell,
),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
for (final cupertino in [false, true]) { testWidgets('1200: run tabs float at the pane\'s bottom beside the '
final host = cupertino ? 'Cupertino' : 'Material'; '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 ' final runTabs = pillOf(tester, find.byKey(const Key('run-detail-tabs')));
'shell bar under the list, and the stage page opens in the pane', ( 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, tester,
) async { find.byKey(const Key('run-visit-tabs')).last,
await pumpSplitRun(tester, cupertino); );
final body = tester.getRect( expect(visitTabs.left, greaterThanOrEqualTo(body.left));
find.byKey(const ValueKey('list-detail-body')), expect(visitTabs.overlaps(main), isFalse);
); expect(visitTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
final list = tester.getRect( expect(tester.takeException(), isNull);
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));
final runTabs = pillOf(tester, find.byKey(const Key('run-detail-tabs'))); // The shell's tabs still work over the open stage page.
expect(runTabs.left, greaterThanOrEqualTo(body.left)); await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
expect(runTabs.right, closeTo(1200 - kFloatingBarMargin, 0.5)); await tester.pumpAndSettle();
expect(runTabs.overlaps(main), isFalse);
expect(runTabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
// Open the stage page from the timeline. // Back closes the page inside the pane, back to the run.
await openRunDetailTab(tester, RunDetailTab.timeline); await tester.tap(find.byKey(const Key('run-visit-back')));
final row = find.byKey(const ValueKey('run-timeline-visit-1')); await tester.pumpAndSettle();
await tester.ensureVisible(row); expect(find.byKey(const Key('run-visit-back')), findsNothing);
await tester.pumpAndSettle(); expect(find.byKey(const Key('run-detail-tabs')), findsOneWidget);
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);
});
}
} }
+45 -56
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.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 /// 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. /// spans the pane minus the page's own padding, with no reading-width cap.
void main() { void main() {
Future<void> openStagePage( Future<void> openStagePage(WidgetTester tester, {required Size size}) async {
WidgetTester tester, {
required bool cupertino,
required Size size,
}) async {
tester.view.physicalSize = size; tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset); addTearDown(tester.view.reset);
@@ -31,7 +26,6 @@ void main() {
addTearDown(controller.dispose); addTearDown(controller.dispose);
await controller.select(77); await controller.select(77);
final shell = AdaptiveShell( final shell = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs, destination: AppDestination.runs,
destinationBodies: { destinationBodies: {
AppDestination.runs: (_) => ListDetailPanes( AppDestination.runs: (_) => ListDetailPanes(
@@ -49,12 +43,10 @@ void main() {
}, },
); );
await tester.pumpWidget( await tester.pumpWidget(
cupertino MaterialApp(
? CupertinoApp(home: shell) theme: ThemeData(platform: TargetPlatform.android),
: MaterialApp( home: shell,
theme: ThemeData(platform: TargetPlatform.android), ),
home: shell,
),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await openRunDetailTab(tester, RunDetailTab.timeline); await openRunDetailTab(tester, RunDetailTab.timeline);
@@ -65,48 +57,45 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
for (final cupertino in [false, true]) { for (final size in const [Size(880, 1000), Size(1400, 900)]) {
final host = cupertino ? 'Cupertino' : 'Material'; testWidgets('${size.width.toInt()}: the stage page spans the '
for (final size in const [Size(880, 1000), Size(1400, 900)]) { 'detail pane edge to edge', (tester) async {
testWidgets('$host ${size.width.toInt()}: the stage page spans the ' await openStagePage(tester, size: size);
'detail pane edge to edge', (tester) async { expect(find.byKey(const Key('run-visit-back')), findsOneWidget);
await openStagePage(tester, cupertino: cupertino, size: size); final body = tester.getRect(
expect(find.byKey(const Key('run-visit-back')), findsOneWidget); find.byKey(const ValueKey('list-detail-body')),
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.
// The pane is the detail's whole share of the window, up to its expect(body.right, size.width);
// right edge. final pane = tester.getRect(find.byKey(const Key('run-visit-pane')));
expect(body.right, size.width); expect(pane.left, body.left);
final pane = tester.getRect(find.byKey(const Key('run-visit-pane'))); expect(pane.right, body.right);
expect(pane.left, body.left); // The facts block and the Input and Output sections span the whole
expect(pane.right, body.right); // pane; only the page's own padding insets their content.
// The facts block and the Input and Output sections span the whole final facts = tester.getRect(find.byKey(const Key('run-visit-facts')));
// pane; only the page's own padding insets their content. expect(facts.left, body.left);
final facts = tester.getRect(find.byKey(const Key('run-visit-facts'))); expect(facts.right, body.right);
expect(facts.left, body.left); final titles = find.descendant(
expect(facts.right, body.right); of: find.byKey(const Key('run-visit-pane')),
final titles = find.descendant( matching: find.byType(StickySectionTitle),
of: find.byKey(const Key('run-visit-pane')), );
matching: find.byType(StickySectionTitle), expect(titles, findsNWidgets(2));
); for (final title in tester.widgetList(titles)) {
expect(titles, findsNWidgets(2)); final rect = tester.getRect(find.byWidget(title));
for (final title in tester.widgetList(titles)) { expect(rect.left, body.left);
final rect = tester.getRect(find.byWidget(title)); expect(rect.right, body.right);
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(
// The heading starts at the page padding and the chevron ends at it. find.descendant(of: titles.first, matching: find.text('Input')),
final input = tester.getRect( );
find.descendant(of: titles.first, matching: find.text('Input')), expect(input.left, body.left + 16);
); final chevron = tester.getRect(
expect(input.left, body.left + 16); find.descendant(of: titles.first, matching: find.byType(Icon)).last,
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);
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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.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 /// An item publishing its bar to the pane, with its own floating tabs
/// placed where the pane says (like run and pipeline detail). /// placed where the pane says (like run and pipeline detail).
Widget tabbedItem(bool cupertino) => ShellBar( Widget tabbedItem() => ShellBar(
title: 'Open item', title: 'Open item',
child: Builder( child: Builder(
builder: (context) { builder: (context) {
@@ -48,7 +47,7 @@ void main() {
bar: KeyedSubtree( bar: KeyedSubtree(
key: const Key('item-tabs'), key: const Key('item-tabs'),
child: FloatingDestinationBar( child: FloatingDestinationBar(
cupertino: cupertino, cupertino: false,
edge: edge, edge: edge,
currentIndex: 0, currentIndex: 0,
onTap: (_) {}, onTap: (_) {},
@@ -71,12 +70,12 @@ void main() {
); );
/// An item drawing its own header over itself (like the chat thread). /// An item drawing its own header over itself (like the chat thread).
Widget overlayItem(bool cupertino) => ShellBar( Widget overlayItem() => ShellBar(
barless: true, barless: true,
child: SegmentedBarOverlay( child: SegmentedBarOverlay(
bar: SegmentedBar( bar: SegmentedBar(
key: const Key('own-header'), key: const Key('own-header'),
cupertino: cupertino, cupertino: false,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
title: 'Own header', title: 'Own header',
), ),
@@ -84,9 +83,8 @@ void main() {
), ),
); );
Widget shell(bool cupertino, Widget Function(bool) item) { Widget shell(Widget item) {
final app = AdaptiveShell( final app = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.runs, destination: AppDestination.runs,
destinationBodies: { destinationBodies: {
AppDestination.runs: (_) => ListDetailPanes( AppDestination.runs: (_) => ListDetailPanes(
@@ -96,12 +94,12 @@ void main() {
detail: DetailPane( detail: DetailPane(
destination: AppDestination.runs, destination: AppDestination.runs,
implyBack: false, 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 Iterable<Rect> pillsOf(WidgetTester tester, Finder bar) => find
@@ -112,99 +110,93 @@ void main() {
return box.localToGlobal(Offset.zero) & box.size; return box.localToGlobal(Offset.zero) & box.size;
}); });
for (final cupertino in [false, true]) { testWidgets('split under a status bar: list and pane bars sit '
final host = cupertino ? 'Cupertino' : 'Material'; '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 ' final listBar = find.byWidgetPredicate(
'below it, content reaches the top edge', (tester) async { (widget) => widget is SegmentedBar && widget.title == 'Runs',
await setUp(tester, const Size(1200, 800)); );
await tester.pumpWidget(shell(cupertino, tabbedItem)); final paneBar = find.byWidgetPredicate(
await tester.pump(); (widget) => widget is SegmentedBar && widget.title == 'Open item',
await tester.pump(); );
for (final bar in [listBar, paneBar]) {
final listBar = find.byWidgetPredicate( final pills = pillsOf(tester, bar);
(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')));
expect(pills, isNotEmpty); expect(pills, isNotEmpty);
for (final pill in pills) { for (final pill in pills) {
expect(pill.top, greaterThanOrEqualTo(statusBar)); 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 ' testWidgets('split under a status bar: a self-drawn header (chat) '
'detail pane, the shell tab bar under the list', (tester) async { 'sits below it', (tester) async {
// A gesture-navigation inset as on the unfolded foldable. await setUp(tester, const Size(1200, 800));
await setUp(tester, const Size(1200, 800), bottom: 24); await tester.pumpWidget(shell(overlayItem()));
await tester.pumpWidget(shell(cupertino, tabbedItem)); await tester.pump();
await tester.pump(); 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( testWidgets('split: the item tabs sit at the bottom right of the '
find.byKey(const ValueKey('list-detail-body')), 'detail pane, the shell tab bar under the list', (tester) async {
); // A gesture-navigation inset as on the unfolded foldable.
final tabs = tester.getRect( await setUp(tester, const Size(1200, 800), bottom: 24);
find.descendant( await tester.pumpWidget(shell(tabbedItem()));
of: find.byKey(const Key('item-tabs')), await tester.pump();
matching: find.byKey(FloatingDestinationBar.rowKey), await tester.pump();
),
); final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
expect(tabs.left, greaterThanOrEqualTo(body.left)); final tabs = tester.getRect(
expect(tabs.right, lessThanOrEqualTo(body.right)); find.descendant(
final shellTabs = tester.getRect( of: find.byKey(const Key('item-tabs')),
find matching: find.byKey(FloatingDestinationBar.rowKey),
.ancestor( ),
of: find.byKey(const ValueKey('shell.destination.runs')).first, );
matching: find.byKey(FloatingDestinationBar.rowKey), expect(tabs.left, greaterThanOrEqualTo(body.left));
) expect(tabs.right, lessThanOrEqualTo(body.right));
.first, final shellTabs = tester.getRect(
); find
// Both bars sit above the system inset: the shell's under the list .ancestor(
// pane, the item's at the detail pane's trailing edge. of: find.byKey(const ValueKey('shell.destination.runs')).first,
final listPane = tester.getRect( matching: find.byKey(FloatingDestinationBar.rowKey),
find.byKey(const ValueKey('list-detail-list')), )
); .first,
expect(shellTabs.bottom, closeTo(800 - 24, 0.5)); );
expect(shellTabs.right, lessThanOrEqualTo(listPane.right)); // Both bars sit above the system inset: the shell's under the list
expect(tabs.bottom, closeTo(800 - 24, 0.5)); // pane, the item's at the detail pane's trailing edge.
expect(tabs.right, closeTo(1200 - kFloatingBarMargin, 0.5)); final listPane = tester.getRect(
expect(shellTabs.overlaps(tabs), isFalse); find.byKey(const ValueKey('list-detail-list')),
// The item's list clears its tabs at rest. );
final list = tester.element(find.byKey(const Key('item-list'))); expect(shellTabs.bottom, closeTo(800 - 24, 0.5));
expect( expect(shellTabs.right, lessThanOrEqualTo(listPane.right));
MediaQuery.paddingOf(list).bottom, expect(tabs.bottom, closeTo(800 - 24, 0.5));
greaterThanOrEqualTo(800 - tabs.top), 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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.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( final shell = AdaptiveShell(
cupertino: cupertino,
destinationBodies: { destinationBodies: {
AppDestination.runs: (_) => split AppDestination.runs: (_) => split
? ListDetailPanes( ? ListDetailPanes(
@@ -69,9 +67,7 @@ void main() {
); );
Widget margins(BuildContext context, Widget? child) => Widget margins(BuildContext context, Widget? child) =>
WindowMargins(child: child!); WindowMargins(child: child!);
return cupertino return MaterialApp(builder: margins, home: shell);
? CupertinoApp(builder: margins, home: shell)
: MaterialApp(builder: margins, home: shell);
} }
Finder pills(Finder bar) => Finder pills(Finder bar) =>
@@ -94,107 +90,92 @@ void main() {
return rects.reduce((a, b) => a.expandToInclude(b)); return rects.reduce((a, b) => a.expandToInclude(b));
} }
for (final cupertino in [false, true]) { testWidgets('1280: list and detail bars keep 16 px from the top '
final host = cupertino ? 'Cupertino' : 'Material'; '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 ' final listPane = tester.getRect(
'and every side', (tester) async { find.byKey(const ValueKey('list-detail-list')),
await setSize(tester, const Size(1280, 800)); );
await tester.pumpWidget(app(cupertino: cupertino, split: true)); final body = tester.getRect(find.byKey(const ValueKey('list-detail-body')));
await tester.pump(); final listBar = span(tester, shellBar);
// The pieces pop in; measure them at rest. final itemBar = span(tester, paneBar);
await tester.pump(const Duration(seconds: 2)); 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( // Each pane's content still starts below its bar (and its 8 px gap)
find.byKey(const ValueKey('list-detail-list')), // at rest, so nothing hides behind the taller margin.
); expect(
final body = tester.getRect( tester.getTopLeft(find.text('list row 0')).dy,
find.byKey(const ValueKey('list-detail-body')), greaterThanOrEqualTo(listBar.bottom + 8 - 0.5),
); );
final listBar = span(tester, shellBar); expect(
final itemBar = span(tester, paneBar); tester.getTopLeft(find.text('item row 0')).dy,
expect(listBar.top, closeTo(16, 0.5)); greaterThanOrEqualTo(itemBar.bottom + 8 - 0.5),
expect(listBar.left, closeTo(listPane.left + 16, 0.5)); );
expect(listBar.right, closeTo(listPane.right - 16, 0.5)); expect(tester.takeException(), isNull);
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) testWidgets('390: the phone keeps the bar at 8 px from the top and '
// at rest, so nothing hides behind the taller margin. '12 px from the sides', (tester) async {
expect( await setSize(tester, const Size(390, 844));
tester.getTopLeft(find.text('list row 0')).dy, await tester.pumpWidget(app(split: false));
greaterThanOrEqualTo(listBar.bottom + 8 - 0.5), await tester.pump();
); // The pieces pop in; measure them at rest.
expect( await tester.pump(const Duration(seconds: 2));
tester.getTopLeft(find.text('item row 0')).dy,
greaterThanOrEqualTo(itemBar.bottom + 8 - 0.5),
);
expect(tester.takeException(), isNull);
});
testWidgets('$host 390: the phone keeps the bar at 8 px from the top and ' final bar = span(tester, shellBar);
'12 px from the sides', (tester) async { expect(bar.top, closeTo(8, 0.5));
await setSize(tester, const Size(390, 844)); expect(bar.left, closeTo(12, 0.5));
await tester.pumpWidget(app(cupertino: cupertino, split: false)); expect(bar.right, closeTo(390 - 12, 0.5));
await tester.pump(); expect(
// The pieces pop in; measure them at rest. tester.getTopLeft(find.text('list row 0')).dy,
await tester.pump(const Duration(seconds: 2)); greaterThanOrEqualTo(bar.bottom + 8 - 0.5),
);
expect(tester.takeException(), isNull);
});
final bar = span(tester, shellBar); testWidgets('1280: a pushed page\'s bar keeps the wide margins', (
expect(bar.top, closeTo(8, 0.5)); tester,
expect(bar.left, closeTo(12, 0.5)); ) async {
expect(bar.right, closeTo(390 - 12, 0.5)); await setSize(tester, const Size(1280, 800));
expect( final bar = SegmentedBar(
tester.getTopLeft(find.text('list row 0')).dy, cupertino: false,
greaterThanOrEqualTo(bar.bottom + 8 - 0.5), title: 'Settings',
); actions: const [Icon(Icons.more_vert, semanticLabel: 'More')],
expect(tester.takeException(), isNull); );
}); 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', ( final pieces = span(tester, find.byType(SegmentedBar));
tester, expect(pieces.top, closeTo(16, 0.5));
) async { expect(pieces.left, closeTo(16, 0.5));
await setSize(tester, const Size(1280, 800)); expect(pieces.right, closeTo(1280 - 16, 0.5));
final bar = SegmentedBar( expect(
cupertino: cupertino, tester.getTopLeft(find.text('first row')).dy,
title: 'Settings', closeTo(pieces.bottom + 8, 0.5),
actions: const [Icon(Icons.more_vert, semanticLabel: 'More')], );
); expect(tester.takeException(), isNull);
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);
});
}
} }
@@ -300,54 +300,48 @@ void main() {
); );
expect(iconWidth(tester, 0), moreOrLessEquals(iconSize)); expect(iconWidth(tester, 0), moreOrLessEquals(iconSize));
}); });
}
testWidgets('$host: switching the shell tabs never replays the main ' testWidgets('switching the shell tabs never replays the main '
"bar's entrance", (tester) async { "bar's entrance", (tester) async {
animate(tester, on: true); final size = FloatingDestinationBar.buttonSize(cupertino: false);
var destination = AppDestination.runs; animate(tester, on: true);
final shell = StatefulBuilder( var destination = AppDestination.runs;
builder: (context, setState) => AdaptiveShell( final shell = StatefulBuilder(
cupertino: cupertino, builder: (context, setState) => AdaptiveShell(
destination: destination, destination: destination,
onDestinationSelected: (value) => setState(() => destination = value), onDestinationSelected: (value) => setState(() => destination = value),
), ),
); );
await tester.pumpWidget( await tester.pumpWidget(MaterialApp(home: shell));
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell), await tester.pumpAndSettle();
); for (final next in [
await tester.pumpAndSettle(); AppDestination.pipelines,
for (final next in [ AppDestination.chat,
AppDestination.pipelines, AppDestination.runs,
AppDestination.chat, ]) {
AppDestination.runs, await tester.tap(find.byKey(ValueKey('shell.destination.${next.name}')));
]) { for (var frame = 0; frame < 12; frame += 1) {
await tester.tap( await tester.pump(const Duration(milliseconds: 25));
find.byKey(ValueKey('shell.destination.${next.name}')), for (final tab in shellTabDestinations) {
); final finder = find.byKey(ValueKey('shell.destination.${tab.name}'));
for (var frame = 0; frame < 12; frame += 1) { expect(
await tester.pump(const Duration(milliseconds: 25)); opacityOf(tester, finder),
for (final tab in shellTabDestinations) { 1,
final finder = find.byKey( reason: '${tab.name} faded switching to ${next.name}',
ValueKey('shell.destination.${tab.name}'), );
); if (tab != next) {
// The previous selection shrinks back to its size; nothing
// pops again from 0.6.
expect( expect(
opacityOf(tester, finder), widthOf(tester, finder),
1, greaterThan(size * 0.9),
reason: '${tab.name} faded switching to ${next.name}', reason: tab.name,
); );
if (tab != next) {
// The previous selection shrinks back to its size; nothing
// pops again from 0.6.
expect(
widthOf(tester, finder),
greaterThan(size * 0.9),
reason: tab.name,
);
}
} }
} }
await tester.pumpAndSettle();
} }
}); await tester.pumpAndSettle();
} }
});
} }
@@ -105,47 +105,42 @@ void main() {
// The actions keep to the trailing edge. // The actions keep to the trailing edge.
expect(pillOf(tester, find.byKey(const Key('action'))).right, 1200 - 12); expect(pillOf(tester, find.byKey(const Key('action'))).right, 1200 - 12);
}); });
testWidgets('$host: a shell tab publishing a field gets it in place of '
'the title, without the Search action', (tester) async {
setSize(tester, 560);
await tester.pumpWidget(
_shellApp(
cupertino,
AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.search,
onSearch: () {},
destinationBodies: {
AppDestination.search: (_) => ShellBar(
titleWidget: field(cupertino),
titleWidgetMaxWidth: 840,
child: const SizedBox.expand(),
),
},
),
),
);
await tester.pump();
final bar = find.byType(SegmentedBar);
expect(
find.descendant(of: bar, matching: find.byKey(fieldKey)),
findsOneWidget,
);
expect(
find.descendant(of: bar, matching: find.text('Search')),
findsNothing,
);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
// Measured at rest, after the pieces' entrance.
await tester.pump(const Duration(seconds: 1));
final pill = pillOf(tester, find.byKey(fieldKey));
expect(pill.left, 12);
expect(pill.right, 560 - 12);
});
} }
}
Widget _shellApp(bool cupertino, Widget shell) => testWidgets('a shell tab publishing a field gets it in place of the title, '
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell); 'without the Search action', (tester) async {
setSize(tester, 560);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.search,
onSearch: () {},
destinationBodies: {
AppDestination.search: (_) => ShellBar(
titleWidget: const TextField(key: fieldKey),
titleWidgetMaxWidth: 840,
child: const SizedBox.expand(),
),
},
),
),
);
await tester.pump();
final bar = find.byType(SegmentedBar);
expect(
find.descendant(of: bar, matching: find.byKey(fieldKey)),
findsOneWidget,
);
expect(
find.descendant(of: bar, matching: find.text('Search')),
findsNothing,
);
expect(find.byKey(const ValueKey('shell.search')), findsNothing);
// Measured at rest, after the pieces' entrance.
await tester.pump(const Duration(seconds: 1));
final pill = pillOf(tester, find.byKey(fieldKey));
expect(pill.left, 12);
expect(pill.right, 560 - 12);
});
}
+2 -49
View File
@@ -1,9 +1,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/main.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
void main() { void main() {
@@ -36,52 +35,6 @@ void main() {
); );
} }
testWidgets('Cupertino shell uses a tab bar on a narrow window', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(const MyApp(cupertino: true));
expect(find.byType(SegmentedBar), findsOneWidget);
expect(find.byType(CupertinoNavigationBar), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
});
testWidgets('Cupertino shell floats its tab bar on a wide window', (
tester,
) async {
tester.view.physicalSize = const Size(1280, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(const MyApp(cupertino: true));
expect(find.byType(FloatingDestinationBar), findsOneWidget);
expect(find.byType(CupertinoListTile), findsNothing);
expect(
find.byKey(const ValueKey('shell.destination.pipelines')),
findsOneWidget,
);
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
await tester.pumpAndSettle();
expect(find.text('Runs — Not implemented'), findsOneWidget);
});
testWidgets('Cupertino content stays inside safe area', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
tester.view.padding = const FakeViewPadding(top: 36, bottom: 28);
addTearDown(tester.view.resetPadding);
await tester.pumpWidget(const MyApp(cupertino: true));
final tabBar = tester.getRect(find.byType(FloatingDestinationBar));
expect(tabBar.bottom, lessThanOrEqualTo(900 - 28));
expect(tester.takeException(), isNull);
});
testWidgets('destination state survives switching tabs', (tester) async { testWidgets('destination state survives switching tabs', (tester) async {
var builds = 0; var builds = 0;
await tester.pumpWidget( await tester.pumpWidget(