Merge commit '84684463204d32bc51ea50ddb5789b0cc17b280a' into pipelines/run-20261111-0240-perf-whole-pixel-window-frames-stop-per-89f6

This commit is contained in:
2026-11-11 03:37:34 +00:00
62 changed files with 1394 additions and 3044 deletions
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar.dart'; import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/floating_bar_layout.dart';
import 'graph_viewport.dart'; import 'graph_viewport.dart';
import 'graph_viewport_controller.dart'; import 'graph_viewport_controller.dart';
@@ -100,23 +98,6 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
Expanded(child: viewport), Expanded(child: viewport),
], ],
); );
if (usesCupertinoHost(context)) {
return CupertinoPageScaffold(
navigationBar: SegmentedBar(
cupertino: true,
automaticallyImplyLeading: false,
leading: SegmentedBackButton(cupertino: true, onPressed: _close),
title: widget.title,
actions: [
_GraphFitButton(
cupertino: true,
onPressed: _controller.fitToViewport,
),
],
),
child: BelowTopBar(child: body),
);
}
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
appBar: SegmentedBar( appBar: SegmentedBar(
@@ -124,12 +105,7 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
title: widget.title, title: widget.title,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
leading: SegmentedBackButton(cupertino: false, onPressed: _close), leading: SegmentedBackButton(cupertino: false, onPressed: _close),
actions: [ actions: [_GraphFitButton(onPressed: _controller.fitToViewport)],
_GraphFitButton(
cupertino: false,
onPressed: _controller.fitToViewport,
),
],
), ),
body: BelowTopBar(child: body), body: BelowTopBar(child: body),
); );
@@ -137,9 +113,8 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
} }
class _GraphFitButton extends StatelessWidget { class _GraphFitButton extends StatelessWidget {
const _GraphFitButton({required this.cupertino, required this.onPressed}); const _GraphFitButton({required this.onPressed});
final bool cupertino;
final VoidCallback onPressed; final VoidCallback onPressed;
@override @override
@@ -147,22 +122,15 @@ class _GraphFitButton extends StatelessWidget {
child: Semantics( child: Semantics(
button: true, button: true,
label: graphFitLabel, label: graphFitLabel,
child: cupertino child: Tooltip(
? CupertinoButton( message: graphFitLabel,
key: const Key('graph-fit'), excludeFromSemantics: true,
padding: const EdgeInsets.all(8), child: IconButton(
onPressed: onPressed, key: const Key('graph-fit'),
child: const ExcludeSemantics(child: Icon(CupertinoIcons.resize)), onPressed: onPressed,
) icon: const ExcludeSemantics(child: Icon(Icons.fit_screen)),
: Tooltip( ),
message: graphFitLabel, ),
excludeFromSemantics: true,
child: IconButton(
key: const Key('graph-fit'),
onPressed: onPressed,
icon: const ExcludeSemantics(child: Icon(Icons.fit_screen)),
),
),
), ),
); );
} }
@@ -190,8 +158,9 @@ Future<void> openGraphExpanded(
selectedStage: selectedStage, selectedStage: selectedStage,
header: header, header: header,
); );
final route = usesCupertinoHost(context) final route = MaterialPageRoute<void>(
? CupertinoPageRoute<void>(fullscreenDialog: true, builder: (_) => page) fullscreenDialog: true,
: MaterialPageRoute<void>(fullscreenDialog: true, builder: (_) => page); builder: (_) => page,
);
return Navigator.of(context).push(route); return Navigator.of(context).push(route);
} }
@@ -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/glass_pill.dart'; import '../../../ui/adaptive/glass_pill.dart';
import 'graph_viewport_controller.dart'; import 'graph_viewport_controller.dart';
@@ -121,20 +119,20 @@ class _GraphViewportState extends State<GraphViewport> {
top: 8, top: 8,
end: 8, end: 8,
child: GlassPill( child: GlassPill(
cupertino: usesCupertinoHost(context), cupertino: false,
child: Wrap( child: Wrap(
spacing: 2, spacing: 2,
children: [ children: [
_ViewportButton( _ViewportButton(
buttonKey: const Key('graph-fit'), buttonKey: const Key('graph-fit'),
icon: _fitIcon(context), icon: Icons.fit_screen,
label: graphFitLabel, label: graphFitLabel,
onPressed: widget.controller.fitToViewport, onPressed: widget.controller.fitToViewport,
), ),
if (widget.onExpand != null) if (widget.onExpand != null)
_ViewportButton( _ViewportButton(
buttonKey: const Key('graph-expand'), buttonKey: const Key('graph-expand'),
icon: _expandIcon(context), icon: Icons.fullscreen,
label: graphExpandLabel, label: graphExpandLabel,
onPressed: widget.onExpand, onPressed: widget.onExpand,
), ),
@@ -147,12 +145,6 @@ class _GraphViewportState extends State<GraphViewport> {
}, },
); );
} }
IconData _fitIcon(BuildContext context) =>
usesCupertinoHost(context) ? CupertinoIcons.resize : Icons.fit_screen;
IconData _expandIcon(BuildContext context) =>
usesCupertinoHost(context) ? CupertinoIcons.fullscreen : Icons.fullscreen;
} }
/// One native graph control inside the shared floating glass pill. /// One native graph control inside the shared floating glass pill.
@@ -160,7 +152,7 @@ class _GraphViewportState extends State<GraphViewport> {
/// The label and the button's own tap action must reach the same semantics /// The label and the button's own tap action must reach the same semantics
/// node: the icon is the only excluded child, and [MergeSemantics] folds the /// node: the icon is the only excluded child, and [MergeSemantics] folds the
/// host button's action into the labelled node, so a screen reader can activate /// host button's action into the labelled node, so a screen reader can activate
/// Fit and Expand on either host. A hand-written `Semantics` sibling around an /// Fit and Expand. A hand-written `Semantics` sibling around an
/// excluded button would announce the control with no action at all. /// excluded button would announce the control with no action at all.
class _ViewportButton extends StatelessWidget { class _ViewportButton extends StatelessWidget {
const _ViewportButton({ const _ViewportButton({
@@ -181,24 +173,17 @@ class _ViewportButton extends StatelessWidget {
child: Semantics( child: Semantics(
button: true, button: true,
label: label, label: label,
child: usesCupertinoHost(context) child: Tooltip(
? CupertinoButton( message: label,
key: buttonKey, // The merged node already carries the label; the tooltip is
padding: const EdgeInsets.all(8), // only the pointer affordance.
onPressed: onPressed, excludeFromSemantics: true,
child: ExcludeSemantics(child: Icon(icon)), child: IconButton(
) key: buttonKey,
: Tooltip( onPressed: onPressed,
message: label, icon: ExcludeSemantics(child: Icon(icon)),
// The merged node already carries the label; the tooltip is ),
// only the pointer affordance. ),
excludeFromSemantics: true,
child: IconButton(
key: buttonKey,
onPressed: onPressed,
icon: ExcludeSemantics(child: Icon(icon)),
),
),
), ),
); );
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart'; import '../../../core/api_gateway.dart';
@@ -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 '../layout/layout_models.dart'; import '../layout/layout_models.dart';
import '../routing/route_models.dart'; import '../routing/route_models.dart';
@@ -32,9 +30,9 @@ RoutingConfig graphCanvasRoutingConfig() => RoutingConfig(
/// The native theme roles one definition graph canvas needs. /// The native theme roles one definition graph canvas needs.
/// ///
/// No palette, font family or size is defined here: every value comes from the /// No palette, font family or size is defined here: every value comes from the
/// ambient Material or Cupertino theme, so light/dark and text scaling follow /// ambient Material theme, so light/dark and text scaling follow the host
/// the host exactly. Edge labels and diagnostics are metadata, so they use the /// exactly. Edge labels and diagnostics are metadata, so they use the host's
/// host's secondary-label role rather than the node's own label style. /// secondary-label role rather than the node's own label style.
class GraphCanvasStyle { class GraphCanvasStyle {
const GraphCanvasStyle({ const GraphCanvasStyle({
required this.labelStyle, required this.labelStyle,
@@ -44,20 +42,6 @@ class GraphCanvasStyle {
}); });
factory GraphCanvasStyle.of(BuildContext context) { factory GraphCanvasStyle.of(BuildContext context) {
if (usesCupertinoHost(context)) {
final theme = CupertinoTheme.of(context);
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return GraphCanvasStyle(
labelStyle: theme.textTheme.tabLabelTextStyle.copyWith(
color: secondary,
),
messageStyle: theme.textTheme.textStyle.copyWith(color: secondary),
edgeColor: CupertinoColors.separator.resolveFrom(context),
// Cupertino has no divider-thickness token; its separators are one
// logical pixel hairlines, so the stroke keeps that native default.
edgeWidth: 1,
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
final secondary = theme.colorScheme.onSurfaceVariant; final secondary = theme.colorScheme.onSurfaceVariant;
return GraphCanvasStyle( return GraphCanvasStyle(
@@ -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/status/run_status_icon.dart'; import '../../../ui/status/run_status_icon.dart';
import '../domain/graph_definition.dart'; import '../domain/graph_definition.dart';
@@ -37,7 +35,7 @@ class GraphStageNode extends StatelessWidget {
/// Reports [node.key] exactly as the definition recorded it. /// Reports [node.key] exactly as the definition recorded it.
final ValueChanged<String> onSelected; final ValueChanged<String> onSelected;
/// Content inset shared by both hosts. It is spacing, not a size: the control /// Content inset for a graph node. It is spacing, not a size: the control
/// still takes its size from its label, and the inset keeps wrapped glyphs /// still takes its size from its label, and the inset keeps wrapped glyphs
/// clear of a rounded surface's corners. /// clear of a rounded surface's corners.
static const EdgeInsets _contentPadding = EdgeInsets.all(16); static const EdgeInsets _contentPadding = EdgeInsets.all(16);
@@ -61,9 +59,7 @@ class GraphStageNode extends StatelessWidget {
button: true, button: true,
selected: selected, selected: selected,
label: _label, label: _label,
child: usesCupertinoHost(context) child: _materialCard(onPressed, content),
? _cupertinoButton(onPressed, content)
: _materialCard(onPressed, content),
), ),
); );
return active ? StageActivityHalo(child: control) : control; return active ? StageActivityHalo(child: control) : control;
@@ -106,12 +102,6 @@ class GraphStageNode extends StatelessWidget {
); );
} }
/// Tinted is Cupertino's stock low-emphasis surface, so an unselected node is
/// still a visible node body; filled raises the selected one.
Widget _cupertinoButton(VoidCallback onPressed, Widget content) => selected
? CupertinoButton.filled(onPressed: onPressed, child: content)
: CupertinoButton.tinted(onPressed: onPressed, child: content);
Widget _content(BuildContext context) { Widget _content(BuildContext context) {
final status = _status; final status = _status;
// The recorded status reads apart from the name: a coloured dot and // The recorded status reads apart from the name: a coloured dot and
@@ -215,10 +205,7 @@ class _StageActivityHaloState extends State<StageActivityHalo>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context); final color = Theme.of(context).colorScheme.primary;
final color = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
return AnimatedBuilder( return AnimatedBuilder(
animation: _controller, animation: _controller,
builder: (context, child) => CustomPaint( builder: (context, child) => CustomPaint(
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show listEquals; import 'package:flutter/foundation.dart' show listEquals;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/graph_definition.dart'; import '../domain/graph_definition.dart';
import '../domain/run_graph_state.dart'; import '../domain/run_graph_state.dart';
import '../layout/layout_models.dart'; import '../layout/layout_models.dart';
@@ -200,10 +198,7 @@ class RunGraphCanvas extends StatelessWidget {
final executedIds = {for (final route in executed) route.id}; final executedIds = {for (final route in executed) route.id};
final size = Size(routing.width, routing.height); final size = Size(routing.width, routing.height);
final activeStage = state.activeStage; final activeStage = state.activeStage;
final cupertino = usesCupertinoHost(context); final executedColor = Theme.of(context).colorScheme.primary;
final executedColor = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
return Stack( return Stack(
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
@@ -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 '../domain/run_graph_state.dart'; import '../domain/run_graph_state.dart';
import 'graph_canvas_style.dart'; import 'graph_canvas_style.dart';
@@ -31,10 +29,7 @@ class RunGraphHeader extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context); final executedColor = Theme.of(context).colorScheme.primary;
final executedColor = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final mutedColor = style.edgeColor; final mutedColor = style.edgeColor;
final active = state.activeStage; final active = state.activeStage;
return Padding( return Padding(
@@ -53,14 +48,12 @@ class RunGraphHeader extends StatelessWidget {
crossAxisAlignment: WrapCrossAlignment.center, crossAxisAlignment: WrapCrossAlignment.center,
children: [ children: [
_LegendEntry( _LegendEntry(
icon: cupertino icon: Icons.arrow_forward,
? CupertinoIcons.arrow_right
: Icons.arrow_forward,
label: runGraphExecuted, label: runGraphExecuted,
color: executedColor, color: executedColor,
), ),
_LegendEntry( _LegendEntry(
icon: cupertino ? CupertinoIcons.minus : Icons.remove, icon: Icons.remove,
label: runGraphNotExecuted, label: runGraphNotExecuted,
color: mutedColor, color: mutedColor,
), ),
@@ -1,14 +1,12 @@
import '../../../ui/adaptive/segmented_bar.dart';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/text/markdown_source_view.dart'; import '../../../ui/text/markdown_source_view.dart';
import '../../chat/ui/transcript/chat_markdown_view.dart'; import '../../chat/ui/transcript/chat_markdown_view.dart';
import '../../../core/api_gateway.dart'; import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/floating_bar_layout.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/graph_protocol.dart'; import '../domain/graph_protocol.dart';
import '../domain/stage_definition.dart'; import '../domain/stage_definition.dart';
@@ -159,30 +157,14 @@ Future<void> openStageDefinition(
// A terminal is a definition target, not its protocol key: the web pane // A terminal is a definition target, not its protocol key: the web pane
// titles it with `nodeDisplayLabel` (`Failure`/`Success`). // titles it with `nodeDisplayLabel` (`Failure`/`Success`).
final title = '${nodeDisplayLabel(stageKey)} definition'; final title = '${nodeDisplayLabel(stageKey)} definition';
final route = usesCupertinoHost(context) final route = MaterialPageRoute<void>(
? CupertinoPageRoute<void>( settings: settings,
settings: settings, builder: (_) => Scaffold(
builder: (_) => CupertinoPageScaffold( extendBodyBehindAppBar: true,
navigationBar: SegmentedBar( appBar: SegmentedBar(cupertino: false, title: title, subtitle: identity),
cupertino: true, body: SafeArea(top: false, bottom: false, child: view),
title: title, ),
subtitle: identity, );
),
child: SafeArea(top: false, bottom: false, child: view),
),
)
: MaterialPageRoute<void>(
settings: settings,
builder: (_) => Scaffold(
extendBodyBehindAppBar: true,
appBar: SegmentedBar(
cupertino: false,
title: title,
subtitle: identity,
),
body: SafeArea(top: false, bottom: false, child: view),
),
);
return Navigator.of(context).push(route); return Navigator.of(context).push(route);
} }
@@ -263,22 +245,6 @@ class _StageDefinitionStyle {
}); });
factory _StageDefinitionStyle.of(BuildContext context) { factory _StageDefinitionStyle.of(BuildContext context) {
if (usesCupertinoHost(context)) {
final theme = CupertinoTheme.of(context);
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return _StageDefinitionStyle(
label: theme.textTheme.tabLabelTextStyle.copyWith(color: secondary),
// SelectableText needs a style it can merge into the default text
// style; Cupertino's textStyle is a complete style with `inherit: false`
// and no baseline.
value: theme.textTheme.textStyle.copyWith(inherit: true),
muted: theme.textTheme.textStyle.copyWith(
inherit: true,
color: secondary,
),
heading: theme.textTheme.navTitleTextStyle,
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
return _StageDefinitionStyle( return _StageDefinitionStyle(
label: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith( label: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith(
+1 -2
View File
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import '../../core/api_gateway.dart'; import '../../core/api_gateway.dart';
import '../../shell/shell_bar.dart'; import '../../shell/shell_bar.dart';
import '../../ui/adaptive/host.dart';
import '../../ui/adaptive/top_bar_notices.dart'; import '../../ui/adaptive/top_bar_notices.dart';
import 'data/template_repository.dart'; import 'data/template_repository.dart';
import 'domain/template_entry.dart'; import 'domain/template_entry.dart';
@@ -170,7 +169,7 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
context: context, context: context,
template: template, template: template,
repository: _repository, repository: _repository,
cupertino: usesCupertinoHost(context), cupertino: false,
onCreated: (detail) => widget.onCreated?.call(detail), onCreated: (detail) => widget.onCreated?.call(detail),
), ),
); );
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'template_create_wording.dart'; import 'template_create_wording.dart';
@@ -13,6 +12,8 @@ class TemplateCreateNameField extends StatelessWidget {
required this.onSubmit, required this.onSubmit,
}); });
/// Retained for callers that still pass it; the field is always the
/// Material one whether this is set or not.
final bool cupertino; final bool cupertino;
final TextEditingController controller; final TextEditingController controller;
final bool enabled; final bool enabled;
@@ -26,24 +27,14 @@ class TemplateCreateNameField extends StatelessWidget {
children: [ children: [
const Text(templateCreateNameLabel), const Text(templateCreateNameLabel),
const SizedBox(height: 8), const SizedBox(height: 8),
if (cupertino) TextField(
CupertinoTextField( key: templateCreateNameKey,
key: templateCreateNameKey, controller: controller,
controller: controller, enabled: enabled,
enabled: enabled, autofocus: true,
autofocus: true, textInputAction: TextInputAction.done,
textInputAction: TextInputAction.done, onSubmitted: (_) => onSubmit(),
onSubmitted: (_) => onSubmit(), ),
)
else
TextField(
key: templateCreateNameKey,
controller: controller,
enabled: enabled,
autofocus: true,
textInputAction: TextInputAction.done,
onSubmitted: (_) => onSubmit(),
),
], ],
), ),
); );
@@ -56,14 +47,6 @@ Widget templateCreateDialogAction({
required Widget child, required Widget child,
bool primary = false, bool primary = false,
}) { }) {
if (cupertino) {
return CupertinoDialogAction(
key: key,
isDefaultAction: primary,
onPressed: onPressed,
child: child,
);
}
if (primary) { if (primary) {
return FilledButton(key: key, onPressed: onPressed, child: child); return FilledButton(key: key, onPressed: onPressed, child: child);
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
@@ -12,6 +11,9 @@ import 'template_create_controls.dart';
/// Cancel send nothing; Create validates the source first and only a passing /// Cancel send nothing; Create validates the source first and only a passing
/// validate submits it create-only. A refusal keeps the typed name; an accepted /// validate submits it create-only. A refusal keeps the typed name; an accepted
/// `detail` is delivered through [onCreated] once. /// `detail` is delivered through [onCreated] once.
///
/// [cupertino] is retained for callers that still pass it; the prompt is
/// always the Material dialog.
Future<void> showTemplateCreateDialog({ Future<void> showTemplateCreateDialog({
required BuildContext context, required BuildContext context,
required TemplateEntry template, required TemplateEntry template,
@@ -22,33 +24,24 @@ Future<void> showTemplateCreateDialog({
final dialog = _TemplateCreateDialog( final dialog = _TemplateCreateDialog(
template: template, template: template,
repository: repository, repository: repository,
cupertino: cupertino,
onCreated: onCreated, onCreated: onCreated,
); );
return cupertino return showDialog<void>(
? showCupertinoDialog<void>( context: context,
context: context, barrierDismissible: false,
barrierDismissible: false, builder: (_) => dialog,
builder: (_) => dialog, );
)
: showDialog<void>(
context: context,
barrierDismissible: false,
builder: (_) => dialog,
);
} }
class _TemplateCreateDialog extends StatefulWidget { class _TemplateCreateDialog extends StatefulWidget {
const _TemplateCreateDialog({ const _TemplateCreateDialog({
required this.template, required this.template,
required this.repository, required this.repository,
required this.cupertino,
required this.onCreated, required this.onCreated,
}); });
final TemplateEntry template; final TemplateEntry template;
final TemplateRepository repository; final TemplateRepository repository;
final bool cupertino;
final ValueChanged<JsonMap> onCreated; final ValueChanged<JsonMap> onCreated;
@override @override
@@ -150,15 +143,13 @@ class _TemplateCreateDialogState extends State<_TemplateCreateDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final color = widget.cupertino final color = Theme.of(context).colorScheme.error;
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error;
final content = Column( final content = Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
TemplateCreateNameField( TemplateCreateNameField(
cupertino: widget.cupertino, cupertino: false,
controller: _name, controller: _name,
enabled: _fieldEnabled, enabled: _fieldEnabled,
onSubmit: _create, onSubmit: _create,
@@ -196,7 +187,7 @@ class _TemplateCreateDialogState extends State<_TemplateCreateDialog> {
); );
final actions = [ final actions = [
templateCreateDialogAction( templateCreateDialogAction(
cupertino: widget.cupertino, cupertino: false,
key: templateCreateCancelKey, key: templateCreateCancelKey,
onPressed: _sending ? null : _cancel, onPressed: _sending ? null : _cancel,
child: Text( child: Text(
@@ -206,7 +197,7 @@ class _TemplateCreateDialogState extends State<_TemplateCreateDialog> {
), ),
), ),
templateCreateDialogAction( templateCreateDialogAction(
cupertino: widget.cupertino, cupertino: false,
key: templateCreateConfirmKey, key: templateCreateConfirmKey,
primary: true, primary: true,
onPressed: _canSubmit ? _create : null, onPressed: _canSubmit ? _create : null,
@@ -216,20 +207,10 @@ class _TemplateCreateDialogState extends State<_TemplateCreateDialog> {
), ),
]; ];
final title = Text(templateCreateTitle(widget.template)); final title = Text(templateCreateTitle(widget.template));
if (!widget.cupertino) {
return PopScope(
canPop: !_sending,
child: AlertDialog(
scrollable: true,
title: title,
content: content,
actions: actions,
),
);
}
return PopScope( return PopScope(
canPop: !_sending, canPop: !_sending,
child: CupertinoAlertDialog( child: AlertDialog(
scrollable: true,
title: title, title: title,
content: content, content: content,
actions: actions, actions: actions,
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/floating_bar_layout.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/adaptive/segmented_bar.dart'; import '../../../ui/adaptive/segmented_bar.dart';
import '../domain/template_entry.dart'; import '../domain/template_entry.dart';
import 'template_gallery.dart' show templatesColumn; import 'template_gallery.dart' show templatesColumn;
@@ -63,14 +61,13 @@ class TemplateDetail extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final muted = templateMutedStyle(context); final muted = templateMutedStyle(context);
final description = entry.description.trim(); final description = entry.description.trim();
return ListView( return ListView(
key: templateDetailKey, key: templateDetailKey,
padding: withBarClearance(context, const EdgeInsets.only(bottom: 24)), padding: withBarClearance(context, const EdgeInsets.only(bottom: 24)),
children: [ children: [
if (showBack) _backRow(context, cupertino), if (showBack) _backRow(context),
templatesColumn( templatesColumn(
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
@@ -91,7 +88,7 @@ class TemplateDetail extends StatelessWidget {
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
], ],
_createButton(cupertino), _createButton(),
const SizedBox(height: 16), const SizedBox(height: 16),
// The key and the schedule on one quiet line, not a // The key and the schedule on one quiet line, not a
// label/value document. // label/value document.
@@ -136,15 +133,7 @@ class TemplateDetail extends StatelessWidget {
/// A compact button at its own width: the page's one action, never a bar /// A compact button at its own width: the page's one action, never a bar
/// spanning a wide window. /// spanning a wide window.
Widget _createButton(bool cupertino) { Widget _createButton() {
if (cupertino) {
return CupertinoButton.filled(
key: templateCreateActionKey,
sizeStyle: CupertinoButtonSize.medium,
onPressed: onCreate,
child: const Text(templateCreateActionLabel),
);
}
return FilledButton.icon( return FilledButton.icon(
key: templateCreateActionKey, key: templateCreateActionKey,
onPressed: onCreate, onPressed: onCreate,
@@ -153,13 +142,13 @@ class TemplateDetail extends StatelessWidget {
); );
} }
Widget _backRow(BuildContext context, bool cupertino) { Widget _backRow(BuildContext context) {
// Only without a bar above: the same round Back the bar would show. // Only without a bar above: the same round Back the bar would show.
final back = SegmentedPill( final back = SegmentedPill(
cupertino: cupertino, cupertino: false,
child: SegmentedBackButton( child: SegmentedBackButton(
key: templateDetailBackKey, key: templateDetailBackKey,
cupertino: cupertino, cupertino: false,
onPressed: onBack, onPressed: onBack,
), ),
); );
@@ -179,35 +168,15 @@ class TemplateDetail extends StatelessWidget {
} }
TextStyle? templateTitleStyle(BuildContext context) => TextStyle? templateTitleStyle(BuildContext context) =>
usesCupertinoHost(context) Theme.of(context).textTheme.headlineSmall;
? CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle
: Theme.of(context).textTheme.headlineSmall;
TextStyle? templateSectionStyle(BuildContext context) => TextStyle? templateSectionStyle(BuildContext context) =>
usesCupertinoHost(context) Theme.of(context).textTheme.titleMedium;
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
: Theme.of(context).textTheme.titleMedium;
TextStyle? templateBodyStyle(BuildContext context) { TextStyle? templateBodyStyle(BuildContext context) =>
if (usesCupertinoHost(context)) { Theme.of(context).textTheme.bodyMedium;
// SelectableText needs an explicit baseline when it inherits no style.
return CupertinoTheme.of(
context,
).textTheme.textStyle.copyWith(inherit: true);
}
return Theme.of(context).textTheme.bodyMedium;
}
TextStyle? templateMutedStyle(BuildContext context) { TextStyle? templateMutedStyle(BuildContext context) {
if (usesCupertinoHost(context)) {
// The list rows' secondary size, not the tab bar's 10pt caption.
// SelectableText needs an explicit baseline when it inherits no style.
return CupertinoTheme.of(context).textTheme.textStyle.copyWith(
inherit: true,
fontSize: 15,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
return theme.textTheme.bodySmall?.copyWith( return theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant, color: theme.colorScheme.onSurfaceVariant,
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/floating_bar_layout.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/layout/app_list_avatar.dart'; import '../../../ui/layout/app_list_avatar.dart';
import '../../../ui/layout/app_list_row.dart'; import '../../../ui/layout/app_list_row.dart';
import '../domain/template_entry.dart'; import '../domain/template_entry.dart';
@@ -70,13 +68,13 @@ class TemplateGallery extends StatelessWidget {
onRetry: onRetry, onRetry: onRetry,
); );
} }
return _loadingState(context); return _loadingState();
} }
if (templates.isEmpty) return _emptyState(context); if (templates.isEmpty) return _emptyState(context);
return _list(context); return _list(context);
} }
Widget _loadingState(BuildContext context) { Widget _loadingState() {
return Center( return Center(
key: templatesLoadingKey, key: templatesLoadingKey,
child: Semantics( child: Semantics(
@@ -85,9 +83,7 @@ class TemplateGallery extends StatelessWidget {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
usesCupertinoHost(context) const CircularProgressIndicator(),
? const CupertinoActivityIndicator()
: const CircularProgressIndicator(),
const SizedBox(height: 12), const SizedBox(height: 12),
const Text(_loadingMessage), const Text(_loadingMessage),
], ],
@@ -107,7 +103,6 @@ class TemplateGallery extends StatelessWidget {
} }
Widget _list(BuildContext context) { Widget _list(BuildContext context) {
final cupertino = usesCupertinoHost(context);
// The rows scroll behind the bar and the floating tab bar. // The rows scroll behind the bar and the floating tab bar.
return ListView.builder( return ListView.builder(
key: templatesGalleryKey, key: templatesGalleryKey,
@@ -118,14 +113,14 @@ class TemplateGallery extends StatelessWidget {
return templatesColumn( return templatesColumn(
AppListRow( AppListRow(
key: templateRowKey(entry.key), key: templateRowKey(entry.key),
cupertino: cupertino, cupertino: false,
divider: index < templates.length - 1, divider: index < templates.length - 1,
onTap: () => onOpen(entry.key), onTap: () => onOpen(entry.key),
leading: ExcludeSemantics( leading: ExcludeSemantics(
child: AppListAvatar.initial( child: AppListAvatar.initial(
templateDetailName(entry), templateDetailName(entry),
key: templateAvatarKey(entry.key), key: templateAvatarKey(entry.key),
color: _avatarColor(context, entry.key, cupertino), color: _avatarColor(context, entry.key),
), ),
), ),
title: Text(templateGalleryName(entry)), title: Text(templateGalleryName(entry)),
@@ -138,18 +133,9 @@ class TemplateGallery extends StatelessWidget {
/// One of the theme's accents, picked by the template key so a row keeps /// One of the theme's accents, picked by the template key so a row keeps
/// its colour across reloads (the Pipelines list's palette). /// its colour across reloads (the Pipelines list's palette).
Color _avatarColor(BuildContext context, String key, bool cupertino) { Color _avatarColor(BuildContext context, String key) {
final List<Color> colors; final scheme = Theme.of(context).colorScheme;
if (cupertino) { final colors = [scheme.primary, scheme.secondary, scheme.tertiary];
colors = [
CupertinoTheme.of(context).primaryColor,
CupertinoColors.systemIndigo.resolveFrom(context),
CupertinoColors.systemTeal.resolveFrom(context),
];
} else {
final scheme = Theme.of(context).colorScheme;
colors = [scheme.primary, scheme.secondary, scheme.tertiary];
}
final hash = key.codeUnits.fold<int>(0, (sum, unit) => sum + unit); final hash = key.codeUnits.fold<int>(0, (sum, unit) => sum + unit);
return colors[hash % colors.length]; return colors[hash % colors.length];
} }
@@ -1,8 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
const templatesErrorKey = ValueKey<String>('templates-error'); const templatesErrorKey = ValueKey<String>('templates-error');
const templatesRetryKey = ValueKey<String>('templates-retry'); const templatesRetryKey = ValueKey<String>('templates-retry');
const templatesErrorBannerKey = ValueKey<String>('templates-error-banner'); const templatesErrorBannerKey = ValueKey<String>('templates-error-banner');
@@ -36,7 +33,6 @@ class TemplatesFailureState extends StatelessWidget {
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
_retryButton( _retryButton(
context,
buttonKey: templatesRetryKey, buttonKey: templatesRetryKey,
retrying: retrying, retrying: retrying,
onRetry: onRetry, onRetry: onRetry,
@@ -76,15 +72,10 @@ class TemplatesFailureBanner extends StatelessWidget {
liveRegion: true, liveRegion: true,
child: Text( child: Text(
message, message,
style: TextStyle( style: TextStyle(color: Theme.of(context).colorScheme.error),
color: usesCupertinoHost(context)
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error,
),
), ),
), ),
_retryButton( _retryButton(
context,
buttonKey: templatesBannerRetryKey, buttonKey: templatesBannerRetryKey,
retrying: retrying, retrying: retrying,
onRetry: onRetry, onRetry: onRetry,
@@ -95,21 +86,12 @@ class TemplatesFailureBanner extends StatelessWidget {
} }
} }
Widget _retryButton( Widget _retryButton({
BuildContext context, {
required Key buttonKey, required Key buttonKey,
required bool retrying, required bool retrying,
required VoidCallback onRetry, required VoidCallback onRetry,
}) { }) {
final onPressed = retrying ? null : onRetry; final onPressed = retrying ? null : onRetry;
if (usesCupertinoHost(context)) {
return CupertinoButton(
key: buttonKey,
padding: EdgeInsets.zero,
onPressed: onPressed,
child: const Text('Retry'),
);
}
return TextButton( return TextButton(
key: buttonKey, key: buttonKey,
onPressed: onPressed, onPressed: onPressed,
@@ -2,10 +2,8 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../shell/shell_bar.dart'; import '../../../shell/shell_bar.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/adaptive/segmented_bar.dart'; import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/navigation/bar_icon_button.dart'; import '../../../ui/navigation/bar_icon_button.dart';
import '../../../ui/theme/app_theme.dart';
const templatesRefreshKey = ValueKey<String>('templates-refresh'); const templatesRefreshKey = ValueKey<String>('templates-refresh');
const templatesBackKey = ValueKey<String>('templates-back'); const templatesBackKey = ValueKey<String>('templates-back');
@@ -44,7 +42,6 @@ class TemplatesFrame extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
if (embedded) { if (embedded) {
if (ShellBar.available(context)) { if (ShellBar.available(context)) {
return ShellBar( return ShellBar(
@@ -70,11 +67,11 @@ class TemplatesFrame extends StatelessWidget {
); );
} }
final bar = SegmentedBar( final bar = SegmentedBar(
cupertino: cupertino, cupertino: false,
leading: canGoBack leading: canGoBack
? SegmentedBackButton( ? SegmentedBackButton(
key: templatesBackKey, key: templatesBackKey,
cupertino: cupertino, cupertino: false,
onPressed: onBack, onPressed: onBack,
) )
: null, : null,
@@ -84,19 +81,12 @@ class TemplatesFrame extends StatelessWidget {
); );
// The body reaches the top edge and scrolls behind the bar. // The body reaches the top edge and scrolls behind the bar.
final page = SafeArea(top: false, bottom: false, child: body); final page = SafeArea(top: false, bottom: false, child: body);
if (cupertino) {
return CupertinoPageScaffold(
// Plain list rows on the page background, like the other lists.
backgroundColor: AppColors.background,
navigationBar: bar,
child: page,
);
}
return Scaffold(extendBodyBehindAppBar: true, appBar: bar, body: page); return Scaffold(extendBodyBehindAppBar: true, appBar: bar, body: page);
} }
Widget _refreshButton() => BarIconButton( Widget _refreshButton() => BarIconButton(
key: templatesRefreshKey, key: templatesRefreshKey,
cupertino: false,
icon: Icons.refresh, icon: Icons.refresh,
cupertinoIcon: CupertinoIcons.refresh, cupertinoIcon: CupertinoIcons.refresh,
label: 'Refresh', label: 'Refresh',
+5 -37
View File
@@ -1,17 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../adaptive/host.dart'; /// The app's one search field.
import 'cupertino_web_search_field.dart';
/// The app's one search field per platform.
/// ///
/// Cupertino uses the stock [CupertinoSearchTextField]. Material uses a /// A [TextField] shaped like the stock iOS field: a stadium with a leading
/// [TextField] shaped like it: a stadium with a leading search icon, a clear /// search icon, a clear button once there is text, no underline and no
/// button once there is text, no underline and no elevation. On a page it is /// elevation. On a page it is filled with the host's raised surface; [inBar]
/// filled with the host's raised surface; [inBar] drops the fill (and the /// drops the fill because a bar's glass pill is already its background.
/// Cupertino grey) because a bar's glass pill is already its background.
class AppSearchField extends StatelessWidget { class AppSearchField extends StatelessWidget {
const AppSearchField({ const AppSearchField({
super.key, super.key,
@@ -58,32 +52,6 @@ class AppSearchField extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (cupertino ?? usesCupertinoHost(context)) {
if (kIsWeb) {
return CupertinoWebSearchField(
controller: controller,
placeholder: placeholder,
fieldKey: fieldKey,
focusNode: focusNode,
autofocus: autofocus,
inBar: inBar,
onChanged: onChanged,
onSubmitted: onSubmitted,
onCleared: _clear,
);
}
return CupertinoSearchTextField(
key: fieldKey,
controller: controller,
focusNode: focusNode,
autofocus: autofocus,
placeholder: placeholder,
backgroundColor: inBar ? const Color(0x00000000) : null,
onChanged: onChanged,
onSubmitted: onSubmitted,
onSuffixTap: _clear,
);
}
final scheme = Theme.of(context).colorScheme; final scheme = Theme.of(context).colorScheme;
const radius = BorderRadius.all(Radius.circular(28)); const radius = BorderRadius.all(Radius.circular(28));
const stadium = OutlineInputBorder( const stadium = OutlineInputBorder(
@@ -1,115 +0,0 @@
import 'package:flutter/cupertino.dart';
/// Keeps the web input's semantics stable when its clear action appears.
/// Nesting the clear button in CupertinoSearchTextField changes its merged
/// editable node into a disabled child node on web. Native sibling controls
/// retain both an enabled input and an independently accessible clear action.
class CupertinoWebSearchField extends StatefulWidget {
const CupertinoWebSearchField({
super.key,
required this.controller,
required this.placeholder,
required this.onCleared,
this.fieldKey,
this.focusNode,
this.autofocus = false,
this.inBar = false,
this.onChanged,
this.onSubmitted,
});
final TextEditingController controller;
final String placeholder;
final VoidCallback onCleared;
final Key? fieldKey;
final FocusNode? focusNode;
final bool autofocus;
final bool inBar;
final ValueChanged<String>? onChanged;
final ValueChanged<String>? onSubmitted;
@override
State<CupertinoWebSearchField> createState() =>
_CupertinoWebSearchFieldState();
}
class _CupertinoWebSearchFieldState extends State<CupertinoWebSearchField> {
FocusNode? _localFocus;
FocusNode get _focus => widget.focusNode ?? (_localFocus ??= FocusNode());
void _clear() {
final focus = _focus;
// The browser can keep the old editing session focused on the semantic
// clear button after it is removed. This explicit action ends that edit,
// then hands focus back after layout; ordinary query changes never refocus.
focus.unfocus();
widget.onCleared();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted || !identical(focus, _focus)) return;
final current = FocusManager.instance.primaryFocus;
if (current == null || current == focus || current is FocusScopeNode) {
focus.requestFocus();
}
});
WidgetsBinding.instance.ensureVisualUpdate();
}
@override
void dispose() {
_localFocus?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => DecoratedBox(
decoration: BoxDecoration(
color: widget.inBar
? const Color(0x00000000)
: CupertinoColors.tertiarySystemFill.resolveFrom(context),
borderRadius: BorderRadius.circular(9),
),
child: ConstrainedBox(
constraints: const BoxConstraints(
minHeight: kMinInteractiveDimensionCupertino,
),
child: TextFieldTapRegion(
child: Row(
children: [
Expanded(
child: CupertinoSearchTextField(
key: widget.fieldKey,
controller: widget.controller,
focusNode: _focus,
autofocus: widget.autofocus,
placeholder: widget.placeholder,
backgroundColor: const Color(0x00000000),
suffixMode: OverlayVisibilityMode.never,
onChanged: widget.onChanged,
onSubmitted: widget.onSubmitted,
),
),
ValueListenableBuilder<TextEditingValue>(
valueListenable: widget.controller,
builder: (context, value, _) => value.text.isEmpty
? const SizedBox.shrink()
: CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 8),
onPressed: _clear,
child: Icon(
CupertinoIcons.clear_thick_circled,
color: CupertinoColors.secondaryLabel.resolveFrom(
context,
),
size: 20,
semanticLabel: CupertinoLocalizations.of(
context,
).clearButtonLabel,
),
),
),
],
),
),
),
);
}
@@ -1,6 +1,3 @@
import 'dart:math' as math;
import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
@@ -21,10 +18,9 @@ abstract interface class ContainerTransformGestureRoute
void endSwipeBack(double velocity); void endSwipeBack(double velocity);
} }
/// The back gestures of a page that shrinks into its item: on a Cupertino /// The back gestures of a page that shrinks into its item: the system's
/// host the native swipe from the start edge; on Android the system's /// predictive back drives the page's own animation, so the shrink follows
/// predictive back. Either one drives the page's own animation, so the /// the finger, and releasing commits or cancels it.
/// shrink follows the finger, and releasing commits or cancels it.
class ContainerTransformBackGestures extends StatelessWidget { class ContainerTransformBackGestures extends StatelessWidget {
const ContainerTransformBackGestures({ const ContainerTransformBackGestures({
super.key, super.key,
@@ -38,96 +34,8 @@ class ContainerTransformBackGestures extends StatelessWidget {
final Widget child; final Widget child;
@override @override
Widget build(BuildContext context) => cupertino Widget build(BuildContext context) =>
? _EdgeSwipeBack(route: route, child: child) _PredictiveBack(route: route, child: child);
: _PredictiveBack(route: route, child: child);
}
/// The width of the start edge that takes a swipe back, as in iOS.
const double _edgeWidth = 20;
class _EdgeSwipeBack extends StatefulWidget {
const _EdgeSwipeBack({required this.route, required this.child});
final ContainerTransformGestureRoute route;
final Widget child;
@override
State<_EdgeSwipeBack> createState() => _EdgeSwipeBackState();
}
class _EdgeSwipeBackState extends State<_EdgeSwipeBack> {
late final HorizontalDragGestureRecognizer _recognizer =
HorizontalDragGestureRecognizer(debugOwner: this)
..onStart = _start
..onUpdate = _update
..onEnd = _end
..onCancel = _cancel;
bool _dragging = false;
@override
void dispose() {
_recognizer.dispose();
if (_dragging) widget.route.endSwipeBack(0);
super.dispose();
}
double _logical(double value) =>
Directionality.of(context) == TextDirection.rtl ? -value : value;
void _start(DragStartDetails details) {
_dragging = true;
widget.route.startSwipeBack();
}
void _update(DragUpdateDetails details) {
if (!_dragging) return;
widget.route.updateSwipeBack(
_logical(details.primaryDelta! / context.size!.width),
);
}
void _end(DragEndDetails details) {
if (!_dragging) return;
_dragging = false;
widget.route.endSwipeBack(
_logical(details.velocity.pixelsPerSecond.dx / context.size!.width),
);
}
void _cancel() {
if (!_dragging) return;
_dragging = false;
widget.route.endSwipeBack(0);
}
@override
Widget build(BuildContext context) {
final padding = MediaQuery.paddingOf(context);
final notch = Directionality.of(context) == TextDirection.rtl
? padding.right
: padding.left;
return Stack(
fit: StackFit.passthrough,
children: [
widget.child,
PositionedDirectional(
start: 0,
top: 0,
bottom: 0,
width: math.max(notch, _edgeWidth),
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
if (widget.route.backGestureEnabled) {
_recognizer.addPointer(event);
}
},
),
),
],
);
}
} }
/// Forwards Android's predictive back to the page, as the stock Material /// Forwards Android's predictive back to the page, as the stock Material
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'container_transform_flight.dart'; import 'container_transform_flight.dart';
@@ -15,10 +14,9 @@ const Duration _droppedSwipeDuration = Duration(milliseconds: 350);
/// [link] resolves the item each time the page animates, so closing after /// [link] resolves the item each time the page animates, so closing after
/// another item took the page shrinks into that one. When the item is not on /// another item took the page shrinks into that one. When the item is not on
/// screen, or the system asks for reduced motion, the page fades instead. /// screen, or the system asks for reduced motion, the page fades instead.
/// The list behind stays put. A Cupertino host keeps the native swipe back /// The list behind stays put. Android's predictive back drives the shrink
/// from the start edge and Android its predictive back; both drive the /// with the finger. The animation-speed setting scales every duration
/// shrink with the finger. The animation-speed setting scales every /// through the scheduler clock.
/// duration through the scheduler clock.
class ContainerTransformPageRoute<T> extends PageRoute<T> class ContainerTransformPageRoute<T> extends PageRoute<T>
implements ContainerTransformGestureRoute { implements ContainerTransformGestureRoute {
ContainerTransformPageRoute({ ContainerTransformPageRoute({
@@ -81,33 +79,16 @@ class ContainerTransformPageRoute<T> extends PageRoute<T>
Widget child, Widget child,
) { ) {
final reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false; final reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
final pageColor = cupertino final page = ContainerTransformFlight(
? CupertinoDynamicColor.resolve(
CupertinoTheme.of(context).scaffoldBackgroundColor,
context,
)
: Theme.of(context).scaffoldBackgroundColor;
Widget page = ContainerTransformFlight(
animation: animation, animation: animation,
origin: reduced ? null : link.resolve, origin: reduced ? null : link.resolve,
closing: () => closing: () =>
animation.status == AnimationStatus.reverse || popGestureInProgress, animation.status == AnimationStatus.reverse || popGestureInProgress,
tracking: () => popGestureInProgress, tracking: () => popGestureInProgress,
pageColor: pageColor, pageColor: Theme.of(context).scaffoldBackgroundColor,
scrimColor: cupertino scrimColor: Theme.of(context).colorScheme.scrim,
? CupertinoColors.black
: Theme.of(context).colorScheme.scrim,
child: child, child: child,
); );
if (cupertino) {
// A page pushed over this one keeps the native parallax.
page = CupertinoPageTransition(
primaryRouteAnimation: kAlwaysCompleteAnimation,
secondaryRouteAnimation: secondaryAnimation,
linearTransition: popGestureInProgress,
child: page,
);
}
return ContainerTransformBackGestures( return ContainerTransformBackGestures(
route: this, route: this,
cupertino: cupertino, cupertino: cupertino,
+7 -30
View File
@@ -1,14 +1,10 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// One icon action of a segmented bar's actions pill (or any toolbar row). /// One icon action of a segmented bar's actions pill (or any toolbar row).
/// ///
/// Every action gets the platform's whole touch target and no extra padding, /// Every action gets the platform's whole touch target and no extra padding,
/// so a row of them is evenly spaced and the last one never touches the /// so a row of them is evenly spaced and the last one never touches the
/// pill's edge: Material's [IconButton] (48dp, with its tooltip), Cupertino's /// pill's edge: Material's [IconButton] (48dp, with its tooltip).
/// [CupertinoButton] at [kMinInteractiveDimensionCupertino] (44pt) square.
/// While [busy] the action shows the platform's activity indicator in the /// While [busy] the action shows the platform's activity indicator in the
/// same box and takes no taps. /// same box and takes no taps.
class BarIconButton extends StatelessWidget { class BarIconButton extends StatelessWidget {
@@ -43,40 +39,21 @@ class BarIconButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final native = cupertino ?? usesCupertinoHost(context);
if (busy) { if (busy) {
final side = native
? kMinInteractiveDimensionCupertino
: kMinInteractiveDimension;
return Semantics( return Semantics(
label: busyLabel ?? label, label: busyLabel ?? label,
liveRegion: true, liveRegion: true,
child: SizedBox.square( child: const SizedBox.square(
dimension: side, dimension: kMinInteractiveDimension,
child: Center( child: Center(
child: native child: SizedBox.square(
? const CupertinoActivityIndicator() dimension: 20,
: const SizedBox.square( child: CircularProgressIndicator(strokeWidth: 2),
dimension: 20, ),
child: CircularProgressIndicator(strokeWidth: 2),
),
), ),
), ),
); );
} }
if (native) {
return Semantics(
button: true,
label: label,
excludeSemantics: true,
child: CupertinoButton(
padding: EdgeInsets.zero,
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
onPressed: onPressed,
child: Icon(cupertinoIcon),
),
);
}
return IconButton( return IconButton(
tooltip: label, tooltip: label,
isSelected: selected, isSelected: selected,
+1 -24
View File
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../adaptive/glass_bar.dart'; import '../adaptive/glass_bar.dart';
import '../adaptive/host.dart';
/// Previous and next as chevrons in one row at the bottom right, with the /// Previous and next as chevrons in one row at the bottom right, with the
/// position before them (`2 of 5`). Each chevron is named for assistive /// position before them (`2 of 5`). Each chevron is named for assistive
@@ -34,33 +32,12 @@ class ChevronPager extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
Widget chevron({ Widget chevron({
required Key? key, required Key? key,
required bool previous, required bool previous,
required String label, required String label,
required VoidCallback? onPressed, required VoidCallback? onPressed,
}) { }) {
if (cupertino) {
return Semantics(
button: true,
enabled: onPressed != null,
label: label,
excludeSemantics: true,
child: CupertinoButton(
key: key,
padding: EdgeInsets.zero,
minimumSize: GlassBarMetrics.cupertinoMinimumSize(),
onPressed: onPressed,
child: Icon(
previous
? CupertinoIcons.chevron_left
: CupertinoIcons.chevron_right,
size: GlassBarMetrics.iconSize(true),
),
),
);
}
return IconButton( return IconButton(
key: key, key: key,
tooltip: label, tooltip: label,
@@ -77,7 +54,7 @@ class ChevronPager extends StatelessWidget {
// The surrounding glass bar supplies the edge gap ([GlassBarMetrics]). // The surrounding glass bar supplies the edge gap ([GlassBarMetrics]).
// The position keeps an icon's inset on each side, so it sits as far from // The position keeps an icon's inset on each side, so it sits as far from
// the bar's edge and from the chevrons as an icon would. // the bar's edge and from the chevrons as an icon would.
final inset = GlassBarMetrics.iconInset(cupertino); final inset = GlassBarMetrics.iconInset(false);
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
-16
View File
@@ -37,7 +37,6 @@ ThemeData appLightTheme({String? fontFamily}) {
colorScheme: scheme, colorScheme: scheme,
pageTransitionsTheme: appPageTransitions, pageTransitionsTheme: appPageTransitions,
fontFamily: fontFamily, fontFamily: fontFamily,
cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme),
); );
} }
@@ -110,7 +109,6 @@ ThemeData appDarkTheme({String? fontFamily}) {
scaffoldBackgroundColor: scheme.surface, scaffoldBackgroundColor: scheme.surface,
pageTransitionsTheme: appPageTransitions, pageTransitionsTheme: appPageTransitions,
fontFamily: fontFamily, fontFamily: fontFamily,
cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme),
); );
} }
@@ -146,17 +144,3 @@ CupertinoTextThemeData appCupertinoTextTheme(
dateTimePickerTextStyle: face(base.dateTimePickerTextStyle), dateTimePickerTextStyle: face(base.dateTimePickerTextStyle),
); );
} }
/// Cupertino widgets on a Material host derive their theme from Material's;
/// only the family is overridden, with Material's primary for actions.
NoDefaultCupertinoThemeData? _cupertinoOverride(
String? fontFamily,
ColorScheme scheme,
) => fontFamily == null
? null
: CupertinoThemeData(
textTheme: appCupertinoTextTheme(
fontFamily,
primaryColor: scheme.primary,
),
);
@@ -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,66 @@ void main() {
channel: channel, channel: channel,
client: PipelinesClient(channelFactory: (_) => channel), client: PipelinesClient(channelFactory: (_) => channel),
provider: provider, provider: provider,
cupertino: cupertino, cupertino: false,
); );
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();
});
}
} }
+85 -91
View File
@@ -30,102 +30,96 @@ 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), cupertino: false,
provider: provider, );
cupertino: cupertino, await replyRunList(tester, channel);
);
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();
});
} }
@@ -801,67 +801,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,10 +1,9 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/templates_destination.dart'; import 'package:pipelines_app/application/templates_destination.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/templates/screen.dart'; import 'package:pipelines_app/features/templates/screen.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 '../core/transport/pipelines_client_test.dart' show FakeChannel; import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../features/pipelines/fixtures.dart'; import '../features/pipelines/fixtures.dart';
@@ -13,81 +12,55 @@ import 'templates_wiring_test.dart' show openSettings, openTemplates, pumpApp;
/// The app-level Templates page: one bar (Back + Refresh), the gallery and an /// The app-level Templates page: one bar (Back + Refresh), the gallery and an
/// open template reach the top edge, start below the bar at rest and scroll /// open template reach the top edge, start below the bar at rest and scroll
/// behind it. Both hosts draw the shared list rows on the page background. /// behind it. The shared list rows sit on the page background.
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('the gallery and detail scroll behind the bar', (tester) async {
final host = cupertino ? 'Cupertino' : 'Material'; final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
testWidgets('$host: the gallery and detail scroll behind the bar', ( final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
);
addTearDown(provider.dispose);
await pumpApp(
tester, tester,
) async { channel: channel,
final channel = FakeChannel()..readyCompleter.complete(); client: client,
final client = PipelinesClient(channelFactory: (_) => channel); provider: provider,
final provider = PlatformRouteInformationProvider( cupertino: false,
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')), );
); await replyPipelines(tester, channel, PipelineFixture());
addTearDown(provider.dispose); await openSettings(tester, channel, provider);
await pumpApp( await openTemplates(tester, channel, provider);
tester, await tester.pumpAndSettle();
channel: channel,
client: client,
provider: provider,
cupertino: cupertino,
);
await replyPipelines(tester, channel, PipelineFixture());
await openSettings(tester, channel, provider);
await openTemplates(tester, channel, provider);
await tester.pumpAndSettle();
final bar = find.ancestor( final bar = find.ancestor(
of: find.byKey(templatesPageBackKey), of: find.byKey(templatesPageBackKey),
matching: find.byType(SegmentedBar), matching: find.byType(SegmentedBar),
); );
final barBottom = tester.getRect(bar).bottom; final barBottom = tester.getRect(bar).bottom;
// One bar: Back and Refresh are its pieces. // One bar: Back and Refresh are its pieces.
expect( expect(
find.descendant(of: bar, matching: find.byKey(templatesRefreshKey)), find.descendant(of: bar, matching: find.byKey(templatesRefreshKey)),
findsOneWidget, findsOneWidget,
); );
final gallery = find.byKey(templatesGalleryKey); final gallery = find.byKey(templatesGalleryKey);
expect(tester.getTopLeft(gallery).dy, 0); expect(tester.getTopLeft(gallery).dy, 0);
final row = find.byKey(templateRowKey('release')); final row = find.byKey(templateRowKey('release'));
expect(tester.getTopLeft(row).dy, greaterThanOrEqualTo(barBottom - 8)); expect(tester.getTopLeft(row).dy, greaterThanOrEqualTo(barBottom - 8));
// Scrolling moves the row up behind the bar. // Scrolling moves the row up behind the bar.
final before = tester.getTopLeft(row).dy; final before = tester.getTopLeft(row).dy;
await tester.drag(gallery, const Offset(0, -40)); await tester.drag(gallery, const Offset(0, -40));
await tester.pump(); await tester.pump();
expect(tester.getTopLeft(row).dy, lessThanOrEqualTo(before)); expect(tester.getTopLeft(row).dy, lessThanOrEqualTo(before));
if (cupertino) { await tester.tap(row);
final scaffold = tester.widget<CupertinoPageScaffold>( await tester.pumpAndSettle();
find final detail = find.byKey(templateDetailKey);
.ancestor( expect(tester.getTopLeft(detail).dy, 0);
of: gallery, expect(
matching: find.byType(CupertinoPageScaffold), tester.getTopLeft(find.byKey(templateCreateActionKey)).dy,
) greaterThanOrEqualTo(barBottom - 8),
.first, );
); });
// Plain shared rows on the page background, like the other lists.
expect(scaffold.backgroundColor, AppColors.background);
expect(
find.descendant(
of: gallery,
matching: find.byType(CupertinoListSection),
),
findsNothing,
);
}
await tester.tap(row);
await tester.pumpAndSettle();
final detail = find.byKey(templateDetailKey);
expect(tester.getTopLeft(detail).dy, 0);
expect(
tester.getTopLeft(find.byKey(templateCreateActionKey)).dy,
greaterThanOrEqualTo(barBottom - 8),
);
});
}
} }
+92 -104
View File
@@ -73,16 +73,12 @@ Future<void> pumpApp(
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio); addTearDown(tester.view.resetDevicePixelRatio);
if (cupertino) {
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
}
SharedPreferences.setMockInitialValues({}); SharedPreferences.setMockInitialValues({});
await tester.pumpWidget( await tester.pumpWidget(
PipelinesApp( PipelinesApp(
server: webServer(), server: webServer(),
client: client, client: client,
cupertino: cupertino, cupertino: false,
routeInformationProvider: provider, routeInformationProvider: provider,
), ),
); );
@@ -156,114 +152,106 @@ void main() {
expect(gateway.callsOf('list_templates'), hasLength(1)); expect(gateway.callsOf('list_templates'), hasLength(1));
}); });
for (final cupertino in [false, true]) { testWidgets(
testWidgets( 'Settings opens the embedded Templates page and Back restores it',
'Settings opens the embedded Templates page and Back restores it ' (tester) async {
'($cupertino)', final fixture = PipelineFixture();
(tester) async { final channel = FakeChannel()..readyCompleter.complete();
final fixture = PipelineFixture(); var sockets = 0;
final channel = FakeChannel()..readyCompleter.complete(); final client = PipelinesClient(
var sockets = 0; channelFactory: (_) {
final client = PipelinesClient( sockets++;
channelFactory: (_) { return channel;
sockets++; },
return channel; );
}, final provider = PlatformRouteInformationProvider(
); initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
final provider = PlatformRouteInformationProvider( );
initialRouteInformation: RouteInformation( addTearDown(provider.dispose);
uri: Uri.parse('/pipelines'),
),
);
addTearDown(provider.dispose);
await pumpApp( await pumpApp(
tester, tester,
channel: channel, channel: channel,
client: client, client: client,
provider: provider, provider: provider,
cupertino: cupertino, cupertino: false,
); );
await replyPipelines(tester, channel, fixture); await replyPipelines(tester, channel, fixture);
await openSettings(tester, channel, provider); await openSettings(tester, channel, provider);
// An edit that only Settings owns must survive the Templates detour. // An edit that only Settings owns must survive the Templates detour.
await tester.enterText(find.byType(EditableText).first, 'edited url'); await tester.enterText(find.byType(EditableText).first, 'edited url');
await tester.pump(); await tester.pump();
expect(find.text('edited url'), findsOneWidget); expect(find.text('edited url'), findsOneWidget);
await openTemplates(tester, channel, provider); await openTemplates(tester, channel, provider);
final screen = tester.widget<TemplatesScreen>( final screen = tester.widget<TemplatesScreen>(
find.byType(TemplatesScreen), find.byType(TemplatesScreen),
); );
expect(screen.embedded, isTrue); expect(screen.embedded, isTrue);
expect(find.text('Release workflow'), findsOneWidget); expect(find.text('Release workflow'), findsOneWidget);
// One visible navigation bar: the Templates page owns it, the shell is // One visible navigation bar: the Templates page owns it, the shell is
// preserved underneath. // preserved underneath.
expect(find.byType(SegmentedBar), findsOneWidget); expect(find.byType(SegmentedBar), findsOneWidget);
if (cupertino) { expect(sockets, 1);
expect(find.byType(Material), findsNothing); expect(requestsOf(channel, 'list_templates'), hasLength(1));
}
expect(sockets, 1);
expect(requestsOf(channel, 'list_templates'), hasLength(1));
// Refresh sits in the bar's actions pill, not in the body. // Refresh sits in the bar's actions pill, not in the body.
Finder inBar(Key key) => find.descendant( Finder inBar(Key key) => find.descendant(
of: find.byType(SegmentedBar), of: find.byType(SegmentedBar),
matching: find.byKey(key), matching: find.byKey(key),
); );
expect(inBar(templatesRefreshKey), findsOneWidget); expect(inBar(templatesRefreshKey), findsOneWidget);
expect(find.byKey(templatesRefreshKey), findsOneWidget); expect(find.byKey(templatesRefreshKey), findsOneWidget);
expect(inBar(templatesPageBackKey), findsOneWidget); expect(inBar(templatesPageBackKey), findsOneWidget);
await tester.tap(find.byKey(templateRowKey('release'))); await tester.tap(find.byKey(templateRowKey('release')));
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
expect(find.text('Definition source'), findsOneWidget); expect(find.text('Definition source'), findsOneWidget);
// One Back at a time, in the bar's round leading piece: the open // One Back at a time, in the bar's round leading piece: the open
// template's Back replaces the page's. // template's Back replaces the page's.
expect(inBar(templateDetailBackKey), findsOneWidget); expect(inBar(templateDetailBackKey), findsOneWidget);
expect(find.byKey(templateDetailBackKey), findsOneWidget); expect(find.byKey(templateDetailBackKey), findsOneWidget);
expect(find.byKey(templatesPageBackKey), findsNothing); expect(find.byKey(templatesPageBackKey), findsNothing);
// Detail Back returns to the gallery, then the page Back restores the // Detail Back returns to the gallery, then the page Back restores the
// same Settings state. // same Settings state.
await tester.tap(find.byKey(templateDetailBackKey)); await tester.tap(find.byKey(templateDetailBackKey));
await tester.pump(); await tester.pump();
// The gallery hands the bar back to the page's Back on the next frame. // The gallery hands the bar back to the page's Back on the next frame.
await tester.pump(); await tester.pump();
await tester.tap(find.byKey(templatesPageBackKey)); await tester.tap(find.byKey(templatesPageBackKey));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(provider.value.uri.path, '/settings'); expect(provider.value.uri.path, '/settings');
expect(find.byType(TemplatesScreen), findsNothing); expect(find.byType(TemplatesScreen), findsNothing);
expect(find.byKey(SettingsKeys.templates), findsOneWidget); expect(find.byKey(SettingsKeys.templates), findsOneWidget);
await selectSettingsTopic(tester, 'Connection'); await selectSettingsTopic(tester, 'Connection');
expect(find.text('edited url'), findsOneWidget); expect(find.text('edited url'), findsOneWidget);
expect(find.text('Server URL'), findsOneWidget); expect(find.text('Server URL'), findsOneWidget);
expect(sockets, 1); expect(sockets, 1);
expect(requestsOf(channel, 'ping'), hasLength(1)); expect(requestsOf(channel, 'ping'), hasLength(1));
// Browser Back from /templates follows the same close path. // Browser Back from /templates follows the same close path.
await openTemplates(tester, channel, provider, listRead: 2); await openTemplates(tester, channel, provider, listRead: 2);
expect(find.byType(TemplatesScreen), findsOneWidget); expect(find.byType(TemplatesScreen), findsOneWidget);
await provider.didPushRouteInformation( await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/settings')), RouteInformation(uri: Uri.parse('/settings')),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(provider.value.uri.path, '/settings'); expect(provider.value.uri.path, '/settings');
expect(find.byType(TemplatesScreen), findsNothing); expect(find.byType(TemplatesScreen), findsNothing);
expect(find.byKey(SettingsKeys.templates), findsOneWidget); expect(find.byKey(SettingsKeys.templates), findsOneWidget);
await selectSettingsTopic(tester, 'Connection'); await selectSettingsTopic(tester, 'Connection');
expect(find.text('edited url'), findsOneWidget); expect(find.text('edited url'), findsOneWidget);
expect(requestsOf(channel, 'list_templates'), hasLength(2)); expect(requestsOf(channel, 'list_templates'), hasLength(2));
expect(sockets, 1); expect(sockets, 1);
await tester.pumpWidget(const SizedBox.shrink()); await tester.pumpWidget(const SizedBox.shrink());
await tester.pump(); await tester.pump();
}, },
); );
}
testWidgets('an accepted create re-reads Pipelines exactly once', ( testWidgets('an accepted create re-reads Pipelines exactly once', (
tester, tester,
@@ -294,59 +294,46 @@ void main() {
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}); });
for (final cupertino in [false, true]) { testWidgets('a file opens as a page that steps to the previous and next '
testWidgets('a file opens as a page that steps to the previous and next ' 'file', (tester) async {
'file (${cupertino ? 'cupertino' : 'material'})', (tester) 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); final viewer = ChangesViewer(
final viewer = ChangesViewer( steps: [
steps: [ stepFixture(
stepFixture( fileChanges: captureFixture(
fileChanges: captureFixture( files: [
files: [ fileChangeFixture(path: 'lib/first.dart', patch: multiHunkPatch),
fileChangeFixture( fileChangeFixture(path: 'lib/second.dart', patch: multiHunkPatch),
path: 'lib/first.dart', ],
patch: multiHunkPatch,
),
fileChangeFixture(
path: 'lib/second.dart',
patch: multiHunkPatch,
),
],
),
), ),
], ),
); ],
await tester.pumpWidget( );
cupertino ? cupertinoHost(viewer) : materialHost(viewer), await tester.pumpWidget(materialHost(viewer));
); await tester.tap(find.byKey(const ValueKey('change-1-lib/first.dart')));
await tester.tap(find.byKey(const ValueKey('change-1-lib/first.dart'))); await tester.pumpAndSettle();
await tester.pumpAndSettle();
Finder control(String label) => Finder control(String label) => find.byTooltip(label);
cupertino ? find.bySemanticsLabel(label) : find.byTooltip(label); expect(find.byType(FileDiffPage), findsOneWidget);
expect(find.byType(FileDiffPage), findsOneWidget); expect(find.text('first.dart'), findsOneWidget);
expect(find.text('first.dart'), findsOneWidget); expect(find.text('1 of 2'), findsOneWidget);
expect(find.text('1 of 2'), findsOneWidget); // The pager sits at the bottom right.
// The pager sits at the bottom right. final pager = tester.getRect(find.byKey(const ValueKey('file-diff-pager')));
final pager = tester.getRect( expect(pager.bottom, greaterThan(844 - 120));
find.byKey(const ValueKey('file-diff-pager')), final next = tester.getRect(control('Next file'));
); expect(next.right, greaterThan(390 - 80));
expect(pager.bottom, greaterThan(844 - 120));
final next = tester.getRect(control('Next file'));
expect(next.right, greaterThan(390 - 80));
await tester.tap(control('Next file')); await tester.tap(control('Next file'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('second.dart'), findsOneWidget); expect(find.text('second.dart'), findsOneWidget);
expect(find.text('2 of 2'), findsOneWidget); expect(find.text('2 of 2'), findsOneWidget);
await tester.tap(control('Previous file')); await tester.tap(control('Previous file'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('first.dart'), findsOneWidget); expect(find.text('first.dart'), findsOneWidget);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}); });
}
final diffFile = FileChange( final diffFile = FileChange(
path: 'lib/feature.dart', path: 'lib/feature.dart',
@@ -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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -85,33 +84,28 @@ void main() {
expect(next.bottom, greaterThan(844 - 80)); expect(next.bottom, greaterThan(844 - 80));
}); });
for (final host in ['Material', 'Cupertino']) { for (final size in [
for (final size in [ const Size(390, 844),
const Size(390, 844), const Size(880, 1000),
const Size(880, 1000), const Size(1100, 800),
const Size(1100, 800), ]) {
]) { testWidgets('Material pager clears an inherited stacked bar at $size', (
testWidgets('$host pager clears an inherited stacked bar at $size', ( tester,
tester, ) async {
) 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); final child = ChangesViewer(steps: twoVisitRun());
final child = ChangesViewer(steps: twoVisitRun()); await tester.pumpWidget(
final hosted = host == 'Material' MediaQuery(
? materialHost(child) data: const MediaQueryData(padding: EdgeInsets.only(bottom: 120)),
: cupertinoHost(child); child: materialHost(child),
await tester.pumpWidget( ),
MediaQuery( );
data: const MediaQueryData(padding: EdgeInsets.only(bottom: 120)), await tester.pump();
child: hosted, final pager = tester.getRect(find.byKey(ChangesVisitPager.nextKey));
), expect(pager.bottom, lessThanOrEqualTo(size.height - 120));
); });
await tester.pump();
final pager = tester.getRect(find.byKey(ChangesVisitPager.nextKey));
expect(pager.bottom, lessThanOrEqualTo(size.height - 120));
});
}
} }
testWidgets('paging stops at both ends instead of wrapping', (tester) async { testWidgets('paging stops at both ends instead of wrapping', (tester) async {
@@ -220,31 +214,4 @@ void main() {
expect(find.text('Visit 1 · completed'), findsOneWidget); expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('lib/c.dart'), findsOneWidget); expect(find.text('lib/c.dart'), findsOneWidget);
}); });
testWidgets('Cupertino pages with native buttons at both ends', (
tester,
) async {
await tester.pumpWidget(cupertinoHost(ChangesViewer(steps: twoVisitRun())));
final previous = tester.widget<CupertinoButton>(
find.byKey(ChangesVisitPager.previousKey),
);
final next = tester.widget<CupertinoButton>(
find.byKey(ChangesVisitPager.nextKey),
);
expect(previous.onPressed, isNull);
expect(next.onPressed, isNotNull);
expect(find.byKey(ChangesVisitPager.previousKey), findsOneWidget);
expect(find.byKey(ChangesVisitPager.nextKey), findsOneWidget);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('reviewer'), findsNothing);
expect(
tester
.widget<CupertinoButton>(find.byKey(ChangesVisitPager.nextKey))
.onPressed,
isNull,
);
});
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart'; import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -164,95 +163,27 @@ void main() {
expect(clamped, lessThan(panned)); expect(clamped, lessThan(panned));
}); });
testWidgets('320px at 2x opens and closes on the dark Cupertino host', ( testWidgets('expanded Fit is an activatable labelled button', (tester) async {
tester,
) async {
tester.view.physicalSize = const Size(320, 700);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final picked = <String>[];
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( _materialHost(
theme: const CupertinoThemeData(brightness: Brightness.dark), graph: linearGraph(),
home: CupertinoPageScaffold( selected: 'build',
child: Builder( onSelected: (_) {},
builder: (context) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: DefinitionGraphView(
graph: linearGraph(),
selectedStage: 'build',
onSelected: picked.add,
),
),
),
),
), ),
); );
await _settle(tester); await _settle(tester);
final inline = _inlineTransform(tester);
final inlineMatrix = Matrix4.copy(inline.value);
await tester.tap(find.byKey(const Key('graph-expand'))); await tester.tap(find.byKey(const Key('graph-expand')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byType(GraphExpandedView), findsOneWidget);
final fit = tester
.getSemantics(_inExpanded(find.byKey(const Key('graph-fit'))))
.getSemanticsData();
expect(fit.label, graphFitLabel);
expect(fit.flagsCollection.isButton, isTrue);
expect( expect(
_inExpanded(find.byType(CupertinoNavigationBarBackButton)), fit.hasAction(SemanticsAction.tap),
findsOneWidget,
);
expect(_inExpanded(find.byKey(const Key('graph-fit'))), findsOneWidget);
expect(
tester.widget<GraphStageNode>(_inExpanded(_node('build'))).selected,
isTrue, isTrue,
reason: 'Fit must expose its tap action on the labelled node',
); );
expect(tester.takeException(), isNull);
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
await tester.pumpAndSettle();
expect(find.byType(GraphExpandedView), findsNothing);
expect(tester.widget<GraphStageNode>(_node('build')).selected, isTrue);
expect(inline.value.storage, orderedEquals(inlineMatrix.storage));
expect(picked, isEmpty);
expect(tester.takeException(), isNull);
});
testWidgets('expanded Fit is an activatable labelled button on both hosts', (
tester,
) async {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(
child: DefinitionGraphView(
graph: linearGraph(),
selectedStage: 'build',
onSelected: (_) {},
),
),
)
: _materialHost(
graph: linearGraph(),
selected: 'build',
onSelected: (_) {},
),
);
await _settle(tester);
await tester.tap(find.byKey(const Key('graph-expand')));
await tester.pumpAndSettle();
final fit = tester
.getSemantics(_inExpanded(find.byKey(const Key('graph-fit'))))
.getSemanticsData();
expect(fit.label, graphFitLabel, reason: '$host Fit must be labelled');
expect(fit.flagsCollection.isButton, isTrue);
expect(
fit.hasAction(SemanticsAction.tap),
isTrue,
reason: '$host Fit must expose its tap action on the labelled node',
);
}
}); });
} }
@@ -7,101 +7,79 @@ import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'graph_viewport_fixtures.dart'; import 'graph_viewport_fixtures.dart';
void main() { void main() {
testWidgets('Fit and Expand stay labelled, activatable buttons on both hosts', ( testWidgets('Fit and Expand stay labelled, activatable buttons', (
tester, tester,
) async { ) async {
for (final cupertino in [false, true]) { final controller = GraphViewportController();
final host = cupertino ? 'cupertino' : 'material'; addTearDown(controller.dispose);
final controller = GraphViewportController(); var expands = 0;
addTearDown(controller.dispose); await tester.pumpWidget(
var expands = 0; viewportHost(
await tester.pumpWidget( controller: controller,
viewportHost( child: viewportTargets([]),
controller: controller, onExpand: () => expands += 1,
child: viewportTargets([]), ),
cupertino: cupertino, );
onExpand: () => expands += 1, await settleViewport(tester);
), final fitted = controller.snapshot;
); expect(
await settleViewport(tester); find.ancestor(
final fitted = controller.snapshot; of: find.byKey(const Key('graph-fit')),
expect( matching: find.byType(GlassPill),
find.ancestor( ),
of: find.byKey(const Key('graph-fit')), findsOneWidget,
matching: find.byType(GlassPill), );
),
findsOneWidget,
);
for (final control in viewportControls().entries) { for (final control in viewportControls().entries) {
final node = tester.getSemantics(find.byKey(control.key)); final node = tester.getSemantics(find.byKey(control.key));
final data = node.getSemanticsData(); final data = node.getSemanticsData();
expect( expect(data.label, control.value);
data.label, expect(data.flagsCollection.isButton, isTrue);
control.value, // A labelled button with no action is unusable with a screen reader;
reason: '$host ${control.key} must have the web name', // this is the regression the excluded-button wrapper introduced.
); expect(data.hasAction(SemanticsAction.tap), isTrue);
expect(
data.flagsCollection.isButton,
isTrue,
reason: '$host ${control.key} must be announced as a button',
);
// A labelled button with no action is unusable with VoiceOver/TalkBack;
// this is the regression the excluded-button wrapper introduced.
expect(
data.hasAction(SemanticsAction.tap),
isTrue,
reason: '$host ${control.key} must expose a tap action',
);
}
// The exposed action must run the real callback, not just be announced.
await pinchViewport(tester, const Offset(200, 150), 2);
await tester.pumpAndSettle();
expect(controller.snapshot, isNot(fitted));
performViewportTap(tester, find.byKey(const Key('graph-fit')));
await tester.pump();
expect(controller.scale, closeTo(fitted.scale, 1e-9));
performViewportTap(tester, find.byKey(const Key('graph-expand')));
await tester.pump();
expect(expands, 1, reason: '$host Expand must activate');
} }
// The exposed action must run the real callback, not just be announced.
await pinchViewport(tester, const Offset(200, 150), 2);
await tester.pumpAndSettle();
expect(controller.snapshot, isNot(fitted));
performViewportTap(tester, find.byKey(const Key('graph-fit')));
await tester.pump();
expect(controller.scale, closeTo(fitted.scale, 1e-9));
performViewportTap(tester, find.byKey(const Key('graph-expand')));
await tester.pump();
expect(expands, 1);
}); });
testWidgets('320px at 2x keeps native controls and gestures on both hosts', ( testWidgets('320px at 2x keeps native controls and gestures', (tester) async {
tester, final controller = GraphViewportController();
) async { addTearDown(controller.dispose);
for (final cupertino in [false, true]) { await tester.pumpWidget(
final controller = GraphViewportController(); viewportHost(
addTearDown(controller.dispose); controller: controller,
await tester.pumpWidget( child: viewportTargets([]),
viewportHost( textScale: 2,
controller: controller, viewport: const Size(320, 300),
child: viewportTargets([]), onExpand: () {},
cupertino: cupertino, ),
dark: cupertino, );
textScale: 2, await settleViewport(tester);
viewport: const Size(320, 300), expect(find.byKey(const Key('graph-fit')), findsOneWidget);
onExpand: () {}, expect(find.byKey(const Key('graph-expand')), findsOneWidget);
), expect(tester.takeException(), isNull);
);
await settleViewport(tester);
expect(find.byKey(const Key('graph-fit')), findsOneWidget);
expect(find.byKey(const Key('graph-expand')), findsOneWidget);
expect(tester.takeException(), isNull);
final before = controller.offset; final before = controller.offset;
await dragViewport( await dragViewport(
tester, tester,
find.byKey(const Key('graph-viewport')), find.byKey(const Key('graph-viewport')),
const Offset(-30, -10), const Offset(-30, -10),
); );
expect(controller.offset, isNot(before)); expect(controller.offset, isNot(before));
await pinchViewport(tester, const Offset(160, 150), 2); await pinchViewport(tester, const Offset(160, 150), 2);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.scale, greaterThan(0.3)); expect(controller.scale, greaterThan(0.3));
expect(tester.takeException(), isNull); 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/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -48,7 +47,6 @@ Widget viewportHost({
required GraphViewportController controller, required GraphViewportController controller,
required Widget child, required Widget child,
VoidCallback? onExpand, VoidCallback? onExpand,
bool cupertino = false,
bool dark = false, bool dark = false,
double textScale = 1, double textScale = 1,
Size viewport = defaultViewportSize, Size viewport = defaultViewportSize,
@@ -65,14 +63,6 @@ Widget viewportHost({
), ),
), ),
); );
if (cupertino) {
return CupertinoApp(
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
home: CupertinoPageScaffold(child: Center(child: graph)),
);
}
return MaterialApp( return MaterialApp(
theme: dark ? ThemeData.dark() : ThemeData.light(), theme: dark ? ThemeData.dark() : ThemeData.light(),
home: Scaffold(body: Center(child: graph)), home: Scaffold(body: Center(child: graph)),
@@ -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';
@@ -57,21 +56,6 @@ Widget _materialHost(
); );
} }
Widget _cupertinoHost(JsonMap graph, {ValueChanged<String>? onSelected}) {
return CupertinoApp(
home: CupertinoPageScaffold(
child: SizedBox(
width: 900,
height: 700,
child: DefinitionGraphView(
graph: graph,
onSelected: onSelected ?? (_) {},
),
),
),
);
}
/// Settles the two-frame measure-then-place contract. /// Settles the two-frame measure-then-place contract.
Future<void> _settle(WidgetTester tester) async { Future<void> _settle(WidgetTester tester) async {
await tester.pump(); await tester.pump();
@@ -315,27 +299,4 @@ void main() {
expect(find.byType(GraphStageNode), findsNothing); expect(find.byType(GraphStageNode), findsNothing);
expect(find.byType(InteractiveViewer), findsNothing); expect(find.byType(InteractiveViewer), findsNothing);
}); });
testWidgets('cupertino host composes native buttons and keeps identity', (
tester,
) async {
final picked = <String>[];
await tester.pumpWidget(
_cupertinoHost(linearGraph(), onSelected: picked.add),
);
await _settle(tester);
expect(
find.descendant(
of: find.byType(GraphStageNode),
matching: find.byType(CupertinoButton),
),
findsNWidgets(5),
);
expect(find.byType(Card), findsNothing);
_expectNoOverlaps(tester);
await _tapNode(tester, '#failure');
expect(picked, ['#failure']);
});
} }
@@ -1,7 +1,6 @@
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -21,10 +20,6 @@ Widget _material(Widget child) => MaterialApp(
home: Scaffold(body: Center(child: child)), home: Scaffold(body: Center(child: child)),
); );
Widget _cupertino(Widget child) => CupertinoApp(
home: CupertinoPageScaffold(child: Center(child: child)),
);
/// The node centred on an opaque page, inside its own repaint boundary so the /// The node centred on an opaque page, inside its own repaint boundary so the
/// painted result can be read back as pixels. /// painted result can be read back as pixels.
Widget _framed(Key key, Widget Function(Widget) wrap, Widget child) => wrap( Widget _framed(Key key, Widget Function(Widget) wrap, Widget child) => wrap(
@@ -153,58 +148,27 @@ void main() {
} }
}); });
testWidgets('unselected cupertino node paints a visible container', ( testWidgets('selected state changes the painted surface', (tester) async {
tester, final colors = <bool, Color>{};
) async { for (final selected in [false, true]) {
final key = GlobalKey(); final key = GlobalKey();
await tester.pumpWidget( await tester.pumpWidget(
_framed( _framed(
key, key,
_cupertino, _material,
GraphStageNode(node: _stage, onSelected: (_) {}), GraphStageNode(node: _stage, selected: selected, onSelected: (_) {}),
), ),
);
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(CupertinoButton));
// Just inside the left edge of the control, clear of the label's inset.
final body = shot.at(rect.centerLeft + const Offset(4, 0));
final page = shot.at(const Offset(4, 4));
expect(
_distance(body, page),
greaterThan(24),
reason: 'an unselected cupertino node needs its own visible surface',
);
});
testWidgets('selected state changes the painted surface in both hosts', (
tester,
) async {
for (final wrap in [_material, _cupertino]) {
final colors = <bool, Color>{};
for (final selected in [false, true]) {
final key = GlobalKey();
await tester.pumpWidget(
_framed(
key,
wrap,
GraphStageNode(
node: _stage,
selected: selected,
onSelected: (_) {},
),
),
);
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(GraphStageNode));
colors[selected] = shot.at(rect.centerLeft + const Offset(4, 0));
}
expect(
_distance(colors[false]!, colors[true]!),
greaterThan(16),
reason:
'selection must be visible, not only announced: the surface fill '
'and the outlined border change together',
); );
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(GraphStageNode));
colors[selected] = shot.at(rect.centerLeft + const Offset(4, 0));
} }
expect(
_distance(colors[false]!, colors[true]!),
greaterThan(16),
reason:
'selection must be visible, not only announced: the surface fill '
'and the outlined border change together',
);
}); });
} }
@@ -1,6 +1,5 @@
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/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@@ -17,10 +16,6 @@ Widget _material(Widget child) => MaterialApp(
home: Scaffold(body: Center(child: child)), home: Scaffold(body: Center(child: child)),
); );
Widget _cupertino(Widget child) => CupertinoApp(
home: CupertinoPageScaffold(child: Center(child: child)),
);
/// Applies a 2x text scale below the app so the fixture renders as a real /// Applies a 2x text scale below the app so the fixture renders as a real
/// scale-2 layout rather than a test-only text property. /// scale-2 layout rather than a test-only text property.
Widget _scaled(Widget child) => Builder( Widget _scaled(Widget child) => Builder(
@@ -65,9 +60,7 @@ void main() {
expect(_semantics(tester).label, 'Success'); expect(_semantics(tester).label, 'Success');
}); });
testWidgets('selected node is announced selected in both native hosts', ( testWidgets('selected node is announced selected', (tester) async {
tester,
) async {
await tester.pumpWidget( await tester.pumpWidget(
_material( _material(
GraphStageNode(node: _stage, selected: true, onSelected: (_) {}), GraphStageNode(node: _stage, selected: true, onSelected: (_) {}),
@@ -76,15 +69,6 @@ void main() {
expect(find.byType(Card), findsOneWidget); expect(find.byType(Card), findsOneWidget);
expect(find.byType(InkWell), findsOneWidget); expect(find.byType(InkWell), findsOneWidget);
_expectSelectable(tester, selected: true); _expectSelectable(tester, selected: true);
await tester.pumpWidget(
_cupertino(
GraphStageNode(node: _stage, selected: true, onSelected: (_) {}),
),
);
expect(find.byType(CupertinoButton), findsOneWidget);
expect(find.byType(Card), findsNothing);
_expectSelectable(tester, selected: true);
}); });
testWidgets('unselected node is not announced selected', (tester) async { testWidgets('unselected node is not announced selected', (tester) async {
@@ -96,17 +80,15 @@ void main() {
}); });
testWidgets('keyboard activation selects the node', (tester) async { testWidgets('keyboard activation selects the node', (tester) async {
for (final wrap in [_material, _cupertino]) { final picked = <String>[];
final picked = <String>[]; await tester.pumpWidget(
await tester.pumpWidget( _material(GraphStageNode(node: _stage, onSelected: picked.add)),
wrap(GraphStageNode(node: _stage, onSelected: picked.add)), );
); await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.sendKeyEvent(LogicalKeyboardKey.tab); await tester.pumpAndSettle();
await tester.pumpAndSettle(); await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.sendKeyEvent(LogicalKeyboardKey.enter); await tester.pumpAndSettle();
await tester.pumpAndSettle(); expect(picked, ['build']);
expect(picked, ['build']);
}
}); });
testWidgets('keyboard selection keeps focus inside the material node', ( testWidgets('keyboard selection keeps focus inside the material node', (
@@ -144,46 +126,44 @@ void main() {
) async { ) async {
const label = 'implementer-with-an-unshortened-stage-label'; const label = 'implementer-with-an-unshortened-stage-label';
const node = GraphNode(key: label, terminal: false, stageIndex: 0); const node = GraphNode(key: label, terminal: false, stageIndex: 0);
for (final wrap in [_material, _cupertino]) { await tester.pumpWidget(
await tester.pumpWidget( _material(
wrap( _scaled(
_scaled( SizedBox(
SizedBox( width: 150,
width: 150, child: GraphStageNode(node: node, onSelected: (_) {}),
child: GraphStageNode(node: node, onSelected: (_) {}),
),
), ),
), ),
); ),
);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
final text = tester.widget<Text>(_visual(label)); final text = tester.widget<Text>(_visual(label));
expect(text.data!.replaceAll('\u200B', ''), label); expect(text.data!.replaceAll('\u200B', ''), label);
expect(text.maxLines, isNull); expect(text.maxLines, isNull);
expect(text.overflow, isNull); expect(text.overflow, isNull);
final paragraph = tester.renderObject<RenderParagraph>(_visual(label)); final paragraph = tester.renderObject<RenderParagraph>(_visual(label));
expect(paragraph.size.width, lessThanOrEqualTo(150)); expect(paragraph.size.width, lessThanOrEqualTo(150));
expect( expect(
paragraph.size.height, paragraph.size.height,
greaterThan(50), greaterThan(50),
reason: 'the 2x label must occupy more than one 2x text line', reason: 'the 2x label must occupy more than one 2x text line',
); );
// No glyph may paint outside the paragraph: every laid-out line, // No glyph may paint outside the paragraph: every laid-out line,
// including a hyphen-broken segment, fits the width the control gave it. // including a hyphen-broken segment, fits the width the control gave it.
final painter = TextPainter( final painter = TextPainter(
text: paragraph.text, text: paragraph.text,
textDirection: paragraph.textDirection, textDirection: paragraph.textDirection,
textScaler: paragraph.textScaler, textScaler: paragraph.textScaler,
textAlign: paragraph.textAlign, textAlign: paragraph.textAlign,
)..layout(maxWidth: paragraph.size.width); )..layout(maxWidth: paragraph.size.width);
expect( expect(
painter.computeLineMetrics().every( painter.computeLineMetrics().every(
(line) => line.width <= paragraph.size.width + 0.5, (line) => line.width <= paragraph.size.width + 0.5,
), ),
isTrue, isTrue,
reason: 'an unshortened label must wrap, not paint over the control', reason: 'an unshortened label must wrap, not paint over the control',
); );
}
}); });
testWidgets('terminal shows its definition label and no invented status', ( testWidgets('terminal shows its definition label and no invented status', (
@@ -207,7 +187,7 @@ void main() {
testWidgets('a recorded status is shown verbatim', (tester) async { testWidgets('a recorded status is shown verbatim', (tester) async {
await tester.pumpWidget( await tester.pumpWidget(
_cupertino( _material(
GraphStageNode( GraphStageNode(
node: _stage, node: _stage,
recordedStatus: 'failed', recordedStatus: 'failed',
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart'; import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -113,35 +112,6 @@ Widget _materialHost(
); );
} }
Widget _cupertinoHost(
JsonMap graph,
JsonMap run, {
ValueChanged<String>? onSelected,
double scale = 1,
}) {
return CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(
child: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: SizedBox(
width: 320,
height: 700,
child: RunGraphView(
graph: graph,
run: run,
onStageSelected: onSelected ?? (_) {},
),
),
),
),
),
);
}
Future<void> _settle(WidgetTester tester) async { Future<void> _settle(WidgetTester tester) async {
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
@@ -450,39 +420,4 @@ void main() {
_expectNoOverlaps(tester); _expectNoOverlaps(tester);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}); });
testWidgets('dark Cupertino host keeps native nodes and evidence', (
tester,
) async {
final picked = <String>[];
await tester.pumpWidget(
_cupertinoHost(linearGraph(), _runningRun(), onSelected: picked.add),
);
await _settle(tester);
expect(find.byType(Card), findsNothing);
expect(
find.descendant(
of: find.byType(GraphStageNode),
matching: find.byType(CupertinoButton),
),
findsNWidgets(5),
);
expect(find.text(runGraphExecuted), findsOneWidget);
expect(find.text(runGraphNotExecuted), findsOneWidget);
expect(
tester.widget<GraphStageNode>(_node('plan')).recordedStatus,
'completed',
);
expect(
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
'running',
);
_expectNoOverlaps(tester);
await tester.tap(_node('plan'));
await tester.pump();
expect(picked, ['plan']);
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';
@@ -37,13 +36,6 @@ Widget _material(Widget child) => MaterialApp(
), ),
); );
Widget _cupertino(Widget child, {bool dark = false}) => CupertinoApp(
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
home: CupertinoPageScaffold(child: child),
);
StageDefinitionView _view({String key = 'plan'}) => StageDefinitionView( StageDefinitionView _view({String key = 'plan'}) => StageDefinitionView(
graph: _graph(), graph: _graph(),
stageKey: key, stageKey: key,
@@ -138,26 +130,6 @@ void main() {
expect(_text('successful'), findsNothing); expect(_text('successful'), findsNothing);
}); });
testWidgets('Cupertino uses its theme roles in dark mode', (tester) async {
late Color secondary;
await tester.pumpWidget(
_cupertino(
Builder(
builder: (context) {
secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return _view();
},
),
dark: true,
),
);
final identity = tester.widget<Text>(_text('Demo pipeline · v7'));
expect(identity.style?.color, secondary);
expect(_text('Plan the change.'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('the Material helper opens one bar and Back closes it', ( testWidgets('the Material helper opens one bar and Back closes it', (
tester, tester,
) async { ) async {
@@ -198,44 +170,6 @@ void main() {
expect(find.byType(StageDefinitionView), findsNothing); expect(find.byType(StageDefinitionView), findsNothing);
}); });
testWidgets('the Cupertino helper opens one native bar and Back closes it', (
tester,
) async {
await tester.pumpWidget(
CupertinoApp(
home: Builder(
builder: (context) => CupertinoPageScaffold(
child: CupertinoButton(
onPressed: () => openStageDefinition(
context,
graph: _graph(),
stageKey: '#success',
pipelineId: 41,
pipelineName: 'Demo pipeline',
version: 7,
),
child: const Text('Open terminal'),
),
),
),
),
);
await tester.tap(find.text('Open terminal'));
await tester.pumpAndSettle();
expect(_text('Success definition'), findsOneWidget);
expect(_text('#success definition'), findsNothing);
expect(find.byType(SegmentedBar), findsOneWidget);
expect(find.byType(CupertinoNavigationBarBackButton), findsOneWidget);
expect(_text('Incoming routes'), findsOneWidget);
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
await tester.pumpAndSettle();
expect(_text('Open terminal'), findsOneWidget);
expect(find.byType(StageDefinitionView), findsNothing);
});
testWidgets('the Material helper titles a terminal with its display label', ( testWidgets('the Material helper titles a terminal with its display label', (
tester, tester,
) async { ) async {
@@ -270,7 +204,11 @@ void main() {
testWidgets('selectable blocks force the host strut for one line rhythm', ( testWidgets('selectable blocks force the host strut for one line rhythm', (
tester, tester,
) async { ) async {
await tester.pumpWidget(_cupertino(_view())); // Tall enough that the raw section below the prompt is built.
tester.view.physicalSize = const Size(800, 2000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(_material(_view()));
final selectable = tester final selectable = tester
.widgetList<SelectableText>(find.byType(SelectableText)) .widgetList<SelectableText>(find.byType(SelectableText))
@@ -68,6 +68,7 @@ void main() {
await mount(tester, onSelected: (id) => selectedRun = id); await mount(tester, onSelected: (id) => selectedRun = id);
// The text filter lives in the filter sheet. // The text filter lives in the filter sheet.
expect(find.byType(TextField), findsNothing);
expect(find.text('Alpha'), findsOneWidget); expect(find.text('Alpha'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('runs.filter'))); await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
+31 -47
View File
@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -39,11 +38,7 @@ void main() {
await gateway.framesController.close(); await gateway.framesController.close();
}); });
Future<void> mount( Future<void> mount(WidgetTester tester, {String? createdAt}) async {
WidgetTester tester, {
required bool cupertino,
String? createdAt,
}) async {
tester.view.physicalSize = const Size(800, 1400); tester.view.physicalSize = const Size(800, 1400);
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetPhysicalSize);
@@ -67,54 +62,44 @@ void main() {
builder: (context, _) => builder: (context, _) =>
RunsList(controller: controller, onSelected: (_) {}), RunsList(controller: controller, onSelected: (_) {}),
); );
await tester.pumpWidget( await tester.pumpWidget(MaterialApp(home: Scaffold(body: list)));
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: list))
: MaterialApp(home: Scaffold(body: list)),
);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
for (final cupertino in [false, true]) { testWidgets('filter sheet has a header whose Done closes it', (tester) async {
final host = cupertino ? 'Cupertino' : 'Material'; await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
testWidgets('$host filter sheet has a header whose Done closes it', ( expect(find.byType(AppSheetHeader), findsOneWidget);
tester, expect(
) async { find.descendant(
await mount(tester, cupertino: cupertino); of: find.byType(AppSheetHeader),
await tester.tap(find.byKey(const ValueKey('runs.filter'))); matching: find.text(runsFilterTitle),
await tester.pumpAndSettle(); ),
findsOneWidget,
);
expect(find.text('Queued'), findsOneWidget);
expect(find.text('queued'), findsNothing);
expect(find.byKey(runsFilterClearKey), findsNothing);
expect(find.byType(AppSheetHeader), findsOneWidget); await tester.tap(find.text('Last 7 days'));
expect( await tester.pumpAndSettle();
find.descendant( expect(controller.timeRange, 'last_7_days');
of: find.byType(AppSheetHeader), // An active filter offers Clear in the header.
matching: find.text(runsFilterTitle), expect(find.byKey(runsFilterClearKey), findsOneWidget);
),
findsOneWidget,
);
expect(find.text('Queued'), findsOneWidget);
expect(find.text('queued'), findsNothing);
expect(find.byKey(runsFilterClearKey), findsNothing);
await tester.tap(find.text('Last 7 days')); await tester.tap(find.byKey(runsFilterDoneKey));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.timeRange, 'last_7_days'); expect(find.byKey(const ValueKey('runs.filter.sheet')), findsNothing);
// An active filter offers Clear in the header. // The applied chip reads in sentence case too.
expect(find.byKey(runsFilterClearKey), findsOneWidget); expect(find.textContaining('Last 7 days'), findsOneWidget);
});
await tester.tap(find.byKey(runsFilterDoneKey));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('runs.filter.sheet')), findsNothing);
// The applied chip reads in sentence case too.
expect(find.textContaining('Last 7 days'), findsOneWidget);
});
}
testWidgets('Material single-choice groups are check rows, not checkboxes', ( testWidgets('Material single-choice groups are check rows, not checkboxes', (
tester, tester,
) async { ) async {
await mount(tester, cupertino: false); await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.filter'))); await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
@@ -139,7 +124,7 @@ void main() {
}); });
testWidgets('Material sort opens an anchored choice menu', (tester) async { testWidgets('Material sort opens an anchored choice menu', (tester) async {
await mount(tester, cupertino: false); await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.sort'))); await tester.tap(find.byKey(const ValueKey('runs.sort')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('app-choice-menu')), findsOneWidget); expect(find.byKey(const ValueKey('app-choice-menu')), findsOneWidget);
@@ -153,7 +138,6 @@ void main() {
) async { ) async {
await mount( await mount(
tester, tester,
cupertino: false,
createdAt: DateTime(2020, 1, 1).toIso8601String(), createdAt: DateTime(2020, 1, 1).toIso8601String(),
); );
await tester.tap(find.byKey(const ValueKey('runs.stats'))); await tester.tap(find.byKey(const ValueKey('runs.stats')));
@@ -171,7 +155,7 @@ void main() {
testWidgets('the 7-day chart shows bars over an axis when runs started', ( testWidgets('the 7-day chart shows bars over an axis when runs started', (
tester, tester,
) async { ) async {
await mount(tester, cupertino: true); await mount(tester);
await tester.tap(find.byKey(const ValueKey('runs.stats'))); await tester.tap(find.byKey(const ValueKey('runs.stats')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('runs.stats.days')), findsOneWidget); expect(find.byKey(const ValueKey('runs.stats.days')), findsOneWidget);
@@ -146,13 +146,13 @@ void main() {
); );
testWidgets( testWidgets(
'cupertino: the filter sheet filters and its chip clears the facet', 'the filter sheet filters and its chip clears the facet',
(tester) async { (tester) async {
await mount(tester, cupertino: true); await mount(tester, cupertino: false);
await tester.tap(find.byKey(const ValueKey('runs.filter'))); await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byType(CupertinoSearchTextField), findsOneWidget); expect(find.byType(TextField), findsOneWidget);
final failed = find.widgetWithText(CupertinoListTile, 'Failed'); final failed = find.widgetWithText(ListTile, 'Failed');
await reveal(tester, failed); await reveal(tester, failed);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(failed); await tester.tap(failed);
@@ -160,10 +160,12 @@ void main() {
expect(controller.statuses, {'failed'}); expect(controller.statuses, {'failed'});
await closeSheet(tester); await closeSheet(tester);
final failedChip = find.widgetWithText(CupertinoButton, 'Failed'); final failedChip = find.widgetWithText(InputChip, 'Failed');
expect(failedChip, findsOneWidget); expect(failedChip, findsOneWidget);
expect(find.text('Alpha'), findsNothing); expect(find.text('Alpha'), findsNothing);
await tester.tap(failedChip); await tester.tap(
find.descendant(of: failedChip, matching: find.byType(Tooltip)),
);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.statuses, isEmpty); expect(controller.statuses, isEmpty);
expect(find.text('Alpha'), findsOneWidget); expect(find.text('Alpha'), findsOneWidget);
@@ -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/schedules/screen.dart'; import 'package:pipelines_app/features/schedules/screen.dart';
@@ -12,7 +11,7 @@ import 'schedule_list_test_support.dart';
/// The schedule list under a floating bar: search, filter and count are a /// The schedule list under a floating bar: search, filter and count are a
/// glass strip under the bar, and the list scrolls behind both. /// glass strip under the bar, and the list scrolls behind both.
void main() { void main() {
Future<void> pump(WidgetTester tester, {required bool cupertino}) async { Future<void> pump(WidgetTester tester) 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);
@@ -20,19 +19,15 @@ void main() {
(type, fields) async => schedulesReply(longScheduleList(30)), (type, fields) async => schedulesReply(longScheduleList(30)),
); );
final screen = SchedulesScreen(gateway: gateway, onOpen: (_) {}); final screen = SchedulesScreen(gateway: gateway, onOpen: (_) {});
final bar = SegmentedBar(cupertino: cupertino, title: 'Schedules'); final bar = const SegmentedBar(cupertino: false, title: 'Schedules');
await tester.pumpWidget( await tester.pumpWidget(
cupertino MaterialApp(
? CupertinoApp( home: Scaffold(
home: CupertinoPageScaffold(navigationBar: bar, child: screen), extendBodyBehindAppBar: true,
) appBar: bar,
: MaterialApp( body: screen,
home: Scaffold( ),
extendBodyBehindAppBar: true, ),
appBar: bar,
body: screen,
),
),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
@@ -41,53 +36,47 @@ void main() {
find.descendant(of: owner, matching: find.byType(GlassPill)).first, find.descendant(of: owner, matching: find.byType(GlassPill)).first,
); );
for (final cupertino in [false, true]) { testWidgets('the toolbar floats under the bar and the list '
final host = cupertino ? 'Cupertino' : 'Material'; 'scrolls behind it', (tester) async {
await pump(tester);
testWidgets('$host: the toolbar floats under the bar and the list ' final bar = pieceOf(tester, find.byType(SegmentedBar));
'scrolls behind it', (tester) async { final strip = pieceOf(tester, find.byKey(scheduleToolbarKey));
await pump(tester, cupertino: cupertino); expect(strip.top, greaterThanOrEqualTo(bar.bottom));
expect(strip.top - bar.bottom, lessThan(24));
expect(
find.descendant(
of: find.byKey(scheduleToolbarKey),
matching: find.byKey(scheduleSearchFieldKey),
),
findsOneWidget,
);
final bar = pieceOf(tester, find.byType(SegmentedBar)); final list = find.byKey(scheduleListKey);
final strip = pieceOf(tester, find.byKey(scheduleToolbarKey)); expect(tester.getTopLeft(list).dy, 0);
expect(strip.top, greaterThanOrEqualTo(bar.bottom)); final firstRow = find.byKey(const ValueKey('schedule-row-0-100'));
expect(strip.top - bar.bottom, lessThan(24)); final rest = tester.getTopLeft(firstRow).dy;
expect( expect(rest, greaterThanOrEqualTo(strip.bottom));
find.descendant(
of: find.byKey(scheduleToolbarKey),
matching: find.byKey(scheduleSearchFieldKey),
),
findsOneWidget,
);
final list = find.byKey(scheduleListKey); await tester.drag(list, const Offset(0, -120));
expect(tester.getTopLeft(list).dy, 0); await tester.pump();
final firstRow = find.byKey(const ValueKey('schedule-row-0-100')); expect(tester.getTopLeft(firstRow).dy, lessThan(strip.bottom));
final rest = tester.getTopLeft(firstRow).dy; });
expect(rest, greaterThanOrEqualTo(strip.bottom));
await tester.drag(list, const Offset(0, -120)); testWidgets('a query that empties the list keeps the field', (tester) async {
await tester.pump(); await pump(tester);
expect(tester.getTopLeft(firstRow).dy, lessThan(strip.bottom)); final field = find.byKey(scheduleSearchFieldKey);
}); await tester.tap(field);
await tester.pump();
final before = tester.element(field);
await tester.enterText(field, 'no schedule matches this');
await tester.pump();
testWidgets('$host: a query that empties the list keeps the field', ( expect(find.text('No schedules match this search.'), findsOneWidget);
tester, expect(tester.element(field), same(before));
) async { final editable = tester.state<EditableTextState>(
await pump(tester, cupertino: cupertino); find.descendant(of: field, matching: find.byType(EditableText)),
final field = find.byKey(scheduleSearchFieldKey); );
await tester.tap(field); expect(editable.widget.focusNode.hasFocus, isTrue);
await tester.pump(); });
final before = tester.element(field);
await tester.enterText(field, 'no schedule matches this');
await tester.pump();
expect(find.text('No schedules match this search.'), findsOneWidget);
expect(tester.element(field), same(before));
final editable = tester.state<EditableTextState>(
find.descendant(of: field, matching: find.byType(EditableText)),
);
expect(editable.widget.focusNode.hasFocus, isTrue);
});
}
} }
@@ -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/schedules/ui/list/schedule_list_controller.dart'; import 'package:pipelines_app/features/schedules/ui/list/schedule_list_controller.dart';
@@ -9,69 +8,55 @@ import 'schedule_list_test_support.dart';
import 'schedule_screen_harness.dart'; import 'schedule_screen_harness.dart';
void main() { void main() {
for (final cupertino in [false, true]) { for (final textScale in [1.0, 2.0]) {
for (final textScale in [1.0, 2.0]) { testWidgets('list at 390px and ${textScale}x text shows server values with '
testWidgets('${cupertino ? 'Cupertino' : 'Material'} list at 390px and ' 'standard controls', (tester) async {
'${textScale}x text shows server values with native controls', ( final gateway = FakeSchedulesGateway(
(type, fields) async => schedulesReply([
scheduleRecord(nextDue: '2026-10-22T09:00:00'),
pausedRecord(),
]),
);
await pumpSchedules(
tester, tester,
) async { cupertino: false,
final gateway = FakeSchedulesGateway( gateway: gateway,
(type, fields) async => schedulesReply([ textScale: textScale,
scheduleRecord(nextDue: '2026-10-22T09:00:00'), );
pausedRecord(),
]),
);
await pumpSchedules(
tester,
cupertino: cupertino,
gateway: gateway,
textScale: textScale,
);
expect(find.text('2 schedules'), findsOneWidget); expect(find.text('2 schedules'), findsOneWidget);
// The strip carries the count only; the helper line lives in the // The strip carries the count only; the helper line lives in the
// empty state. // empty state.
expect(find.textContaining('not pipeline definitions'), findsNothing); expect(find.textContaining('not pipeline definitions'), findsNothing);
// Two lines per row: the name with its next run, then the timer // Two lines per row: the name with its next run, then the timer
// and pinned pipeline version. The editor holds the rest. // and pinned pipeline version. The editor holds the rest.
expect(find.text('Research batteries'), findsOneWidget); expect(find.text('Research batteries'), findsOneWidget);
expect(find.text('22 Oct'), findsOneWidget); expect(find.text('22 Oct'), findsOneWidget);
expect( expect(
find.text('Every 24h · mon, wed · Pipeline 4 · v2'), find.text('Every 24h · mon, wed · Pipeline 4 · v2'),
findsOneWidget, findsOneWidget,
); );
expect(find.text('Find battery chemistry sources'), findsNothing); expect(find.text('Find battery chemistry sources'), findsNothing);
await tester.scrollUntilVisible( await tester.scrollUntilVisible(
find.text('Nightly report'), find.text('Nightly report'),
300, 300,
scrollable: find.descendant( scrollable: find.descendant(
of: find.byKey(scheduleListKey), of: find.byKey(scheduleListKey),
matching: find.byType(Scrollable), matching: find.byType(Scrollable),
), ),
); );
expect(find.text('Nightly report'), findsOneWidget); expect(find.text('Nightly report'), findsOneWidget);
expect(find.text('10:00, 18:30 · Pipeline 7 · v5'), findsOneWidget); expect(find.text('10:00, 18:30 · Pipeline 7 · v5'), findsOneWidget);
expect(find.text('Paused'), findsOneWidget); expect(find.text('Paused'), findsOneWidget);
if (cupertino) { expect(find.byKey(scheduleSearchFieldKey), findsOneWidget);
expect(find.byType(CupertinoSearchTextField), findsOneWidget); expect(
expect( find.byType(SegmentedButton<ScheduleListFilter>),
find.byType(CupertinoSlidingSegmentedControl<ScheduleListFilter>), findsOneWidget,
findsOneWidget, );
); expect(find.byType(TextField), findsOneWidget);
expect(find.byType(CupertinoButton), findsWidgets); expect(tester.takeException(), isNull);
expect(find.byType(TextField), findsNothing); });
} else {
expect(find.byKey(scheduleSearchFieldKey), findsOneWidget);
expect(
find.byType(SegmentedButton<ScheduleListFilter>),
findsOneWidget,
);
expect(find.byType(TextField), findsOneWidget);
}
expect(tester.takeException(), isNull);
});
}
} }
} }
@@ -9,60 +9,52 @@ import 'schedule_list_test_support.dart';
import 'schedule_screen_harness.dart'; import 'schedule_screen_harness.dart';
void main() { void main() {
testWidgets('search covers name, prompt and pipeline in both themes', ( testWidgets('search covers name, prompt and pipeline', (tester) async {
tester, final gateway = FakeSchedulesGateway(
) async { (type, fields) async =>
for (final cupertino in [false, true]) { schedulesReply([scheduleRecord(), pausedRecord()]),
final gateway = FakeSchedulesGateway( );
(type, fields) async => await pumpSchedules(tester, cupertino: false, gateway: gateway);
schedulesReply([scheduleRecord(), pausedRecord()]),
);
await pumpSchedules(tester, cupertino: cupertino, gateway: gateway);
await tester.enterText(find.byKey(scheduleSearchFieldKey), 'pipeline 7'); await tester.enterText(find.byKey(scheduleSearchFieldKey), 'pipeline 7');
await tester.pump(); await tester.pump();
expect(find.text('Nightly report'), findsOneWidget); expect(find.text('Nightly report'), findsOneWidget);
expect(find.text('Research batteries'), findsNothing); expect(find.text('Research batteries'), findsNothing);
expect(find.text('1 of 2 schedules'), findsOneWidget); expect(find.text('1 of 2 schedules'), findsOneWidget);
await tester.enterText( await tester.enterText(
find.byKey(scheduleSearchFieldKey), find.byKey(scheduleSearchFieldKey),
'battery chemistry', 'battery chemistry',
); );
await tester.pump(); await tester.pump();
expect(find.text('Research batteries'), findsOneWidget); expect(find.text('Research batteries'), findsOneWidget);
expect(find.text('Nightly report'), findsNothing); expect(find.text('Nightly report'), findsNothing);
await tester.enterText(find.byKey(scheduleSearchFieldKey), 'no match'); await tester.enterText(find.byKey(scheduleSearchFieldKey), 'no match');
await tester.pump(); await tester.pump();
expect(find.text('No schedules match this search.'), findsOneWidget); expect(find.text('No schedules match this search.'), findsOneWidget);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}
}); });
testWidgets('enabled filter removes paused schedules in both themes', ( testWidgets('enabled filter removes paused schedules', (tester) async {
tester, final gateway = FakeSchedulesGateway(
) async { (type, fields) async =>
for (final cupertino in [false, true]) { schedulesReply([scheduleRecord(), pausedRecord()]),
final gateway = FakeSchedulesGateway( );
(type, fields) async => await pumpSchedules(tester, cupertino: false, gateway: gateway);
schedulesReply([scheduleRecord(), pausedRecord()]),
);
await pumpSchedules(tester, cupertino: cupertino, gateway: gateway);
await tester.tap( await tester.tap(
find.descendant( find.descendant(
of: find.byKey(scheduleFilterKey), of: find.byKey(scheduleFilterKey),
matching: find.text('Enabled'), matching: find.text('Enabled'),
), ),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Research batteries'), findsOneWidget); expect(find.text('Research batteries'), findsOneWidget);
expect(find.text('Nightly report'), findsNothing); expect(find.text('Nightly report'), findsNothing);
expect(find.text('1 of 2 schedules'), findsOneWidget); expect(find.text('1 of 2 schedules'), findsOneWidget);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}
}); });
testWidgets('row selection opens the exact record and never mutates', ( testWidgets('row selection opens the exact record and never mutates', (
@@ -10,45 +10,41 @@ import 'schedule_screen_harness.dart';
/// On a wide window the rows share the toolbar strip's width, and the strip /// On a wide window the rows share the toolbar strip's width, and the strip
/// is one row: the field, the filter and the count as a muted label. /// is one row: the field, the filter and the count as a muted label.
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('Material 1200: rows end under the strip and the strip is one '
final host = cupertino ? 'Cupertino' : 'Material'; 'row', (tester) async {
await pumpSchedules(
tester,
cupertino: false,
size: const Size(1200, 800),
gateway: FakeSchedulesGateway(
(type, fields) async => schedulesReply([
scheduleRecord(nextDue: '2026-10-22T09:00:00'),
pausedRecord(),
]),
),
);
final strip = tester.getRect(find.byKey(scheduleToolbarKey));
final row = tester.getRect(find.byKey(appListRowSurfaceKey).first);
expect(row.left, 0);
expect(row.width, kScheduleListMaxWidth);
// The row's trailing time ends inside the strip's trailing edge.
// The trailing time is the row's rightmost text, whatever its wording.
final time = find
.descendant(
of: find.byKey(appListRowSurfaceKey).first,
matching: find.byType(Text),
)
.evaluate()
.map((element) => tester.getRect(find.byWidget(element.widget)))
.reduce((a, b) => a.right >= b.right ? a : b);
expect(time.right, lessThanOrEqualTo(strip.right - 12 + 0.5));
testWidgets('$host 1200: rows end under the strip and the strip is one ' // Field, filter and count on one line.
'row', (tester) async { final field = tester.getRect(find.byKey(scheduleSearchFieldKey));
await pumpSchedules( final filter = tester.getRect(find.byKey(scheduleFilterKey));
tester, final count = tester.getRect(find.text('2 schedules'));
cupertino: cupertino, expect((field.center.dy - filter.center.dy).abs(), lessThan(4));
size: const Size(1200, 800), expect((count.center.dy - filter.center.dy).abs(), lessThan(4));
gateway: FakeSchedulesGateway( expect(find.textContaining('not pipeline definitions'), findsNothing);
(type, fields) async => schedulesReply([ });
scheduleRecord(nextDue: '2026-10-22T09:00:00'),
pausedRecord(),
]),
),
);
final strip = tester.getRect(find.byKey(scheduleToolbarKey));
final row = tester.getRect(find.byKey(appListRowSurfaceKey).first);
expect(row.left, 0);
expect(row.width, kScheduleListMaxWidth);
// The row's trailing time ends inside the strip's trailing edge.
// The trailing time is the row's rightmost text, whatever its wording.
final time = find
.descendant(
of: find.byKey(appListRowSurfaceKey).first,
matching: find.byType(Text),
)
.evaluate()
.map((element) => tester.getRect(find.byWidget(element.widget)))
.reduce((a, b) => a.right >= b.right ? a : b);
expect(time.right, lessThanOrEqualTo(strip.right - 12 + 0.5));
// Field, filter and count on one line.
final field = tester.getRect(find.byKey(scheduleSearchFieldKey));
final filter = tester.getRect(find.byKey(scheduleFilterKey));
final count = tester.getRect(find.text('2 schedules'));
expect((field.center.dy - filter.center.dy).abs(), lessThan(4));
expect((count.center.dy - filter.center.dy).abs(), lessThan(4));
expect(find.textContaining('not pipeline definitions'), findsNothing);
});
}
} }
@@ -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/search/search_screen.dart'; import 'package:pipelines_app/features/search/search_screen.dart';
@@ -25,177 +24,141 @@ Future<void> _search(WidgetTester tester, String query) async {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
Widget _app(bool cupertino, Widget child) => Widget _app(Widget child) => MaterialApp(home: child);
cupertino ? CupertinoApp(home: child) : MaterialApp(home: child);
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('the field, Kind and help live in the bar pill', (tester) async {
final host = cupertino ? 'Cupertino' : 'Material'; _size(tester, 390);
final gateway = ImmediateGateway((_, _) => response([pipeline]));
await tester.pumpWidget(
_app(SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false)),
);
testWidgets('$host: the field, Kind and help live in the bar pill', ( for (final key in [searchFieldKey, searchKindKey, searchHelpKey]) {
tester,
) async {
_size(tester, 390);
final gateway = ImmediateGateway((_, _) => response([pipeline]));
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino),
),
);
for (final key in [searchFieldKey, searchKindKey, searchHelpKey]) {
expect(
find.descendant(
of: find.byType(SegmentedBar),
matching: find.byKey(key),
),
findsOneWidget,
reason: '$key is in the bar',
);
}
// One field per platform: no elevated SearchBar, no dropdown.
expect(find.byType(SearchBar), findsNothing);
expect(find.byType(DropdownButton), findsNothing);
expect(
find.byType(CupertinoSearchTextField),
cupertino ? findsOneWidget : findsNothing,
);
// The syntax help is behind the info button, not on the page.
expect(find.text(searchTokenHint), findsNothing);
await tester.tap(find.byKey(searchHelpKey));
await tester.pumpAndSettle();
expect(find.text(searchTokenHint), findsOneWidget);
});
testWidgets('$host: stats appear only for a truncated answer', (
tester,
) async {
_size(tester, 390);
var truncated = false;
final gateway = ImmediateGateway((_, _) {
final reply = response([pipeline]);
(reply['search_results'] as Map)['truncated'] = truncated;
return reply;
});
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino),
),
);
await _search(tester, 'release');
expect(find.text('Release planner'), findsOneWidget);
expect(find.byKey(searchBoundsKey), findsNothing);
expect(find.textContaining('scanned'), findsNothing);
truncated = true;
await _search(tester, 'releases');
expect(find.byKey(searchBoundsKey), findsOneWidget);
expect(find.textContaining('Results truncated'), findsOneWidget);
});
testWidgets('$host: rows are the shared row: title, kind-led line', (
tester,
) async {
_size(tester, 390);
final gateway = ImmediateGateway((_, _) => response([field]));
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino),
),
);
await _search(tester, 'release');
final row = find.byKey(const ValueKey('search.result.run:11:4:output'));
expect(row, findsOneWidget);
expect(tester.widget<AppListRow>(row).cupertino, cupertino);
// The kind leads the one muted line, before the snippet.
expect(
find.descendant(of: row, matching: find.textContaining('Field · ')),
findsOneWidget,
);
expect( expect(
find.descendant( find.descendant(
of: row, of: find.byType(SegmentedBar),
matching: find.textContaining('the release is ready'), matching: find.byKey(key),
), ),
findsOneWidget, findsOneWidget,
reason: '$key is in the bar',
); );
}); }
// One field: no elevated SearchBar, no dropdown and no native field.
expect(find.byType(SearchBar), findsNothing);
expect(find.byType(DropdownButton), findsNothing);
// The syntax help is behind the info button, not on the page.
expect(find.text(searchTokenHint), findsNothing);
await tester.tap(find.byKey(searchHelpKey));
await tester.pumpAndSettle();
expect(find.text(searchTokenHint), findsOneWidget);
});
testWidgets('$host: results run behind the bar in a capped column', ( testWidgets('stats appear only for a truncated answer', (tester) async {
tester, _size(tester, 390);
) async { var truncated = false;
_size(tester, 1200); final gateway = ImmediateGateway((_, _) {
final reply = response([pipeline]);
(reply['search_results'] as Map)['truncated'] = truncated;
return reply;
});
await tester.pumpWidget(
_app(SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false)),
);
await _search(tester, 'release');
expect(find.text('Release planner'), findsOneWidget);
expect(find.byKey(searchBoundsKey), findsNothing);
expect(find.textContaining('scanned'), findsNothing);
truncated = true;
await _search(tester, 'releases');
expect(find.byKey(searchBoundsKey), findsOneWidget);
expect(find.textContaining('Results truncated'), findsOneWidget);
});
testWidgets('rows are the shared row: title, kind-led line', (tester) async {
_size(tester, 390);
final gateway = ImmediateGateway((_, _) => response([field]));
await tester.pumpWidget(
_app(SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false)),
);
await _search(tester, 'release');
final row = find.byKey(const ValueKey('search.result.run:11:4:output'));
expect(row, findsOneWidget);
expect(tester.widget<AppListRow>(row).cupertino, isFalse);
// The kind leads the one muted line, before the snippet.
expect(
find.descendant(of: row, matching: find.textContaining('Field · ')),
findsOneWidget,
);
expect(
find.descendant(
of: row,
matching: find.textContaining('the release is ready'),
),
findsOneWidget,
);
});
testWidgets('results run behind the bar in a capped column', (tester) async {
_size(tester, 1200);
final gateway = ImmediateGateway((_, _) => response([pipeline]));
await tester.pumpWidget(
_app(SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false)),
);
await _search(tester, 'release');
// The scroll view reaches the top edge; its first row starts below
// the floating bar.
final scroll = find.byType(CustomScrollView);
expect(tester.getTopLeft(scroll).dy, 0);
final barBottom = tester.getBottomLeft(find.byType(SegmentedBar)).dy;
final row = find.byKey(const ValueKey('search.result.pipeline:7'));
expect(tester.getTopLeft(row).dy, greaterThanOrEqualTo(barBottom - 8));
// The row spans the whole window between the bar's insets: no
// reading-width cap on a wide window.
final rect = tester.getRect(row);
expect(rect.left, kSearchContentInset);
expect(rect.right, 1200 - kSearchContentInset);
});
for (final width in [390.0, 880.0, 1200.0, 1400.0]) {
testWidgets('at $width the field takes the title\'s place and '
'the results line up with it', (tester) async {
_size(tester, width);
final gateway = ImmediateGateway((_, _) => response([pipeline])); final gateway = ImmediateGateway((_, _) => response([pipeline]));
await tester.pumpWidget( await tester.pumpWidget(
_app( _app(SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false)),
cupertino,
SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino),
),
); );
await _search(tester, 'release'); await _search(tester, 'release');
// The scroll view reaches the top edge; its first row starts below final bar = find.byType(SegmentedBar);
// the floating bar. // No Search title pill: the field's pill is the bar's only piece.
final scroll = find.byType(CustomScrollView); expect(
expect(tester.getTopLeft(scroll).dy, 0); find.descendant(of: bar, matching: find.text('Search')),
final barBottom = tester.getBottomLeft(find.byType(SegmentedBar)).dy; findsNothing,
final row = find.byKey(const ValueKey('search.result.pipeline:7')); );
expect(tester.getTopLeft(row).dy, greaterThanOrEqualTo(barBottom - 8)); expect(
// The row spans the whole window between the bar's insets: no find.descendant(of: bar, matching: find.byType(GlassPill)),
// reading-width cap on a wide window. findsOneWidget,
final rect = tester.getRect(row); );
expect(rect.left, kSearchContentInset); final pill = tester.getRect(
expect(rect.right, 1200 - kSearchContentInset); find.descendant(of: bar, matching: find.byType(GlassPill)),
);
expect(pill.left, kSearchContentInset);
// The pill grows with the bar: the whole width between its insets.
expect(pill.width, width - 2 * kSearchContentInset);
// The field fills the pill beside Kind and the help.
final field = tester.getRect(find.byKey(searchFieldKey));
expect(field.width, greaterThan(pill.width * 0.6));
// The result column shares the pill's edges, so it spans the pane.
final row = tester.getRect(
find.byKey(const ValueKey('search.result.pipeline:7')),
);
expect(row.left, pill.left);
expect(row.right, pill.right);
}); });
for (final width in [390.0, 880.0, 1200.0, 1400.0]) {
testWidgets('$host: at $width the field takes the title\'s place and '
'the results line up with it', (tester) async {
_size(tester, width);
final gateway = ImmediateGateway((_, _) => response([pipeline]));
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(
gateway: gateway,
onOpen: (_) {},
cupertino: cupertino,
),
),
);
await _search(tester, 'release');
final bar = find.byType(SegmentedBar);
// No Search title pill: the field's pill is the bar's only piece.
expect(
find.descendant(of: bar, matching: find.text('Search')),
findsNothing,
);
expect(
find.descendant(of: bar, matching: find.byType(GlassPill)),
findsOneWidget,
);
final pill = tester.getRect(
find.descendant(of: bar, matching: find.byType(GlassPill)),
);
expect(pill.left, kSearchContentInset);
// The pill grows with the bar: the whole width between its insets.
expect(pill.width, width - 2 * kSearchContentInset);
// The field fills the pill beside Kind and the help.
final field = tester.getRect(find.byKey(searchFieldKey));
expect(field.width, greaterThan(pill.width * 0.6));
// The result column shares the pill's edges, so it spans the pane.
final row = tester.getRect(
find.byKey(const ValueKey('search.result.pipeline:7')),
);
expect(row.left, pill.left);
expect(row.right, pill.right);
});
}
} }
} }
@@ -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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -17,67 +16,59 @@ JsonMap replies(String query, String kind) => kind == 'chat'
]) ])
: response([field]); : response([field]);
Widget host(Widget child, {required bool cupertino}) => Widget host(Widget child) => MaterialApp(home: child);
cupertino ? CupertinoApp(home: child) : MaterialApp(home: child);
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('chat hits lead as a Chats group with title, '
final platform = cupertino ? 'Cupertino' : 'Material'; 'harness, directory and snippet, and open their chat', (tester) async {
useNarrowSurface(tester);
testWidgets('$platform: chat hits lead as a Chats group with title, ' final gateway = ImmediateGateway(replies);
'harness, directory and snippet, and open their chat', (tester) async { JsonMap? opened;
useNarrowSurface(tester); await tester.pumpWidget(
final gateway = ImmediateGateway(replies); host(
JsonMap? opened; SearchScreen(
await tester.pumpWidget( gateway: gateway,
host( onOpen: (value) => opened = value,
SearchScreen( cupertino: false,
gateway: gateway,
onOpen: (value) => opened = value,
cupertino: cupertino,
),
cupertino: cupertino,
), ),
); ),
await search(tester, 'release'); );
await search(tester, 'release');
expect(gateway.calls.single['search'], { expect(gateway.calls.single['search'], {
'query': 'release', 'query': 'release',
'kind': '', 'kind': '',
'limit': 0, 'limit': 0,
});
expect(gateway.chatCalls.single['search'], {
'query': 'release',
'kind': 'chat',
'limit': 0,
});
expect(find.text('Chats (2)'), findsOneWidget);
expect(find.text('Pipelines and runs'), findsOneWidget);
final chats = tester.getTopLeft(find.byKey(searchChatsSectionKey));
final others = tester.getTopLeft(find.byKey(searchOthersSectionKey));
final chatRow = find.byKey(const ValueKey('search.result.chat:ses_a'));
final runRow = find.byKey(
const ValueKey('search.result.run:11:4:output'),
);
expect(chats.dy, lessThan(tester.getTopLeft(chatRow).dy));
expect(tester.getTopLeft(chatRow).dy, lessThan(others.dy));
expect(others.dy, lessThan(tester.getTopLeft(runRow).dy));
expect(find.text('API refactor'), findsOneWidget);
expect(find.text('Release notes'), findsOneWidget);
expect(
find.textContaining('Chat · Claude Code · /work/api'),
findsNWidgets(2),
);
expect(find.textContaining('the release retry'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(chatRow);
await tester.pump();
expect(opened?['target'], 'chat:ses_a');
expect((opened?['chat'] as Map)['session_id'], 'ses_a');
}); });
} expect(gateway.chatCalls.single['search'], {
'query': 'release',
'kind': 'chat',
'limit': 0,
});
expect(find.text('Chats (2)'), findsOneWidget);
expect(find.text('Pipelines and runs'), findsOneWidget);
final chats = tester.getTopLeft(find.byKey(searchChatsSectionKey));
final others = tester.getTopLeft(find.byKey(searchOthersSectionKey));
final chatRow = find.byKey(const ValueKey('search.result.chat:ses_a'));
final runRow = find.byKey(const ValueKey('search.result.run:11:4:output'));
expect(chats.dy, lessThan(tester.getTopLeft(chatRow).dy));
expect(tester.getTopLeft(chatRow).dy, lessThan(others.dy));
expect(others.dy, lessThan(tester.getTopLeft(runRow).dy));
expect(find.text('API refactor'), findsOneWidget);
expect(find.text('Release notes'), findsOneWidget);
expect(
find.textContaining('Chat · Claude Code · /work/api'),
findsNWidgets(2),
);
expect(find.textContaining('the release retry'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(chatRow);
await tester.pump();
expect(opened?['target'], 'chat:ses_a');
expect((opened?['chat'] as Map)['session_id'], 'ses_a');
});
testWidgets('Chats selected alone lists chats without group headings', ( testWidgets('Chats selected alone lists chats without group headings', (
tester, tester,
@@ -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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -145,34 +144,6 @@ void main() {
); );
} }
testWidgets(
'Cupertino search uses native controls and opens the real target',
(tester) async {
useNarrowSurface(tester);
final gateway = ImmediateGateway((_, _) => response([pipeline]));
JsonMap? opened;
await tester.pumpWidget(
CupertinoApp(
home: largeText(
SearchScreen(
gateway: gateway,
onOpen: (value) => opened = value,
cupertino: true,
),
),
),
);
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
await search(tester, 'release');
expect(find.text('Release planner'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(const ValueKey('search.result.pipeline:7')));
expect(opened?['target'], 'pipeline:7');
},
);
testWidgets('a read-only hit cannot be opened', (tester) async { testWidgets('a read-only hit cannot be opened', (tester) async {
useNarrowSurface(tester); useNarrowSurface(tester);
final unknown = hit( final unknown = hit(
@@ -192,34 +192,28 @@ void main() {
); );
}); });
testWidgets('the name field is labelled for screen readers on both hosts', ( testWidgets('the name field is labelled for screen readers', (tester) async {
tester,
) async {
final handle = tester.ensureSemantics(); final handle = tester.ensureSemantics();
for (final cupertino in <bool>[false, true]) { await tester.pumpWidget(
await tester.pumpWidget( templateCreateApp(
templateCreateApp( TemplateCreateHost(
TemplateCreateHost( gateway: FakeTemplateCreateGateway(acceptedTemplateCreate),
gateway: FakeTemplateCreateGateway(acceptedTemplateCreate), onCreated: (_) {},
onCreated: (_) {},
cupertino: cupertino,
),
cupertino: cupertino,
textScale: 2,
), ),
); textScale: 2,
await tester.tap(find.byKey(templateCreateOpenKey)); ),
await tester.pumpAndSettle(); );
await tester.enterText(find.byKey(templateCreateNameKey), 'Scaled'); await tester.tap(find.byKey(templateCreateOpenKey));
await tester.pump(); await tester.pumpAndSettle();
await tester.enterText(find.byKey(templateCreateNameKey), 'Scaled');
await tester.pump();
final data = tester final data = tester
.getSemantics(find.byKey(templateCreateNameKey)) .getSemantics(find.byKey(templateCreateNameKey))
.getSemanticsData(); .getSemanticsData();
expect(data.label, templateCreateNameLabel); expect(data.label, templateCreateNameLabel);
expect(data.value, 'Scaled'); expect(data.value, 'Scaled');
expect(data.flagsCollection.isTextField, isTrue); expect(data.flagsCollection.isTextField, isTrue);
}
handle.dispose(); handle.dispose();
}); });
} }
@@ -1,13 +1,11 @@
import 'dart:async'; import 'dart:async';
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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart'; import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/templates/ui/template_create_wording.dart'; import 'package:pipelines_app/features/templates/ui/template_create_wording.dart';
import '../data/template_test_support.dart' show source;
import 'template_create_test_support.dart'; import 'template_create_test_support.dart';
void main() { void main() {
@@ -107,65 +105,4 @@ void main() {
findsOneWidget, findsOneWidget,
); );
}); });
testWidgets('cupertino prompt uses native controls for the same flow', (
tester,
) async {
final gateway = FakeTemplateCreateGateway(
(type, fields) async => type == 'validate'
? {'graph': {}}
: {
'detail': {'id': 3},
},
);
final created = <JsonMap>[];
await tester.pumpWidget(
templateCreateApp(
TemplateCreateHost(
gateway: gateway,
onCreated: created.add,
cupertino: true,
),
cupertino: true,
),
);
await tester.tap(find.byKey(templateCreateOpenKey));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
expect(find.byType(AlertDialog), findsNothing);
expect(find.byType(CupertinoTextField), findsOneWidget);
expect(find.text(templateCreateNameLabel), findsOneWidget);
expect(cupertinoTemplateName(tester), '');
expect(
tester
.widget<CupertinoDialogAction>(find.byKey(templateCreateConfirmKey))
.onPressed,
isNull,
);
await tester.enterText(find.byKey(templateCreateNameKey), ' Unicode 🚀 ');
await tester.pump();
await tester.tap(find.byKey(templateCreateConfirmKey));
await tester.pumpAndSettle();
expect(gateway.calls.map((call) => call.type), ['validate', 'submit']);
expect(gateway.calls[1].fields, {
'name': 'Unicode 🚀',
'source': source,
'create_only': true,
});
expect(
find.text('Created "Unicode 🚀". It is in the Pipelines list.'),
findsOneWidget,
);
expect(created.single, {'id': 3});
expect(
tester
.widget<CupertinoTextField>(find.byKey(templateCreateNameKey))
.enabled,
isFalse,
);
expect(find.text('Close'), findsOneWidget);
});
} }
@@ -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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -46,11 +45,6 @@ String materialTemplateName(WidgetTester tester) => tester
.controller! .controller!
.text; .text;
String cupertinoTemplateName(WidgetTester tester) => tester
.widget<CupertinoTextField>(find.byKey(templateCreateNameKey))
.controller!
.text;
Future<JsonMap> acceptedTemplateCreate(String type, JsonMap fields) async { Future<JsonMap> acceptedTemplateCreate(String type, JsonMap fields) async {
if (type == 'validate') { if (type == 'validate') {
return {'graph': {}}; return {'graph': {}};
@@ -75,6 +69,8 @@ class TemplateCreateHost extends StatelessWidget {
final FakeTemplateCreateGateway gateway; final FakeTemplateCreateGateway gateway;
final ValueChanged<JsonMap> onCreated; final ValueChanged<JsonMap> onCreated;
/// Retained for callers that still pass it; the host is always Material.
final bool cupertino; final bool cupertino;
final TemplateEntry template; final TemplateEntry template;
@@ -91,21 +87,12 @@ class TemplateCreateHost extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final body = Center( final body = Center(
child: cupertino child: FilledButton(
? CupertinoButton( key: templateCreateOpenKey,
key: templateCreateOpenKey, onPressed: () => _open(context),
onPressed: () => _open(context), child: const Text('Open'),
child: const Text('Open'), ),
)
: FilledButton(
key: templateCreateOpenKey,
onPressed: () => _open(context),
child: const Text('Open'),
),
); );
if (cupertino) {
return CupertinoPageScaffold(child: body);
}
return Scaffold(body: body); return Scaffold(body: body);
} }
} }
@@ -121,7 +108,5 @@ Widget templateCreateApp(
).copyWith(textScaler: TextScaler.linear(textScale)), ).copyWith(textScaler: TextScaler.linear(textScale)),
child: app!, child: app!,
); );
return cupertino return MaterialApp(builder: media, home: child);
? CupertinoApp(builder: media, home: child)
: MaterialApp(builder: media, home: child);
} }
@@ -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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -76,30 +75,4 @@ void main() {
expect(gateway.callsOf('submit'), hasLength(1)); expect(gateway.callsOf('submit'), hasLength(1));
}, },
); );
testWidgets('the callback is optional and Cupertino uses its native prompt', (
tester,
) async {
final gateway = GalleryGateway((type, fields) async {
if (type == 'list_templates') return templatesReply(galleryTemplates);
return acceptedCreate(type, fields);
});
await pumpGallery(tester, gateway, cupertino: true);
await openRelease(tester);
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
expect(find.byType(AlertDialog), findsNothing);
await tester.enterText(find.byKey(templateCreateNameKey), 'Cupertino');
await tester.pump();
await tester.tap(find.byKey(templateCreateConfirmKey));
await tester.pumpAndSettle();
expect(gateway.callsOf('validate'), hasLength(3));
expect(gateway.callsOf('submit'), hasLength(1));
expect(
find.text('Created "Created release". It is in the Pipelines list.'),
findsOneWidget,
);
expect(find.byKey(templateCreateCancelKey), findsOneWidget);
});
} }
@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -241,85 +240,54 @@ void main() {
expect(find.byKey(templatesGalleryKey), findsOneWidget); expect(find.byKey(templatesGalleryKey), findsOneWidget);
}); });
testWidgets('Cupertino host uses its own list, back and detail controls', (
tester,
) async {
final gateway = GalleryGateway(
(type, fields) async => templatesReply(galleryTemplates),
);
await pumpGallery(tester, gateway, cupertino: true);
expect(find.byType(AppListRow), findsNWidgets(2));
expect(find.byType(CupertinoListTile), findsNothing);
expect(find.byType(Scaffold), findsNothing);
await tester.tap(find.byKey(templateRowKey('release')));
await tester.pumpAndSettle();
expect(find.byKey(templateDetailKey), findsOneWidget);
expect(selectableSource(source), findsOneWidget);
expect(
tester
.widget<CupertinoButton>(find.byKey(templateCreateActionKey))
.onPressed,
isNotNull,
);
expect(find.byType(BackButton), findsNothing);
await tester.tap(find.byKey(templatesBackKey));
await tester.pumpAndSettle();
expect(find.byType(AppListRow), findsNWidgets(2));
});
testWidgets( testWidgets(
'a failed refresh with a template open is visible and retryable', 'a failed refresh with a template open is visible and retryable',
(tester) async { (tester) async {
for (final cupertino in [false, true]) { var mode = 'ok';
var mode = 'ok'; final gateway = GalleryGateway((type, fields) async {
final gateway = GalleryGateway((type, fields) async { if (type != 'list_templates') throw StateError('unexpected $type');
if (type != 'list_templates') throw StateError('unexpected $type'); if (mode == 'refuse') throw Exception('refresh unavailable');
if (mode == 'refuse') throw Exception('refresh unavailable'); return templatesReply(galleryTemplates);
return templatesReply(galleryTemplates); });
});
await pumpGallery(tester, gateway, cupertino: cupertino); await pumpGallery(tester, gateway);
await tester.tap(find.byKey(templateRowKey('release'))); await tester.tap(find.byKey(templateRowKey('release')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(templateDetailKey), findsOneWidget); expect(find.byKey(templateDetailKey), findsOneWidget);
mode = 'refuse'; mode = 'refuse';
await tester.tap(find.byKey(templatesRefreshKey)); await tester.tap(find.byKey(templatesRefreshKey));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(gateway.callsOf('list_templates'), hasLength(2)); expect(gateway.callsOf('list_templates'), hasLength(2));
expect(find.byKey(templateDetailKey), findsOneWidget); expect(find.byKey(templateDetailKey), findsOneWidget);
expect(find.byKey(templatesErrorBannerKey), findsOneWidget); expect(find.byKey(templatesErrorBannerKey), findsOneWidget);
expect(find.text('refresh unavailable'), findsOneWidget); expect(find.text('refresh unavailable'), findsOneWidget);
expect(find.byKey(templatesBannerRetryKey), findsOneWidget); expect(find.byKey(templatesBannerRetryKey), findsOneWidget);
expect(find.byKey(templatesErrorKey), findsNothing); expect(find.byKey(templatesErrorKey), findsNothing);
expect(find.text(templateSourceLabel), findsOneWidget); expect(find.text(templateSourceLabel), findsOneWidget);
expect(find.text(templateCreateActionLabel), findsOneWidget); expect(find.text(templateCreateActionLabel), findsOneWidget);
expect( expect(
tester.widget(find.byKey(templatesBannerRetryKey)), tester.widget(find.byKey(templatesBannerRetryKey)),
cupertino ? isA<CupertinoButton>() : isA<TextButton>(), isA<TextButton>(),
); );
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
mode = 'ok'; mode = 'ok';
await tester.tap(find.byKey(templatesBannerRetryKey)); await tester.tap(find.byKey(templatesBannerRetryKey));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('refresh unavailable'), findsNothing); expect(find.text('refresh unavailable'), findsNothing);
expect(find.byKey(templatesErrorBannerKey), findsNothing); expect(find.byKey(templatesErrorBannerKey), findsNothing);
expect(find.byKey(templateDetailKey), findsOneWidget); expect(find.byKey(templateDetailKey), findsOneWidget);
expect(find.text(templateSourceLabel), findsOneWidget); expect(find.text(templateSourceLabel), findsOneWidget);
expect(gateway.callsOf('list_templates'), hasLength(3)); expect(gateway.callsOf('list_templates'), hasLength(3));
await tester.tap(find.byKey(templatesBackKey)); await tester.tap(find.byKey(templatesBackKey));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(templatesGalleryKey), findsOneWidget); expect(find.byKey(templatesGalleryKey), findsOneWidget);
expect(find.text('Release workflow'), findsOneWidget); expect(find.text('Release workflow'), findsOneWidget);
expect(find.text('(unnamed template)'), findsOneWidget); expect(find.text('(unnamed template)'), findsOneWidget);
}
}, },
); );
@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
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/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -79,7 +78,7 @@ Future<JsonMap> acceptedCreate(String type, JsonMap fields) async {
throw StateError('Unexpected request $type'); throw StateError('Unexpected request $type');
} }
/// Pumps the gallery in a real Material or Cupertino host without fixed sizes. /// Pumps the gallery in a real Material host without fixed sizes.
Future<void> pumpGallery( Future<void> pumpGallery(
WidgetTester tester, WidgetTester tester,
GalleryGateway gateway, { GalleryGateway gateway, {
@@ -105,16 +104,8 @@ Future<void> pumpGallery(
embedded: embedded, embedded: embedded,
onCreated: onCreated, onCreated: onCreated,
); );
final home = embedded final home = embedded ? Scaffold(body: screen) : screen;
? (cupertino await tester.pumpWidget(MaterialApp(builder: media, home: home));
? CupertinoPageScaffold(child: screen)
: Scaffold(body: screen))
: screen;
await tester.pumpWidget(
cupertino
? CupertinoApp(builder: media, home: home)
: MaterialApp(builder: media, home: home),
);
if (settle) await tester.pumpAndSettle(); if (settle) await tester.pumpAndSettle();
} }
@@ -11,62 +11,52 @@ import 'template_gallery_test_support.dart';
/// Settings reading width, start-aligned; the bar names the open template and /// Settings reading width, start-aligned; the bar names the open template and
/// the Create action is a compact button, not a full-width bar. /// the Create action is a compact button, not a full-width bar.
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('rows and detail are capped at 720 on a wide window', (
final host = cupertino ? 'Cupertino' : 'Material'; tester,
) async {
final gateway = GalleryGateway(
(type, fields) async => templatesReply(galleryTemplates),
);
await pumpGallery(tester, gateway, size: const Size(1200, 800));
testWidgets('$host: rows and detail are capped at 720 on a wide window', ( final row = tester.getRect(find.byKey(templateRowKey('release')));
expect(row.left, 0);
expect(row.width, templatesContentMaxWidth);
expect(find.text('Templates'), findsOneWidget);
await tester.tap(find.byKey(templateRowKey('release')));
await tester.pumpAndSettle();
final bar = find.byType(SegmentedBar);
expect(
find.descendant(of: bar, matching: find.text('Release workflow')),
findsOneWidget,
);
expect(find.text('Templates'), findsNothing);
final create = tester.getRect(find.byKey(templateCreateActionKey));
expect(create.left, 16);
// Its own width, not stretched across the 688 content column.
expect(create.width, lessThan(templatesContentMaxWidth - 32));
final body = tester.getRect(selectableSource(source));
expect(body.right, lessThanOrEqualTo(templatesContentMaxWidth));
expect(tester.takeException(), isNull);
});
testWidgets('the detail fits 320 at 2x text', (tester) async {
final gateway = GalleryGateway(
(type, fields) async => templatesReply(galleryTemplates),
);
await pumpGallery(
tester, tester,
) async { gateway,
final gateway = GalleryGateway( size: const Size(320, 800),
(type, fields) async => templatesReply(galleryTemplates), textScale: 2,
); );
await pumpGallery( expect(tester.takeException(), isNull);
tester, await tester.tap(find.byKey(templateRowKey('release')));
gateway, await tester.pumpAndSettle();
cupertino: cupertino, expect(find.byKey(templateCreateActionKey), findsOneWidget);
size: const Size(1200, 800), expect(tester.takeException(), isNull);
); });
final row = tester.getRect(find.byKey(templateRowKey('release')));
expect(row.left, 0);
expect(row.width, templatesContentMaxWidth);
expect(find.text('Templates'), findsOneWidget);
await tester.tap(find.byKey(templateRowKey('release')));
await tester.pumpAndSettle();
final bar = find.byType(SegmentedBar);
expect(
find.descendant(of: bar, matching: find.text('Release workflow')),
findsOneWidget,
);
expect(find.text('Templates'), findsNothing);
final create = tester.getRect(find.byKey(templateCreateActionKey));
expect(create.left, 16);
// Its own width, not stretched across the 688 content column.
expect(create.width, lessThan(templatesContentMaxWidth - 32));
final body = tester.getRect(selectableSource(source));
expect(body.right, lessThanOrEqualTo(templatesContentMaxWidth));
expect(tester.takeException(), isNull);
});
testWidgets('$host: the detail fits 320 at 2x text', (tester) async {
final gateway = GalleryGateway(
(type, fields) async => templatesReply(galleryTemplates),
);
await pumpGallery(
tester,
gateway,
cupertino: cupertino,
size: const Size(320, 800),
textScale: 2,
);
expect(tester.takeException(), isNull);
await tester.tap(find.byKey(templateRowKey('release')));
await tester.pumpAndSettle();
expect(find.byKey(templateCreateActionKey), findsOneWidget);
expect(tester.takeException(), isNull);
});
}
} }
+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),
);
} }
+197 -241
View File
@@ -1,7 +1,6 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
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/artifacts/domain/artifact_groups.dart'; import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
@@ -23,21 +22,18 @@ import '../../features/artifacts/ui/artifact_visit_list_fixture.dart';
import '../../features/chat/conversation/chat_composer_bar_fixtures.dart'; import '../../features/chat/conversation/chat_composer_bar_fixtures.dart';
/// Every glass control bar keeps its first and last controls as far from the /// Every glass control bar keeps its first and last controls as far from the
/// pill's sides as from its top and bottom, and spaces neighbours evenly, on /// pill's sides as from its top and bottom, and spaces neighbours evenly, at
/// both hosts, at phone width and at a larger text size. /// phone width and at a larger text size.
const _phone = Size(390, 844); const _phone = Size(390, 844);
const _scales = [1.0, 1.3]; const _scales = [1.0, 1.3];
const _hosts = [false, true];
final Uint8List _png = base64Decode( final Uint8List _png = base64Decode(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAE' 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAE'
'hQGAhKmMIQAAAABJRU5ErkJggg==', 'hQGAhKmMIQAAAABJRU5ErkJggg==',
); );
Widget _host(bool cupertino, Widget child) => cupertino Widget _host(Widget child) => MaterialApp(home: Scaffold(body: child));
? CupertinoApp(home: CupertinoPageScaffold(child: child))
: MaterialApp(home: Scaffold(body: child));
Future<void> _setUp(WidgetTester tester, double scale) async { Future<void> _setUp(WidgetTester tester, double scale) async {
tester.view.physicalSize = _phone * tester.view.devicePixelRatio; tester.view.physicalSize = _phone * tester.view.devicePixelRatio;
@@ -50,9 +46,7 @@ Future<void> _setUp(WidgetTester tester, double scale) async {
List<Rect> _controls(WidgetTester tester, Finder pill) { List<Rect> _controls(WidgetTester tester, Finder pill) {
final found = find.descendant( final found = find.descendant(
of: pill, of: pill,
matching: find.byWidgetPredicate( matching: find.byWidgetPredicate((widget) => widget is IconButton),
(widget) => widget is IconButton || widget is CupertinoButton,
),
); );
final rects = [ final rects = [
for (var i = 0; i < found.evaluate().length; i++) for (var i = 0; i < found.evaluate().length; i++)
@@ -101,248 +95,210 @@ Rect _pillOf(WidgetTester tester, Finder inside) => tester.getRect(
); );
void main() { void main() {
for (final cupertino in _hosts) { for (final scale in _scales) {
final host = cupertino ? 'Cupertino' : 'Material'; final when = 'text x$scale';
for (final scale in _scales) {
final when = '$host, text x$scale';
testWidgets('artifact viewer bar: equal end gaps ($when)', ( testWidgets('artifact viewer bar: equal end gaps ($when)', (tester) async {
tester, await _setUp(tester, scale);
) async { for (final count in [1, 3]) {
await _setUp(tester, scale); final artifacts = [
for (final count in [1, 3]) { for (var i = 0; i < count; i++)
final artifacts = [ recordedArtifact(
for (var i = 0; i < count; i++) 'shot-$i.png',
recordedArtifact( url: '/artifacts/1/1/shot-$i.png',
'shot-$i.png', contentType: 'image/png',
url: '/artifacts/1/1/shot-$i.png',
contentType: 'image/png',
),
];
final group = ArtifactGroup(
stageKey: 'review',
visit: 1,
artifacts: artifacts,
);
await tester.pumpWidget(
_host(
cupertino,
ArtifactViewerPage(
key: ValueKey(count),
groups: [group],
selectedIdentity: artifactVisitIdentity(group, artifacts.first),
configuredEndpoint: 'ws://127.0.0.1:8081/connect',
fetch: (_) async =>
ArtifactFetchResult(status: 200, bytes: _png),
markdownBuilder: (context, value) => Text(value),
openExternal: (_) async => true,
),
), ),
);
await tester.pumpAndSettle();
final row = find.byKey(const Key('artifact-viewer-actions'));
final pill = _pillOf(tester, row);
final controls = _controls(tester, row);
expect(controls.length, greaterThanOrEqualTo(2));
_expectEqualEnds(pill, controls.first, controls.last);
_expectEvenNeighbours(
count > 1 ? controls.sublist(0, controls.length - 2) : controls,
);
if (count > 1) {
_expectEvenNeighbours(controls.sublist(controls.length - 2));
}
expect(pill.height, closeTo(GlassBarMetrics.height(cupertino), 1));
expect(tester.takeException(), isNull);
}
});
testWidgets('diff page pager: position and chevrons inset ($when)', (
tester,
) async {
await _setUp(tester, scale);
await tester.pumpWidget(
_host(
cupertino,
FileDiffPage(
files: [
for (final name in ['a', 'b', 'c'])
FileChange(
path: 'lib/$name.dart',
kind: ChangeKind.modified,
patch:
'--- a/lib/$name.dart\n+++ b/lib/$name.dart\n'
'@@ -1 +1 @@\n-x\n+y\n',
),
],
),
),
);
await tester.pumpAndSettle();
final pager = find.byKey(const ValueKey('file-diff-pager'));
_expectPager(tester, pager, cupertino, find.text('1 of 3'));
});
testWidgets('changes visit pager: equal end gaps ($when)', (
tester,
) async {
await _setUp(tester, scale);
Map<String, dynamic> visit(String stage, int sequence) => {
'stage': stage,
'sequence': sequence,
'status': 'completed',
'file_changes': {
'status': 'complete',
'scope': 'Git tracked files',
'skipped': 0,
'omitted': 0,
'diagnostic': '',
'files': [
{'path': 'lib/$stage.dart', 'kind': 'added'},
],
},
};
await tester.pumpWidget(
_host(
cupertino,
ChangesViewer(
steps: [visit('build', 1), visit('review', 2)],
showSummary: false,
),
),
);
await tester.pumpAndSettle();
final position = find.byKey(
const ValueKey<String>('changes-visit-position'),
);
_expectPager(
tester,
find.ancestor(of: position, matching: find.byType(Row)).first,
cupertino,
position,
);
});
testWidgets('chat composer: + and Send keep the pill gap ($when)', (
tester,
) async {
await _setUp(tester, scale);
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
final composer = ChatComposerController(
gateway,
's',
drafts: MemoryChatDraftStore(),
);
addTearDown(composer.dispose);
await tester.pumpWidget(
_host(
cupertino,
Align(
alignment: Alignment.bottomCenter,
child: ChatComposerBar(
composer: composer,
running: false,
placeholder: 'Message',
),
),
),
);
await tester.pumpAndSettle();
final pill = tester.getRect(
find.byKey(const Key('chat-composer-pill')),
);
final attach = tester.getRect(
find.byKey(const Key('chat-composer-attach')),
);
final send = tester.getRect(
find.byKey(const Key('chat-composer-primary')),
);
// The controls keep to the field's last line: each end control is as
// far from the pill's side as from its bottom, and while the field is
// one line (no taller than a control) as far from its top.
final row = GlassBarMetrics.controlExtent(cupertino);
final oneLine =
pill.height <= row + 2 * GlassBarMetrics.fieldEdgeGap + 0.5;
for (final (control, start) in [(attach, true), (send, false)]) {
final bottom = pill.bottom - control.bottom;
final side = start
? control.left - pill.left
: pill.right - control.right;
expect(side, closeTo(bottom, 1), reason: 'side vs bottom');
if (oneLine) {
expect(control.top - pill.top, closeTo(bottom, 1), reason: 'top');
expect(bottom, closeTo((pill.height - control.height) / 2, 1));
}
}
if (scale == 1.0) expect(oneLine, isTrue, reason: 'pill $pill');
expect(tester.takeException(), isNull);
});
testWidgets('top bar actions pill: controls fill it evenly ($when)', (
tester,
) async {
await _setUp(tester, scale);
final actions = [
for (final name in ['a', 'b', 'c'])
cupertino
? CupertinoButton(
key: Key('action-$name'),
padding: EdgeInsets.zero,
onPressed: () {},
child: const Icon(CupertinoIcons.info),
)
: IconButton(
key: Key('action-$name'),
onPressed: () {},
icon: const Icon(Icons.info_outline),
),
]; ];
final group = ArtifactGroup(
stageKey: 'review',
visit: 1,
artifacts: artifacts,
);
await tester.pumpWidget( await tester.pumpWidget(
cupertino _host(
? CupertinoApp( ArtifactViewerPage(
home: CupertinoPageScaffold( key: ValueKey(count),
navigationBar: SegmentedBar( groups: [group],
cupertino: true, selectedIdentity: artifactVisitIdentity(group, artifacts.first),
title: 'Title', configuredEndpoint: 'ws://127.0.0.1:8081/connect',
actions: actions, fetch: (_) async => ArtifactFetchResult(status: 200, bytes: _png),
), markdownBuilder: (context, value) => Text(value),
child: const SizedBox.expand(), openExternal: (_) async => true,
), ),
) ),
: MaterialApp(
home: Scaffold(
appBar: SegmentedBar(
cupertino: false,
title: 'Title',
actions: actions,
),
),
),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final first = find.byKey(const Key('action-a')); final row = find.byKey(const Key('artifact-viewer-actions'));
final pill = _pillOf(tester, first); final pill = _pillOf(tester, row);
final controls = [ final controls = _controls(tester, row);
for (final name in ['a', 'b', 'c']) expect(controls.length, greaterThanOrEqualTo(2));
tester.getRect(find.byKey(Key('action-$name'))),
];
_expectEqualEnds(pill, controls.first, controls.last); _expectEqualEnds(pill, controls.first, controls.last);
_expectEvenNeighbours(controls); _expectEvenNeighbours(
count > 1 ? controls.sublist(0, controls.length - 2) : controls,
);
if (count > 1) {
_expectEvenNeighbours(controls.sublist(controls.length - 2));
}
expect(pill.height, closeTo(GlassBarMetrics.height(false), 1));
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}); }
} });
testWidgets('diff page pager: position and chevrons inset ($when)', (
tester,
) async {
await _setUp(tester, scale);
await tester.pumpWidget(
_host(
FileDiffPage(
files: [
for (final name in ['a', 'b', 'c'])
FileChange(
path: 'lib/$name.dart',
kind: ChangeKind.modified,
patch:
'--- a/lib/$name.dart\n+++ b/lib/$name.dart\n'
'@@ -1 +1 @@\n-x\n+y\n',
),
],
),
),
);
await tester.pumpAndSettle();
final pager = find.byKey(const ValueKey('file-diff-pager'));
_expectPager(tester, pager, find.text('1 of 3'));
});
testWidgets('changes visit pager: equal end gaps ($when)', (tester) async {
await _setUp(tester, scale);
Map<String, dynamic> visit(String stage, int sequence) => {
'stage': stage,
'sequence': sequence,
'status': 'completed',
'file_changes': {
'status': 'complete',
'scope': 'Git tracked files',
'skipped': 0,
'omitted': 0,
'diagnostic': '',
'files': [
{'path': 'lib/$stage.dart', 'kind': 'added'},
],
},
};
await tester.pumpWidget(
_host(
ChangesViewer(
steps: [visit('build', 1), visit('review', 2)],
showSummary: false,
),
),
);
await tester.pumpAndSettle();
final position = find.byKey(
const ValueKey<String>('changes-visit-position'),
);
_expectPager(
tester,
find.ancestor(of: position, matching: find.byType(Row)).first,
position,
);
});
testWidgets('chat composer: + and Send keep the pill gap ($when)', (
tester,
) async {
await _setUp(tester, scale);
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
final composer = ChatComposerController(
gateway,
's',
drafts: MemoryChatDraftStore(),
);
addTearDown(composer.dispose);
await tester.pumpWidget(
_host(
Align(
alignment: Alignment.bottomCenter,
child: ChatComposerBar(
composer: composer,
running: false,
placeholder: 'Message',
),
),
),
);
await tester.pumpAndSettle();
final pill = tester.getRect(find.byKey(const Key('chat-composer-pill')));
final attach = tester.getRect(
find.byKey(const Key('chat-composer-attach')),
);
final send = tester.getRect(
find.byKey(const Key('chat-composer-primary')),
);
// The controls keep to the field's last line: each end control is as
// far from the pill's side as from its bottom, and while the field is
// one line (no taller than a control) as far from its top.
final row = GlassBarMetrics.controlExtent(false);
final oneLine =
pill.height <= row + 2 * GlassBarMetrics.fieldEdgeGap + 0.5;
for (final (control, start) in [(attach, true), (send, false)]) {
final bottom = pill.bottom - control.bottom;
final side = start
? control.left - pill.left
: pill.right - control.right;
expect(side, closeTo(bottom, 1), reason: 'side vs bottom');
if (oneLine) {
expect(control.top - pill.top, closeTo(bottom, 1), reason: 'top');
expect(bottom, closeTo((pill.height - control.height) / 2, 1));
}
}
if (scale == 1.0) expect(oneLine, isTrue, reason: 'pill $pill');
expect(tester.takeException(), isNull);
});
testWidgets('top bar actions pill: controls fill it evenly ($when)', (
tester,
) async {
await _setUp(tester, scale);
final actions = [
for (final name in ['a', 'b', 'c'])
IconButton(
key: Key('action-$name'),
onPressed: () {},
icon: const Icon(Icons.info_outline),
),
];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
appBar: SegmentedBar(
cupertino: false,
title: 'Title',
actions: actions,
),
),
),
);
await tester.pumpAndSettle();
final first = find.byKey(const Key('action-a'));
final pill = _pillOf(tester, first);
final controls = [
for (final name in ['a', 'b', 'c'])
tester.getRect(find.byKey(Key('action-$name'))),
];
_expectEqualEnds(pill, controls.first, controls.last);
_expectEvenNeighbours(controls);
expect(tester.takeException(), isNull);
});
} }
} }
/// A pager row: its position text starts an icon's inset in from the pill's /// A pager row: its position text starts an icon's inset in from the pill's
/// edge (where an icon at that end would be drawn), and its chevrons keep the /// edge (where an icon at that end would be drawn), and its chevrons keep the
/// rule's equal gaps at the other end. /// rule's equal gaps at the other end.
void _expectPager( void _expectPager(WidgetTester tester, Finder inside, Finder position) {
WidgetTester tester,
Finder inside,
bool cupertino,
Finder position,
) {
final pill = _pillOf(tester, inside); final pill = _pillOf(tester, inside);
final controls = _controls(tester, inside); final controls = _controls(tester, inside);
expect(controls, hasLength(2)); expect(controls, hasLength(2));
@@ -353,14 +309,14 @@ void _expectPager(
final gap = (pill.height - last.height) / 2; final gap = (pill.height - last.height) / 2;
expect( expect(
text.left - pill.left, text.left - pill.left,
closeTo(gap + GlassBarMetrics.iconInset(cupertino), 1), closeTo(gap + GlassBarMetrics.iconInset(false), 1),
); );
// The chevrons keep the same gap from the position as from each other's // The chevrons keep the same gap from the position as from each other's
// icons: one icon inset on each side. // icons: one icon inset on each side.
expect( expect(
controls.first.left - text.right, controls.first.left - text.right,
greaterThanOrEqualTo(GlassBarMetrics.iconInset(cupertino) - 1), greaterThanOrEqualTo(GlassBarMetrics.iconInset(false) - 1),
); );
expect(pill.height, closeTo(GlassBarMetrics.height(cupertino), 1)); expect(pill.height, closeTo(GlassBarMetrics.height(false), 1));
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
} }
@@ -1,89 +0,0 @@
import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/input/cupertino_web_search_field.dart';
void main() {
for (final provided in [false, true]) {
testWidgets(
'native clear preserves semantics and focus (provided node: $provided)',
(tester) async {
final semantics = tester.ensureSemantics();
try {
final text = TextEditingController();
final focus = FocusNode();
addTearDown(text.dispose);
addTearDown(focus.dispose);
var clears = 0;
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
child: Center(
child: CupertinoWebSearchField(
controller: text,
placeholder: 'Search',
focusNode: provided ? focus : null,
onCleared: () {
clears++;
text.clear();
},
),
),
),
),
);
final field = find.byType(EditableText);
final effective = tester.widget<EditableText>(field).focusNode;
effective.requestFocus();
await tester.pumpAndSettle();
final height = tester
.getSize(find.byType(CupertinoWebSearchField))
.height;
final before = tester.getSemantics(field);
final identity = before.id;
expect(
before.getSemanticsData().flagsCollection.isEnabled,
Tristate.isTrue,
);
await tester.enterText(
find.byType(CupertinoSearchTextField),
'release',
);
await tester.pumpAndSettle();
final after = tester.getSemantics(field);
expect(after.id, identity);
expect(
tester.getSize(find.byType(CupertinoWebSearchField)).height,
height,
);
expect(
after.getSemanticsData().flagsCollection.isEnabled,
Tristate.isTrue,
);
expect(effective.hasPrimaryFocus, isTrue);
await tester.tap(find.byType(CupertinoButton));
await tester.pumpAndSettle();
expect(text.text, isEmpty);
expect(clears, 1);
expect(
tester.getSize(find.byType(CupertinoWebSearchField)).height,
height,
);
expect(effective.hasPrimaryFocus, isTrue);
expect(tester.getSemantics(field).id, identity);
await tester.enterText(
find.byType(CupertinoSearchTextField),
'again',
);
await tester.pumpAndSettle();
expect(text.text, 'again');
expect(effective.hasPrimaryFocus, isTrue);
} finally {
semantics.dispose();
}
},
);
}
}
@@ -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';
@@ -11,10 +10,9 @@ const _rowColor = Color(0xFFE3F2FD);
/// A list of three rows; tapping one pushes its page, grown from that row. /// A list of three rows; tapping one pushes its page, grown from that row.
class _List extends StatelessWidget { class _List extends StatelessWidget {
const _List({required this.sources, required this.cupertino}); const _List({required this.sources});
final ContainerTransformSources sources; final ContainerTransformSources sources;
final bool cupertino;
@override @override
Widget build(BuildContext context) => ContainerTransformScope( Widget build(BuildContext context) => ContainerTransformScope(
@@ -33,8 +31,8 @@ class _List extends StatelessWidget {
onTap: () => Navigator.of(context).push( onTap: () => Navigator.of(context).push(
ContainerTransformPageRoute<void>( ContainerTransformPageRoute<void>(
link: sources.link(() => id), link: sources.link(() => id),
cupertino: cupertino, cupertino: false,
builder: (_) => _Page(id: id, cupertino: cupertino), builder: (_) => _Page(id: id),
), ),
), ),
child: SizedBox(height: 72, child: Text('row $id')), child: SizedBox(height: 72, child: Text('row $id')),
@@ -46,42 +44,31 @@ class _List extends StatelessWidget {
} }
class _Page extends StatelessWidget { class _Page extends StatelessWidget {
const _Page({required this.id, required this.cupertino}); const _Page({required this.id});
final String id; final String id;
final bool cupertino;
@override @override
Widget build(BuildContext context) => cupertino Widget build(BuildContext context) => Scaffold(
? CupertinoPageScaffold( appBar: AppBar(),
navigationBar: const CupertinoNavigationBar(), body: Center(child: Text('page $id')),
child: Center(child: Text('page $id')), );
)
: Scaffold(
appBar: AppBar(),
body: Center(child: Text('page $id')),
);
} }
Future<ContainerTransformSources> _pump( Future<ContainerTransformSources> _pump(
WidgetTester tester, { WidgetTester tester, {
bool cupertino = false,
bool reduced = false, bool reduced = false,
}) async { }) async {
tester.view.physicalSize = _screen; tester.view.physicalSize = _screen;
tester.view.devicePixelRatio = 1; tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset); addTearDown(tester.view.reset);
final sources = ContainerTransformSources(); final sources = ContainerTransformSources();
final home = _List(sources: sources, cupertino: cupertino); final home = _List(sources: sources);
Widget media(BuildContext context, Widget? child) => MediaQuery( Widget media(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reduced), data: MediaQuery.of(context).copyWith(disableAnimations: reduced),
child: child!, child: child!,
); );
await tester.pumpWidget( await tester.pumpWidget(MaterialApp(builder: media, home: home));
cupertino
? CupertinoApp(builder: media, home: home)
: MaterialApp(builder: media, home: home),
);
return sources; return sources;
} }
@@ -186,7 +173,7 @@ void main() {
ContainerTransformPageRoute<void>( ContainerTransformPageRoute<void>(
link: sources.link(() => 'missing'), link: sources.link(() => 'missing'),
cupertino: false, cupertino: false,
builder: (_) => const _Page(id: 'x', cupertino: false), builder: (_) => const _Page(id: 'x'),
), ),
); );
await tester.pump(); await tester.pump();
@@ -196,54 +183,6 @@ void main() {
expect(find.text('page x'), findsOneWidget); expect(find.text('page x'), findsOneWidget);
}); });
testWidgets('a Cupertino swipe back shrinks the page with the finger', (
tester,
) async {
await _pump(tester, cupertino: true);
final row = tester.getRect(find.byKey(const Key('row-b')));
await tester.tap(find.byKey(const Key('row-b')));
await tester.pumpAndSettle();
expect(_surface(tester), Offset.zero & _screen);
final gesture = await tester.startGesture(const Offset(5, 400));
await gesture.moveBy(const Offset(20, 0));
await gesture.moveBy(const Offset(100, 0));
await tester.pump();
final early = _surface(tester);
_expectBetween(early, row);
await gesture.moveBy(const Offset(100, 0));
await tester.pump();
final later = _surface(tester);
expect(later.height, lessThan(early.height), reason: 'follows the finger');
// Back toward the start edge, the page grows again.
await gesture.moveBy(const Offset(-150, 0));
await tester.pump();
expect(_surface(tester).height, greaterThan(later.height));
await gesture.moveBy(const Offset(200, 0));
await gesture.up();
await tester.pumpAndSettle();
expect(find.text('page b'), findsNothing);
expect(find.byKey(const Key('row-b')), findsOneWidget);
});
testWidgets('a short Cupertino swipe released early stays on the page', (
tester,
) async {
await _pump(tester, cupertino: true);
await tester.tap(find.byKey(const Key('row-b')));
await tester.pumpAndSettle();
final gesture = await tester.startGesture(const Offset(5, 400));
await gesture.moveBy(const Offset(20, 0));
await gesture.moveBy(const Offset(40, 0));
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();
expect(find.text('page b'), findsOneWidget);
expect(_surface(tester), Offset.zero & _screen);
});
testWidgets('Android predictive back drives the shrink, then commits', ( testWidgets('Android predictive back drives the shrink, then commits', (
tester, tester,
) async { ) async {
@@ -4,13 +4,11 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/input/app_search_field.dart'; import 'package:pipelines_app/ui/input/app_search_field.dart';
import 'package:pipelines_app/ui/navigation/bar_icon_button.dart'; import 'package:pipelines_app/ui/navigation/bar_icon_button.dart';
Widget _row(bool cupertino, List<Widget> children) { Widget _row(List<Widget> children) {
final row = Center( final row = Center(
child: Row(mainAxisSize: MainAxisSize.min, children: children), child: Row(mainAxisSize: MainAxisSize.min, children: children),
); );
return cupertino return MaterialApp(home: Scaffold(body: row));
? CupertinoApp(home: CupertinoPageScaffold(child: row))
: MaterialApp(home: Scaffold(body: row));
} }
BarIconButton _action(Key key, {bool busy = false}) => BarIconButton( BarIconButton _action(Key key, {bool busy = false}) => BarIconButton(
@@ -23,73 +21,58 @@ BarIconButton _action(Key key, {bool busy = false}) => BarIconButton(
); );
void main() { void main() {
for (final cupertino in [false, true]) { const side = kMinInteractiveDimension;
final host = cupertino ? 'Cupertino' : 'Material';
final side = cupertino
? kMinInteractiveDimensionCupertino
: kMinInteractiveDimension;
testWidgets('$host bar actions are whole, evenly sized touch targets', ( testWidgets('bar actions are whole, evenly sized touch targets', (
tester, tester,
) async { ) async {
await tester.pumpWidget( await tester.pumpWidget(
_row(cupertino, [ _row([
_action(const ValueKey('a')), _action(const ValueKey('a')),
_action(const ValueKey('b')), _action(const ValueKey('b')),
_action(const ValueKey('c'), busy: true), _action(const ValueKey('c'), busy: true),
]), ]),
); );
for (final key in const ['a', 'b', 'c']) { for (final key in const ['a', 'b', 'c']) {
expect(tester.getSize(find.byKey(ValueKey(key))), Size(side, side)); expect(tester.getSize(find.byKey(ValueKey(key))), Size(side, side));
} }
// Adjacent actions abut: the spacing is the targets', not padding. // Adjacent actions abut: the spacing is the targets', not padding.
expect( expect(
tester.getTopLeft(find.byKey(const ValueKey('b'))).dx - tester.getTopLeft(find.byKey(const ValueKey('b'))).dx -
tester.getTopLeft(find.byKey(const ValueKey('a'))).dx, tester.getTopLeft(find.byKey(const ValueKey('a'))).dx,
side, side,
); );
if (cupertino) expect(find.byType(Material), findsNothing); expect(find.bySemanticsLabel('Refresh'), findsWidgets);
expect(find.bySemanticsLabel('Refresh'), findsWidgets); });
});
testWidgets('$host search field is one stadium field with a clear', ( testWidgets('search field is one stadium field with a clear', (tester) async {
tester, final text = TextEditingController();
) async { addTearDown(text.dispose);
final text = TextEditingController(); var cleared = false;
addTearDown(text.dispose); await tester.pumpWidget(
var cleared = false; _row([
await tester.pumpWidget( SizedBox(
_row(cupertino, [ width: 300,
SizedBox( child: AppSearchField(
width: 300, fieldKey: const ValueKey('field'),
child: AppSearchField( controller: text,
fieldKey: const ValueKey('field'), placeholder: 'Search',
controller: text, onCleared: () => cleared = true,
placeholder: 'Search',
onCleared: () => cleared = true,
),
), ),
]), ),
); ]),
if (cupertino) { );
expect(find.byType(CupertinoSearchTextField), findsOneWidget); final field = tester.widget<TextField>(find.byKey(const ValueKey('field')));
expect(find.byType(Material), findsNothing); final border = field.decoration!.enabledBorder! as OutlineInputBorder;
return; expect(border.borderSide, BorderSide.none);
} expect(field.decoration!.filled, isTrue);
final field = tester.widget<TextField>( expect(find.byTooltip('Clear search'), findsNothing);
find.byKey(const ValueKey('field')),
);
final border = field.decoration!.enabledBorder! as OutlineInputBorder;
expect(border.borderSide, BorderSide.none);
expect(field.decoration!.filled, isTrue);
expect(find.byTooltip('Clear search'), findsNothing);
await tester.enterText(find.byKey(const ValueKey('field')), 'abc'); await tester.enterText(find.byKey(const ValueKey('field')), 'abc');
await tester.pump(); await tester.pump();
await tester.tap(find.byTooltip('Clear search')); await tester.tap(find.byTooltip('Clear search'));
await tester.pump(); await tester.pump();
expect(text.text, isEmpty); expect(text.text, isEmpty);
expect(cleared, isTrue); expect(cleared, isTrue);
}); });
}
} }
+29 -61
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/application/app.dart'; import 'package:pipelines_app/application/app.dart';
@@ -27,69 +26,38 @@ void main() {
expect(b?.fontSize, a?.fontSize); expect(b?.fontSize, a?.fontSize);
expect(b?.fontWeight, a?.fontWeight); expect(b?.fontWeight, a?.fontWeight);
} }
expect(
build(
fontFamily: 'Inter',
).cupertinoOverrideTheme?.textTheme?.textStyle.fontFamily,
'Inter',
);
expect(build().cupertinoOverrideTheme, isNull);
} }
}); });
test('the Cupertino theme takes the family in every text role', () { testWidgets('the Material host switches font live, without a restart', (
expect(appCupertinoThemeWith(), same(appCupertinoTheme)); tester,
final text = appCupertinoThemeWith(fontFamily: 'Inter').textTheme; ) async {
const stock = CupertinoTextThemeData(); final fonts = AppFontController(
for (final (a, b) in <(TextStyle, TextStyle)>[ store: MemoryAppFontStore(),
(stock.textStyle, text.textStyle), loader: (family, assets) async {},
(stock.navTitleTextStyle, text.navTitleTextStyle),
(stock.navLargeTitleTextStyle, text.navLargeTitleTextStyle),
(stock.tabLabelTextStyle, text.tabLabelTextStyle),
(stock.actionTextStyle, text.actionTextStyle),
(stock.pickerTextStyle, text.pickerTextStyle),
]) {
expect(b.fontFamily, 'Inter');
expect(b.fontSize, a.fontSize);
expect(b.fontWeight, a.fontWeight);
}
expect(
appCupertinoThemeWith(fontFamily: 'Inter').scaffoldBackgroundColor,
AppColors.background,
); );
String? family;
await tester.pumpWidget(
MyApp(
fonts: fonts,
destination: AppDestination.settings,
destinationBodies: <AppDestination, WidgetBuilder>{
AppDestination.settings: (context) => Builder(
builder: (context) {
family = DefaultTextStyle.of(context).style.fontFamily;
return const Text('body');
},
),
},
),
);
final before = family;
expect(before, isNot('IBM Plex Sans'));
await fonts.select(AppFont.ibmPlexSans);
await tester.pumpAndSettle();
expect(family, 'IBM Plex Sans');
await fonts.select(AppFont.system);
await tester.pumpAndSettle();
expect(family, before);
}); });
for (final cupertino in <bool>[false, true]) {
testWidgets('the ${cupertino ? 'Cupertino' : 'Material'} host switches '
'font live, without a restart', (tester) async {
final fonts = AppFontController(
store: MemoryAppFontStore(),
loader: (family, assets) async {},
);
String? family;
await tester.pumpWidget(
MyApp(
cupertino: cupertino,
fonts: fonts,
destination: AppDestination.settings,
destinationBodies: <AppDestination, WidgetBuilder>{
AppDestination.settings: (context) => Builder(
builder: (context) {
family = DefaultTextStyle.of(context).style.fontFamily;
return const Text('body');
},
),
},
),
);
final before = family;
expect(before, isNot('IBM Plex Sans'));
await fonts.select(AppFont.ibmPlexSans);
await tester.pumpAndSettle();
expect(family, 'IBM Plex Sans');
await fonts.select(AppFont.system);
await tester.pumpAndSettle();
expect(family, before);
});
}
} }
+5 -4
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/ui/theme/app_theme.dart'; import 'package:pipelines_app/ui/theme/app_theme.dart';
@@ -20,11 +19,13 @@ void main() {
} }
}); });
test('the Cupertino page is gray in dark mode and unchanged in light', () { test('page backgrounds are gray in dark mode and unchanged in light', () {
expect(AppColors.background.darkColor, const Color(0xFF141416)); expect(AppColors.background.darkColor, const Color(0xFF141416));
expect(AppColors.background.color, const Color(0xFFFFFFFF)); expect(AppColors.background.color, const Color(0xFFFFFFFF));
expect(appCupertinoTheme.scaffoldBackgroundColor, AppColors.background); expect(
expect(AppColors.groupedBackground.darkColor, isNot(CupertinoColors.black)); AppColors.groupedBackground.darkColor,
isNot(const Color(0xFF000000)),
);
}); });
test('Android pages retain native predictive Back in both themes', () { test('Android pages retain native predictive Back in both themes', () {