diff --git a/app/lib/core/servers/chat/machine_sign_in_dialog.dart b/app/lib/core/servers/chat/machine_sign_in_dialog.dart index 4768dbf4..66b2b94f 100644 --- a/app/lib/core/servers/chat/machine_sign_in_dialog.dart +++ b/app/lib/core/servers/chat/machine_sign_in_dialog.dart @@ -1,8 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; - /// Asks for one machine's own password. [signIn] returns null on success, /// otherwise the sentence to show; the dialog stays open for a retry. Future showMachineSignIn( @@ -11,9 +8,7 @@ Future showMachineSignIn( required Future Function(String password) signIn, }) { final dialog = MachineSignInDialog(name: name, signIn: signIn); - return usesCupertinoHost(context) - ? showCupertinoDialog(context: context, builder: (_) => dialog) - : showDialog(context: context, builder: (_) => dialog); + return showDialog(context: context, builder: (_) => dialog); } class MachineSignInDialog extends StatefulWidget { @@ -68,24 +63,14 @@ class _MachineSignInDialogState extends State { @override Widget build(BuildContext context) { - final cupertino = usesCupertinoHost(context); - final field = cupertino - ? CupertinoTextField( - key: const Key('machine-password'), - controller: password, - obscureText: true, - autofocus: true, - placeholder: 'Password', - onSubmitted: busy ? null : (_) => submit(), - ) - : TextField( - key: const Key('machine-password'), - controller: password, - obscureText: true, - autofocus: true, - decoration: const InputDecoration(labelText: 'Password'), - onSubmitted: busy ? null : (_) => submit(), - ); + final field = TextField( + key: const Key('machine-password'), + controller: password, + obscureText: true, + autofocus: true, + decoration: const InputDecoration(labelText: 'Password'), + onSubmitted: busy ? null : (_) => submit(), + ); final content = Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, @@ -103,36 +88,20 @@ class _MachineSignInDialogState extends State { ], ); final title = Text('Sign in to ${widget.name}'); - return cupertino - ? CupertinoAlertDialog( - title: title, - content: content, - actions: [ - CupertinoDialogAction( - onPressed: busy ? null : () => Navigator.pop(context), - child: const Text('Cancel'), - ), - CupertinoDialogAction( - key: const Key('machine-sign-in'), - onPressed: busy ? null : submit, - child: Text(busy ? 'Signing in…' : 'Sign in'), - ), - ], - ) - : AlertDialog( - title: title, - content: content, - actions: [ - TextButton( - onPressed: busy ? null : () => Navigator.pop(context), - child: const Text('Cancel'), - ), - FilledButton( - key: const Key('machine-sign-in'), - onPressed: busy ? null : submit, - child: Text(busy ? 'Signing in…' : 'Sign in'), - ), - ], - ); + return AlertDialog( + title: title, + content: content, + actions: [ + TextButton( + onPressed: busy ? null : () => Navigator.pop(context), + child: const Text('Cancel'), + ), + FilledButton( + key: const Key('machine-sign-in'), + onPressed: busy ? null : submit, + child: Text(busy ? 'Signing in…' : 'Sign in'), + ), + ], + ); } } diff --git a/app/lib/core/servers/elevation/elevation_dialog.dart b/app/lib/core/servers/elevation/elevation_dialog.dart index cc22e086..1daeb811 100644 --- a/app/lib/core/servers/elevation/elevation_dialog.dart +++ b/app/lib/core/servers/elevation/elevation_dialog.dart @@ -1,7 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import 'machine_elevation.dart'; /// The app's elevation prompt: the native password dialog over whatever @@ -21,12 +19,10 @@ Future showElevationDialog( MachineElevation machine, ) async { final dialog = ElevationDialog(name: machine.name, submit: machine.submit); - final result = usesCupertinoHost(context) - ? await showCupertinoDialog( - context: context, - builder: (_) => dialog, - ) - : await showDialog(context: context, builder: (_) => dialog); + final result = await showDialog( + context: context, + builder: (_) => dialog, + ); return result ?? false; } @@ -74,24 +70,14 @@ class _ElevationDialogState extends State { @override Widget build(BuildContext context) { - final cupertino = usesCupertinoHost(context); - final field = cupertino - ? CupertinoTextField( - key: const Key('elevation-password'), - controller: password, - obscureText: true, - autofocus: true, - placeholder: 'Password', - onSubmitted: busy ? null : (_) => confirm(), - ) - : TextField( - key: const Key('elevation-password'), - controller: password, - obscureText: true, - autofocus: true, - decoration: const InputDecoration(labelText: 'Password'), - onSubmitted: busy ? null : (_) => confirm(), - ); + final field = TextField( + key: const Key('elevation-password'), + controller: password, + obscureText: true, + autofocus: true, + decoration: const InputDecoration(labelText: 'Password'), + onSubmitted: busy ? null : (_) => confirm(), + ); final content = Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, @@ -111,37 +97,20 @@ class _ElevationDialogState extends State { ); const title = Text('Confirm password'); final confirmLabel = Text(busy ? 'Confirming…' : 'Confirm'); - return cupertino - ? CupertinoAlertDialog( - title: title, - content: content, - actions: [ - CupertinoDialogAction( - onPressed: busy ? null : () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - CupertinoDialogAction( - key: const Key('elevation-confirm'), - isDefaultAction: true, - onPressed: busy ? null : confirm, - child: confirmLabel, - ), - ], - ) - : AlertDialog( - title: title, - content: content, - actions: [ - TextButton( - onPressed: busy ? null : () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - FilledButton( - key: const Key('elevation-confirm'), - onPressed: busy ? null : confirm, - child: confirmLabel, - ), - ], - ); + return AlertDialog( + title: title, + content: content, + actions: [ + TextButton( + onPressed: busy ? null : () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + FilledButton( + key: const Key('elevation-confirm'), + onPressed: busy ? null : confirm, + child: confirmLabel, + ), + ], + ); } } diff --git a/app/lib/features/attention/ui/needs_you_bell.dart b/app/lib/features/attention/ui/needs_you_bell.dart index 036ec199..7048a799 100644 --- a/app/lib/features/attention/ui/needs_you_bell.dart +++ b/app/lib/features/attention/ui/needs_you_bell.dart @@ -1,9 +1,7 @@ import 'dart:math' as math; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../domain/attention_models.dart'; import 'needs_you_keys.dart'; import 'needs_you_sheet.dart'; @@ -43,8 +41,8 @@ class NeedsYouBell extends StatefulWidget { final ValueChanged onDismiss; final ValueChanged> onClearAll; - /// Forces the native host in tests and fixtures; otherwise the ambient - /// [usesCupertinoHost] decides. + /// Retained for callers that still pass it; the bell is the Material action + /// whether this is set or not. final bool? cupertino; @override @@ -150,17 +148,14 @@ class _NeedsYouBellState extends State { @override Widget build(BuildContext context) { - final native = widget.cupertino ?? usesCupertinoHost(context); final label = attentionBadgeLabel(widget.entries.length); - final action = native ? _cupertino(context) : _material(context, label); final semantics = Semantics( label: label, button: true, onTap: _open, excludeSemantics: true, - child: action, + child: _material(label), ); - if (native) return semantics; // The reserved badge room is outside the semantics box, so the focus // rectangle stays the size of the action rather than the empty end room. return Padding( @@ -169,57 +164,18 @@ class _NeedsYouBellState extends State { ); } - Widget _material(BuildContext context, String label) { + Widget _material(String label) { return IconButton( key: attentionBellKey, focusNode: _focus, tooltip: label, onPressed: _open, - icon: _badged( - context, - hostCupertino: false, - icon: const Icon(Icons.notifications_outlined), - ), + icon: _badged(const Icon(Icons.notifications_outlined)), ); } - Widget _cupertino(BuildContext context) { - final theme = CupertinoTheme.of(context); - // The whole 44pt target and no extra padding, like every bar action. - return CupertinoButton( - key: attentionBellKey, - focusNode: _focus, - padding: EdgeInsets.zero, - minimumSize: const Size.square(kMinInteractiveDimensionCupertino), - onPressed: _open, - child: _badged( - context, - hostCupertino: true, - icon: const Icon(CupertinoIcons.bell), - textStyle: theme.textTheme.tabLabelTextStyle, - ), - ); - } - - Widget _badged( - BuildContext context, { - required bool hostCupertino, - required Widget icon, - TextStyle? textStyle, - }) { + Widget _badged(Widget icon) { final count = widget.entries.length; - // No native Cupertino badge exists; the framework Badge is used with the - // host's semantic red and the host's smallest text role. - if (hostCupertino && count > 0) { - return Badge.count( - key: attentionBadgeKey, - count: count, - textStyle: textStyle, - backgroundColor: CupertinoColors.systemRed.resolveFrom(context), - textColor: CupertinoColors.white, - child: icon, - ); - } if (count > 0) { return Badge.count(key: attentionBadgeKey, count: count, child: icon); } diff --git a/app/lib/features/attention/ui/needs_you_keys.dart b/app/lib/features/attention/ui/needs_you_keys.dart index b9e42cc2..754c9aee 100644 --- a/app/lib/features/attention/ui/needs_you_keys.dart +++ b/app/lib/features/attention/ui/needs_you_keys.dart @@ -6,13 +6,13 @@ const attentionBellKey = ValueKey('attention-bell'); /// The visible count badge. Absent when nothing needs the operator. const attentionBadgeKey = ValueKey('attention-badge'); -/// The open sheet itself, whichever native host draws it. +/// The open sheet itself. const attentionSheetKey = ValueKey('attention-sheet'); /// The honest empty line shown when the open snapshot has no entries. const attentionEmptyKey = ValueKey('attention-empty'); -/// The header's Done action, which closes the sheet on both hosts. +/// The header's Done action, which closes the sheet. const attentionDoneKey = ValueKey('attention-done'); /// The bulk dismissal action, present only while the snapshot has entries. diff --git a/app/lib/features/attention/ui/needs_you_runs_heading.dart b/app/lib/features/attention/ui/needs_you_runs_heading.dart index 7e856574..7c051807 100644 --- a/app/lib/features/attention/ui/needs_you_runs_heading.dart +++ b/app/lib/features/attention/ui/needs_you_runs_heading.dart @@ -15,8 +15,7 @@ import 'needs_you_bell.dart'; /// It owns the live attention state for this destination: [rows] are the /// already-loaded `list_runs` summaries and [frames] is the shared gateway's /// unsolicited stream, so it never polls or issues an attention request. The -/// bell has no built-in host choice; the ambient app host (or [cupertino] in a -/// fixture) selects the native Material or Cupertino action and sheet. +/// bell is always the Material action and sheet. class NeedsYouRunsHeading extends StatefulWidget { const NeedsYouRunsHeading({ super.key, @@ -49,7 +48,8 @@ class NeedsYouRunsHeading extends StatefulWidget { /// Injected clock for deterministic local-day windows. final DateTime Function()? now; - /// Forces the native host in tests and fixtures. + /// Retained for callers that still pass it; the heading is always the + /// Material bell whether this is set or not. final bool? cupertino; /// The app-level notification capability. Absent in fixtures that only draw diff --git a/app/lib/features/attention/ui/needs_you_sheet.dart b/app/lib/features/attention/ui/needs_you_sheet.dart index 21843ddc..bd4e0899 100644 --- a/app/lib/features/attention/ui/needs_you_sheet.dart +++ b/app/lib/features/attention/ui/needs_you_sheet.dart @@ -1,10 +1,7 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../domain/attention_models.dart'; -import 'needs_you_sheet_cupertino.dart'; import 'needs_you_sheet_material.dart'; /// Opens the native `Needs you` sheet over the live [entries]. @@ -17,8 +14,8 @@ import 'needs_you_sheet_material.dart'; /// /// The sheet stays open after Dismiss and Clear all, so several rows can be /// dealt with in one visit. Choosing a row closes it; Escape, the barrier and -/// system back are native route behaviour. The caller supplies the native host -/// explicitly when it already knows it; otherwise the ambient app host decides. +/// system back are native route behaviour. The sheet is always the Material +/// bottom sheet; [cupertino] is retained for callers that still pass it. Future showNeedsYouSheet({ required BuildContext context, required ValueListenable> entries, @@ -28,19 +25,6 @@ Future showNeedsYouSheet({ bool? cupertino, }) { final snapshot = attentionDismissalSnapshot(entries.value); - final native = cupertino ?? usesCupertinoHost(context); - if (native) { - return showCupertinoModalPopup( - context: context, - builder: (_) => CupertinoNeedsYouSheet( - entries: entries, - snapshot: snapshot, - onOpen: onOpen, - onDismiss: onDismiss, - onClearAll: onClearAll, - ), - ); - } return showModalBottomSheet( context: context, isScrollControlled: true, diff --git a/app/lib/features/attention/ui/needs_you_sheet_cupertino.dart b/app/lib/features/attention/ui/needs_you_sheet_cupertino.dart deleted file mode 100644 index 4c3456da..00000000 --- a/app/lib/features/attention/ui/needs_you_sheet_cupertino.dart +++ /dev/null @@ -1,190 +0,0 @@ -import '../../../ui/theme/app_theme.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; - -import '../../../ui/layout/app_sheet_header.dart'; -import 'attention_status_icon.dart'; -import '../domain/attention_models.dart'; -import 'needs_you_copy.dart'; -import 'needs_you_keys.dart'; - -/// The Cupertino popup body of the `Needs you` surface. -/// -/// It reads as a native action-sheet style grouped list: an inset-grouped iOS -/// list in a [CupertinoPopupSurface], with a Close action, one grouped row per -/// live entry and a separate Clear-all group. Dismissing and Clear all leave the -/// sheet open and redraw it, matching the browser; [snapshot] is the set Clear -/// all may remove, so a later arrival is shown but never cleared by this visit. -/// Rows use host text roles without a line cap so a long label and description -/// wrap at a narrow, scaled width. -class CupertinoNeedsYouSheet extends StatelessWidget { - const CupertinoNeedsYouSheet({ - super.key, - required this.entries, - required this.snapshot, - required this.onOpen, - required this.onDismiss, - required this.onClearAll, - }); - - /// The caller's current rows; a dismissal removed there redraws the sheet. - final ValueListenable> entries; - - /// The identities captured when the sheet opened, all Clear all may remove. - final List snapshot; - - final ValueChanged onOpen; - final ValueChanged onDismiss; - final ValueChanged> onClearAll; - - void _close(BuildContext context) => Navigator.of(context).pop(); - - void _open(BuildContext context, AttentionEntry entry) { - _close(context); - onOpen(entry); - } - - @override - Widget build(BuildContext context) { - return ValueListenableBuilder>( - valueListenable: entries, - builder: (context, rows, _) => _sheet(context, rows), - ); - } - - Widget _sheet(BuildContext context, List rows) { - final theme = CupertinoTheme.of(context); - final dismissLabels = attentionDismissLabels(rows); - return SafeArea( - key: attentionSheetKey, - top: false, - child: Padding( - padding: const EdgeInsets.all(8), - child: CupertinoPopupSurface( - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Padding( - padding: const EdgeInsets.only(top: 8), - child: AppSheetHeader( - title: attentionSheetTitle, - cupertino: true, - doneKey: attentionDoneKey, - onDone: () => _close(context), - ), - ), - if (rows.isEmpty) - Padding( - key: attentionEmptyKey, - padding: const EdgeInsetsDirectional.fromSTEB(20, 8, 20, 24), - child: Text( - attentionEmptyCopy, - style: theme.textTheme.textStyle.copyWith( - color: CupertinoColors.secondaryLabel.resolveFrom( - context, - ), - ), - ), - ) - else - Flexible( - child: SingleChildScrollView( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CupertinoListSection.insetGrouped( - backgroundColor: AppColors.groupedBackground, - children: [ - for (final entry in rows) - _AttentionRow( - key: attentionRowKey(entry.key), - entry: entry, - dismissLabel: dismissLabels[entry.key]!, - onOpen: () => _open(context, entry), - onDismiss: () => onDismiss(entry), - ), - ], - ), - CupertinoListSection.insetGrouped( - backgroundColor: AppColors.groupedBackground, - children: [ - CupertinoListTile( - key: attentionClearAllKey, - title: Center(child: Text(attentionClearAllCopy)), - onTap: () => onClearAll(snapshot), - ), - ], - ), - ], - ), - ), - ), - ], - ), - ), - ), - ); - } -} - -/// One native grouped row: an open action over the host's text roles and a -/// separate Dismiss control named after the row it removes. It deliberately does -/// not use [CupertinoListTile], whose single-line title/subtitle would truncate a -/// long scaled label. -class _AttentionRow extends StatelessWidget { - const _AttentionRow({ - super.key, - required this.entry, - required this.dismissLabel, - required this.onOpen, - required this.onDismiss, - }); - - final AttentionEntry entry; - final String dismissLabel; - final VoidCallback onOpen; - final VoidCallback onDismiss; - - @override - Widget build(BuildContext context) { - final theme = CupertinoTheme.of(context); - final secondary = theme.textTheme.textStyle.copyWith( - color: CupertinoColors.secondaryLabel.resolveFrom(context), - ); - return Padding( - padding: const EdgeInsetsDirectional.fromSTEB(16, 10, 8, 10), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(top: 4), - child: attentionStatusIcon(entry), - ), - const SizedBox(width: 12), - Expanded( - child: CupertinoButton( - padding: EdgeInsets.zero, - alignment: AlignmentDirectional.centerStart, - onPressed: onOpen, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(entry.label, style: theme.textTheme.textStyle), - const SizedBox(height: 4), - Text(attentionRowDescription(entry), style: secondary), - ], - ), - ), - ), - CupertinoButton( - key: attentionDismissKey(entry.key), - padding: EdgeInsets.zero, - onPressed: onDismiss, - child: Icon(CupertinoIcons.xmark, semanticLabel: dismissLabel), - ), - ], - ), - ); - } -} diff --git a/app/lib/features/attention/ui/notification_permission_tile.dart b/app/lib/features/attention/ui/notification_permission_tile.dart index d88713f7..32762e46 100644 --- a/app/lib/features/attention/ui/notification_permission_tile.dart +++ b/app/lib/features/attention/ui/notification_permission_tile.dart @@ -1,10 +1,8 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../notify/notification_models.dart'; -/// The permission tile's root, so a caller can find it whichever host draws it. +/// The permission tile's root, so a caller can find it. const notificationTileKey = ValueKey('notification-permission-tile'); /// The explicit-gesture Enable action, present only when a request is possible. @@ -44,28 +42,20 @@ class NotificationPermissionTile extends StatelessWidget { /// request would be possible. final VoidCallback? onRequest; - /// Forces the native host in tests and fixtures; otherwise the ambient - /// [usesCupertinoHost] decides. + /// Retained for callers that still pass it; the tile is the Material row + /// whether this is set or not. final bool? cupertino; @override Widget build(BuildContext context) { final view = notificationPermissionView(state, asked: asked); - final native = cupertino ?? usesCupertinoHost(context); final action = view.canRequest && onRequest != null - ? _action(native, view.actionLabel!, onRequest!) + ? _action(view.actionLabel!, onRequest!) : null; - final titleStyle = native - ? CupertinoTheme.of(context).textTheme.textStyle - : Theme.of(context).textTheme.bodyLarge; - final helperStyle = native - ? CupertinoTheme.of(context).textTheme.textStyle.copyWith( - fontSize: 15, - color: CupertinoColors.secondaryLabel.resolveFrom(context), - ) - : Theme.of(context).textTheme.bodyMedium?.copyWith( - color: Theme.of(context).colorScheme.onSurfaceVariant, - ); + final titleStyle = Theme.of(context).textTheme.bodyLarge; + final helperStyle = Theme.of(context).textTheme.bodyMedium?.copyWith( + color: Theme.of(context).colorScheme.onSurfaceVariant, + ); // One compact row: the state, one short helper line and Enable at the // end. The full sentence for the state is what a screen reader hears. // The Settings section supplies the `Notifications` heading. @@ -97,20 +87,13 @@ class NotificationPermissionTile extends StatelessWidget { } /// A short `Enable`, named in full for assistive technology. - Widget _action(bool native, String label, VoidCallback onRequest) { + Widget _action(String label, VoidCallback onRequest) { const text = Text(notificationEnableShortLabel); - final Widget button = native - ? CupertinoButton.tinted( - key: notificationEnableKey, - sizeStyle: CupertinoButtonSize.small, - onPressed: onRequest, - child: text, - ) - : FilledButton.tonal( - key: notificationEnableKey, - onPressed: onRequest, - child: text, - ); + final Widget button = FilledButton.tonal( + key: notificationEnableKey, + onPressed: onRequest, + child: text, + ); return Semantics( button: true, label: label, diff --git a/app/lib/features/chat/chat_screen_workspace.dart b/app/lib/features/chat/chat_screen_workspace.dart index 7b28f157..dde1b317 100644 --- a/app/lib/features/chat/chat_screen_workspace.dart +++ b/app/lib/features/chat/chat_screen_workspace.dart @@ -338,9 +338,7 @@ mixin _ChatScreenWorkspace on State { context, chatSessionColor(_rowFor(pane.sessionId)), ) ?? - (chatControlsStyleOf(context) == ChatControlsStyle.cupertino - ? CupertinoTheme.of(context).primaryColor - : Theme.of(context).colorScheme.primary) + Theme.of(context).colorScheme.primary : Colors.transparent; return Semantics( selected: active, diff --git a/app/lib/features/chat/files/files_delete_dialog.dart b/app/lib/features/chat/files/files_delete_dialog.dart index 7c71f616..2d02d5ba 100644 --- a/app/lib/features/chat/files/files_delete_dialog.dart +++ b/app/lib/features/chat/files/files_delete_dialog.dart @@ -1,8 +1,6 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../data/directory_listing.dart'; -import '../ui/sessions/chat_adaptive.dart'; /// Confirms deleting [entry]. A folder is described as deleted only when /// empty; the server refuses a folder with contents and the panel then asks @@ -38,41 +36,22 @@ Future _confirm( required String body, required String action, }) async { - final confirmed = chatControlsStyleOf(context) == ChatControlsStyle.cupertino - ? await showCupertinoDialog( - context: context, - builder: (context) => CupertinoAlertDialog( - title: Text(title), - content: Text(body), - actions: [ - CupertinoDialogAction( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - CupertinoDialogAction( - isDestructiveAction: true, - onPressed: () => Navigator.pop(context, true), - child: Text(action), - ), - ], - ), - ) - : await showDialog( - context: context, - builder: (context) => AlertDialog( - title: Text(title), - content: Text(body), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - FilledButton( - onPressed: () => Navigator.pop(context, true), - child: Text(action), - ), - ], - ), - ); + final confirmed = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text(title), + content: Text(body), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + FilledButton( + onPressed: () => Navigator.pop(context, true), + child: Text(action), + ), + ], + ), + ); return confirmed == true; } diff --git a/app/lib/features/chat/files/files_download.dart b/app/lib/features/chat/files/files_download.dart index bdad75d3..328613e6 100644 --- a/app/lib/features/chat/files/files_download.dart +++ b/app/lib/features/chat/files/files_download.dart @@ -1,6 +1,4 @@ import 'package:flutter/foundation.dart'; -import 'package:flutter/cupertino.dart'; -import '../../../ui/adaptive/host.dart'; import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -115,25 +113,17 @@ class _FileDownloadButtonState extends State { Widget build(BuildContext context) => Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (usesCupertinoHost(context)) - CupertinoButton.filled( - onPressed: _busy ? null : _download, - child: _busy - ? const CupertinoActivityIndicator() - : const Text('Download'), - ) - else - FilledButton.icon( - onPressed: _busy ? null : _download, - icon: _busy - ? const SizedBox( - width: 18, - height: 18, - child: CircularProgressIndicator(strokeWidth: 2), - ) - : const Icon(Icons.download_outlined), - label: const Text('Download'), - ), + FilledButton.icon( + onPressed: _busy ? null : _download, + icon: _busy + ? const SizedBox( + width: 18, + height: 18, + child: CircularProgressIndicator(strokeWidth: 2), + ) + : const Icon(Icons.download_outlined), + label: const Text('Download'), + ), if (_status != null) Padding(padding: const EdgeInsets.only(top: 8), child: Text(_status!)), ], diff --git a/app/lib/features/chat/files/files_header.dart b/app/lib/features/chat/files/files_header.dart index 33b7251e..6c59c479 100644 --- a/app/lib/features/chat/files/files_header.dart +++ b/app/lib/features/chat/files/files_header.dart @@ -1,9 +1,7 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/layout/app_overflow_menu.dart'; import '../data/directory_listing.dart'; import '../domain/chat_attachment_picker.dart'; -import '../ui/sessions/chat_adaptive.dart'; import 'files_controller.dart'; import 'files_models.dart'; @@ -103,42 +101,27 @@ class FilesHeader extends StatelessWidget { child: Row( children: [ for (final crumb in folderCrumbs(listing.home, listing.path)) - chatControlsStyleOf(context) == ChatControlsStyle.cupertino - ? CupertinoButton( - padding: const EdgeInsets.symmetric(horizontal: 6), - onPressed: controller.loading - ? null - : () => controller.open(crumb.path), - child: Text(crumb.label), - ) - : TextButton( - onPressed: controller.loading - ? null - : () => controller.open(crumb.path), - child: Text(crumb.label), - ), + TextButton( + onPressed: controller.loading + ? null + : () => controller.open(crumb.path), + child: Text(crumb.label), + ), ], ), ), Row( children: [ Expanded( - child: - chatControlsStyleOf(context) == ChatControlsStyle.cupertino - ? CupertinoSearchTextField( - controller: filter, - onChanged: controller.setFilter, - placeholder: 'Filter files', - ) - : TextField( - controller: filter, - onChanged: controller.setFilter, - decoration: const InputDecoration( - prefixIcon: Icon(Icons.search), - hintText: 'Filter files', - isDense: true, - ), - ), + child: TextField( + controller: filter, + onChanged: controller.setFilter, + decoration: const InputDecoration( + prefixIcon: Icon(Icons.search), + hintText: 'Filter files', + isDense: true, + ), + ), ), IconButton( tooltip: 'Show hidden files', diff --git a/app/lib/features/chat/files/files_panel.dart b/app/lib/features/chat/files/files_panel.dart index af0d2ba7..2a091e8d 100644 --- a/app/lib/features/chat/files/files_panel.dart +++ b/app/lib/features/chat/files/files_panel.dart @@ -1,6 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/cupertino.dart'; -import '../../../ui/adaptive/host.dart'; import '../../../core/transport/pipelines_client.dart'; import '../data/directory_listing.dart'; import '../domain/chat_attachment_picker.dart'; @@ -100,73 +98,60 @@ class _FilesPanelState extends State { if (controller.missingDirectory) { return const _FilesMessage('This chat has no working directory.'); } - return Theme( - data: usesCupertinoHost(context) - ? ThemeData( - brightness: CupertinoTheme.brightnessOf(context), - colorSchemeSeed: CupertinoTheme.of(context).primaryColor, - ) - : Theme.of(context), - child: Builder( - builder: (context) => Material( - color: Theme.of(context).colorScheme.surface, - child: FilesDropArea( - drop: _drop, - folderLabel: listing == null - ? null - : homeRelativeLabel(listing.home, listing.path), - onFiles: controller.upload, - onError: (error) => controller.reportUploadError( - 'A dropped item could not be read: $error', + return Material( + color: Theme.of(context).colorScheme.surface, + child: FilesDropArea( + drop: _drop, + folderLabel: listing == null + ? null + : homeRelativeLabel(listing.home, listing.path), + onFiles: controller.upload, + onError: (error) => controller.reportUploadError( + 'A dropped item could not be read: $error', + ), + child: Column( + children: [ + FilesHeader( + controller: controller, + filter: _filter, + picker: _picker, + onUpload: _pickAndUpload, ), - child: Column( - children: [ - FilesHeader( - controller: controller, - filter: _filter, - picker: _picker, - onUpload: _pickAndUpload, + if (controller.error != null) + ChatErrorNotice( + message: controller.error!, + onRetry: controller.retry, + ), + FilesUploadNotice(controller: controller), + if (controller.loading && listing == null) + const Expanded(child: ChatLoadingIndicator()) + else if (listing != null && entries.isEmpty && !controller.loading) + Expanded( + child: _FilesMessage( + controller.filter.isEmpty + ? 'This folder is empty.' + : 'No files match your filter.', ), - if (controller.error != null) - ChatErrorNotice( - message: controller.error!, - onRetry: controller.retry, - ), - FilesUploadNotice(controller: controller), - if (controller.loading && listing == null) - const Expanded(child: ChatLoadingIndicator()) - else if (listing != null && - entries.isEmpty && - !controller.loading) - Expanded( - child: _FilesMessage( - controller.filter.isEmpty - ? 'This folder is empty.' - : 'No files match your filter.', - ), - ) - else - Expanded( - child: FilesEntries( - entries: entries, - view: controller.view, - endpoint: _endpoint, - onTap: (entry) => entry.isDir - ? controller.open(entry.path) - : _open(entry), - menu: _menu, - onDrop: (dragged, folder) => - controller.move(dragged, folder.path), - ), - ), - if (listing?.truncated == true) - const Padding( - padding: EdgeInsets.all(8), - child: Text('Some entries are not shown.'), - ), - ], - ), - ), + ) + else + Expanded( + child: FilesEntries( + entries: entries, + view: controller.view, + endpoint: _endpoint, + onTap: (entry) => + entry.isDir ? controller.open(entry.path) : _open(entry), + menu: _menu, + onDrop: (dragged, folder) => + controller.move(dragged, folder.path), + ), + ), + if (listing?.truncated == true) + const Padding( + padding: EdgeInsets.all(8), + child: Text('Some entries are not shown.'), + ), + ], ), ), ); diff --git a/app/lib/features/chat/files/files_rename_dialog.dart b/app/lib/features/chat/files/files_rename_dialog.dart index 7afdea55..c7609de3 100644 --- a/app/lib/features/chat/files/files_rename_dialog.dart +++ b/app/lib/features/chat/files/files_rename_dialog.dart @@ -1,8 +1,6 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../data/directory_listing.dart'; -import '../ui/sessions/chat_adaptive.dart'; import 'files_mutations.dart'; /// Asks for [entry]'s new name, prefilled and selected. Resolves to the @@ -14,9 +12,7 @@ Future showRenameEntryDialog( DirectoryEntry entry, ) { final dialog = _RenameEntryDialog(entry: entry); - return chatControlsStyleOf(context) == ChatControlsStyle.cupertino - ? showCupertinoDialog(context: context, builder: (_) => dialog) - : showDialog(context: context, builder: (_) => dialog); + return showDialog(context: context, builder: (_) => dialog); } class _RenameEntryDialog extends StatefulWidget { @@ -62,44 +58,6 @@ class _RenameEntryDialogState extends State<_RenameEntryDialog> { builder: (context, value, _) { final error = renameNameError(value.text); final canSave = error == null && value.text.trim() != widget.entry.name; - if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { - return CupertinoAlertDialog( - title: Text(title), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const SizedBox(height: 8), - CupertinoTextField( - key: const Key('files-rename-field'), - controller: _name, - autofocus: true, - placeholder: 'Name', - onSubmitted: (_) => _save(), - ), - if (error != null) ...[ - const SizedBox(height: 8), - Text( - error, - style: TextStyle( - color: CupertinoColors.systemRed.resolveFrom(context), - ), - ), - ], - ], - ), - actions: [ - CupertinoDialogAction( - onPressed: () => Navigator.pop(context), - child: const Text('Cancel'), - ), - CupertinoDialogAction( - isDefaultAction: true, - onPressed: canSave ? _save : null, - child: const Text('Save'), - ), - ], - ); - } return AlertDialog( scrollable: true, title: Text(title), diff --git a/app/lib/features/chat/files/files_upload_notice.dart b/app/lib/features/chat/files/files_upload_notice.dart index 3cb3cdf3..ef6b1e04 100644 --- a/app/lib/features/chat/files/files_upload_notice.dart +++ b/app/lib/features/chat/files/files_upload_notice.dart @@ -1,7 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../ui/sessions/chat_adaptive.dart'; import 'files_controller.dart'; /// The Files panel's operation feedback: a progress strip while files are @@ -15,8 +13,6 @@ class FilesUploadNotice extends StatelessWidget { @override Widget build(BuildContext context) { - final cupertino = - chatControlsStyleOf(context) == ChatControlsStyle.cupertino; final progress = controller.uploading > 0 ? controller.uploadLabel : controller.mutationLabel; @@ -29,11 +25,7 @@ class FilesUploadNotice extends StatelessWidget { padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), child: Row( children: [ - Expanded( - child: cupertino - ? const CupertinoActivityIndicator() - : const LinearProgressIndicator(), - ), + const Expanded(child: LinearProgressIndicator()), const SizedBox(width: 12), Text(progress), ], @@ -42,13 +34,11 @@ class FilesUploadNotice extends StatelessWidget { ), if (controller.uploadError != null) _Refusal( - cupertino: cupertino, message: controller.uploadError!, onDismiss: controller.dismissUploadError, ), if (controller.mutationError != null) _Refusal( - cupertino: cupertino, message: controller.mutationError!, onDismiss: controller.dismissMutationError, ), @@ -58,27 +48,13 @@ class FilesUploadNotice extends StatelessWidget { } class _Refusal extends StatelessWidget { - const _Refusal({ - required this.cupertino, - required this.message, - required this.onDismiss, - }); - final bool cupertino; + const _Refusal({required this.message, required this.onDismiss}); final String message; final VoidCallback onDismiss; @override - Widget build(BuildContext context) => cupertino - ? ChatCupertinoMessage( - message: message, - icon: CupertinoIcons.exclamationmark_circle, - actionLabel: 'Dismiss', - onAction: onDismiss, - ) - : MaterialBanner( - content: Text(message), - actions: [ - TextButton(onPressed: onDismiss, child: const Text('Dismiss')), - ], - ); + Widget build(BuildContext context) => MaterialBanner( + content: Text(message), + actions: [TextButton(onPressed: onDismiss, child: const Text('Dismiss'))], + ); } diff --git a/app/lib/features/chat/files/files_viewer.dart b/app/lib/features/chat/files/files_viewer.dart index 65cd8024..93e9342e 100644 --- a/app/lib/features/chat/files/files_viewer.dart +++ b/app/lib/features/chat/files/files_viewer.dart @@ -1,7 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../../artifacts/actions/artifact_file_bridge.dart'; import '../../artifacts/actions/artifact_transfer.dart'; import '../../artifacts/domain/artifact_groups.dart'; @@ -100,11 +98,9 @@ class FilesViewer { fileBridge: bridge, ); if (!context.mounted) return; - Navigator.of(context).push( - usesCupertinoHost(context) - ? CupertinoPageRoute(builder: (_) => page) - : MaterialPageRoute(builder: (_) => page), - ); + Navigator.of( + context, + ).push(MaterialPageRoute(builder: (_) => page)); } /// Downloads [entry] straight from a row or tile menu and reports the @@ -127,7 +123,7 @@ class FilesViewer { messenger.showSnackBar(SnackBar(content: Text(result.message))); return; } - // A Cupertino host has no snack bar; a failure still has to be said. + // Without a scaffold messenger a failure still has to be said. if (result.state != ArtifactTransferState.failed || !context.mounted) { return; } @@ -137,16 +133,10 @@ class FilesViewer { title: Text(entry.name), content: Text(result.message), actions: [ - if (usesCupertinoHost(dialog)) - CupertinoDialogAction( - onPressed: () => Navigator.pop(dialog), - child: const Text('OK'), - ) - else - TextButton( - onPressed: () => Navigator.pop(dialog), - child: const Text('OK'), - ), + TextButton( + onPressed: () => Navigator.pop(dialog), + child: const Text('OK'), + ), ], ), ); diff --git a/app/lib/features/chat/workspace/chat_center_stage_strip.dart b/app/lib/features/chat/workspace/chat_center_stage_strip.dart index 7dc576bc..f0a02220 100644 --- a/app/lib/features/chat/workspace/chat_center_stage_strip.dart +++ b/app/lib/features/chat/workspace/chat_center_stage_strip.dart @@ -1,8 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; - /// Covers a chat beside the stage too narrow to use: its colour and title, /// running down the column. A press brings that chat to center stage. The /// retained chat underneath keeps its state. @@ -22,20 +19,13 @@ class ChatCenterStageStrip extends StatelessWidget { @override Widget build(BuildContext context) { - final cupertino = usesCupertinoHost(context); final scheme = Theme.of(context).colorScheme; - final accent = - color ?? - (cupertino ? CupertinoTheme.of(context).primaryColor : scheme.primary); + final accent = color ?? scheme.primary; final background = Color.alphaBlend( accent.withValues(alpha: .12), - cupertino - ? CupertinoColors.secondarySystemBackground.resolveFrom(context) - : scheme.surfaceContainer, + scheme.surfaceContainer, ); - final style = cupertino - ? CupertinoTheme.of(context).textTheme.textStyle - : Theme.of(context).textTheme.titleSmall; + final style = Theme.of(context).textTheme.titleSmall; final label = Padding( padding: const EdgeInsets.symmetric(vertical: 16), child: Column( @@ -62,25 +52,17 @@ class ChatCenterStageStrip extends StatelessWidget { label: 'Show $title on center stage', excludeSemantics: true, onTap: onSelected, - child: cupertino - ? CupertinoButton( - padding: EdgeInsets.zero, - color: background, - borderRadius: BorderRadius.zero, - onPressed: onSelected, - child: SizedBox.expand(child: label), - ) - : Tooltip( - message: title, - excludeFromSemantics: true, - child: Material( - color: background, - child: InkWell( - onTap: onSelected, - child: SizedBox.expand(child: label), - ), - ), - ), + child: Tooltip( + message: title, + excludeFromSemantics: true, + child: Material( + color: background, + child: InkWell( + onTap: onSelected, + child: SizedBox.expand(child: label), + ), + ), + ), ); } } diff --git a/app/lib/features/chat/workspace/chat_pane_move_actions.dart b/app/lib/features/chat/workspace/chat_pane_move_actions.dart index 1c50b5d9..1f5d4688 100644 --- a/app/lib/features/chat/workspace/chat_pane_move_actions.dart +++ b/app/lib/features/chat/workspace/chat_pane_move_actions.dart @@ -7,8 +7,8 @@ import 'chat_workspace_pane_scope.dart'; /// "Move up/down/left/right" for a tiled pane's actions (More) menu. A move /// swaps the pane with the one across that edge. A direction with no pane is -/// disabled in the Material menu (and left out of a Cupertino action sheet). -/// Nothing is offered when the panes are not tiled (one pane, or a phone). +/// disabled in the menu. Nothing is offered when the panes are not tiled (one +/// pane, or a phone). List chatPaneMoveActions( ChatWorkspacePaneScope? scope, { required void Function(String targetPaneId) onMove, diff --git a/app/lib/features/chat/workspace/chat_peek_header.dart b/app/lib/features/chat/workspace/chat_peek_header.dart index ca3fbc90..f1b5445e 100644 --- a/app/lib/features/chat/workspace/chat_peek_header.dart +++ b/app/lib/features/chat/workspace/chat_peek_header.dart @@ -1,6 +1,4 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; /// A named, explicit switch action above the inactive transcript. It occupies /// space rather than obscuring the small chat's readable content. @@ -17,20 +15,11 @@ class ChatPeekHeader extends StatelessWidget { Widget build(BuildContext context) => LayoutBuilder( builder: (context, constraints) { final compact = constraints.maxHeight < 44; - final cupertino = usesCupertinoHost(context); - final textStyle = cupertino - ? (compact - ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle - : CupertinoTheme.of(context).textTheme.textStyle) - : (compact - ? Theme.of(context).textTheme.labelMedium - : Theme.of(context).textTheme.labelLarge); - final foreground = cupertino - ? CupertinoColors.label.resolveFrom(context) - : Theme.of(context).colorScheme.onSurface; - final background = cupertino - ? CupertinoColors.secondarySystemBackground.resolveFrom(context) - : Theme.of(context).colorScheme.surfaceContainer; + final textStyle = compact + ? Theme.of(context).textTheme.labelMedium + : Theme.of(context).textTheme.labelLarge; + final foreground = Theme.of(context).colorScheme.onSurface; + final background = Theme.of(context).colorScheme.surfaceContainer; final content = Row( children: [ Expanded( @@ -44,34 +33,23 @@ class ChatPeekHeader extends StatelessWidget { const SizedBox(width: 8), Text('Switch', style: textStyle?.copyWith(color: foreground)), const SizedBox(width: 4), - Icon( - cupertino ? CupertinoIcons.arrow_up : Icons.arrow_upward, - color: foreground, - size: 18, - ), + Icon(Icons.arrow_upward, color: foreground, size: 18), ], ); return ColoredBox( color: background, child: Tooltip( message: 'Switch to $title', - child: cupertino - ? CupertinoButton( - minimumSize: const Size(0, 44), - padding: const EdgeInsets.symmetric(horizontal: 12), - onPressed: onActivate, - child: content, - ) - : TextButton( - style: TextButton.styleFrom( - minimumSize: const Size(0, 44), - tapTargetSize: MaterialTapTargetSize.shrinkWrap, - padding: const EdgeInsets.symmetric(horizontal: 12), - shape: const RoundedRectangleBorder(), - ), - onPressed: onActivate, - child: content, - ), + child: TextButton( + style: TextButton.styleFrom( + minimumSize: const Size(0, 44), + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + padding: const EdgeInsets.symmetric(horizontal: 12), + shape: const RoundedRectangleBorder(), + ), + onPressed: onActivate, + child: content, + ), ), ); }, diff --git a/app/lib/features/chat/workspace/chat_switch_card.dart b/app/lib/features/chat/workspace/chat_switch_card.dart index 25fb3023..7d78c5bb 100644 --- a/app/lib/features/chat/workspace/chat_switch_card.dart +++ b/app/lib/features/chat/workspace/chat_switch_card.dart @@ -1,6 +1,4 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../../../ui/motion/quick_switch_effect.dart'; import 'chat_pane_switch_motion.dart'; @@ -24,12 +22,8 @@ class ChatSwitchCard extends StatelessWidget { motion.isAnimating ? motion.progress : 1, outgoing: outgoing, ); - final shadow = usesCupertinoHost(context) - ? CupertinoColors.black - : Theme.of(context).shadowColor; - final surface = usesCupertinoHost(context) - ? CupertinoTheme.of(context).scaffoldBackgroundColor - : Theme.of(context).colorScheme.surface; + final shadow = Theme.of(context).shadowColor; + final surface = Theme.of(context).colorScheme.surface; return LayoutBuilder( builder: (context, constraints) => Opacity( opacity: pose.opacity, diff --git a/app/lib/features/chat/workspace/chat_workspace_divider.dart b/app/lib/features/chat/workspace/chat_workspace_divider.dart index 18c8ad66..1c0ed511 100644 --- a/app/lib/features/chat/workspace/chat_workspace_divider.dart +++ b/app/lib/features/chat/workspace/chat_workspace_divider.dart @@ -1,9 +1,7 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/semantics.dart'; import 'package:flutter/services.dart'; -import '../../../ui/adaptive/host.dart'; import 'chat_workspace_controller.dart'; import '../../../ui/adaptive/resize_grip.dart'; import 'chat_workspace_geometry.dart'; @@ -50,9 +48,7 @@ class _ChatWorkspaceDividerState extends State { @override Widget build(BuildContext context) { final verticalLine = _horizontal; - final color = usesCupertinoHost(context) - ? CupertinoColors.separator.resolveFrom(context) - : Theme.of(context).dividerColor; + final color = Theme.of(context).dividerColor; return Semantics( identifier: 'chat-divider-${widget.geometry.split.id}', label: 'Resize chat panes ${_horizontal ? 'horizontally' : 'vertically'}', diff --git a/app/lib/features/chat/workspace/chat_workspace_entrance.dart b/app/lib/features/chat/workspace/chat_workspace_entrance.dart index 16a49e8e..2c9f080f 100644 --- a/app/lib/features/chat/workspace/chat_workspace_entrance.dart +++ b/app/lib/features/chat/workspace/chat_workspace_entrance.dart @@ -1,4 +1,4 @@ -import 'package:flutter/cupertino.dart'; +import 'package:flutter/widgets.dart'; import '../../../ui/motion/motion.dart'; import '../../../ui/motion/surface_visibility.dart'; @@ -78,23 +78,16 @@ class _ChatWorkspaceEntranceState extends State ), ), ); - final transition = widget.cupertino - ? CupertinoPageTransition( - primaryRouteAnimation: _controller, - secondaryRouteAnimation: const AlwaysStoppedAnimation(0), - linearTransition: false, - child: content, - ) - : FadeTransition( - opacity: _curve, - child: SlideTransition( - position: Tween( - begin: const Offset(0, 0.08), - end: Offset.zero, - ).animate(_curve), - child: content, - ), - ); + final transition = FadeTransition( + opacity: _curve, + child: SlideTransition( + position: Tween( + begin: const Offset(0, 0.08), + end: Offset.zero, + ).animate(_curve), + child: content, + ), + ); return AnimatedBuilder( animation: _controller, child: transition, diff --git a/app/lib/features/chat/workspace/chat_workspace_surface.dart b/app/lib/features/chat/workspace/chat_workspace_surface.dart index f8138cb7..ea55ea46 100644 --- a/app/lib/features/chat/workspace/chat_workspace_surface.dart +++ b/app/lib/features/chat/workspace/chat_workspace_surface.dart @@ -1,6 +1,4 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import 'chat_center_stage_motion.dart'; import 'chat_center_stage_strip.dart'; import 'chat_mobile_panes.dart'; @@ -130,11 +128,7 @@ Widget chatWorkspaceSurface({ clipBehavior: Clip.hardEdge, children: [ if (mobile != null) - ColoredBox( - color: usesCupertinoHost(context) - ? CupertinoTheme.of(context).scaffoldBackgroundColor - : Theme.of(context).colorScheme.surface, - ), + ColoredBox(color: Theme.of(context).colorScheme.surface), picture, for (final pane in livePanes) if (motion.isTape || diff --git a/app/lib/features/graph/viewport/graph_expanded_view.dart b/app/lib/features/graph/viewport/graph_expanded_view.dart index 9efa09bc..012196d7 100644 --- a/app/lib/features/graph/viewport/graph_expanded_view.dart +++ b/app/lib/features/graph/viewport/graph_expanded_view.dart @@ -1,8 +1,6 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/adaptive/segmented_bar.dart'; -import '../../../ui/adaptive/host.dart'; import '../../../ui/adaptive/floating_bar_layout.dart'; import 'graph_viewport.dart'; import 'graph_viewport_controller.dart'; @@ -100,23 +98,6 @@ class _GraphExpandedViewState extends State { 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( extendBodyBehindAppBar: true, appBar: SegmentedBar( @@ -124,12 +105,7 @@ class _GraphExpandedViewState extends State { title: widget.title, automaticallyImplyLeading: false, leading: SegmentedBackButton(cupertino: false, onPressed: _close), - actions: [ - _GraphFitButton( - cupertino: false, - onPressed: _controller.fitToViewport, - ), - ], + actions: [_GraphFitButton(onPressed: _controller.fitToViewport)], ), body: BelowTopBar(child: body), ); @@ -137,9 +113,8 @@ class _GraphExpandedViewState extends State { } class _GraphFitButton extends StatelessWidget { - const _GraphFitButton({required this.cupertino, required this.onPressed}); + const _GraphFitButton({required this.onPressed}); - final bool cupertino; final VoidCallback onPressed; @override @@ -147,22 +122,15 @@ class _GraphFitButton extends StatelessWidget { child: Semantics( button: true, label: graphFitLabel, - child: cupertino - ? CupertinoButton( - key: const Key('graph-fit'), - padding: const EdgeInsets.all(8), - onPressed: onPressed, - child: const ExcludeSemantics(child: Icon(CupertinoIcons.resize)), - ) - : Tooltip( - message: graphFitLabel, - excludeFromSemantics: true, - child: IconButton( - key: const Key('graph-fit'), - onPressed: onPressed, - icon: const ExcludeSemantics(child: Icon(Icons.fit_screen)), - ), - ), + child: 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 openGraphExpanded( selectedStage: selectedStage, header: header, ); - final route = usesCupertinoHost(context) - ? CupertinoPageRoute(fullscreenDialog: true, builder: (_) => page) - : MaterialPageRoute(fullscreenDialog: true, builder: (_) => page); + final route = MaterialPageRoute( + fullscreenDialog: true, + builder: (_) => page, + ); return Navigator.of(context).push(route); } diff --git a/app/lib/features/graph/viewport/graph_viewport.dart b/app/lib/features/graph/viewport/graph_viewport.dart index 071b432d..787741fd 100644 --- a/app/lib/features/graph/viewport/graph_viewport.dart +++ b/app/lib/features/graph/viewport/graph_viewport.dart @@ -1,7 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../../../ui/adaptive/glass_pill.dart'; import 'graph_viewport_controller.dart'; @@ -121,20 +119,20 @@ class _GraphViewportState extends State { top: 8, end: 8, child: GlassPill( - cupertino: usesCupertinoHost(context), + cupertino: false, child: Wrap( spacing: 2, children: [ _ViewportButton( buttonKey: const Key('graph-fit'), - icon: _fitIcon(context), + icon: Icons.fit_screen, label: graphFitLabel, onPressed: widget.controller.fitToViewport, ), if (widget.onExpand != null) _ViewportButton( buttonKey: const Key('graph-expand'), - icon: _expandIcon(context), + icon: Icons.fullscreen, label: graphExpandLabel, onPressed: widget.onExpand, ), @@ -147,12 +145,6 @@ class _GraphViewportState extends State { }, ); } - - 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. @@ -160,7 +152,7 @@ class _GraphViewportState extends State { /// 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 /// 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. class _ViewportButton extends StatelessWidget { const _ViewportButton({ @@ -181,24 +173,17 @@ class _ViewportButton extends StatelessWidget { child: Semantics( button: true, label: label, - child: usesCupertinoHost(context) - ? CupertinoButton( - key: buttonKey, - padding: const EdgeInsets.all(8), - onPressed: onPressed, - child: ExcludeSemantics(child: Icon(icon)), - ) - : Tooltip( - message: label, - // 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)), - ), - ), + child: Tooltip( + message: label, + // 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)), + ), + ), ), ); } diff --git a/app/lib/features/graph/widgets/definition_graph_view.dart b/app/lib/features/graph/widgets/definition_graph_view.dart index c1285fb5..7eed93ee 100644 --- a/app/lib/features/graph/widgets/definition_graph_view.dart +++ b/app/lib/features/graph/widgets/definition_graph_view.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; diff --git a/app/lib/features/graph/widgets/graph_canvas_style.dart b/app/lib/features/graph/widgets/graph_canvas_style.dart index b4c97ef6..03347dce 100644 --- a/app/lib/features/graph/widgets/graph_canvas_style.dart +++ b/app/lib/features/graph/widgets/graph_canvas_style.dart @@ -1,7 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../layout/layout_models.dart'; import '../routing/route_models.dart'; @@ -32,9 +30,9 @@ RoutingConfig graphCanvasRoutingConfig() => RoutingConfig( /// The native theme roles one definition graph canvas needs. /// /// 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 -/// the host exactly. Edge labels and diagnostics are metadata, so they use the -/// host's secondary-label role rather than the node's own label style. +/// ambient Material theme, so light/dark and text scaling follow the host +/// exactly. Edge labels and diagnostics are metadata, so they use the host's +/// secondary-label role rather than the node's own label style. class GraphCanvasStyle { const GraphCanvasStyle({ required this.labelStyle, @@ -44,20 +42,6 @@ class GraphCanvasStyle { }); 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 secondary = theme.colorScheme.onSurfaceVariant; return GraphCanvasStyle( diff --git a/app/lib/features/graph/widgets/graph_stage_node.dart b/app/lib/features/graph/widgets/graph_stage_node.dart index c72ebbd3..2cbf7667 100644 --- a/app/lib/features/graph/widgets/graph_stage_node.dart +++ b/app/lib/features/graph/widgets/graph_stage_node.dart @@ -1,7 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../../../ui/status/run_status_icon.dart'; import '../domain/graph_definition.dart'; @@ -37,7 +35,7 @@ class GraphStageNode extends StatelessWidget { /// Reports [node.key] exactly as the definition recorded it. final ValueChanged 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 /// clear of a rounded surface's corners. static const EdgeInsets _contentPadding = EdgeInsets.all(16); @@ -61,9 +59,7 @@ class GraphStageNode extends StatelessWidget { button: true, selected: selected, label: _label, - child: usesCupertinoHost(context) - ? _cupertinoButton(onPressed, content) - : _materialCard(onPressed, content), + child: _materialCard(onPressed, content), ), ); 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) { final status = _status; // The recorded status reads apart from the name: a coloured dot and @@ -215,10 +205,7 @@ class _StageActivityHaloState extends State @override Widget build(BuildContext context) { - final cupertino = usesCupertinoHost(context); - final color = cupertino - ? CupertinoTheme.of(context).primaryColor - : Theme.of(context).colorScheme.primary; + final color = Theme.of(context).colorScheme.primary; return AnimatedBuilder( animation: _controller, builder: (context, child) => CustomPaint( diff --git a/app/lib/features/graph/widgets/run_graph_canvas.dart b/app/lib/features/graph/widgets/run_graph_canvas.dart index 953bb2ba..113a3f1b 100644 --- a/app/lib/features/graph/widgets/run_graph_canvas.dart +++ b/app/lib/features/graph/widgets/run_graph_canvas.dart @@ -1,8 +1,6 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart' show listEquals; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../domain/graph_definition.dart'; import '../domain/run_graph_state.dart'; import '../layout/layout_models.dart'; @@ -200,10 +198,7 @@ class RunGraphCanvas extends StatelessWidget { final executedIds = {for (final route in executed) route.id}; final size = Size(routing.width, routing.height); final activeStage = state.activeStage; - final cupertino = usesCupertinoHost(context); - final executedColor = cupertino - ? CupertinoTheme.of(context).primaryColor - : Theme.of(context).colorScheme.primary; + final executedColor = Theme.of(context).colorScheme.primary; return Stack( clipBehavior: Clip.none, children: [ diff --git a/app/lib/features/graph/widgets/run_graph_header.dart b/app/lib/features/graph/widgets/run_graph_header.dart index ac7af652..ef0181bf 100644 --- a/app/lib/features/graph/widgets/run_graph_header.dart +++ b/app/lib/features/graph/widgets/run_graph_header.dart @@ -1,7 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/host.dart'; import '../domain/run_graph_state.dart'; import 'graph_canvas_style.dart'; @@ -31,10 +29,7 @@ class RunGraphHeader extends StatelessWidget { @override Widget build(BuildContext context) { - final cupertino = usesCupertinoHost(context); - final executedColor = cupertino - ? CupertinoTheme.of(context).primaryColor - : Theme.of(context).colorScheme.primary; + final executedColor = Theme.of(context).colorScheme.primary; final mutedColor = style.edgeColor; final active = state.activeStage; return Padding( @@ -53,14 +48,12 @@ class RunGraphHeader extends StatelessWidget { crossAxisAlignment: WrapCrossAlignment.center, children: [ _LegendEntry( - icon: cupertino - ? CupertinoIcons.arrow_right - : Icons.arrow_forward, + icon: Icons.arrow_forward, label: runGraphExecuted, color: executedColor, ), _LegendEntry( - icon: cupertino ? CupertinoIcons.minus : Icons.remove, + icon: Icons.remove, label: runGraphNotExecuted, color: mutedColor, ), diff --git a/app/lib/features/graph/widgets/stage_definition_view.dart b/app/lib/features/graph/widgets/stage_definition_view.dart index 3244d9e9..42ba6dc9 100644 --- a/app/lib/features/graph/widgets/stage_definition_view.dart +++ b/app/lib/features/graph/widgets/stage_definition_view.dart @@ -1,14 +1,12 @@ -import '../../../ui/adaptive/segmented_bar.dart'; import 'dart:convert'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../ui/adaptive/segmented_bar.dart'; import '../../../ui/text/markdown_source_view.dart'; import '../../chat/ui/transcript/chat_markdown_view.dart'; import '../../../core/api_gateway.dart'; import '../../../ui/adaptive/floating_bar_layout.dart'; -import '../../../ui/adaptive/host.dart'; import '../domain/graph_protocol.dart'; import '../domain/stage_definition.dart'; @@ -159,30 +157,14 @@ Future openStageDefinition( // A terminal is a definition target, not its protocol key: the web pane // titles it with `nodeDisplayLabel` (`Failure`/`Success`). final title = '${nodeDisplayLabel(stageKey)} definition'; - final route = usesCupertinoHost(context) - ? CupertinoPageRoute( - settings: settings, - builder: (_) => CupertinoPageScaffold( - navigationBar: SegmentedBar( - cupertino: true, - title: title, - subtitle: identity, - ), - child: SafeArea(top: false, bottom: false, child: view), - ), - ) - : MaterialPageRoute( - settings: settings, - builder: (_) => Scaffold( - extendBodyBehindAppBar: true, - appBar: SegmentedBar( - cupertino: false, - title: title, - subtitle: identity, - ), - body: SafeArea(top: false, bottom: false, child: view), - ), - ); + final route = MaterialPageRoute( + 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); } @@ -263,22 +245,6 @@ class _StageDefinitionStyle { }); 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); return _StageDefinitionStyle( label: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith( diff --git a/app/lib/features/settings/health/health_header.dart b/app/lib/features/settings/health/health_header.dart index 93139a37..b6389812 100644 --- a/app/lib/features/settings/health/health_header.dart +++ b/app/lib/features/settings/health/health_header.dart @@ -1,7 +1,5 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; -import '../settings_theme.dart'; import 'health_models.dart'; import 'health_widgets.dart'; @@ -46,12 +44,7 @@ class HealthHeader extends StatelessWidget { const SizedBox(width: 8), Semantics( label: 'Auto-refresh', - child: usesCupertinoControls(context) - ? CupertinoSwitch( - value: autoRefresh, - onChanged: onAutoRefresh, - ) - : Switch(value: autoRefresh, onChanged: onAutoRefresh), + child: Switch(value: autoRefresh, onChanged: onAutoRefresh), ), ], ), diff --git a/app/lib/features/settings/health/health_screen.dart b/app/lib/features/settings/health/health_screen.dart index de72067a..20d3a264 100644 --- a/app/lib/features/settings/health/health_screen.dart +++ b/app/lib/features/settings/health/health_screen.dart @@ -1,9 +1,7 @@ import 'dart:async'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../settings_page_body.dart'; -import '../settings_theme.dart'; import 'health_controller.dart'; import 'health_models.dart'; import 'health_sections.dart'; @@ -142,16 +140,9 @@ class _HealthScreenState extends State ], ], ); - return usesCupertinoControls(context) - ? CupertinoPageScaffold( - navigationBar: const CupertinoNavigationBar( - middle: Text('Server health'), - ), - child: SafeArea(child: content), - ) - : Scaffold( - appBar: AppBar(title: const Text('Server health')), - body: content, - ); + return Scaffold( + appBar: AppBar(title: const Text('Server health')), + body: content, + ); } } diff --git a/app/lib/features/settings/health/health_widgets.dart b/app/lib/features/settings/health/health_widgets.dart index e1bd626c..3b05a28d 100644 --- a/app/lib/features/settings/health/health_widgets.dart +++ b/app/lib/features/settings/health/health_widgets.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../settings_theme.dart'; import 'health_models.dart'; @@ -20,22 +19,7 @@ class HealthCard extends StatelessWidget { ], ), ); - if (!usesCupertinoControls(context)) return Card(child: content); - return Padding( - padding: const EdgeInsets.symmetric(vertical: 4), - child: DecoratedBox( - decoration: BoxDecoration( - color: CupertinoColors.secondarySystemGroupedBackground.resolveFrom( - context, - ), - borderRadius: BorderRadius.circular(12), - ), - child: DefaultTextStyle( - style: settingsTextStyle(context), - child: content, - ), - ), - ); + return Card(child: content); } } @@ -47,23 +31,13 @@ class HealthMeter extends StatelessWidget { Widget build(BuildContext context) { final scheme = Theme.of(context).colorScheme; final percent = value == null ? null : value! * 100; - final cupertino = usesCupertinoControls(context); - final normal = cupertino - ? CupertinoTheme.of(context).primaryColor - : scheme.primary; - final high = cupertino - ? CupertinoColors.systemOrange.resolveFrom(context) - : scheme.tertiary; - final critical = cupertino - ? CupertinoColors.systemRed.resolveFrom(context) - : scheme.error; final color = percent == null ? scheme.outline : percent >= healthMeterCritical - ? critical + ? scheme.error : percent >= healthMeterHigh - ? high - : normal; + ? scheme.tertiary + : scheme.primary; return Row( children: [ Expanded( @@ -111,7 +85,6 @@ class HealthAction extends StatelessWidget { final String label; final VoidCallback? onPressed; @override - Widget build(BuildContext context) => usesCupertinoControls(context) - ? CupertinoButton(onPressed: onPressed, child: Text(label)) - : TextButton(onPressed: onPressed, child: Text(label)); + Widget build(BuildContext context) => + TextButton(onPressed: onPressed, child: Text(label)); } diff --git a/app/lib/features/settings/health/settings_health_section.dart b/app/lib/features/settings/health/settings_health_section.dart index 64747a41..d6de3747 100644 --- a/app/lib/features/settings/health/settings_health_section.dart +++ b/app/lib/features/settings/health/settings_health_section.dart @@ -1,8 +1,6 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../settings_row.dart'; -import '../settings_theme.dart'; import 'health_screen.dart'; class SettingsHealthSection extends StatelessWidget { @@ -10,21 +8,13 @@ class SettingsHealthSection extends StatelessWidget { final ApiGateway gateway; @override Widget build(BuildContext context) => SettingsRow( - leading: Icon( - usesCupertinoControls(context) - ? CupertinoIcons.heart - : Icons.monitor_heart_outlined, - ), + leading: const Icon(Icons.monitor_heart_outlined), title: const Text('Server health'), subtitle: const Text('CPU, memory, GPU, storage and process'), chevron: true, onTap: () { final page = HealthScreen(gateway: gateway); - Navigator.of(context).push( - usesCupertinoControls(context) - ? CupertinoPageRoute(builder: (_) => page) - : MaterialPageRoute(builder: (_) => page), - ); + Navigator.of(context).push(MaterialPageRoute(builder: (_) => page)); }, ); } diff --git a/app/lib/features/settings/security/settings_security_section.dart b/app/lib/features/settings/security/settings_security_section.dart index 491549f9..7c053433 100644 --- a/app/lib/features/settings/security/settings_security_section.dart +++ b/app/lib/features/settings/security/settings_security_section.dart @@ -1,9 +1,7 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../../../core/session/server_session.dart'; -import '../../../ui/adaptive/host.dart'; import 'session_security_api.dart'; /// The server's sign-in security: a warning when its password predates the @@ -72,28 +70,6 @@ class _SettingsSecuritySectionState extends State { 'Every browser and device signed in to this server, this one ' 'included, must sign in again. Open connections close now.', ); - if (usesCupertinoHost(context)) { - return await showCupertinoDialog( - context: context, - builder: (context) => CupertinoAlertDialog( - title: title, - content: body, - actions: [ - CupertinoDialogAction( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - CupertinoDialogAction( - key: const Key('settings-revoke-all-confirm'), - isDestructiveAction: true, - onPressed: () => Navigator.pop(context, true), - child: const Text('Sign out everywhere'), - ), - ], - ), - ) ?? - false; - } return await showDialog( context: context, builder: (context) => AlertDialog( @@ -148,17 +124,11 @@ class _SettingsSecuritySectionState extends State { @override Widget build(BuildContext context) { final security = _security; - final button = usesCupertinoHost(context) - ? CupertinoButton( - key: const Key('settings-revoke-all'), - onPressed: _busy ? null : _revokeAll, - child: const Text('Sign out everywhere'), - ) - : OutlinedButton( - key: const Key('settings-revoke-all'), - onPressed: _busy ? null : _revokeAll, - child: const Text('Sign out everywhere'), - ); + final button = OutlinedButton( + key: const Key('settings-revoke-all'), + onPressed: _busy ? null : _revokeAll, + child: const Text('Sign out everywhere'), + ); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ diff --git a/app/lib/features/settings/storage/settings_storage_section.dart b/app/lib/features/settings/storage/settings_storage_section.dart index 16a56504..c1a6b786 100644 --- a/app/lib/features/settings/storage/settings_storage_section.dart +++ b/app/lib/features/settings/storage/settings_storage_section.dart @@ -1,8 +1,6 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../settings_row.dart'; -import '../settings_theme.dart'; import 'storage_screen.dart'; class SettingsStorageSection extends StatelessWidget { @@ -10,21 +8,13 @@ class SettingsStorageSection extends StatelessWidget { final ApiGateway gateway; @override Widget build(BuildContext context) => SettingsRow( - leading: Icon( - usesCupertinoControls(context) - ? CupertinoIcons.archivebox - : Icons.storage_outlined, - ), + leading: const Icon(Icons.storage_outlined), title: const Text('Storage'), subtitle: const Text('Usage, worktrees and retention policy'), chevron: true, onTap: () { final page = StorageScreen(gateway: gateway); - Navigator.of(context).push( - usesCupertinoControls(context) - ? CupertinoPageRoute(builder: (_) => page) - : MaterialPageRoute(builder: (_) => page), - ); + Navigator.of(context).push(MaterialPageRoute(builder: (_) => page)); }, ); } diff --git a/app/lib/features/settings/storage/storage_controls.dart b/app/lib/features/settings/storage/storage_controls.dart index dbc500fc..192f935c 100644 --- a/app/lib/features/settings/storage/storage_controls.dart +++ b/app/lib/features/settings/storage/storage_controls.dart @@ -1,6 +1,4 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../settings_theme.dart'; class StorageAction extends StatelessWidget { const StorageAction({ @@ -13,27 +11,15 @@ class StorageAction extends StatelessWidget { final VoidCallback? onPressed; final bool destructive; @override - Widget build(BuildContext context) => usesCupertinoControls(context) - ? CupertinoButton( - onPressed: onPressed, - child: Text( - label, - style: destructive - ? TextStyle( - color: CupertinoColors.destructiveRed.resolveFrom(context), - ) - : null, - ), - ) - : TextButton( - onPressed: onPressed, - style: destructive - ? TextButton.styleFrom( - foregroundColor: Theme.of(context).colorScheme.error, - ) - : null, - child: Text(label), - ); + Widget build(BuildContext context) => TextButton( + onPressed: onPressed, + style: destructive + ? TextButton.styleFrom( + foregroundColor: Theme.of(context).colorScheme.error, + ) + : null, + child: Text(label), + ); } class StorageSwitch extends StatelessWidget { @@ -52,9 +38,7 @@ class StorageSwitch extends StatelessWidget { Expanded(child: Text(label)), Semantics( label: label, - child: usesCupertinoControls(context) - ? CupertinoSwitch(value: value, onChanged: onChanged) - : Switch(value: value, onChanged: onChanged), + child: Switch(value: value, onChanged: onChanged), ), ], ); @@ -77,35 +61,17 @@ class StorageInput extends StatelessWidget { @override Widget build(BuildContext context) { final keyboard = TextInputType.numberWithOptions(decimal: decimal); - return usesCupertinoControls(context) - ? Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Text(label), - const SizedBox(height: 8), - Semantics( - label: label, - child: CupertinoTextField( - controller: controller, - enabled: enabled, - keyboardType: keyboard, - onChanged: onChanged, - placeholder: 'No limit', - ), - ), - ], - ) - : TextField( - controller: controller, - enabled: enabled, - keyboardType: keyboard, - onChanged: onChanged, - decoration: InputDecoration( - labelText: label, - hintText: 'No limit', - border: const OutlineInputBorder(), - ), - ); + return TextField( + controller: controller, + enabled: enabled, + keyboardType: keyboard, + onChanged: onChanged, + decoration: InputDecoration( + labelText: label, + hintText: 'No limit', + border: const OutlineInputBorder(), + ), + ); } } diff --git a/app/lib/features/settings/storage/storage_screen.dart b/app/lib/features/settings/storage/storage_screen.dart index bc7b1028..22895189 100644 --- a/app/lib/features/settings/storage/storage_screen.dart +++ b/app/lib/features/settings/storage/storage_screen.dart @@ -1,9 +1,7 @@ import 'dart:async'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../settings_page_body.dart'; -import '../settings_theme.dart'; import 'storage_cleanup.dart'; import 'storage_controller.dart'; import 'storage_controls.dart'; @@ -93,45 +91,23 @@ class _StorageScreenState extends State { final preview = _controller.preview!; final message = 'Permanently remove ${storageInt(preview['candidate_count'])} eligible items and reclaim up to ${storageBytes(storageInt(preview['reclaimable_bytes']))}? This cannot be undone.'; - final bool? confirmed; - if (usesCupertinoControls(context)) { - confirmed = await showCupertinoDialog( - context: context, - builder: (context) => CupertinoAlertDialog( - title: const Text('Apply cleanup?'), - content: Text(message), - actions: [ - CupertinoDialogAction( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - CupertinoDialogAction( - isDestructiveAction: true, - onPressed: () => Navigator.pop(context, true), - child: const Text('Remove items'), - ), - ], - ), - ); - } else { - confirmed = await showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text('Apply cleanup?'), - content: Text(message), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - TextButton( - onPressed: () => Navigator.pop(context, true), - child: const Text('Remove items'), - ), - ], - ), - ); - } + final confirmed = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Apply cleanup?'), + content: Text(message), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () => Navigator.pop(context, true), + child: const Text('Remove items'), + ), + ], + ), + ); if (confirmed == true && mounted) await _controller.apply(policy); } @@ -145,7 +121,6 @@ class _StorageScreenState extends State { @override Widget build(BuildContext context) { - final cupertino = usesCupertinoControls(context); final content = SettingsPageBody( children: [ if (_controller.busy) @@ -196,16 +171,9 @@ class _StorageScreenState extends State { ), ], ); - return cupertino - ? CupertinoPageScaffold( - navigationBar: const CupertinoNavigationBar( - middle: Text('Storage'), - ), - child: SafeArea(child: content), - ) - : Scaffold( - appBar: AppBar(title: const Text('Storage')), - body: content, - ); + return Scaffold( + appBar: AppBar(title: const Text('Storage')), + body: content, + ); } } diff --git a/app/lib/features/settings/storage/storage_usage.dart b/app/lib/features/settings/storage/storage_usage.dart index b7337501..333d2f86 100644 --- a/app/lib/features/settings/storage/storage_usage.dart +++ b/app/lib/features/settings/storage/storage_usage.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/cupertino.dart'; import '../settings_group.dart'; import 'storage_controls.dart'; import 'storage_models.dart'; @@ -67,10 +66,7 @@ class StorageUsage extends StatelessWidget { context, MaterialLocalizations, ); - if (material != null) { - return '${time.day} ${material.formatMonthYear(time)} · ${material.formatTimeOfDay(TimeOfDay.fromDateTime(time), alwaysUse24HourFormat: true)}'; - } - final local = CupertinoLocalizations.of(context); - return '${time.day} ${local.datePickerMonth(time.month)} ${time.year} · ${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}'; + if (material == null) return null; + return '${time.day} ${material.formatMonthYear(time)} · ${material.formatTimeOfDay(TimeOfDay.fromDateTime(time), alwaysUse24HourFormat: true)}'; } } diff --git a/app/lib/shell/windows/window_layer.dart b/app/lib/shell/windows/window_layer.dart index df969711..f17c23da 100644 --- a/app/lib/shell/windows/window_layer.dart +++ b/app/lib/shell/windows/window_layer.dart @@ -55,6 +55,16 @@ class _WindowLayerState extends State final GlobalKey _navigator = GlobalKey(); late final LocalKey _rootPage = ValueKey('window-root-${widget.entry.id}'); + /// The page-transition theme handed to the window's navigator, rebuilt only + /// when the app's theme itself changes. + ThemeData? _themeSource; + ThemeData? _pageTheme; + + /// The root page kept across builds: a new page object would rebuild the + /// window's content on every move and resize. + WindowKind? _pageKind; + Page? _page; + String get _id => widget.entry.id; @override @@ -160,6 +170,22 @@ class _WindowLayerState extends State widget.manager.raise(_id); } + ThemeData _pageThemeFor(ThemeData theme) { + if (identical(theme, _themeSource)) return _pageTheme!; + _themeSource = theme; + return _pageTheme = WindowNavigator.themeData(theme); + } + + Page _rootPageFor(WindowKind kind) { + final page = _page; + if (page != null && identical(kind, _pageKind)) return page; + _pageKind = kind; + return _page = MaterialPage( + key: _rootPage, + child: _WindowContent(kind: kind), + ); + } + @override Widget build(BuildContext context) { final manager = widget.manager; @@ -174,6 +200,7 @@ class _WindowLayerState extends State frame.bottom, ); final title = kind.title(context, entry); + final pageTheme = _pageThemeFor(Theme.of(context)); final hiding = !widget.visible; final content = Stack( fit: StackFit.expand, @@ -185,17 +212,21 @@ class _WindowLayerState extends State explicitChildNodes: true, label: 'Window: $title', identifier: 'window-${entry.kind}', - child: WindowFrame( - title: title, - icon: kind.icon, - actions: kind.actions(context, entry), - maximized: entry.maximized, - onMove: _move, - onMoveEnd: _moveEnded, - onMinimize: () => manager.setMinimized(_id, true), - onToggleMaximized: () => - manager.setMaximized(_id, !entry.maximized), - onClose: () => manager.close(_id), + // Its own layer: moving the window moves the title bar without + // repainting it. + child: RepaintBoundary( + child: WindowFrame( + title: title, + icon: kind.icon, + actions: kind.actions(context, entry), + maximized: entry.maximized, + onMove: _move, + onMoveEnd: _moveEnded, + onMinimize: () => manager.setMinimized(_id, true), + onToggleMaximized: () => + manager.setMaximized(_id, !entry.maximized), + onClose: () => manager.close(_id), + ), ), ), ), @@ -210,19 +241,16 @@ class _WindowLayerState extends State child: WindowScope( manager: manager, entry: entry, - body: body, - child: ScaffoldMessenger( - child: WindowNavigator.theme( - context, - child: WindowNavigator( - key: _navigator, - pages: [ - MaterialPage( - key: _rootPage, - child: _WindowContent(kind: kind), - ), - ], - onDidRemovePage: (_) {}, + child: WindowBodyScope( + body: body, + child: ScaffoldMessenger( + child: Theme( + data: pageTheme, + child: WindowNavigator( + key: _navigator, + pages: [_rootPageFor(kind)], + onDidRemovePage: (_) {}, + ), ), ), ), diff --git a/app/lib/shell/windows/window_navigator.dart b/app/lib/shell/windows/window_navigator.dart index 5d594c2c..26e5f1da 100644 --- a/app/lib/shell/windows/window_navigator.dart +++ b/app/lib/shell/windows/window_navigator.dart @@ -18,23 +18,21 @@ import 'window_scope.dart'; class WindowNavigator extends Navigator { const WindowNavigator({super.key, super.pages, super.onDidRemovePage}); - /// [child] with page transitions that keep every `MaterialPageRoute` of a - /// window navigator below it inside the window's content area. - static Widget theme(BuildContext context, {required Widget child}) { - final theme = Theme.of(context); + /// [theme] with page transitions that keep every `MaterialPageRoute` of a + /// window navigator inside the window's content area. The caller keeps the + /// result, so rebuilding a window layer does not hand its contents a new + /// theme. + static ThemeData themeData(ThemeData theme) { final builders = theme.pageTransitionsTheme.builders; - return Theme( - data: theme.copyWith( - pageTransitionsTheme: PageTransitionsTheme( - builders: { - for (final platform in TargetPlatform.values) - platform: _WindowPageTransitions( - builders[platform] ?? const ZoomPageTransitionsBuilder(), - ), - }, - ), + return theme.copyWith( + pageTransitionsTheme: PageTransitionsTheme( + builders: { + for (final platform in TargetPlatform.values) + platform: _WindowPageTransitions( + builders[platform] ?? const ZoomPageTransitionsBuilder(), + ), + }, ), - child: child, ); } @@ -117,9 +115,8 @@ class WindowPageBox extends StatelessWidget { @override Widget build(BuildContext context) { - final scope = WindowScope.maybeOf(context); - if (scope == null) return child; - final body = scope.body; + final body = WindowBodyScope.maybeOf(context); + if (body == null) return child; const radius = Radius.circular(windowCornerRadius); return Stack( children: [ @@ -140,7 +137,9 @@ class WindowPageBox extends StatelessWidget { child: Scaffold( backgroundColor: Colors.transparent, primary: false, - body: child, + // Its own layer: moving or resizing the window repositions the + // page without repainting it. + body: RepaintBoundary(child: child), ), ), ), diff --git a/app/lib/shell/windows/window_scope.dart b/app/lib/shell/windows/window_scope.dart index 0bbf7abd..e490e9e8 100644 --- a/app/lib/shell/windows/window_scope.dart +++ b/app/lib/shell/windows/window_scope.dart @@ -1,27 +1,26 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'window_entry.dart'; import 'window_manager.dart'; -/// The floating window some content is in: its entry, the manager, and where -/// the content area is drawn in the window host. Absent outside a window, so -/// shared content can tell the tiled app from a window. +/// The floating window some content is in: its entry and the manager. Absent +/// outside a window, so shared content can tell the tiled app from a window. +/// +/// Content depends on what it can read of the entry, not on where the window +/// is drawn: moving, resizing, minimising or maximising a window keeps its +/// content as it is. class WindowScope extends InheritedWidget { const WindowScope({ super.key, required this.manager, required this.entry, - required this.body, required super.child, }); final WindowManager manager; final WindowEntry entry; - /// The content area (the window less its title bar), in the host's - /// coordinates. - final Rect body; - static WindowScope? maybeOf(BuildContext context) => context.dependOnInheritedWidgetOfExactType(); @@ -30,6 +29,26 @@ class WindowScope extends InheritedWidget { @override bool updateShouldNotify(WindowScope oldWidget) => oldWidget.manager != manager || - oldWidget.entry != entry || - oldWidget.body != body; + oldWidget.entry.id != entry.id || + oldWidget.entry.kind != entry.kind || + oldWidget.entry.contentId != entry.contentId || + oldWidget.entry.serverKey != entry.serverKey || + !mapEquals(oldWidget.entry.data, entry.data); +} + +/// Where a window's content area is drawn in the window host. Kept apart from +/// [WindowScope] so a move or a resize repositions the page without rebuilding +/// what the page shows. +class WindowBodyScope extends InheritedWidget { + const WindowBodyScope({super.key, required this.body, required super.child}); + + /// The content area (the window less its title bar), in the host's + /// coordinates. + final Rect body; + + static Rect? maybeOf(BuildContext context) => + context.dependOnInheritedWidgetOfExactType()?.body; + + @override + bool updateShouldNotify(WindowBodyScope oldWidget) => oldWidget.body != body; } diff --git a/app/notes/perf-round5.md b/app/notes/perf-round5.md new file mode 100644 index 00000000..91022c70 --- /dev/null +++ b/app/notes/perf-round5.md @@ -0,0 +1,102 @@ +# Performance round 5: moving a window does not rebuild its content + +Round 5's candidate: every pointer event of a window drag rebuilt every +window's whole content. `WindowScope` carried the body `Rect` and compared the +whole `WindowEntry`, the navigator's `ThemeData` was rebuilt with `copyWith` on +every build, and the root `MaterialPage` was a new object on every build. + +## Change + +`lib/shell/windows/`: + +- `window_scope.dart`: `WindowScope` keeps only `manager` and `entry`, and + notifies only when what content can read changes (id, kind, contentId, + serverKey, `data`). A new `WindowBodyScope` (an `InheritedWidget` with the + body `Rect`) carries the position and size that used to be in `WindowScope`. +- `window_navigator.dart`: `WindowNavigator.theme(context, child:)` became + `WindowNavigator.themeData(theme)`, so the layer can keep the + page-transition `ThemeData`. `WindowPageBox` reads the body from + `WindowBodyScope`, and its page child is a `RepaintBoundary`. +- `window_layer.dart`: `_WindowLayerState` keeps the page-transition theme in a + field and rebuilds it only when `Theme.of(context)` is a different object; it + keeps the root `MaterialPage` in a field (same key) and rebuilds it only when + the kind changes. `WindowFrame` is wrapped in a `RepaintBoundary`. + +No behaviour change: frames, snapping, resize limits, popups, pushed pages, +minimise/maximise, focus and the shell's APIs are as before. + +`tool/capture/window_probe.dart`: `ProbeContentState.lastSize` records the +`MediaQuery` size the content built at, so tests can see a resize reach it +(no visual change). + +## Deterministic build counts + +`test/shell/windows/window_rebuild_test.dart`: + +- dragging a window's title over 8 pointer moves: the dragged window's content + and the other window's content keep their `builds` count (0 rebuilds); +- resizing a window over 5 pointer moves: the other window keeps its count, + the resized window's content rebuilds and sees the new `MediaQuery` size + (360x380 -> 280x330 body); +- `manager.setContent` retargets a content whose element is keyed stably: the + same state rebuilds with the new contentId. + +Against the old implementation (lib changes stashed, test run unchanged): 2 +failed — `dragged window rebuilt at move 0` (builds 2 -> 3) and `other window +rebuilt at move 0` (2 -> 3). The new code passes all 3. + +## Browser bench + +Built twice: the old code (lib/shell/windows changes stashed) into +`build/probe-before`, and this branch into `build/probe-app`: + +``` +/Users/alan/development/flutter/bin/flutter build web \ + --target tool/search_selection_probe_entry.dart --output build/probe-before +/Users/alan/development/flutter/bin/flutter build web \ + --target tool/search_selection_probe_entry.dart --output build/probe-app +``` + +Run, from `app/`, against each build in turn: + +``` +node tool/perf/interaction_bench.mjs --build build/probe-before --out /tmp/bench \ + --gpu --only 'desktop: drag a probe window' --repeat 3 +node tool/perf/interaction_bench.mjs --build build/probe-app --out /tmp/bench \ + --gpu --only 'desktop: drag a probe window' --repeat 3 +``` + +Three before/after rounds (the machine was shared with other pipeline test +runs; load average 9-14 during these, so frame counts vary. `buildMs/frame = +buildSum / frames`): + +| round | code | frames | buildSum | ms/frame | buildMax | longest | over16 | rasterSum | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | +| 1 | before | 50 | 952.2 | 19.0 | 63.5 | 73.9 | 31 | 107.4 | +| 1 | after | 49 | 824.8 | 16.8 | 59.1 | 74.0 | 27 | 107.9 | +| 2 | before | 49 | 615.6 | 12.6 | 25.5 | 28.4 | 15 | 62.1 | +| 2 | after | 51 | 583.0 | 11.4 | 37.4 | 39.9 | 13 | 87.2 | +| 3 | before | 51 | 527.9 | 10.4 | 16.2 | 20.3 | 9 | 68.3 | +| 3 | after | 47 | 606.8 | 12.9 | 24.1 | 26.9 | 18 | 83.5 | + +The browser numbers are inconclusive on this loaded machine: only round 1 +shows less build work, and the spread between rounds (10.4-19.0 ms/frame on the +same code) is larger than the change. The reliable result is the build count: +the drag went from one content build per pointer event per window (120 builds +over a 40-move drag with three windows) to none. Window chrome and framework +layout still run on every pointer event; that is the remaining build cost in +this scenario, not content. + +## Checks + +- `tool/memwatch/full.sh 'test/shell/windows test/features/chat/chat_floating_pane_test.dart test/features/terminal'`: + 119 passed, 0 failed. +- `tool/analyze.sh`: clean. + +## Affected UI states (for ui-review) + +`/runs?windows=2` at 1280x800 light: the windows after a title drag +(`drag=250,132>300,150`), after a corner resize +(`drag=483,523>120,80`), and a page pushed inside a window (click `page`) then +dragged: the content must follow the window, stay inside it, and show no stale +or clipped frame. diff --git a/app/test/core/servers/elevation/elevation_dialog_test.dart b/app/test/core/servers/elevation/elevation_dialog_test.dart index e499dd7e..b0a3c9ad 100644 --- a/app/test/core/servers/elevation/elevation_dialog_test.dart +++ b/app/test/core/servers/elevation/elevation_dialog_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; @@ -15,7 +14,7 @@ void main() { final navigator = GlobalKey(); Future? pending; - Future pump(WidgetTester tester, {bool cupertino = false}) async { + Future pump(WidgetTester tester) async { machine = FakeMachine(); gateway = ElevatingGateway( machine, @@ -35,12 +34,10 @@ void main() { ), ); await tester.pumpWidget( - cupertino - ? CupertinoApp(navigatorKey: navigator, home: home) - : MaterialApp( - navigatorKey: navigator, - home: Scaffold(body: home), - ), + MaterialApp( + navigatorKey: navigator, + home: Scaffold(body: home), + ), ); await tester.tap(find.text('Run')); await tester.pumpAndSettle(); @@ -99,18 +96,6 @@ void main() { expect(machine.calls, ['chat_shell_run']); }); - testWidgets('a Cupertino host gets the Cupertino dialog', (tester) async { - await pump(tester, cupertino: true); - expect(find.byType(CupertinoAlertDialog), findsOneWidget); - await tester.enterText( - find.byKey(const Key('elevation-password')), - 'right', - ); - await tester.tap(find.byKey(const Key('elevation-confirm'))); - await tester.pumpAndSettle(); - expect((await pending!)['type'], 'chat_shell_run_ok'); - }); - testWidgets('without a mounted navigator the refusal is reported', ( tester, ) async { diff --git a/app/test/features/attention/runtime/attention_runs_layout_test.dart b/app/test/features/attention/runtime/attention_runs_layout_test.dart index 16b57207..0ee8e9d3 100644 --- a/app/test/features/attention/runtime/attention_runs_layout_test.dart +++ b/app/test/features/attention/runtime/attention_runs_layout_test.dart @@ -6,10 +6,10 @@ import 'package:pipelines_app/features/attention/ui/needs_you_keys.dart'; import 'attention_runs_test_support.dart'; /// The hardest real-app case: a narrow phone at a doubled text scale. Both the -/// Runs list chrome and the native sheet must keep the bell and every action -/// inside the viewport. +/// Runs list chrome and the sheet must keep the bell and every action inside the +/// viewport. void main() { - testWidgets('both hosts fit the bell and sheet at 320 logical px and 2x', ( + testWidgets('Material fits the bell and sheet at 320 logical px and 2x', ( tester, ) async { tester.view.devicePixelRatio = 2; @@ -19,54 +19,49 @@ void main() { final gateway = AttentionRunsGateway(); addTearDown(gateway.framesController.close); - for (final native in [false, true]) { - await mountAttentionRuns( - tester, - gateway, - cupertino: native, - store: MemoryAttentionStore(), - runs: [ - attentionRun( - 1, - 'waiting', - title: 'Approve a release candidate at 320 px', - ), - attentionRun( - 2, - 'failed', - title: 'A failed run with a label long enough to wrap', - diagnostic: 'Stage 3 stopped because the credential is missing.', - ), - ], - request: native ? 1 : 0, - textScale: 2, - key: ValueKey(native), - ); - expect(find.byKey(attentionBellKey), findsOneWidget); - final listError = tester.takeException(); - expect( - listError, - isNull, - reason: listError is FlutterError - ? '${native ? 'Cupertino' : 'Material'} list: ${listError.toStringDeep()}' - : '${native ? 'Cupertino' : 'Material'} list: $listError', - ); - await openAttentionSheet(tester); - final sheetError = tester.takeException(); - expect( - sheetError, - isNull, - reason: sheetError is FlutterError - ? '${native ? 'Cupertino' : 'Material'} sheet: ${sheetError.toStringDeep()}' - : '${native ? 'Cupertino' : 'Material'} sheet: $sheetError', - ); - final sheet = tester.getRect(find.byKey(attentionSheetKey)); - expect(sheet.left, greaterThanOrEqualTo(0)); - expect(sheet.right, lessThanOrEqualTo(320)); - expect(sheet.top, greaterThanOrEqualTo(0)); - expect(sheet.bottom, lessThanOrEqualTo(640)); - await tester.binding.handlePopRoute(); - await tester.pumpAndSettle(); - } + await mountAttentionRuns( + tester, + gateway, + store: MemoryAttentionStore(), + runs: [ + attentionRun( + 1, + 'waiting', + title: 'Approve a release candidate at 320 px', + ), + attentionRun( + 2, + 'failed', + title: 'A failed run with a label long enough to wrap', + diagnostic: 'Stage 3 stopped because the credential is missing.', + ), + ], + textScale: 2, + ); + expect(find.byKey(attentionBellKey), findsOneWidget); + final listError = tester.takeException(); + expect( + listError, + isNull, + reason: listError is FlutterError + ? 'Material list: ${listError.toStringDeep()}' + : 'Material list: $listError', + ); + await openAttentionSheet(tester); + final sheetError = tester.takeException(); + expect( + sheetError, + isNull, + reason: sheetError is FlutterError + ? 'Material sheet: ${sheetError.toStringDeep()}' + : 'Material sheet: $sheetError', + ); + final sheet = tester.getRect(find.byKey(attentionSheetKey)); + expect(sheet.left, greaterThanOrEqualTo(0)); + expect(sheet.right, lessThanOrEqualTo(320)); + expect(sheet.top, greaterThanOrEqualTo(0)); + expect(sheet.bottom, lessThanOrEqualTo(640)); + await tester.binding.handlePopRoute(); + await tester.pumpAndSettle(); }); } diff --git a/app/test/features/attention/runtime/attention_runs_test_support.dart b/app/test/features/attention/runtime/attention_runs_test_support.dart index 0dd459b6..234fce8c 100644 --- a/app/test/features/attention/runtime/attention_runs_test_support.dart +++ b/app/test/features/attention/runtime/attention_runs_test_support.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; @@ -63,7 +62,6 @@ class AttentionRunsGateway implements ApiGateway { Widget attentionRunsApp( AttentionRunsGateway gateway, { - required bool cupertino, required AttentionStore store, double textScale = 1, Key? key, @@ -80,13 +78,6 @@ Widget attentionRunsApp( attentionStore: store, attentionNow: () => attentionTestNow, ); - if (cupertino) { - return CupertinoApp( - theme: const CupertinoThemeData(brightness: Brightness.dark), - builder: scaled, - home: CupertinoPageScaffold(child: screen), - ); - } return MaterialApp( theme: ThemeData(platform: TargetPlatform.android), builder: scaled, @@ -97,7 +88,6 @@ Widget attentionRunsApp( Future mountAttentionRuns( WidgetTester tester, AttentionRunsGateway gateway, { - required bool cupertino, required AttentionStore store, required List runs, int request = 0, @@ -107,7 +97,6 @@ Future mountAttentionRuns( await tester.pumpWidget( attentionRunsApp( gateway, - cupertino: cupertino, store: store, textScale: textScale, key: key, diff --git a/app/test/features/attention/runtime/attention_runs_wiring_test.dart b/app/test/features/attention/runtime/attention_runs_wiring_test.dart index 6bc71a6a..1ab8d7d4 100644 --- a/app/test/features/attention/runtime/attention_runs_wiring_test.dart +++ b/app/test/features/attention/runtime/attention_runs_wiring_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/attention/domain/attention_models.dart'; @@ -14,183 +13,173 @@ void main() { setUp(() => gateway = AttentionRunsGateway()); tearDown(() => gateway.framesController.close()); - for (final native in [false, true]) { - final host = native ? 'Cupertino' : 'Material'; - - testWidgets( - '$host Runs list bell opens the native sheet and dismisses one', - (tester) async { - final semantics = tester.ensureSemantics(); - final store = MemoryAttentionStore(); - await mountAttentionRuns( - tester, - gateway, - cupertino: native, - store: store, - runs: [ - attentionRun(1, 'waiting', title: 'Approve the release'), - attentionRun( - 2, - 'failed', - title: 'Ship the release', - diagnostic: 'Stage 2', - ), - attentionRun(3, 'waiting', title: 'Machine export') - ..['export_pending_sequence'] = 2, - attentionRun(4, 'running', title: 'Still running'), - ], - ); - - expect( - find.bySemanticsLabel('Notifications, 2 needing attention'), - findsOneWidget, - ); - await openAttentionSheet(tester); - expect(find.byKey(attentionSheetKey), findsOneWidget); - expect(find.byKey(attentionRowKey('3:Decision')), findsNothing); - expect(find.byKey(attentionRowKey('4:Failed')), findsNothing); - expect(find.byKey(attentionRowKey('2:Failed')), findsOneWidget); - - await tester.tap(find.byKey(attentionDismissKey('2:Failed'))); - await tester.pumpAndSettle(); - expect(find.byKey(attentionSheetKey), findsOneWidget); - expect(find.byKey(attentionRowKey('2:Failed')), findsNothing); - expect(store.stored, encodeAttentionDismissals({'2:Failed'})); - - // Closing and rebuilding from the same store keeps the dismissal. - await tester.binding.handlePopRoute(); - await tester.pumpAndSettle(); - await tester.pumpWidget(const SizedBox()); - await mountAttentionRuns( - tester, - gateway, - cupertino: native, - store: store, - runs: [ - attentionRun(1, 'waiting', title: 'Approve the release'), - attentionRun( - 2, - 'failed', - title: 'Ship the release', - diagnostic: 'Stage 2', - ), - ], - request: 1, - key: const ValueKey('rebuilt'), - ); - expect( - find.bySemanticsLabel('Notifications, 1 needing attention'), - findsOneWidget, - ); - semantics.dispose(); - }, + testWidgets('Material Runs list bell opens the sheet and dismisses one', ( + tester, + ) async { + final semantics = tester.ensureSemantics(); + final store = MemoryAttentionStore(); + await mountAttentionRuns( + tester, + gateway, + store: store, + runs: [ + attentionRun(1, 'waiting', title: 'Approve the release'), + attentionRun( + 2, + 'failed', + title: 'Ship the release', + diagnostic: 'Stage 2', + ), + attentionRun(3, 'waiting', title: 'Machine export') + ..['export_pending_sequence'] = 2, + attentionRun(4, 'running', title: 'Still running'), + ], ); - testWidgets('$host rows follow the browser open/dismiss rules', ( + expect( + find.bySemanticsLabel('Notifications, 2 needing attention'), + findsOneWidget, + ); + await openAttentionSheet(tester); + expect(find.byKey(attentionSheetKey), findsOneWidget); + expect(find.byKey(attentionRowKey('3:Decision')), findsNothing); + expect(find.byKey(attentionRowKey('4:Failed')), findsNothing); + expect(find.byKey(attentionRowKey('2:Failed')), findsOneWidget); + + await tester.tap(find.byKey(attentionDismissKey('2:Failed'))); + await tester.pumpAndSettle(); + expect(find.byKey(attentionSheetKey), findsOneWidget); + expect(find.byKey(attentionRowKey('2:Failed')), findsNothing); + expect(store.stored, encodeAttentionDismissals({'2:Failed'})); + + // Closing and rebuilding from the same store keeps the dismissal. + await tester.binding.handlePopRoute(); + await tester.pumpAndSettle(); + await tester.pumpWidget(const SizedBox()); + await mountAttentionRuns( tester, - ) async { - final store = MemoryAttentionStore(); - await mountAttentionRuns( - tester, - gateway, - cupertino: native, - store: store, - runs: [ - attentionRun(1, 'waiting', title: 'Approve the release'), - attentionRun(2, 'failed', title: 'Ship the release'), - ], - ); + gateway, + store: store, + runs: [ + attentionRun(1, 'waiting', title: 'Approve the release'), + attentionRun( + 2, + 'failed', + title: 'Ship the release', + diagnostic: 'Stage 2', + ), + ], + request: 1, + key: const ValueKey('rebuilt'), + ); + expect( + find.bySemanticsLabel('Notifications, 1 needing attention'), + findsOneWidget, + ); + semantics.dispose(); + }); - await openAttentionSheet(tester); - await tester.tap(find.byKey(attentionRowKey('1:Decision'))); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 400)); - expect(gateway.detailRequests[1], hasLength(1)); - expect( - store.stored, - isNull, - reason: 'a Decision opens without dismissing', - ); - gateway.replyDetail(1, {'id': 1, 'title': 'Approve the release'}); - await tester.pump(); - await tester.pumpAndSettle(); - - // The wide list and its bell stay available beside the open detail. - expect(find.byKey(const ValueKey('run-row-2')), findsOneWidget); - await openAttentionSheet(tester); - await tester.tap(find.byKey(attentionRowKey('2:Failed'))); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 400)); - expect(gateway.detailRequests[2], hasLength(1)); - expect(store.stored, encodeAttentionDismissals({'2:Failed'})); - gateway.replyDetail(2, {'id': 2, 'title': 'Ship the release'}); - await tester.pump(); - }); - - testWidgets('$host live frame and Clear-all snapshot reach the bell', ( + testWidgets('Material rows follow the browser open/dismiss rules', ( + tester, + ) async { + final store = MemoryAttentionStore(); + await mountAttentionRuns( tester, - ) async { - final semantics = tester.ensureSemantics(); - final store = MemoryAttentionStore(); - await mountAttentionRuns( - tester, - gateway, - cupertino: native, - store: store, - runs: [attentionRun(1, 'failed', title: 'First failure')], - ); - expect( - find.bySemanticsLabel('Notifications, 1 needing attention'), - findsOneWidget, - ); + gateway, + store: store, + runs: [ + attentionRun(1, 'waiting', title: 'Approve the release'), + attentionRun(2, 'failed', title: 'Ship the release'), + ], + ); - await openAttentionSheet(tester); - gateway.framesController.add({ - 'type': 'run_event', - 'run_id': 9, - 'pipeline_id': 4, - 'name': 'nightly', - 'title': 'Arrived while open', - 'status': 'waiting', - 'created_at': attentionTestNow - .subtract(const Duration(minutes: 5)) - .toIso8601String(), - }); - await tester.pump(); - await tester.pumpAndSettle(); - expect(find.byKey(attentionRowKey('9:Decision')), findsOneWidget); + await openAttentionSheet(tester); + await tester.tap(find.byKey(attentionRowKey('1:Decision'))); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 400)); + expect(gateway.detailRequests[1], hasLength(1)); + expect( + store.stored, + isNull, + reason: 'a Decision opens without dismissing', + ); + gateway.replyDetail(1, {'id': 1, 'title': 'Approve the release'}); + await tester.pump(); + await tester.pumpAndSettle(); - await tester.tap(find.byKey(attentionClearAllKey)); - await tester.pumpAndSettle(); - expect(find.byKey(attentionRowKey('1:Failed')), findsNothing); - expect( - find.byKey(attentionRowKey('9:Decision')), - findsOneWidget, - reason: 'Clear all acts on the snapshot it opened with', - ); - expect(store.stored, encodeAttentionDismissals({'1:Failed'})); - semantics.dispose(); - }); + // The wide list and its bell stay available beside the open detail. + expect(find.byKey(const ValueKey('run-row-2')), findsOneWidget); + await openAttentionSheet(tester); + await tester.tap(find.byKey(attentionRowKey('2:Failed'))); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 400)); + expect(gateway.detailRequests[2], hasLength(1)); + expect(store.stored, encodeAttentionDismissals({'2:Failed'})); + gateway.replyDetail(2, {'id': 2, 'title': 'Ship the release'}); + await tester.pump(); + }); - testWidgets('$host empty runs hide the badge but keep the bell', ( + testWidgets('Material live frame and Clear-all snapshot reach the bell', ( + tester, + ) async { + final semantics = tester.ensureSemantics(); + final store = MemoryAttentionStore(); + await mountAttentionRuns( tester, - ) async { - final semantics = tester.ensureSemantics(); - await mountAttentionRuns( - tester, - gateway, - cupertino: native, - store: MemoryAttentionStore(), - runs: const [], - ); + gateway, + store: store, + runs: [attentionRun(1, 'failed', title: 'First failure')], + ); + expect( + find.bySemanticsLabel('Notifications, 1 needing attention'), + findsOneWidget, + ); - expect(find.byKey(attentionBellKey), findsOneWidget); - expect(find.byKey(attentionBadgeKey), findsNothing); - expect(find.bySemanticsLabel('Notifications'), findsOneWidget); - await openAttentionSheet(tester); - expect(find.text('Nothing needs you right now.'), findsOneWidget); - expect(find.byKey(attentionClearAllKey), findsNothing); - semantics.dispose(); + await openAttentionSheet(tester); + gateway.framesController.add({ + 'type': 'run_event', + 'run_id': 9, + 'pipeline_id': 4, + 'name': 'nightly', + 'title': 'Arrived while open', + 'status': 'waiting', + 'created_at': attentionTestNow + .subtract(const Duration(minutes: 5)) + .toIso8601String(), }); - } + await tester.pump(); + await tester.pumpAndSettle(); + expect(find.byKey(attentionRowKey('9:Decision')), findsOneWidget); + + await tester.tap(find.byKey(attentionClearAllKey)); + await tester.pumpAndSettle(); + expect(find.byKey(attentionRowKey('1:Failed')), findsNothing); + expect( + find.byKey(attentionRowKey('9:Decision')), + findsOneWidget, + reason: 'Clear all acts on the snapshot it opened with', + ); + expect(store.stored, encodeAttentionDismissals({'1:Failed'})); + semantics.dispose(); + }); + + testWidgets('Material empty runs hide the badge but keep the bell', ( + tester, + ) async { + final semantics = tester.ensureSemantics(); + await mountAttentionRuns( + tester, + gateway, + store: MemoryAttentionStore(), + runs: const [], + ); + + expect(find.byKey(attentionBellKey), findsOneWidget); + expect(find.byKey(attentionBadgeKey), findsNothing); + expect(find.bySemanticsLabel('Notifications'), findsOneWidget); + await openAttentionSheet(tester); + expect(find.text('Nothing needs you right now.'), findsOneWidget); + expect(find.byKey(attentionClearAllKey), findsNothing); + semantics.dispose(); + }); } diff --git a/app/test/features/attention/ui/needs_you_bell_test.dart b/app/test/features/attention/ui/needs_you_bell_test.dart index 8ab74547..a6cf1859 100644 --- a/app/test/features/attention/ui/needs_you_bell_test.dart +++ b/app/test/features/attention/ui/needs_you_bell_test.dart @@ -1,126 +1,137 @@ +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/attention/ui/needs_you_bell.dart'; import 'package:pipelines_app/features/attention/ui/needs_you_keys.dart'; import 'needs_you_test_support.dart'; void main() { - for (final native in [false, true]) { - final host = native ? 'Cupertino' : 'Material'; + testWidgets('Material bell is plain and announced when nothing needs you', ( + tester, + ) async { + final semantics = tester.ensureSemantics(); + await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const []))); - testWidgets('$host bell is plain and announced when nothing needs you', ( - tester, - ) async { - final semantics = tester.ensureSemantics(); - await tester.pumpWidget( - attentionApp(NeedsYouPage(entries: const [], cupertino: native)), - ); + expect(find.bySemanticsLabel('Notifications'), findsOneWidget); + expect(find.byKey(attentionBadgeKey), findsNothing); + expect(find.text('0'), findsNothing); + semantics.dispose(); + }); - expect(find.bySemanticsLabel('Notifications'), findsOneWidget); - expect(find.byKey(attentionBadgeKey), findsNothing); - expect(find.text('0'), findsNothing); - semantics.dispose(); - }); + testWidgets('Material bell announces the count and shows one badge', ( + tester, + ) async { + final semantics = tester.ensureSemantics(); + final entries = [ + attentionFixture(id: 1), + attentionFixture(id: 2, status: 'waiting', title: 'Approve release'), + attentionFixture(id: 3, diagnostic: 'Stage 2 failed'), + ]; + await tester.pumpWidget(attentionApp(NeedsYouPage(entries: entries))); - testWidgets('$host bell announces the count and shows one badge', ( - tester, - ) async { - final semantics = tester.ensureSemantics(); - final entries = [ - attentionFixture(id: 1), - attentionFixture(id: 2, status: 'waiting', title: 'Approve release'), - attentionFixture(id: 3, diagnostic: 'Stage 2 failed'), - ]; - await tester.pumpWidget( - attentionApp( - NeedsYouPage(entries: entries, cupertino: native), - cupertino: native, + expect( + find.bySemanticsLabel('Notifications, 3 needing attention'), + findsOneWidget, + ); + expect(find.byKey(attentionBadgeKey), findsOneWidget); + expect(find.text('3'), findsOneWidget); + semantics.dispose(); + }); + + testWidgets('Material bell opens the honest empty sheet and back closes it', ( + tester, + ) async { + await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const []))); + + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + + expect(find.byKey(attentionSheetKey), findsOneWidget); + expect(find.text('Needs you'), findsOneWidget); + expect(find.text('Nothing needs you right now.'), findsOneWidget); + expect(find.byKey(attentionEmptyKey), findsOneWidget); + expect(find.byKey(attentionClearAllKey), findsNothing); + expect(find.text('Dismiss'), findsNothing); + + await tester.binding.handlePopRoute(); + await tester.pumpAndSettle(); + expect(find.byKey(attentionSheetKey), findsNothing); + }); + + testWidgets('Material sheet is a named heading and Escape closes it', ( + tester, + ) async { + final semantics = tester.ensureSemantics(); + await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const []))); + + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + final title = tester.getSemantics(find.text('Needs you')); + expect( + title.getSemanticsData().flagsCollection.isHeader, + isTrue, + reason: 'the sheet title must reach assistive tech as a heading', + ); + + await tester.sendKeyEvent(LogicalKeyboardKey.escape); + await tester.pumpAndSettle(); + expect(find.byKey(attentionSheetKey), findsNothing); + semantics.dispose(); + }); + + testWidgets('Material sheet closes on a barrier tap', (tester) async { + await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const []))); + + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + expect(find.byKey(attentionSheetKey), findsOneWidget); + + // Above the sheet body: only the native modal barrier is there. + await tester.tapAt(const Offset(20, 20)); + await tester.pumpAndSettle(); + expect(find.byKey(attentionSheetKey), findsNothing); + }); + + testWidgets('Material closing the sheet returns focus to the bell', ( + tester, + ) async { + await tester.pumpWidget(attentionApp(NeedsYouPage(entries: const []))); + + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + await tester.binding.handlePopRoute(); + await tester.pumpAndSettle(); + + expect(find.byKey(attentionSheetKey), findsNothing); + expect(bellHasFocus(tester), isTrue); + }); + + testWidgets('a stale cupertino flag still draws the Material bell and sheet', ( + tester, + ) async { + await tester.pumpWidget( + attentionApp( + Scaffold( + body: Center( + child: NeedsYouBell( + entries: [attentionFixture()], + cupertino: true, + onOpen: (_) {}, + onDismiss: (_) {}, + onClearAll: (_) {}, + ), + ), ), - ); + ), + ); - expect( - find.bySemanticsLabel('Notifications, 3 needing attention'), - findsOneWidget, - ); - expect(find.byKey(attentionBadgeKey), findsOneWidget); - expect(find.text('3'), findsOneWidget); - semantics.dispose(); - }); + expect(tester.widget(find.byKey(attentionBellKey)), isA()); + expect(find.byIcon(Icons.notifications_outlined), findsOneWidget); - testWidgets('$host bell opens the honest empty sheet and back closes it', ( - tester, - ) async { - await tester.pumpWidget( - attentionApp(NeedsYouPage(entries: const [], cupertino: native)), - ); - - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - - expect(find.byKey(attentionSheetKey), findsOneWidget); - expect(find.text('Needs you'), findsOneWidget); - expect(find.text('Nothing needs you right now.'), findsOneWidget); - expect(find.byKey(attentionEmptyKey), findsOneWidget); - expect(find.byKey(attentionClearAllKey), findsNothing); - expect(find.text('Dismiss'), findsNothing); - - await tester.binding.handlePopRoute(); - await tester.pumpAndSettle(); - expect(find.byKey(attentionSheetKey), findsNothing); - }); - - testWidgets('$host sheet is a named heading and Escape closes it', ( - tester, - ) async { - final semantics = tester.ensureSemantics(); - await tester.pumpWidget( - attentionApp(NeedsYouPage(entries: const [], cupertino: native)), - ); - - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - final title = tester.getSemantics(find.text('Needs you')); - expect( - title.getSemanticsData().flagsCollection.isHeader, - isTrue, - reason: 'the sheet title must reach assistive tech as a heading', - ); - - await tester.sendKeyEvent(LogicalKeyboardKey.escape); - await tester.pumpAndSettle(); - expect(find.byKey(attentionSheetKey), findsNothing); - semantics.dispose(); - }); - - testWidgets('$host sheet closes on a barrier tap', (tester) async { - await tester.pumpWidget( - attentionApp(NeedsYouPage(entries: const [], cupertino: native)), - ); - - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - expect(find.byKey(attentionSheetKey), findsOneWidget); - - // Above the sheet body: only the native modal barrier is there. - await tester.tapAt(const Offset(20, 20)); - await tester.pumpAndSettle(); - expect(find.byKey(attentionSheetKey), findsNothing); - }); - - testWidgets('$host closing the sheet returns focus to the bell', ( - tester, - ) async { - await tester.pumpWidget( - attentionApp(NeedsYouPage(entries: const [], cupertino: native)), - ); - - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - await tester.binding.handlePopRoute(); - await tester.pumpAndSettle(); - - expect(find.byKey(attentionSheetKey), findsNothing); - expect(bellHasFocus(tester), isTrue); - }); - } + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + expect(find.byType(BottomSheet), findsOneWidget); + expect(find.byKey(attentionSheetKey), findsOneWidget); + }); } diff --git a/app/test/features/attention/ui/needs_you_layout_test.dart b/app/test/features/attention/ui/needs_you_layout_test.dart index da295b41..0d37f5ab 100644 --- a/app/test/features/attention/ui/needs_you_layout_test.dart +++ b/app/test/features/attention/ui/needs_you_layout_test.dart @@ -6,65 +6,60 @@ import 'needs_you_test_support.dart'; /// Layout evidence for the hardest case: a narrow phone at a doubled text scale. void main() { - for (final native in [false, true]) { - final host = native ? 'Cupertino' : 'Material'; + testWidgets('Material sheet wraps at 320 logical px and 2x in dark', ( + tester, + ) async { + tester.view.devicePixelRatio = 2; + tester.view.physicalSize = const Size(640, 1280); + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + const longTitle = + 'Implementer-with-an-unshortened-stage-label that the operator sees'; + const longDetail = + 'Stage 3 stopped at the export archive step because the credential ' + 'it needs is no longer configured on this server.'; + final entry = attentionFixture( + id: 1, + name: 'Release', + title: longTitle, + diagnostic: longDetail, + ); + await tester.pumpWidget( + attentionApp( + NeedsYouPage(entries: [entry]), + dark: true, + textScale: 2, + ), + ); - testWidgets('$host sheet wraps at 320 logical px and 2x in dark', ( - tester, - ) async { - tester.view.devicePixelRatio = 2; - tester.view.physicalSize = const Size(640, 1280); - addTearDown(tester.view.resetPhysicalSize); - addTearDown(tester.view.resetDevicePixelRatio); - const longTitle = - 'Implementer-with-an-unshortened-stage-label that the operator sees'; - const longDetail = - 'Stage 3 stopped at the export archive step because the credential ' - 'it needs is no longer configured on this server.'; - final entry = attentionFixture( - id: 1, - name: 'Release', - title: longTitle, - diagnostic: longDetail, - ); - await tester.pumpWidget( - attentionApp( - NeedsYouPage(entries: [entry], cupertino: native), - cupertino: native, - dark: true, - textScale: 2, - ), - ); + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + expect(tester.takeException(), isNull); - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - expect(tester.takeException(), isNull); + final label = find.text(longTitle); + final description = find.text('Release · $longDetail'); + expect(label, findsOneWidget); + expect(description, findsOneWidget); + await tester.ensureVisible(label); + final paragraph = tester.renderObject(label); + expect(paragraph.didExceedMaxLines, isFalse); + final unscaled = TextPainter( + text: paragraph.text, + textDirection: paragraph.textDirection, + textScaler: TextScaler.noScaling, + )..layout(); + expect( + unscaled.width, + greaterThan(paragraph.size.width), + reason: 'the long label wraps instead of shrinking to one line', + ); + unscaled.dispose(); - final label = find.text(longTitle); - final description = find.text('Release · $longDetail'); - expect(label, findsOneWidget); - expect(description, findsOneWidget); - await tester.ensureVisible(label); - final paragraph = tester.renderObject(label); - expect(paragraph.didExceedMaxLines, isFalse); - final unscaled = TextPainter( - text: paragraph.text, - textDirection: paragraph.textDirection, - textScaler: TextScaler.noScaling, - )..layout(); - expect( - unscaled.width, - greaterThan(paragraph.size.width), - reason: 'the long label wraps instead of shrinking to one line', - ); - unscaled.dispose(); - - final sheet = tester.getRect(find.byKey(attentionSheetKey)); - expect(sheet.left, greaterThanOrEqualTo(0)); - expect(sheet.right, lessThanOrEqualTo(320)); - expect(sheet.top, greaterThanOrEqualTo(0)); - expect(sheet.bottom, lessThanOrEqualTo(640)); - expect(tester.takeException(), isNull); - }); - } + final sheet = tester.getRect(find.byKey(attentionSheetKey)); + expect(sheet.left, greaterThanOrEqualTo(0)); + expect(sheet.right, lessThanOrEqualTo(320)); + expect(sheet.top, greaterThanOrEqualTo(0)); + expect(sheet.bottom, lessThanOrEqualTo(640)); + expect(tester.takeException(), isNull); + }); } diff --git a/app/test/features/attention/ui/needs_you_live_rows_test.dart b/app/test/features/attention/ui/needs_you_live_rows_test.dart index f2fc7da1..ad1f476f 100644 --- a/app/test/features/attention/ui/needs_you_live_rows_test.dart +++ b/app/test/features/attention/ui/needs_you_live_rows_test.dart @@ -9,109 +9,97 @@ import 'needs_you_test_support.dart'; /// arrive, disappear or change text must redraw, while Clear all stays limited /// to the snapshot the route opened with. void main() { - for (final native in [false, true]) { - final host = native ? 'Cupertino' : 'Material'; - - testWidgets( - '$host same-identity content change reaches the open and reopened sheet', - (tester) async { - final before = attentionFixture(id: 1, title: 'Old title'); - final changed = attentionFixture( - id: 1, - title: 'New title', - diagnostic: 'Stage 3 failed', - ); - final reopened = attentionFixture(id: 1, title: 'Newest title'); - expect(changed.key, before.key); - final source = ValueNotifier>([before]); - addTearDown(source.dispose); - await tester.pumpWidget( - attentionApp( - AttentionHarness( - source: source, - opened: [], - dismissed: [], - cleared: >[], - cupertino: native, - ), - cupertino: native, - ), - ); - - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - expect(find.text('Old title'), findsOneWidget); - - // Same run and kind, new title and diagnostic: the open sheet must - // redraw from the caller's list, as the browser does. - source.value = [changed]; - await tester.pumpAndSettle(); - expect(find.text('New title'), findsOneWidget); - expect(find.text('Old title'), findsNothing); - expect(find.text('Release · Stage 3 failed'), findsOneWidget); - expect( - attentionDismissName(tester, changed), - 'Dismiss New title', - reason: 'the row action is named from the row it now shows', - ); - - await tester.binding.handlePopRoute(); - await tester.pumpAndSettle(); - expect(find.byKey(attentionSheetKey), findsNothing); - - // A closed sheet must not keep the list it was last opened with either. - source.value = [reopened]; - await tester.pumpAndSettle(); - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - expect(find.text('Newest title'), findsOneWidget); - expect(find.text('New title'), findsNothing); - expect(attentionDismissName(tester, reopened), 'Dismiss Newest title'); - }, + testWidgets('Material same-identity content change reaches the open and ' + 'reopened sheet', (tester) async { + final before = attentionFixture(id: 1, title: 'Old title'); + final changed = attentionFixture( + id: 1, + title: 'New title', + diagnostic: 'Stage 3 failed', + ); + final reopened = attentionFixture(id: 1, title: 'Newest title'); + expect(changed.key, before.key); + final source = ValueNotifier>([before]); + addTearDown(source.dispose); + await tester.pumpWidget( + attentionApp( + AttentionHarness( + source: source, + opened: [], + dismissed: [], + cleared: >[], + ), + ), ); - testWidgets( - '$host Clear all uses the open snapshot and leaves later arrivals', - (tester) async { - final a = attentionFixture(id: 1, title: 'Ship the release'); - final b = attentionFixture(id: 2, title: 'Arrived while open'); - final source = ValueNotifier>([a]); - addTearDown(source.dispose); - final cleared = >[]; - await tester.pumpWidget( - attentionApp( - AttentionHarness( - source: source, - opened: [], - dismissed: [], - cleared: cleared, - cupertino: native, - ), - cupertino: native, - ), - ); + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + expect(find.text('Old title'), findsOneWidget); - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - source.value = [a, b]; - await tester.pumpAndSettle(); - expect( - find.byKey(attentionRowKey(b.key)), - findsOneWidget, - reason: 'the open sheet shows the live list, as the browser does', - ); - - await tester.tap(find.byKey(attentionClearAllKey)); - await tester.pumpAndSettle(); - - expect(cleared, hasLength(1)); - expect(cleared.single.map((entry) => entry.key), [a.key]); - expect(source.value.map((entry) => entry.key), [b.key]); - // Clearing keeps the sheet open; only the snapshot it opened with is gone. - expect(find.byKey(attentionSheetKey), findsOneWidget); - expect(find.byKey(attentionRowKey(b.key)), findsOneWidget); - expect(find.byKey(attentionRowKey(a.key)), findsNothing); - }, + // Same run and kind, new title and diagnostic: the open sheet must + // redraw from the caller's list, as the browser does. + source.value = [changed]; + await tester.pumpAndSettle(); + expect(find.text('New title'), findsOneWidget); + expect(find.text('Old title'), findsNothing); + expect(find.text('Release · Stage 3 failed'), findsOneWidget); + expect( + attentionDismissName(tester, changed), + 'Dismiss New title', + reason: 'the row action is named from the row it now shows', ); - } + + await tester.binding.handlePopRoute(); + await tester.pumpAndSettle(); + expect(find.byKey(attentionSheetKey), findsNothing); + + // A closed sheet must not keep the list it was last opened with either. + source.value = [reopened]; + await tester.pumpAndSettle(); + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + expect(find.text('Newest title'), findsOneWidget); + expect(find.text('New title'), findsNothing); + expect(attentionDismissName(tester, reopened), 'Dismiss Newest title'); + }); + + testWidgets('Material Clear all uses the open snapshot and leaves later ' + 'arrivals', (tester) async { + final a = attentionFixture(id: 1, title: 'Ship the release'); + final b = attentionFixture(id: 2, title: 'Arrived while open'); + final source = ValueNotifier>([a]); + addTearDown(source.dispose); + final cleared = >[]; + await tester.pumpWidget( + attentionApp( + AttentionHarness( + source: source, + opened: [], + dismissed: [], + cleared: cleared, + ), + ), + ); + + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + source.value = [a, b]; + await tester.pumpAndSettle(); + expect( + find.byKey(attentionRowKey(b.key)), + findsOneWidget, + reason: 'the open sheet shows the live list, as the browser does', + ); + + await tester.tap(find.byKey(attentionClearAllKey)); + await tester.pumpAndSettle(); + + expect(cleared, hasLength(1)); + expect(cleared.single.map((entry) => entry.key), [a.key]); + expect(source.value.map((entry) => entry.key), [b.key]); + // Clearing keeps the sheet open; only the snapshot it opened with is gone. + expect(find.byKey(attentionSheetKey), findsOneWidget); + expect(find.byKey(attentionRowKey(b.key)), findsOneWidget); + expect(find.byKey(attentionRowKey(a.key)), findsNothing); + }); } diff --git a/app/test/features/attention/ui/needs_you_sheet_test.dart b/app/test/features/attention/ui/needs_you_sheet_test.dart index cce693cc..2438d630 100644 --- a/app/test/features/attention/ui/needs_you_sheet_test.dart +++ b/app/test/features/attention/ui/needs_you_sheet_test.dart @@ -7,166 +7,140 @@ import 'package:pipelines_app/ui/status/run_status_icon.dart'; import 'needs_you_test_support.dart'; void main() { - for (final native in [false, true]) { - final host = native ? 'Cupertino' : 'Material'; + testWidgets('Material sheet names every row and every dismiss action', ( + tester, + ) async { + final a = attentionFixture(id: 1, title: 'Ship the release'); + final b = attentionFixture(id: 2, name: 'Nightly audit', status: 'waiting'); + await tester.pumpWidget(attentionApp(NeedsYouPage(entries: [a, b]))); - testWidgets('$host sheet names every row and every dismiss action', ( - tester, - ) async { - final a = attentionFixture(id: 1, title: 'Ship the release'); - final b = attentionFixture( - id: 2, - name: 'Nightly audit', - status: 'waiting', - ); - await tester.pumpWidget( - attentionApp( - NeedsYouPage(entries: [a, b], cupertino: native), - cupertino: native, + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + + expect(find.byKey(attentionSheetKey), findsOneWidget); + expect(find.text('Needs you'), findsOneWidget); + expect(find.byKey(attentionRowKey(a.key)), findsOneWidget); + expect(find.byKey(attentionRowKey(b.key)), findsOneWidget); + expect(find.text('Ship the release'), findsOneWidget); + expect(find.text('Release · Run failed'), findsOneWidget); + expect(find.text('Nightly audit'), findsOneWidget); + expect(find.text('Nightly audit · Waiting for your decision'), findsOneWidget); + expect(find.byKey(attentionClearAllKey), findsOneWidget); + // Each row leads with the shared run status glyph, as the web's rows. + expect( + tester + .widgetList(find.byType(RunStatusIcon)) + .map((icon) => icon.state), + unorderedEquals(['failed', 'waiting']), + ); + + // The browser names each destructive control after the row it removes. + expect(attentionDismissName(tester, a), 'Dismiss Ship the release'); + expect(attentionDismissName(tester, b), 'Dismiss Nightly audit'); + expect(find.text('Dismiss'), findsNothing); + }); + + testWidgets('Material repeated labels add the run id to the dismiss name', ( + tester, + ) async { + final first = attentionFixture(id: 11, title: 'Nightly audit'); + final second = attentionFixture(id: 12, title: 'Nightly audit'); + await tester.pumpWidget( + attentionApp(NeedsYouPage(entries: [first, second])), + ); + + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + + expect(attentionDismissName(tester, first), 'Dismiss Nightly audit (run 11)'); + expect( + attentionDismissName(tester, second), + 'Dismiss Nightly audit (run 12)', + ); + }); + + testWidgets('Material row Dismiss names its identity and stays open', ( + tester, + ) async { + final a = attentionFixture(id: 1, title: 'Ship the release'); + final b = attentionFixture(id: 2, title: 'Fix the export'); + final source = ValueNotifier>([a, b]); + addTearDown(source.dispose); + final opened = []; + final dismissed = []; + await tester.pumpWidget( + attentionApp( + AttentionHarness( + source: source, + opened: opened, + dismissed: dismissed, + cleared: >[], ), - ); + ), + ); - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(attentionDismissKey(b.key))); + await tester.pumpAndSettle(); - expect(find.byKey(attentionSheetKey), findsOneWidget); - expect(find.text('Needs you'), findsOneWidget); - expect(find.byKey(attentionRowKey(a.key)), findsOneWidget); - expect(find.byKey(attentionRowKey(b.key)), findsOneWidget); - expect(find.text('Ship the release'), findsOneWidget); - expect(find.text('Release · Run failed'), findsOneWidget); - expect(find.text('Nightly audit'), findsOneWidget); - expect( - find.text('Nightly audit · Waiting for your decision'), - findsOneWidget, - ); - expect(find.byKey(attentionClearAllKey), findsOneWidget); - // Each row leads with the shared run status glyph, as the web's rows. - expect( - tester - .widgetList(find.byType(RunStatusIcon)) - .map((icon) => icon.state), - unorderedEquals(['failed', 'waiting']), - ); + expect(dismissed.map((entry) => entry.key), [b.key]); + expect(opened, isEmpty); + // The browser keeps the sheet open and redraws it; the caller removed the + // dismissed identity, so the remaining row is still there for a second one. + expect(find.byKey(attentionSheetKey), findsOneWidget); + expect(find.byKey(attentionRowKey(b.key)), findsNothing); + expect(find.byKey(attentionRowKey(a.key)), findsOneWidget); + }); - // The browser names each destructive control after the row it removes. - expect(attentionDismissName(tester, a), 'Dismiss Ship the release'); - expect(attentionDismissName(tester, b), 'Dismiss Nightly audit'); - expect(find.text('Dismiss'), findsNothing); - }); - - testWidgets('$host repeated labels add the run id to the dismiss name', ( - tester, - ) async { - final first = attentionFixture(id: 11, title: 'Nightly audit'); - final second = attentionFixture(id: 12, title: 'Nightly audit'); - await tester.pumpWidget( - attentionApp( - NeedsYouPage(entries: [first, second], cupertino: native), - cupertino: native, + testWidgets('Material row opens its run and only a Failed row is dismissed', ( + tester, + ) async { + final failed = attentionFixture(id: 1, title: 'Ship the release'); + final decision = attentionFixture( + id: 2, + title: 'Approve the release', + status: 'waiting', + ); + final source = ValueNotifier>([failed, decision]); + addTearDown(source.dispose); + final opened = []; + final dismissed = []; + await tester.pumpWidget( + attentionApp( + AttentionHarness( + source: source, + opened: opened, + dismissed: dismissed, + cleared: >[], ), - ); + ), + ); - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(attentionRowKey(failed.key))); + await tester.pumpAndSettle(); - expect( - attentionDismissName(tester, first), - 'Dismiss Nightly audit (run 11)', - ); - expect( - attentionDismissName(tester, second), - 'Dismiss Nightly audit (run 12)', - ); - }); + expect(opened.map((entry) => entry.key), [failed.key]); + expect( + dismissed.map((entry) => entry.key), + [failed.key], + reason: 'opening a failed run is the operator dealing with it', + ); + expect(find.byKey(attentionSheetKey), findsNothing); - testWidgets('$host row Dismiss names its identity and stays open', ( - tester, - ) async { - final a = attentionFixture(id: 1, title: 'Ship the release'); - final b = attentionFixture(id: 2, title: 'Fix the export'); - final source = ValueNotifier>([a, b]); - addTearDown(source.dispose); - final opened = []; - final dismissed = []; - await tester.pumpWidget( - attentionApp( - AttentionHarness( - source: source, - opened: opened, - dismissed: dismissed, - cleared: >[], - cupertino: native, - ), - cupertino: native, - ), - ); + await tester.tap(find.byKey(attentionBellKey)); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(attentionRowKey(decision.key))); + await tester.pumpAndSettle(); - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - await tester.tap(find.byKey(attentionDismissKey(b.key))); - await tester.pumpAndSettle(); - - expect(dismissed.map((entry) => entry.key), [b.key]); - expect(opened, isEmpty); - // The browser keeps the sheet open and redraws it; the caller removed the - // dismissed identity, so the remaining row is still there for a second one. - expect(find.byKey(attentionSheetKey), findsOneWidget); - expect(find.byKey(attentionRowKey(b.key)), findsNothing); - expect(find.byKey(attentionRowKey(a.key)), findsOneWidget); - }); - - testWidgets('$host row opens its run and only a Failed row is dismissed', ( - tester, - ) async { - final failed = attentionFixture(id: 1, title: 'Ship the release'); - final decision = attentionFixture( - id: 2, - title: 'Approve the release', - status: 'waiting', - ); - final source = ValueNotifier>([failed, decision]); - addTearDown(source.dispose); - final opened = []; - final dismissed = []; - await tester.pumpWidget( - attentionApp( - AttentionHarness( - source: source, - opened: opened, - dismissed: dismissed, - cleared: >[], - cupertino: native, - ), - cupertino: native, - ), - ); - - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - await tester.tap(find.byKey(attentionRowKey(failed.key))); - await tester.pumpAndSettle(); - - expect(opened.map((entry) => entry.key), [failed.key]); - expect( - dismissed.map((entry) => entry.key), - [failed.key], - reason: 'opening a failed run is the operator dealing with it', - ); - expect(find.byKey(attentionSheetKey), findsNothing); - - await tester.tap(find.byKey(attentionBellKey)); - await tester.pumpAndSettle(); - await tester.tap(find.byKey(attentionRowKey(decision.key))); - await tester.pumpAndSettle(); - - expect(opened.map((entry) => entry.key), [failed.key, decision.key]); - expect( - dismissed.map((entry) => entry.key), - [failed.key], - reason: 'a decision stays until the operator answers it', - ); - expect(find.byKey(attentionSheetKey), findsNothing); - }); - } + expect(opened.map((entry) => entry.key), [failed.key, decision.key]); + expect( + dismissed.map((entry) => entry.key), + [failed.key], + reason: 'a decision stays until the operator answers it', + ); + expect(find.byKey(attentionSheetKey), findsNothing); + }); } diff --git a/app/test/features/attention/ui/needs_you_test_support.dart b/app/test/features/attention/ui/needs_you_test_support.dart index c53cc177..a1877879 100644 --- a/app/test/features/attention/ui/needs_you_test_support.dart +++ b/app/test/features/attention/ui/needs_you_test_support.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/attention/domain/attention_models.dart'; @@ -27,27 +26,13 @@ AttentionEntry attentionFixture({ })!; } -Widget attentionApp( - Widget home, { - bool cupertino = false, - bool dark = false, - double textScale = 1, -}) { +Widget attentionApp(Widget home, {bool dark = false, double textScale = 1}) { Widget scaled(BuildContext context, Widget? app) => MediaQuery( data: MediaQuery.of( context, ).copyWith(textScaler: TextScaler.linear(textScale)), child: app!, ); - if (cupertino) { - return CupertinoApp( - theme: CupertinoThemeData( - brightness: dark ? Brightness.dark : Brightness.light, - ), - builder: scaled, - home: home, - ); - } return MaterialApp( theme: ThemeData( platform: TargetPlatform.android, @@ -63,14 +48,12 @@ class NeedsYouPage extends StatelessWidget { const NeedsYouPage({ super.key, required this.entries, - this.cupertino = false, this.onOpen, this.onDismiss, this.onClearAll, }); final List entries; - final bool cupertino; final ValueChanged? onOpen; final ValueChanged? onDismiss; final ValueChanged>? onClearAll; @@ -79,15 +62,11 @@ class NeedsYouPage extends StatelessWidget { Widget build(BuildContext context) { final bell = NeedsYouBell( entries: entries, - cupertino: cupertino, onOpen: onOpen ?? (_) {}, onDismiss: onDismiss ?? (_) {}, onClearAll: onClearAll ?? (_) {}, ); - final body = Center(child: bell); - return cupertino - ? CupertinoPageScaffold(child: SafeArea(child: body)) - : Scaffold(body: SafeArea(child: body)); + return Scaffold(body: SafeArea(child: Center(child: bell))); } } @@ -101,14 +80,12 @@ class AttentionHarness extends StatelessWidget { required this.opened, required this.dismissed, required this.cleared, - this.cupertino = false, }); final ValueNotifier> source; final List opened; final List dismissed; final List> cleared; - final bool cupertino; @override Widget build(BuildContext context) { @@ -116,7 +93,6 @@ class AttentionHarness extends StatelessWidget { valueListenable: source, builder: (context, entries, _) => NeedsYouPage( entries: entries, - cupertino: cupertino, onOpen: opened.add, onDismiss: (entry) { dismissed.add(entry); @@ -143,24 +119,16 @@ bool bellHasFocus(WidgetTester tester) { final widget = tester.widget(find.byKey(attentionBellKey)); final node = switch (widget) { IconButton() => widget.focusNode, - CupertinoButton() => widget.focusNode, _ => null, }; return node?.hasPrimaryFocus ?? false; } -/// The accessible name of one row's Dismiss action, whichever host drew it. +/// The accessible name of one row's Dismiss action. /// -/// Material exposes it as the button tooltip, Cupertino as the xmark icon's -/// semantic label; both must name the row they remove. +/// The Material control exposes it as the button tooltip; it must name the row +/// it removes. String attentionDismissName(WidgetTester tester, AttentionEntry entry) { final key = attentionDismissKey(entry.key); - final xmark = find.descendant( - of: find.byKey(key), - matching: find.byIcon(CupertinoIcons.xmark), - ); - if (xmark.evaluate().isNotEmpty) { - return tester.widget(xmark).semanticLabel ?? ''; - } return tester.widget(find.byKey(key)).tooltip ?? ''; } diff --git a/app/test/features/attention/ui/notification_permission_tile_test.dart b/app/test/features/attention/ui/notification_permission_tile_test.dart index d4f00510..e3742852 100644 --- a/app/test/features/attention/ui/notification_permission_tile_test.dart +++ b/app/test/features/attention/ui/notification_permission_tile_test.dart @@ -6,12 +6,11 @@ import 'package:pipelines_app/features/attention/ui/notification_permission_tile import 'needs_you_test_support.dart'; -/// The tile inside a normal page, so both native hosts can draw it. The page -/// scrolls like the Settings list does, so the tile is never given a fixed +/// The tile inside a normal page, so it is drawn the way Settings draws it. The +/// page scrolls like the Settings list does, so the tile is never given a fixed /// height to overflow. Widget _page({ required NotificationPermissionState state, - bool cupertino = false, bool asked = false, VoidCallback? onRequest, }) => attentionApp( @@ -24,124 +23,130 @@ Widget _page({ ), ), ), - cupertino: cupertino, ); void _noop() {} void main() { - for (final native in [false, true]) { - final host = native ? 'Cupertino' : 'Material'; - - testWidgets('$host shows a compact row for each state', (tester) async { - final cases = { - NotificationPermissionState.unsupported: notificationUnsupportedCopy, - NotificationPermissionState.needsSecureContext: - notificationInsecureCopy, - NotificationPermissionState.granted: notificationGrantedCopy, - NotificationPermissionState.denied: notificationDeniedCopy, - NotificationPermissionState.notRequested: notificationDefaultCopy, - }; - for (final entry in cases.entries) { - await tester.pumpWidget( - _page(state: entry.key, cupertino: native, onRequest: _noop), - ); - final view = notificationPermissionView(entry.key); - // The Settings section owns the heading; the tile is one short row. - expect(find.text(notificationSectionTitle), findsNothing); - expect(find.text(notificationRationale), findsNothing); - expect(find.text(view.headline), findsOneWidget); - expect(find.text(view.helper), findsOneWidget); - // The full honest sentence is what assistive technology reads. - expect(view.body, entry.value); - expect(find.bySemanticsLabel(entry.value), findsOneWidget); - expect( - find.byKey(notificationEnableKey), - entry.key == NotificationPermissionState.notRequested - ? findsOneWidget - : findsNothing, - reason: '${entry.key}', - ); - } - }); - - testWidgets('$host shows the asked wording without an action', ( - tester, - ) async { - await tester.pumpWidget( - _page( - state: NotificationPermissionState.notRequested, - asked: true, - cupertino: native, - ), + testWidgets('Material shows a compact row for each state', (tester) async { + final cases = { + NotificationPermissionState.unsupported: notificationUnsupportedCopy, + NotificationPermissionState.needsSecureContext: notificationInsecureCopy, + NotificationPermissionState.granted: notificationGrantedCopy, + NotificationPermissionState.denied: notificationDeniedCopy, + NotificationPermissionState.notRequested: notificationDefaultCopy, + }; + for (final entry in cases.entries) { + await tester.pumpWidget(_page(state: entry.key, onRequest: _noop)); + final view = notificationPermissionView(entry.key); + // The Settings section owns the heading; the tile is one short row. + expect(find.text(notificationSectionTitle), findsNothing); + expect(find.text(notificationRationale), findsNothing); + expect(find.text(view.headline), findsOneWidget); + expect(find.text(view.helper), findsOneWidget); + // The full honest sentence is what assistive technology reads. + expect(view.body, entry.value); + expect(find.bySemanticsLabel(entry.value), findsOneWidget); + expect( + find.byKey(notificationEnableKey), + entry.key == NotificationPermissionState.notRequested + ? findsOneWidget + : findsNothing, + reason: '${entry.key}', ); - expect(find.text('Alerts are still off'), findsOneWidget); - expect(find.bySemanticsLabel(notificationDefaultAskedCopy), findsOne); - expect(find.bySemanticsLabel(notificationDefaultCopy), findsNothing); - }); + } + }); - testWidgets('$host Enable runs the explicit request', (tester) async { - var requested = 0; - await tester.pumpWidget( - _page( - state: NotificationPermissionState.notRequested, - cupertino: native, - onRequest: () => requested++, - ), - ); - await tester.tap(find.byKey(notificationEnableKey)); - await tester.pump(); - expect(requested, 1); - }); + testWidgets('Material shows the asked wording without an action', ( + tester, + ) async { + await tester.pumpWidget( + _page(state: NotificationPermissionState.notRequested, asked: true), + ); + expect(find.text('Alerts are still off'), findsOneWidget); + expect(find.bySemanticsLabel(notificationDefaultAskedCopy), findsOne); + expect(find.bySemanticsLabel(notificationDefaultCopy), findsNothing); + }); - testWidgets('$host tile wraps at 320 logical px and 2x in dark', ( - tester, - ) async { - tester.view.devicePixelRatio = 2; - tester.view.physicalSize = const Size(640, 1280); - addTearDown(tester.view.resetPhysicalSize); - addTearDown(tester.view.resetDevicePixelRatio); + testWidgets('Material Enable runs the explicit request', (tester) async { + var requested = 0; + await tester.pumpWidget( + _page( + state: NotificationPermissionState.notRequested, + onRequest: () => requested++, + ), + ); + await tester.tap(find.byKey(notificationEnableKey)); + await tester.pump(); + expect(requested, 1); + }); - // The undecided state is the hardest: it carries the Enable action as well - // as the longest copy, so the section title must still have room to read. - await tester.pumpWidget( - attentionApp( - Scaffold( - body: SingleChildScrollView( - child: NotificationPermissionTile( - state: NotificationPermissionState.notRequested, - onRequest: _noop, - ), + testWidgets('a stale cupertino flag still draws the Material row', ( + tester, + ) async { + await tester.pumpWidget( + attentionApp( + Scaffold( + body: SingleChildScrollView( + child: NotificationPermissionTile( + state: NotificationPermissionState.notRequested, + cupertino: true, + onRequest: _noop, ), ), - cupertino: native, - dark: true, - textScale: 2, ), - ); - expect(tester.takeException(), isNull); + ), + ); - final view = notificationPermissionView( - NotificationPermissionState.notRequested, - ); - final helper = tester.renderObject( - find.text(view.helper), - ); - expect( - helper.size.width, - greaterThan(100), - reason: 'the action must not squeeze the row copy', - ); - final body = tester.renderObject( - find.text(view.headline), - ); - expect(body.didExceedMaxLines, isFalse); - expect(find.byKey(notificationEnableKey), findsOneWidget); + expect( + tester.widget(find.byKey(notificationEnableKey)), + isA(), + ); + expect(find.text(notificationEnableShortLabel), findsOneWidget); + }); - final rect = tester.getRect(find.byKey(notificationStateKey)); - expect(rect.left, greaterThanOrEqualTo(0)); - expect(rect.right, lessThanOrEqualTo(320)); - expect(tester.takeException(), isNull); - }); - } + testWidgets('Material tile wraps at 320 logical px and 2x in dark', ( + tester, + ) async { + tester.view.devicePixelRatio = 2; + tester.view.physicalSize = const Size(640, 1280); + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + + // The undecided state is the hardest: it carries the Enable action as well + // as the longest copy, so the section title must still have room to read. + await tester.pumpWidget( + attentionApp( + Scaffold( + body: SingleChildScrollView( + child: NotificationPermissionTile( + state: NotificationPermissionState.notRequested, + onRequest: _noop, + ), + ), + ), + dark: true, + textScale: 2, + ), + ); + expect(tester.takeException(), isNull); + + final view = notificationPermissionView( + NotificationPermissionState.notRequested, + ); + final helper = tester.renderObject(find.text(view.helper)); + expect( + helper.size.width, + greaterThan(100), + reason: 'the action must not squeeze the row copy', + ); + final body = tester.renderObject(find.text(view.headline)); + expect(body.didExceedMaxLines, isFalse); + expect(find.byKey(notificationEnableKey), findsOneWidget); + + final rect = tester.getRect(find.byKey(notificationStateKey)); + expect(rect.left, greaterThanOrEqualTo(0)); + expect(rect.right, lessThanOrEqualTo(320)); + expect(tester.takeException(), isNull); + }); } diff --git a/app/test/features/chat/chat_active_session_test.dart b/app/test/features/chat/chat_active_session_test.dart index fddd5156..07fc87e4 100644 --- a/app/test/features/chat/chat_active_session_test.dart +++ b/app/test/features/chat/chat_active_session_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -34,61 +33,53 @@ class _Gateway extends FakeChatGateway { } void main() { - for (final cupertino in [false, true]) { - testWidgets( - 'a pushed phone chat stays read and preserves underlying list chrome ($cupertino)', - (tester) async { - tester.view.physicalSize = const Size(390, 844); - tester.view.devicePixelRatio = 1; - addTearDown(tester.view.reset); - SharedPreferences.setMockInitialValues({}); - final gateway = _Gateway()..history = (_) async => chatPage([]); - addTearDown(gateway.close); - final bar = ShellBarRegistry(); - addTearDown(bar.dispose); - final selected = ValueNotifier('s1'); - addTearDown(selected.dispose); - final screen = ShellBarScope( - registry: bar, - destination: AppDestination.chat, - child: ValueListenableBuilder( - valueListenable: selected, - builder: (_, id, _) => ChatScreen( - gateway: gateway, - initialSessionId: id, - onBack: () => selected.value = null, - ), + testWidgets( + 'a pushed phone chat stays read and preserves underlying list chrome', + (tester) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + SharedPreferences.setMockInitialValues({}); + final gateway = _Gateway()..history = (_) async => chatPage([]); + addTearDown(gateway.close); + final bar = ShellBarRegistry(); + addTearDown(bar.dispose); + final selected = ValueNotifier('s1'); + addTearDown(selected.dispose); + final screen = ShellBarScope( + registry: bar, + destination: AppDestination.chat, + child: ValueListenableBuilder( + valueListenable: selected, + builder: (_, id, _) => ChatScreen( + gateway: gateway, + initialSessionId: id, + onBack: () => selected.value = null, ), - ); - await tester.pumpWidget( - cupertino - ? CupertinoApp(home: CupertinoPageScaffold(child: screen)) - : MaterialApp(home: Scaffold(body: screen)), - ); - await tester.pumpAndSettle(); - final list = tester.widget( - find.byType(ChatSessionsScreen, skipOffstage: false), - ); - final controller = list.controller!; - expect(controller.activeSessionId, 's1'); - expect(bar.specFor(AppDestination.chat)?.actions, isNotEmpty); - gateway.emitEvent(chatTextFrame('New live answer', session: 's1')); - await tester.pumpAndSettle(); - expect(controller.sessions.where(controller.isUnseen), isEmpty); - gateway.emitEvent(chatTextFrame('Different answer', session: 's2')); - await tester.pumpAndSettle(); - expect( - controller.sessions - .where(controller.isUnseen) - .map((row) => row['id']), - ['s2'], - ); - await tester.binding.handlePopRoute(); - await tester.pumpAndSettle(); - expect(controller.activeSessionId, isNull); - expect(find.text('Open conversation'), findsOneWidget); - await tester.pumpWidget(const SizedBox.shrink()); - }, - ); - } + ), + ); + await tester.pumpWidget(MaterialApp(home: Scaffold(body: screen))); + await tester.pumpAndSettle(); + final list = tester.widget( + find.byType(ChatSessionsScreen, skipOffstage: false), + ); + final controller = list.controller!; + expect(controller.activeSessionId, 's1'); + expect(bar.specFor(AppDestination.chat)?.actions, isNotEmpty); + gateway.emitEvent(chatTextFrame('New live answer', session: 's1')); + await tester.pumpAndSettle(); + expect(controller.sessions.where(controller.isUnseen), isEmpty); + gateway.emitEvent(chatTextFrame('Different answer', session: 's2')); + await tester.pumpAndSettle(); + expect( + controller.sessions.where(controller.isUnseen).map((row) => row['id']), + ['s2'], + ); + await tester.binding.handlePopRoute(); + await tester.pumpAndSettle(); + expect(controller.activeSessionId, isNull); + expect(find.text('Open conversation'), findsOneWidget); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); } diff --git a/app/test/features/chat/files/files_panel_test.dart b/app/test/features/chat/files/files_panel_test.dart index f8377874..a562f6c6 100644 --- a/app/test/features/chat/files/files_panel_test.dart +++ b/app/test/features/chat/files/files_panel_test.dart @@ -75,6 +75,24 @@ void main() { return controller; } + testWidgets('the panel filters entries through its Material field', ( + tester, + ) async { + await pump(tester); + final field = find.byType(TextField); + expect(field, findsOneWidget); + expect( + tester.widget(field).decoration?.hintText, + 'Filter files', + ); + await tester.enterText(field, 'notes'); + await tester.pumpAndSettle(); + expect(find.text('notes.txt'), findsOneWidget); + expect(find.text('picture.png'), findsNothing); + expect(find.widgetWithText(TextButton, '~'), findsOneWidget); + expect(find.widgetWithText(TextButton, 'demo'), findsOneWidget); + }); + testWidgets('text tap opens shared viewer and fetches inline URL', ( tester, ) async { diff --git a/app/test/features/chat/workspace/chat_center_stage_test.dart b/app/test/features/chat/workspace/chat_center_stage_test.dart index 545f1df2..9f915f09 100644 --- a/app/test/features/chat/workspace/chat_center_stage_test.dart +++ b/app/test/features/chat/workspace/chat_center_stage_test.dart @@ -192,6 +192,13 @@ void main() { await tester.pumpAndSettle(); expect(widthOf(tester, 'three'), 950); expect(find.byType(ChatCenterStageStrip), findsNWidgets(2)); + expect( + find.descendant( + of: find.byType(ChatCenterStageStrip).first, + matching: find.byType(InkWell), + ), + findsOneWidget, + ); expect(find.text('draft'), findsOneWidget); stage.value = false; diff --git a/app/test/features/chat/workspace/chat_peek_identity_test.dart b/app/test/features/chat/workspace/chat_peek_identity_test.dart index ba0917f3..0b3b5521 100644 --- a/app/test/features/chat/workspace/chat_peek_identity_test.dart +++ b/app/test/features/chat/workspace/chat_peek_identity_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/workspace/chat_mobile_panes.dart'; @@ -36,54 +35,48 @@ class _ThreadState extends State<_Thread> { } void main() { - for (final cupertino in [false, true]) { - for (final height in [32.0, 48.0]) { - testWidgets( - 'peek title and switch fit $height height at 2x ($cupertino)', - (tester) async { - var activated = 0; - Size? bodySize; - final viewport = MediaQuery( - data: const MediaQueryData(textScaler: TextScaler.linear(2)), - child: Align( - alignment: Alignment.topLeft, - child: SizedBox( - width: 320, - height: height, - child: ChatMobilePaneViewport( - peek: true, - active: false, - barReveal: const AlwaysStoppedAnimation(0), - onActivate: () => activated++, - label: 'A long working project name', - paneId: 'first', - child: LayoutBuilder( - builder: (context, constraints) { - bodySize = constraints.biggest; - return const SizedBox.expand(); - }, - ), - ), + for (final height in [32.0, 48.0]) { + testWidgets('peek title and switch fit $height height at 2x', ( + tester, + ) async { + var activated = 0; + Size? bodySize; + final viewport = MediaQuery( + data: const MediaQueryData(textScaler: TextScaler.linear(2)), + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: 320, + height: height, + child: ChatMobilePaneViewport( + peek: true, + active: false, + barReveal: const AlwaysStoppedAnimation(0), + onActivate: () => activated++, + label: 'A long working project name', + paneId: 'first', + child: LayoutBuilder( + builder: (context, constraints) { + bodySize = constraints.biggest; + return const SizedBox.expand(); + }, ), ), - ); - await tester.pumpWidget( - cupertino - ? CupertinoApp(home: CupertinoPageScaffold(child: viewport)) - : MaterialApp(home: Scaffold(body: viewport)), - ); - expect(find.text('A long working project name'), findsOneWidget); - expect(find.text('Switch'), findsOneWidget); - final headerSize = tester.getSize(find.byType(ChatPeekHeader)); - expect(headerSize.height, lessThanOrEqualTo(height)); - expect(bodySize!.height, closeTo(height - headerSize.height, .01)); - await tester.tap(find.text('Switch')); - await tester.pump(); - expect(activated, 1); - expect(tester.takeException(), isNull); - }, + ), + ), ); - } + await tester.pumpWidget(MaterialApp(home: Scaffold(body: viewport))); + expect(find.text('A long working project name'), findsOneWidget); + expect(find.text('Switch'), findsOneWidget); + expect(find.byType(TextButton), findsOneWidget); + final headerSize = tester.getSize(find.byType(ChatPeekHeader)); + expect(headerSize.height, lessThanOrEqualTo(height)); + expect(bodySize!.height, closeTo(height - headerSize.height, .01)); + await tester.tap(find.text('Switch')); + await tester.pump(); + expect(activated, 1); + expect(tester.takeException(), isNull); + }); } testWidgets('peek header reserves real body space and keeps reading state', ( tester, diff --git a/app/test/features/chat/workspace/chat_workspace_entrance_test.dart b/app/test/features/chat/workspace/chat_workspace_entrance_test.dart index 8ae3a24e..c92a22ef 100644 --- a/app/test/features/chat/workspace/chat_workspace_entrance_test.dart +++ b/app/test/features/chat/workspace/chat_workspace_entrance_test.dart @@ -3,56 +3,47 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/workspace/chat_workspace_entrance.dart'; void main() { - for (final cupertino in [false, true]) { - testWidgets('retained entrance moves the same child ($cupertino)', ( - tester, - ) async { - tester.platformDispatcher.accessibilityFeaturesTestValue = - const FakeAccessibilityFeatures(disableAnimations: false); - addTearDown( - tester.platformDispatcher.clearAccessibilityFeaturesTestValue, - ); - final childKey = GlobalKey(); - final child = TextField(key: childKey); - Widget host(bool visible, {bool reduced = false}) => MaterialApp( - home: MediaQuery( - data: MediaQueryData(disableAnimations: reduced), - child: SizedBox.expand( - child: ChatWorkspaceEntrance( - visible: visible, - cupertino: cupertino, - child: Material(child: child), - ), + testWidgets('retained entrance moves the same child', (tester) async { + tester.platformDispatcher.accessibilityFeaturesTestValue = + const FakeAccessibilityFeatures(disableAnimations: false); + addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue); + final childKey = GlobalKey(); + final child = TextField(key: childKey); + Widget host(bool visible, {bool reduced = false}) => MaterialApp( + home: MediaQuery( + data: MediaQueryData(disableAnimations: reduced), + child: SizedBox.expand( + child: ChatWorkspaceEntrance( + visible: visible, + cupertino: false, + child: Material(child: child), ), ), - ); - await tester.pumpWidget(host(false)); - final element = childKey.currentContext; - final state = childKey.currentState; - expect(find.byKey(childKey), findsNothing); - await tester.pumpWidget(host(true)); - final start = tester.getTopLeft(find.byKey(childKey)); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 80)); - final middle = tester.getTopLeft(find.byKey(childKey)); - await tester.pumpAndSettle(); - final end = tester.getTopLeft(find.byKey(childKey)); - expect(cupertino ? middle.dx : middle.dy, greaterThan(0)); - expect( - cupertino ? middle.dx : middle.dy, - lessThan(cupertino ? start.dx : start.dy), - ); - expect(end, Offset.zero); - expect(childKey.currentContext, same(element)); - expect(childKey.currentState, same(state)); - await tester.enterText(find.byType(TextField), 'Retained draft'); - await tester.pumpWidget(host(false)); - await tester.pumpAndSettle(); - await tester.pumpWidget(host(true, reduced: true)); - expect(tester.getTopLeft(find.byKey(childKey)), Offset.zero); - expect(find.text('Retained draft'), findsOneWidget); - expect(childKey.currentState, same(state)); - expect(tester.takeException(), isNull); - }); - } + ), + ); + await tester.pumpWidget(host(false)); + final element = childKey.currentContext; + final state = childKey.currentState; + expect(find.byKey(childKey), findsNothing); + await tester.pumpWidget(host(true)); + final start = tester.getTopLeft(find.byKey(childKey)); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 80)); + final middle = tester.getTopLeft(find.byKey(childKey)); + await tester.pumpAndSettle(); + final end = tester.getTopLeft(find.byKey(childKey)); + expect(middle.dy, greaterThan(0)); + expect(middle.dy, lessThan(start.dy)); + expect(end, Offset.zero); + expect(childKey.currentContext, same(element)); + expect(childKey.currentState, same(state)); + await tester.enterText(find.byType(TextField), 'Retained draft'); + await tester.pumpWidget(host(false)); + await tester.pumpAndSettle(); + await tester.pumpWidget(host(true, reduced: true)); + expect(tester.getTopLeft(find.byKey(childKey)), Offset.zero); + expect(find.text('Retained draft'), findsOneWidget); + expect(childKey.currentState, same(state)); + expect(tester.takeException(), isNull); + }); } diff --git a/app/test/features/graph/viewport/graph_expanded_view_test.dart b/app/test/features/graph/viewport/graph_expanded_view_test.dart index a1a7d077..84c680e4 100644 --- a/app/test/features/graph/viewport/graph_expanded_view_test.dart +++ b/app/test/features/graph/viewport/graph_expanded_view_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/semantics.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -164,95 +163,27 @@ void main() { expect(clamped, lessThan(panned)); }); - testWidgets('320px at 2x opens and closes on the dark Cupertino host', ( - tester, - ) async { - tester.view.physicalSize = const Size(320, 700); - tester.view.devicePixelRatio = 1; - addTearDown(tester.view.reset); - final picked = []; + testWidgets('expanded Fit is an activatable labelled button', (tester) async { await tester.pumpWidget( - CupertinoApp( - theme: const CupertinoThemeData(brightness: Brightness.dark), - home: CupertinoPageScaffold( - child: Builder( - builder: (context) => MediaQuery( - data: MediaQuery.of( - context, - ).copyWith(textScaler: const TextScaler.linear(2)), - child: DefinitionGraphView( - graph: linearGraph(), - selectedStage: 'build', - onSelected: picked.add, - ), - ), - ), - ), + _materialHost( + graph: linearGraph(), + selected: 'build', + onSelected: (_) {}, ), ); await _settle(tester); - final inline = _inlineTransform(tester); - final inlineMatrix = Matrix4.copy(inline.value); - await tester.tap(find.byKey(const Key('graph-expand'))); 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( - _inExpanded(find.byType(CupertinoNavigationBarBackButton)), - findsOneWidget, - ); - expect(_inExpanded(find.byKey(const Key('graph-fit'))), findsOneWidget); - expect( - tester.widget(_inExpanded(_node('build'))).selected, + fit.hasAction(SemanticsAction.tap), 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(_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', - ); - } }); } diff --git a/app/test/features/graph/viewport/graph_viewport_controls_test.dart b/app/test/features/graph/viewport/graph_viewport_controls_test.dart index cba0ed0a..7c305052 100644 --- a/app/test/features/graph/viewport/graph_viewport_controls_test.dart +++ b/app/test/features/graph/viewport/graph_viewport_controls_test.dart @@ -7,101 +7,79 @@ import 'package:pipelines_app/ui/adaptive/glass_pill.dart'; import 'graph_viewport_fixtures.dart'; void main() { - testWidgets('Fit and Expand stay labelled, activatable buttons on both hosts', ( + testWidgets('Fit and Expand stay labelled, activatable buttons', ( tester, ) async { - for (final cupertino in [false, true]) { - final host = cupertino ? 'cupertino' : 'material'; - final controller = GraphViewportController(); - addTearDown(controller.dispose); - var expands = 0; - await tester.pumpWidget( - viewportHost( - controller: controller, - child: viewportTargets([]), - cupertino: cupertino, - onExpand: () => expands += 1, - ), - ); - await settleViewport(tester); - final fitted = controller.snapshot; - expect( - find.ancestor( - of: find.byKey(const Key('graph-fit')), - matching: find.byType(GlassPill), - ), - findsOneWidget, - ); + final controller = GraphViewportController(); + addTearDown(controller.dispose); + var expands = 0; + await tester.pumpWidget( + viewportHost( + controller: controller, + child: viewportTargets([]), + onExpand: () => expands += 1, + ), + ); + await settleViewport(tester); + final fitted = controller.snapshot; + expect( + find.ancestor( + of: find.byKey(const Key('graph-fit')), + matching: find.byType(GlassPill), + ), + findsOneWidget, + ); - for (final control in viewportControls().entries) { - final node = tester.getSemantics(find.byKey(control.key)); - final data = node.getSemanticsData(); - expect( - data.label, - control.value, - reason: '$host ${control.key} must have the web name', - ); - 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'); + for (final control in viewportControls().entries) { + final node = tester.getSemantics(find.byKey(control.key)); + final data = node.getSemanticsData(); + expect(data.label, control.value); + expect(data.flagsCollection.isButton, isTrue); + // A labelled button with no action is unusable with a screen reader; + // this is the regression the excluded-button wrapper introduced. + expect(data.hasAction(SemanticsAction.tap), isTrue); } + + // 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', ( - tester, - ) async { - for (final cupertino in [false, true]) { - final controller = GraphViewportController(); - addTearDown(controller.dispose); - await tester.pumpWidget( - viewportHost( - controller: controller, - child: viewportTargets([]), - cupertino: cupertino, - dark: cupertino, - textScale: 2, - viewport: const Size(320, 300), - onExpand: () {}, - ), - ); - await settleViewport(tester); - expect(find.byKey(const Key('graph-fit')), findsOneWidget); - expect(find.byKey(const Key('graph-expand')), findsOneWidget); - expect(tester.takeException(), isNull); + testWidgets('320px at 2x keeps native controls and gestures', (tester) async { + final controller = GraphViewportController(); + addTearDown(controller.dispose); + await tester.pumpWidget( + viewportHost( + controller: controller, + child: viewportTargets([]), + textScale: 2, + viewport: const Size(320, 300), + onExpand: () {}, + ), + ); + 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; - await dragViewport( - tester, - find.byKey(const Key('graph-viewport')), - const Offset(-30, -10), - ); - expect(controller.offset, isNot(before)); - await pinchViewport(tester, const Offset(160, 150), 2); - await tester.pumpAndSettle(); - expect(controller.scale, greaterThan(0.3)); - expect(tester.takeException(), isNull); - } + final before = controller.offset; + await dragViewport( + tester, + find.byKey(const Key('graph-viewport')), + const Offset(-30, -10), + ); + expect(controller.offset, isNot(before)); + await pinchViewport(tester, const Offset(160, 150), 2); + await tester.pumpAndSettle(); + expect(controller.scale, greaterThan(0.3)); + expect(tester.takeException(), isNull); }); } diff --git a/app/test/features/graph/viewport/graph_viewport_fixtures.dart b/app/test/features/graph/viewport/graph_viewport_fixtures.dart index 72b7eb88..f467ffaa 100644 --- a/app/test/features/graph/viewport/graph_viewport_fixtures.dart +++ b/app/test/features/graph/viewport/graph_viewport_fixtures.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -48,7 +47,6 @@ Widget viewportHost({ required GraphViewportController controller, required Widget child, VoidCallback? onExpand, - bool cupertino = false, bool dark = false, double textScale = 1, 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( theme: dark ? ThemeData.dark() : ThemeData.light(), home: Scaffold(body: Center(child: graph)), diff --git a/app/test/features/graph/widgets/definition_graph_view_test.dart b/app/test/features/graph/widgets/definition_graph_view_test.dart index 1051d604..d80fda54 100644 --- a/app/test/features/graph/widgets/definition_graph_view_test.dart +++ b/app/test/features/graph/widgets/definition_graph_view_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -57,21 +56,6 @@ Widget _materialHost( ); } -Widget _cupertinoHost(JsonMap graph, {ValueChanged? 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. Future _settle(WidgetTester tester) async { await tester.pump(); @@ -315,27 +299,4 @@ void main() { expect(find.byType(GraphStageNode), findsNothing); expect(find.byType(InteractiveViewer), findsNothing); }); - - testWidgets('cupertino host composes native buttons and keeps identity', ( - tester, - ) async { - final picked = []; - 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']); - }); } diff --git a/app/test/features/graph/widgets/graph_stage_node_render_test.dart b/app/test/features/graph/widgets/graph_stage_node_render_test.dart index 113a09ae..9135044d 100644 --- a/app/test/features/graph/widgets/graph_stage_node_render_test.dart +++ b/app/test/features/graph/widgets/graph_stage_node_render_test.dart @@ -1,7 +1,6 @@ import 'dart:typed_data'; import 'dart:ui' as ui; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -21,10 +20,6 @@ Widget _material(Widget child) => MaterialApp( 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 /// painted result can be read back as pixels. 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', ( - tester, - ) async { - final key = GlobalKey(); - await tester.pumpWidget( - _framed( - key, - _cupertino, - GraphStageNode(node: _stage, 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 = {}; - 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', + testWidgets('selected state changes the painted surface', (tester) async { + final colors = {}; + for (final selected in [false, true]) { + final key = GlobalKey(); + await tester.pumpWidget( + _framed( + key, + _material, + 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', + ); }); } diff --git a/app/test/features/graph/widgets/graph_stage_node_test.dart b/app/test/features/graph/widgets/graph_stage_node_test.dart index 3d2ade29..34b0e428 100644 --- a/app/test/features/graph/widgets/graph_stage_node_test.dart +++ b/app/test/features/graph/widgets/graph_stage_node_test.dart @@ -1,6 +1,5 @@ import 'dart:ui' show Tristate; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; @@ -17,10 +16,6 @@ Widget _material(Widget child) => MaterialApp( 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 /// scale-2 layout rather than a test-only text property. Widget _scaled(Widget child) => Builder( @@ -65,9 +60,7 @@ void main() { expect(_semantics(tester).label, 'Success'); }); - testWidgets('selected node is announced selected in both native hosts', ( - tester, - ) async { + testWidgets('selected node is announced selected', (tester) async { await tester.pumpWidget( _material( GraphStageNode(node: _stage, selected: true, onSelected: (_) {}), @@ -76,15 +69,6 @@ void main() { expect(find.byType(Card), findsOneWidget); expect(find.byType(InkWell), findsOneWidget); _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 { @@ -96,17 +80,15 @@ void main() { }); testWidgets('keyboard activation selects the node', (tester) async { - for (final wrap in [_material, _cupertino]) { - final picked = []; - await tester.pumpWidget( - wrap(GraphStageNode(node: _stage, onSelected: picked.add)), - ); - await tester.sendKeyEvent(LogicalKeyboardKey.tab); - await tester.pumpAndSettle(); - await tester.sendKeyEvent(LogicalKeyboardKey.enter); - await tester.pumpAndSettle(); - expect(picked, ['build']); - } + final picked = []; + await tester.pumpWidget( + _material(GraphStageNode(node: _stage, onSelected: picked.add)), + ); + await tester.sendKeyEvent(LogicalKeyboardKey.tab); + await tester.pumpAndSettle(); + await tester.sendKeyEvent(LogicalKeyboardKey.enter); + await tester.pumpAndSettle(); + expect(picked, ['build']); }); testWidgets('keyboard selection keeps focus inside the material node', ( @@ -144,46 +126,44 @@ void main() { ) async { const label = 'implementer-with-an-unshortened-stage-label'; const node = GraphNode(key: label, terminal: false, stageIndex: 0); - for (final wrap in [_material, _cupertino]) { - await tester.pumpWidget( - wrap( - _scaled( - SizedBox( - width: 150, - child: GraphStageNode(node: node, onSelected: (_) {}), - ), + await tester.pumpWidget( + _material( + _scaled( + SizedBox( + width: 150, + child: GraphStageNode(node: node, onSelected: (_) {}), ), ), - ); + ), + ); - expect(tester.takeException(), isNull); - final text = tester.widget(_visual(label)); - expect(text.data!.replaceAll('\u200B', ''), label); - expect(text.maxLines, isNull); - expect(text.overflow, isNull); - final paragraph = tester.renderObject(_visual(label)); - expect(paragraph.size.width, lessThanOrEqualTo(150)); - expect( - paragraph.size.height, - greaterThan(50), - reason: 'the 2x label must occupy more than one 2x text line', - ); - // No glyph may paint outside the paragraph: every laid-out line, - // including a hyphen-broken segment, fits the width the control gave it. - final painter = TextPainter( - text: paragraph.text, - textDirection: paragraph.textDirection, - textScaler: paragraph.textScaler, - textAlign: paragraph.textAlign, - )..layout(maxWidth: paragraph.size.width); - expect( - painter.computeLineMetrics().every( - (line) => line.width <= paragraph.size.width + 0.5, - ), - isTrue, - reason: 'an unshortened label must wrap, not paint over the control', - ); - } + expect(tester.takeException(), isNull); + final text = tester.widget(_visual(label)); + expect(text.data!.replaceAll('\u200B', ''), label); + expect(text.maxLines, isNull); + expect(text.overflow, isNull); + final paragraph = tester.renderObject(_visual(label)); + expect(paragraph.size.width, lessThanOrEqualTo(150)); + expect( + paragraph.size.height, + greaterThan(50), + reason: 'the 2x label must occupy more than one 2x text line', + ); + // No glyph may paint outside the paragraph: every laid-out line, + // including a hyphen-broken segment, fits the width the control gave it. + final painter = TextPainter( + text: paragraph.text, + textDirection: paragraph.textDirection, + textScaler: paragraph.textScaler, + textAlign: paragraph.textAlign, + )..layout(maxWidth: paragraph.size.width); + expect( + painter.computeLineMetrics().every( + (line) => line.width <= paragraph.size.width + 0.5, + ), + isTrue, + reason: 'an unshortened label must wrap, not paint over the control', + ); }); 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 { await tester.pumpWidget( - _cupertino( + _material( GraphStageNode( node: _stage, recordedStatus: 'failed', diff --git a/app/test/features/graph/widgets/run_graph_view_test.dart b/app/test/features/graph/widgets/run_graph_view_test.dart index 30a12979..ac47e2af 100644 --- a/app/test/features/graph/widgets/run_graph_view_test.dart +++ b/app/test/features/graph/widgets/run_graph_view_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/semantics.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -113,35 +112,6 @@ Widget _materialHost( ); } -Widget _cupertinoHost( - JsonMap graph, - JsonMap run, { - ValueChanged? 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 _settle(WidgetTester tester) async { await tester.pump(); await tester.pump(); @@ -450,39 +420,4 @@ void main() { _expectNoOverlaps(tester); expect(tester.takeException(), isNull); }); - - testWidgets('dark Cupertino host keeps native nodes and evidence', ( - tester, - ) async { - final picked = []; - 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(_node('plan')).recordedStatus, - 'completed', - ); - expect( - tester.widget(_node('build')).recordedStatus, - 'running', - ); - _expectNoOverlaps(tester); - - await tester.tap(_node('plan')); - await tester.pump(); - expect(picked, ['plan']); - expect(tester.takeException(), isNull); - }); } diff --git a/app/test/features/graph/widgets/stage_definition_view_test.dart b/app/test/features/graph/widgets/stage_definition_view_test.dart index 115d89ed..9c345748 100644 --- a/app/test/features/graph/widgets/stage_definition_view_test.dart +++ b/app/test/features/graph/widgets/stage_definition_view_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.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( graph: _graph(), stageKey: key, @@ -138,26 +130,6 @@ void main() { 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('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', ( tester, ) async { @@ -198,44 +170,6 @@ void main() { 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', ( tester, ) async { @@ -270,7 +204,11 @@ void main() { testWidgets('selectable blocks force the host strut for one line rhythm', ( tester, ) 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 .widgetList(find.byType(SelectableText)) diff --git a/app/test/features/runs/ui/runs_list_widget_test.dart b/app/test/features/runs/ui/runs_list_widget_test.dart index 43a2bcd0..b316d8e6 100644 --- a/app/test/features/runs/ui/runs_list_widget_test.dart +++ b/app/test/features/runs/ui/runs_list_widget_test.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; @@ -45,7 +44,6 @@ void main() { Future mount( WidgetTester tester, { - required bool cupertino, ValueChanged? onSelected, }) async { gateway.reply = { @@ -60,29 +58,24 @@ void main() { builder: (context, _) => RunsList(controller: controller, onSelected: onSelected ?? (_) {}), ); - await tester.pumpWidget( - cupertino - ? CupertinoApp(home: CupertinoPageScaffold(child: list)) - : MaterialApp(home: Scaffold(body: list)), - ); + await tester.pumpWidget(MaterialApp(home: Scaffold(body: list))); } testWidgets( - 'the filter sheet searches and filters runs', + 'filters runs from the filter sheet', (tester) async { num? selectedRun; - await mount( - tester, - cupertino: false, - onSelected: (id) => selectedRun = id, - ); + await mount(tester, onSelected: (id) => selectedRun = id); // The text filter lives in the filter sheet. expect(find.byType(TextField), findsNothing); expect(find.text('Alpha'), findsOneWidget); await tester.tap(find.byKey(const ValueKey('runs.filter'))); await tester.pumpAndSettle(); - await tester.enterText(find.byType(TextField), 'Beta'); + await tester.enterText( + find.byKey(const ValueKey('runs.filter.query')), + 'Beta', + ); await tester.pumpAndSettle(); await tester.tapAt(const Offset(4, 4)); await tester.pumpAndSettle(); @@ -147,9 +140,9 @@ void main() { gateway.gate = Completer(); final loading = controller.load(); await tester.pumpWidget( - CupertinoApp( - home: CupertinoPageScaffold( - child: AnimatedBuilder( + MaterialApp( + home: Scaffold( + body: AnimatedBuilder( animation: controller, builder: (_, child) => RunsList(controller: controller, onSelected: (_) {}), @@ -158,7 +151,7 @@ void main() { ), ); await tester.pump(); - expect(find.byType(CupertinoActivityIndicator), findsOneWidget); + expect(find.byType(CircularProgressIndicator), findsOneWidget); gateway.gate!.complete(); await loading; await tester.pumpAndSettle(); @@ -173,49 +166,45 @@ void main() { expect(find.textContaining('offline'), findsNothing); expect(tester.takeException(), isNull); }, - variant: TargetPlatformVariant.only(TargetPlatform.iOS), + variant: TargetPlatformVariant.only(TargetPlatform.android), ); - for (final cupertino in [false, true]) { - testWidgets('the attention bell is one of the actions ' - '(${cupertino ? 'Cupertino' : 'Material'})', (tester) async { - await mount(tester, cupertino: cupertino); - await tester.pumpAndSettle(); - final bell = find.byType(NeedsYouRunsHeading); - expect(bell, findsOneWidget); - // Not in a row of its own: it shares the actions' line, before filter. - final filter = find.byKey(const ValueKey('runs.filter')); - expect( - (tester.getCenter(bell).dy - tester.getCenter(filter).dy).abs(), - lessThan(2), - ); - expect(tester.getCenter(bell).dx, lessThan(tester.getCenter(filter).dx)); - expect( - find.descendant(of: find.byType(RunsFilters), matching: bell), - findsNothing, - ); - expect(tester.takeException(), isNull); - }); - } + testWidgets('the attention bell is one of the actions', (tester) async { + await mount(tester); + await tester.pumpAndSettle(); + final bell = find.byType(NeedsYouRunsHeading); + expect(bell, findsOneWidget); + // Not in a row of its own: it shares the actions' line, before filter. + final filter = find.byKey(const ValueKey('runs.filter')); + expect( + (tester.getCenter(bell).dy - tester.getCenter(filter).dy).abs(), + lessThan(2), + ); + expect(tester.getCenter(bell).dx, lessThan(tester.getCenter(filter).dx)); + expect( + find.descendant(of: find.byType(RunsFilters), matching: bell), + findsNothing, + ); + expect(tester.takeException(), isNull); + }); - for (final cupertino in [false, true]) { - testWidgets('rows lead with the status glyph, not a status word ' - '(${cupertino ? 'Cupertino' : 'Material'})', (tester) async { - await mount(tester, cupertino: cupertino); - await tester.pumpAndSettle(); - final icons = tester - .widgetList(find.byType(RunStatusIcon)) - .map((icon) => (icon.state, icon.label)) - .toList(); - expect( - icons, - unorderedEquals([('running', 'running'), ('failed', 'failed')]), - ); - expect(find.text('failed'), findsNothing); - expect( - tester.getCenter(find.byType(RunStatusIcon).first).dx, - lessThan(tester.getTopLeft(find.text('Alpha')).dx), - ); - }); - } + testWidgets('rows lead with the status glyph, not a status word', ( + tester, + ) async { + await mount(tester); + await tester.pumpAndSettle(); + final icons = tester + .widgetList(find.byType(RunStatusIcon)) + .map((icon) => (icon.state, icon.label)) + .toList(); + expect( + icons, + unorderedEquals([('running', 'running'), ('failed', 'failed')]), + ); + expect(find.text('failed'), findsNothing); + expect( + tester.getCenter(find.byType(RunStatusIcon).first).dx, + lessThan(tester.getTopLeft(find.text('Alpha')).dx), + ); + }); } diff --git a/app/test/features/settings/saved_server_sign_in_test.dart b/app/test/features/settings/saved_server_sign_in_test.dart index f6fbb283..fee7c3e3 100644 --- a/app/test/features/settings/saved_server_sign_in_test.dart +++ b/app/test/features/settings/saved_server_sign_in_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/servers/machine_access.dart'; @@ -64,96 +63,90 @@ Future addServer( } void main() { - for (final cupertino in [false, true]) { - testWidgets('a new machine asks for its own password ($cupertino)', ( - tester, - ) async { - final connections = ServerConnections( - store: MemoryServerCatalogStore( - catalog: ServerCatalog( - servers: [ - SavedServer.validated( - id: 'mac', - name: 'Mac', - endpoints: ['ws://10.0.0.75:8083/connect'], - ), - ], - selectedId: 'mac', - ), + testWidgets('a new machine asks for its own password', (tester) async { + final connections = ServerConnections( + store: MemoryServerCatalogStore( + catalog: ServerCatalog( + servers: [ + SavedServer.validated( + id: 'mac', + name: 'Mac', + endpoints: ['ws://10.0.0.75:8083/connect'], + ), + ], + selectedId: 'mac', ), - onSelected: (_) async {}, - ); - addTearDown(connections.dispose); - await connections.load(); - final auth = FakeAuthenticator() - ..verdicts['mac'] = const MachineAccessResult(MachineAccess.connected); - connections.authenticator = auth; - final body = SingleChildScrollView( - child: SavedServersSection(connections: connections), - ); - await tester.pumpWidget( - cupertino - ? CupertinoApp( - home: CupertinoPageScaffold(child: SafeArea(child: body)), - ) - : MaterialApp(home: Scaffold(body: body)), - ); - expect(find.text('Connected'), findsOneWidget); - // The new machine is unknown to the authenticator until saved; a - // password verdict arrives for whatever id the editor assigned. - auth.verdicts.addAll({ - for (final id in ['pending']) id: const MachineAccessResult( - MachineAccess.needsPassword, - ), - }); - await tester.tap(find.text('Add server')); - await tester.pumpAndSettle(); - await tester.enterText(find.byKey(const Key('server-profile-name')), 'tank'); - await tester.enterText( - find.byKey(const Key('server-profile-addresses')), - 'ws://10.0.0.100:8082/connect', - ); - // Whatever id the editor chose, that machine wants a password. - connections.addListener(() { - for (final server in connections.catalog.servers) { - auth.verdicts.putIfAbsent( - server.id, - () => const MachineAccessResult(MachineAccess.needsPassword), - ); - auth.passwords.putIfAbsent(server.id, () => 'tank-secret'); - } - }); - await revealSave(tester); - await tester.tap(find.text('Save server')); - await tester.pumpAndSettle(); - final tank = connections.catalog.servers.firstWhere((s) => s.name == 'tank'); - expect(auth.probes, [tank.id]); - // Saved, and the editor now asks this machine's password; the first - // machine's sign-in is not reused. - expect(find.byKey(const Key('server-profile-password')), findsOneWidget); - expect(find.textContaining('asks for its own password'), findsOneWidget); - await tester.enterText( - find.byKey(const Key('server-profile-password')), - 'wrong', - ); - await tester.tap(find.byKey(const Key('server-profile-sign-in'))); - await tester.pumpAndSettle(); - expect(find.text('Wrong password.'), findsOneWidget); - expect(find.byKey(const Key('server-profile-password')), findsOneWidget); - await tester.enterText( - find.byKey(const Key('server-profile-password')), - 'tank-secret', - ); - await tester.tap(find.byKey(const Key('server-profile-sign-in'))); - await tester.pumpAndSettle(); - expect(auth.signIns, [(tank.id, 'wrong'), (tank.id, 'tank-secret')]); - // Back on the list: both machines connected, each on its own sign-in. - expect(find.byKey(const Key('server-profile-password')), findsNothing); - expect(find.text('Connected'), findsNWidgets(2)); - expect(find.text('Address: ws://10.0.0.100:8082/connect'), findsOneWidget); - expect(connections.catalog.active?.id, 'mac'); + ), + onSelected: (_) async {}, + ); + addTearDown(connections.dispose); + await connections.load(); + final auth = FakeAuthenticator() + ..verdicts['mac'] = const MachineAccessResult(MachineAccess.connected); + connections.authenticator = auth; + final body = SingleChildScrollView( + child: SavedServersSection(connections: connections), + ); + await tester.pumpWidget(MaterialApp(home: Scaffold(body: body))); + expect(find.text('Connected'), findsOneWidget); + // The new machine is unknown to the authenticator until saved; a + // password verdict arrives for whatever id the editor assigned. + auth.verdicts.addAll({ + for (final id in ['pending']) + id: const MachineAccessResult(MachineAccess.needsPassword), }); - } + await tester.tap(find.text('Add server')); + await tester.pumpAndSettle(); + await tester.enterText( + find.byKey(const Key('server-profile-name')), + 'tank', + ); + await tester.enterText( + find.byKey(const Key('server-profile-addresses')), + 'ws://10.0.0.100:8082/connect', + ); + // Whatever id the editor chose, that machine wants a password. + connections.addListener(() { + for (final server in connections.catalog.servers) { + auth.verdicts.putIfAbsent( + server.id, + () => const MachineAccessResult(MachineAccess.needsPassword), + ); + auth.passwords.putIfAbsent(server.id, () => 'tank-secret'); + } + }); + await revealSave(tester); + await tester.tap(find.text('Save server')); + await tester.pumpAndSettle(); + final tank = connections.catalog.servers.firstWhere( + (s) => s.name == 'tank', + ); + expect(auth.probes, [tank.id]); + // Saved, and the editor now asks this machine's password; the first + // machine's sign-in is not reused. + expect(find.byKey(const Key('server-profile-password')), findsOneWidget); + expect(find.textContaining('asks for its own password'), findsOneWidget); + await tester.enterText( + find.byKey(const Key('server-profile-password')), + 'wrong', + ); + await tester.tap(find.byKey(const Key('server-profile-sign-in'))); + await tester.pumpAndSettle(); + expect(find.text('Wrong password.'), findsOneWidget); + expect(find.byKey(const Key('server-profile-password')), findsOneWidget); + await tester.enterText( + find.byKey(const Key('server-profile-password')), + 'tank-secret', + ); + await tester.tap(find.byKey(const Key('server-profile-sign-in'))); + await tester.pumpAndSettle(); + expect(auth.signIns, [(tank.id, 'wrong'), (tank.id, 'tank-secret')]); + // Back on the list: both machines connected, each on its own sign-in. + expect(find.byKey(const Key('server-profile-password')), findsNothing); + expect(find.text('Connected'), findsNWidgets(2)); + expect(find.text('Address: ws://10.0.0.100:8082/connect'), findsOneWidget); + expect(connections.catalog.active?.id, 'mac'); + }); testWidgets('an unreachable machine stays saved with the reason shown', ( tester, @@ -172,7 +165,8 @@ void main() { server.id, () => const MachineAccessResult( MachineAccess.unreachable, - detail: 'The HTTPS certificate of 100.85.25.33:8443 does not ' + detail: + 'The HTTPS certificate of 100.85.25.33:8443 does not ' 'cover an IP address.', ), ); @@ -198,7 +192,10 @@ void main() { await tester.tap(find.byKey(const Key('server-sign-in-later'))); await tester.pumpAndSettle(); expect(connections.catalog.servers.single.name, 'Mac by IP'); - expect(find.textContaining('Unreachable: The HTTPS certificate'), findsOneWidget); + expect( + find.textContaining('Unreachable: The HTTPS certificate'), + findsOneWidget, + ); }); testWidgets('a saved machine that wants a password offers Sign in', ( @@ -218,7 +215,9 @@ void main() { addTearDown(connections.dispose); await connections.load(); final auth = FakeAuthenticator() - ..verdicts['tank'] = const MachineAccessResult(MachineAccess.needsPassword) + ..verdicts['tank'] = const MachineAccessResult( + MachineAccess.needsPassword, + ) ..passwords['tank'] = 'tank-secret'; connections.authenticator = auth; await tester.pumpWidget( @@ -231,7 +230,10 @@ void main() { await tester.pumpAndSettle(); await tester.tap(find.text('Sign in to tank')); await tester.pumpAndSettle(); - await tester.enterText(find.byKey(const Key('machine-password')), 'tank-secret'); + await tester.enterText( + find.byKey(const Key('machine-password')), + 'tank-secret', + ); await tester.tap(find.byKey(const Key('machine-sign-in'))); await tester.pumpAndSettle(); expect(auth.signIns, [('tank', 'tank-secret')]); @@ -248,7 +250,9 @@ void main() { endpoints: ['ws://10.0.0.75:8083/connect'], ); final auth = FakeAuthenticator() - ..verdicts['mac'] = const MachineAccessResult(MachineAccess.needsPassword); + ..verdicts['mac'] = const MachineAccessResult( + MachineAccess.needsPassword, + ); SavedServer? saved; await tester.pumpWidget( MaterialApp( @@ -269,7 +273,10 @@ void main() { ); await tester.tap(find.text('Edit')); await tester.pumpAndSettle(); - await tester.enterText(find.byKey(const Key('server-profile-name')), 'Studio'); + await tester.enterText( + find.byKey(const Key('server-profile-name')), + 'Studio', + ); await revealSave(tester); await tester.tap(find.text('Save server')); await tester.pumpAndSettle(); diff --git a/app/test/features/settings/storage/storage_screen_test.dart b/app/test/features/settings/storage/storage_screen_test.dart index 4eb577fc..7360a324 100644 --- a/app/test/features/settings/storage/storage_screen_test.dart +++ b/app/test/features/settings/storage/storage_screen_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/settings/storage/storage_screen.dart'; @@ -7,8 +6,7 @@ import '../../../../tool/storage_probe_fixture.dart'; Future _mount( WidgetTester tester, - StorageProbeGateway gateway, - bool cupertino, { + StorageProbeGateway gateway, { double width = 900, double scale = 1, }) async { @@ -20,11 +18,7 @@ Future _mount( data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)), child: child!, ); - await tester.pumpWidget( - cupertino - ? CupertinoApp(builder: builder, home: screen) - : MaterialApp(builder: builder, home: screen), - ); + await tester.pumpWidget(MaterialApp(builder: builder, home: screen)); await tester.pumpAndSettle(); } @@ -43,83 +37,72 @@ Finder _field(String label) => find.descendant( matching: find.byType(EditableText), ); void main() { - for (final cupertino in [false, true]) { - final style = cupertino ? 'Cupertino' : 'Material'; - testWidgets( - '$style usage and partial measurement remain honest at 2x narrow', - (tester) async { - final gateway = StorageProbeGateway(); - await _mount(tester, gateway, cupertino, width: 560, scale: 2); - expect(find.text('At least 15.0 GiB used'), findsOneWidget); - expect( - find.text('Measurement is incomplete. See details below.'), - findsOneWidget, - ); - expect(find.text('Database'), findsOneWidget); - expect(find.textContaining('6 November 2026'), findsOneWidget); - expect(find.text('Worktrees'), findsOneWidget); - await _tap(tester, 'Preview cleanup'); - expect(find.text('Cleanup preview'), findsOneWidget); - expect( - find.text('Protected · worktree active-item · 4.00 GiB'), - findsOneWidget, - ); - expect(tester.takeException(), isNull); - }, + testWidgets('usage and partial measurement remain honest at 2x narrow', ( + tester, + ) async { + final gateway = StorageProbeGateway(); + await _mount(tester, gateway, width: 560, scale: 2); + expect(find.text('At least 15.0 GiB used'), findsOneWidget); + expect( + find.text('Measurement is incomplete. See details below.'), + findsOneWidget, ); - testWidgets( - '$style cleanup cancellation does not mutate and confirmation uses token', - (tester) async { - final gateway = StorageProbeGateway(); - await _mount(tester, gateway, cupertino); - await _tap(tester, 'Preview cleanup'); - await _tap(tester, 'Apply cleanup'); - expect(find.text('Apply cleanup?'), findsOneWidget); - await _tap(tester, 'Cancel'); - expect( - gateway.calls.where((call) => call.type == 'apply_storage_cleanup'), - isEmpty, - ); - await _tap(tester, 'Apply cleanup'); - await _tap(tester, 'Remove items'); - expect( - gateway.calls - .singleWhere((call) => call.type == 'apply_storage_cleanup') - .fields['storage_cleanup_token'], - 'fixture-preview-token', - ); - expect(find.text('Cleanup result'), findsOneWidget); - expect( - find.text('Worktree became active and was kept.'), - findsOneWidget, - ); - expect(tester.takeException(), isNull); - }, + expect(find.text('Database'), findsOneWidget); + expect(find.textContaining('6 November 2026'), findsOneWidget); + expect(find.text('Worktrees'), findsOneWidget); + await _tap(tester, 'Preview cleanup'); + expect(find.text('Cleanup preview'), findsOneWidget); + expect( + find.text('Protected · worktree active-item · 4.00 GiB'), + findsOneWidget, ); - testWidgets('$style invalid limits do not send a policy', (tester) async { + expect(tester.takeException(), isNull); + }); + testWidgets( + 'cleanup cancellation does not mutate and confirmation uses token', + (tester) async { final gateway = StorageProbeGateway(); - await _mount(tester, gateway, cupertino); - await tester.ensureVisible(_field('Retain data for days')); - await tester.enterText(_field('Retain data for days'), '-1'); - await _tap(tester, 'Save policy'); + await _mount(tester, gateway); + await _tap(tester, 'Preview cleanup'); + await _tap(tester, 'Apply cleanup'); + expect(find.text('Apply cleanup?'), findsOneWidget); + await _tap(tester, 'Cancel'); expect( - find.textContaining('Enter a whole number of days'), - findsOneWidget, - ); - expect( - gateway.calls.where((call) => call.type == 'set_storage_policy'), + gateway.calls.where((call) => call.type == 'apply_storage_cleanup'), isEmpty, ); - }); - testWidgets( - '$style unsupported server has an actionable error and no fake usage', - (tester) async { - final gateway = StorageProbeGateway()..unsupported = true; - await _mount(tester, gateway, cupertino); - expect(find.text('Unknown command: get_storage'), findsOneWidget); - expect(find.text('Server storage'), findsNothing); - expect(find.text('Refresh storage'), findsOneWidget); - }, + await _tap(tester, 'Apply cleanup'); + await _tap(tester, 'Remove items'); + expect( + gateway.calls + .singleWhere((call) => call.type == 'apply_storage_cleanup') + .fields['storage_cleanup_token'], + 'fixture-preview-token', + ); + expect(find.text('Cleanup result'), findsOneWidget); + expect(find.text('Worktree became active and was kept.'), findsOneWidget); + expect(tester.takeException(), isNull); + }, + ); + testWidgets('invalid limits do not send a policy', (tester) async { + final gateway = StorageProbeGateway(); + await _mount(tester, gateway); + await tester.ensureVisible(_field('Retain data for days')); + await tester.enterText(_field('Retain data for days'), '-1'); + await _tap(tester, 'Save policy'); + expect(find.textContaining('Enter a whole number of days'), findsOneWidget); + expect( + gateway.calls.where((call) => call.type == 'set_storage_policy'), + isEmpty, ); - } + }); + testWidgets('unsupported server has an actionable error and no fake usage', ( + tester, + ) async { + final gateway = StorageProbeGateway()..unsupported = true; + await _mount(tester, gateway); + expect(find.text('Unknown command: get_storage'), findsOneWidget); + expect(find.text('Server storage'), findsNothing); + expect(find.text('Refresh storage'), findsOneWidget); + }); } diff --git a/app/test/shell/windows/window_rebuild_test.dart b/app/test/shell/windows/window_rebuild_test.dart new file mode 100644 index 00000000..dcbf9252 --- /dev/null +++ b/app/test/shell/windows/window_rebuild_test.dart @@ -0,0 +1,130 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/shell/windows/window_entry.dart'; +import 'package:pipelines_app/shell/windows/window_kind.dart'; +import 'package:pipelines_app/shell/windows/window_layer.dart'; +import 'package:pipelines_app/shell/windows/window_manager.dart'; + +import 'window_test_harness.dart'; + +/// A probe kind whose content keeps its element when the window is retargeted, +/// so a rebuild is visible in the same state's counter. +class _StableProbeKind extends WindowKind { + @override + String get key => 'stable'; + @override + bool get serverScoped => false; + @override + IconData get icon => Icons.science_outlined; + @override + String title(BuildContext context, WindowEntry entry) => + 'Probe ${entry.contentId}'; + @override + Widget build(BuildContext context, WindowEntry entry) => + ProbeContent(key: const ValueKey('stable-content'), id: entry.contentId); +} + +void main() { + late WindowManager manager; + setUp(() => manager = probeManager()); + + Finder window(String title) => find.byWidgetPredicate( + (w) => w is WindowLayer && 'Probe ${w.entry.contentId}' == title, + ); + Finder inWindow(String title, Finder what) => + find.descendant(of: window(title), matching: what); + ProbeContentState content(WidgetTester tester, String id) => + tester.state(find.byKey(ValueKey('content-$id'))); + + Future openTwo(WidgetTester tester) async { + manager.open('probe', 'a', frame: const Rect.fromLTWH(100, 80, 360, 420)); + manager.open('probe', 'b', frame: const Rect.fromLTWH(600, 200, 360, 420)); + await pumpProbe(tester, manager); + } + + testWidgets('dragging a window moves it without rebuilding any content', ( + tester, + ) async { + await openTwo(tester); + final a = content(tester, 'a'); + final b = content(tester, 'b'); + final beforeA = a.builds; + final beforeB = b.builds; + final start = windowRect(tester, 'Probe a').topLeft; + final fieldStart = tester + .getRect(find.byKey(const ValueKey('a-field'))) + .topLeft; + final gesture = await tester.startGesture( + tester.getCenter( + inWindow('Probe a', find.byKey(const ValueKey('window-title'))), + ), + ); + for (var i = 0; i < 8; i++) { + await gesture.moveBy(const Offset(12, 6)); + await tester.pump(); + expect(a.builds, beforeA, reason: 'dragged window rebuilt at move $i'); + expect(b.builds, beforeB, reason: 'other window rebuilt at move $i'); + } + await gesture.up(); + await tester.pumpAndSettle(); + // It really moved, and its content followed it. + expect(windowRect(tester, 'Probe a').topLeft, start + const Offset(96, 48)); + expect( + tester.getRect(find.byKey(const ValueKey('a-field'))).topLeft, + fieldStart + const Offset(96, 48), + ); + expect(content(tester, 'a').builds, beforeA); + expect(content(tester, 'b').builds, beforeB); + }); + + testWidgets('resizing a window keeps another window and sees the new size', ( + tester, + ) async { + await openTwo(tester); + final a = content(tester, 'a'); + final b = content(tester, 'b'); + final beforeA = a.builds; + final beforeB = b.builds; + final beforeSize = b.lastSize!; + final gesture = await tester.startGesture( + tester.getCenter( + inWindow('Probe b', find.byKey(const ValueKey('window-resize'))), + ), + ); + for (var i = 0; i < 5; i++) { + await gesture.moveBy(const Offset(-16, -10)); + await tester.pump(); + expect(a.builds, beforeA, reason: 'other window rebuilt at move $i'); + } + await gesture.up(); + await tester.pumpAndSettle(); + expect(content(tester, 'a').builds, beforeA); + final state = content(tester, 'b'); + expect(state.builds, greaterThan(beforeB)); + expect(state.lastSize!.width, beforeSize.width - 80); + expect(state.lastSize!.height, beforeSize.height - 50); + }); + + testWidgets('content still rebuilds when its window is retargeted', ( + tester, + ) async { + manager = WindowManager( + kinds: WindowKinds()..register(_StableProbeKind()), + ); + final entry = manager.open('stable', 'a'); + await pumpProbe(tester, manager); + final state = tester.state( + find.byKey(const ValueKey('stable-content')), + ); + final before = state.builds; + manager.setContent(entry.id, 'c'); + await tester.pumpAndSettle(); + final after = tester.state( + find.byKey(const ValueKey('stable-content')), + ); + expect(after, same(state)); + expect(after.builds, greaterThan(before)); + expect(after.widget.id, 'c'); + expect(find.text('Probe c'), findsOneWidget); + }); +} diff --git a/app/tool/capture/browser.mjs b/app/tool/capture/browser.mjs index 3a5531ee..c6f973ae 100644 --- a/app/tool/capture/browser.mjs +++ b/app/tool/capture/browser.mjs @@ -11,11 +11,14 @@ import { setTimeout as delay } from 'node:timers/promises'; const CALL_TIMEOUT_MS = 30000; const DEFAULT_CHROME ='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; -async function launch(chromePath) { +async function launch(chromePath, gpu) { const profile = await mkdtemp(join(tmpdir(), 'pipelines-capture-chrome-')); const chrome = spawn(chromePath, [ '--headless=new', '--no-first-run', '--no-default-browser-check', - '--disable-gpu', '--hide-scrollbars', '--mute-audio', + // Without a GPU CanvasKit rasterises on the CPU; `gpu` keeps WebGL (Metal + // through ANGLE on a Mac) for benches that measure raster time. + ...(gpu ? ['--use-angle=metal', '--enable-gpu-rasterization', '--ignore-gpu-blocklist'] : ['--disable-gpu']), + '--hide-scrollbars', '--mute-audio', '--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank', ], { stdio: ['ignore', 'ignore', 'pipe'] }); let stderr = ''; @@ -49,8 +52,8 @@ async function attach(cdp) { * talks to the page session; `on(method, fn)` subscribes to its events and * returns the unsubscribe function; `newPage()` opens a scratch page. */ -export async function openBrowser({ cdp, chromePath = process.env.CHROME_PATH ?? DEFAULT_CHROME } = {}) { - const { ws: endpoint, cleanup } = cdp ? await attach(cdp) : await launch(chromePath); +export async function openBrowser({ cdp, gpu = false, chromePath = process.env.CHROME_PATH ?? DEFAULT_CHROME } = {}) { + const { ws: endpoint, cleanup } = cdp ? await attach(cdp) : await launch(chromePath, gpu); const ws = new WebSocket(endpoint); try { await new Promise((ok, fail) => { ws.onopen = ok; ws.onerror = () => fail(new Error(`Cannot open ${endpoint}`)); }); diff --git a/app/tool/capture/window_probe.dart b/app/tool/capture/window_probe.dart index ec2c7f34..8a8e3de7 100644 --- a/app/tool/capture/window_probe.dart +++ b/app/tool/capture/window_probe.dart @@ -52,6 +52,10 @@ class ProbeContentState extends State { int builds = 0; String? picked; + /// The size the content was last laid out at (the window's content area), + /// so tests can see a resize reach it. + Size? lastSize; + @override void dispose() { text.dispose(); @@ -67,6 +71,7 @@ class ProbeContentState extends State { @override Widget build(BuildContext context) { builds++; + lastSize = MediaQuery.sizeOf(context); final id = widget.id; return ListView( children: [ diff --git a/app/tool/perf/interaction_bench.mjs b/app/tool/perf/interaction_bench.mjs index 70571bba..64eb5ddf 100644 --- a/app/tool/perf/interaction_bench.mjs +++ b/app/tool/perf/interaction_bench.mjs @@ -15,12 +15,13 @@ // build and raster time; --shots writes a screenshot after each scenario. // // node tool/perf/interaction_bench.mjs --build build/probe-app --out /tmp/bench \ -// [--repeat 5] [--only name,name] [--size 560x900] [--shots] [--cpuprofile] [--frames] +// [--repeat 5] [--only name,name] [--size 560x900] [--shots] [--cpuprofile] [--frames] [--gpu] // // Clicks are points (CSS px at 560x900, Material, light), so Flutter's // semantics tree stays off as for most users. Headless Chrome without a GPU: // CanvasKit rasterises on the CPU, so compare builds with each other rather -// than predicting a device. +// than predicting a device. --gpu keeps the GPU (WebGL), which is what a +// desktop user has: use it to judge raster time. import { mkdir, writeFile } from 'node:fs/promises'; import { join } from 'node:path'; import { parseArgs } from 'node:util'; @@ -32,19 +33,26 @@ import { attribute, loadSourceMap } from './cpu_attribution.mjs'; const { values: opts } = parseArgs({ options: { build: { type: 'string' }, out: { type: 'string' }, repeat: { type: 'string', default: '5' }, - only: { type: 'string' }, cpuprofile: { type: 'boolean' }, frames: { type: 'boolean' }, shots: { type: 'boolean' }, size: { type: 'string', default: '560x900' }, + only: { type: 'string' }, cpuprofile: { type: 'boolean' }, frames: { type: 'boolean' }, shots: { type: 'boolean' }, gpu: { type: 'boolean' }, size: { type: 'string', default: '560x900' }, }, }); if (!opts.build || !opts.out) throw new Error('usage: --build --out '); -const [width, height] = opts.size.split('x').map(Number); // Bottom tab bar and top-bar points at 560x900 (Material). const TAB = { first: [337, 854], second: [396, 854], third: [455, 854], fourth: [514, 854] }; const TOP_RIGHT = [524, 32]; const FIRST_ROW = [280, 138]; +// A rich two-chat fixture at 1280x800, and the steps that put the second +// chat in a floating window (More actions, Add chat pane, the chat, Alt+Y). +const DESKTOP_CHAT = { size: '1280x800', route: '/chat/perf-chat-0', q: { chats: '2', header: '1', rich: '1' } }; +const FLOAT_CHAT = [{ click: [1240, 40] }, { click: [1198, 96] }, { click: [650, 245] }, { key: 'Alt+y' }, { wait: 800 }]; + // `setup` runs unrecorded after load; `act` is recorded. A step is -// `{ click: [x, y] }`, `{ type: 'text' }` (one character per 120 ms), `{ wait }`. +// `{ click: [x, y] }`, `{ type: 'text' }` (one character per 120 ms), `{ wait }`, +// `{ key: 'Alt+y' }`, `{ drag: [x, y, dx, dy] }` (40 moves, 16 ms apart) or +// `{ wheel: [x, y, deltaY, count] }` (one notch per 16 ms). A scenario's `size` +// overrides --size. const SCENARIOS = [ { name: 'startup', route: '/runs', act: [] }, { name: 'tab:runs->pipelines', route: '/runs', act: [{ click: TAB.first }] }, @@ -71,6 +79,24 @@ const SCENARIOS = [ { name: 'pipeline tab:->source', route: '/pipelines/24', act: [{ click: TAB.fourth }] }, { name: 'chat list->open chat', route: '/chat', q: { chats: '30' }, act: [{ click: FIRST_ROW }] }, { name: 'pipelines->settings', route: '/pipelines', act: [{ click: TOP_RIGHT }] }, + // Desktop (1280x800): floating windows and the chat beside its list. + { name: 'desktop: drag a chat window', ...DESKTOP_CHAT, setup: FLOAT_CHAT, + act: [{ drag: [300, 116, 500, 120] }] }, + { name: 'desktop: resize a chat window', ...DESKTOP_CHAT, setup: FLOAT_CHAT, + act: [{ drag: [591, 647, 300, 80] }] }, + { name: 'desktop: hide and show chat windows', ...DESKTOP_CHAT, setup: FLOAT_CHAT, + act: [{ key: 'Alt+y' }, { wait: 600 }, { key: 'Alt+y' }] }, + { name: 'desktop: float a chat', ...DESKTOP_CHAT, setup: FLOAT_CHAT.slice(0, 3), + act: [{ key: 'Alt+y' }] }, + { name: 'desktop: drag a probe window', size: '1280x800', route: '/runs', q: { windows: '3' }, + act: [{ drag: [250, 164, 500, 120] }] }, + { name: 'desktop: scroll a rich chat', ...DESKTOP_CHAT, + act: [{ wheel: [860, 400, -240, 30] }] }, + { name: 'desktop: type in the composer', ...DESKTOP_CHAT, setup: [{ click: [860, 748] }], + act: [{ type: 'hello world, typing' }] }, + { name: 'desktop: switch chat', ...DESKTOP_CHAT, act: [{ click: [220, 260] }] }, + { name: 'desktop: open the terminal panel', ...DESKTOP_CHAT, q: { chats: '2', header: '1', terminals: '1' }, + act: [{ key: 'Alt+t' }] }, ]; const median = (xs) => { const s = [...xs].sort((a, b) => a - b); return s[Math.floor(s.length / 2)]; }; @@ -78,7 +104,7 @@ const r1 = (x) => Math.round(x * 10) / 10; const lookup = opts.cpuprofile ? await loadSourceMap(opts.build) : null; const server = await serveBuild(opts.build); -const browser = await openBrowser(); +const browser = await openBrowser({ gpu: Boolean(opts.gpu) }); const { send, on } = browser; const evaluate = async (expression) => (await send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true })).result?.value; let frames = []; @@ -102,8 +128,40 @@ async function run(steps) { if (step.click) { await tap(step.click); await delay(1200); } if (step.type) for (const ch of step.type) { await send('Input.insertText', { text: ch }); await delay(120); } if (step.wait) await delay(step.wait); + if (step.key) { await key(step.key); await delay(800); } + if (step.drag) { await drag(step.drag); await delay(400); } + if (step.wheel) { + const [x, y, deltaY, count] = step.wheel; + for (let i = 0; i < count; i++) { + await send('Input.dispatchMouseEvent', { type: 'mouseWheel', x, y, deltaX: 0, deltaY }); + await delay(16); + } + await delay(400); + } } } +const MODIFIERS = { Alt: 1, Control: 2, Meta: 4, Shift: 8 }; +async function key(chord) { + const parts = chord.split('+'); + const name = parts.pop(); + const modifiers = parts.reduce((bits, part) => bits | MODIFIERS[part], 0); + const code = /^[a-z]$/i.test(name) ? `Key${name.toUpperCase()}` : name; + const base = { modifiers, key: name, code, windowsVirtualKeyCode: name.toUpperCase().charCodeAt(0) }; + for (const part of parts) await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: part, code: `${part}Left`, modifiers }); + await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', ...base }); + await send('Input.dispatchKeyEvent', { type: 'keyUp', ...base }); + for (const part of parts) await send('Input.dispatchKeyEvent', { type: 'keyUp', key: part, code: `${part}Left`, modifiers: 0 }); +} +async function drag([x, y, dx, dy]) { + const steps = 40; + await send('Input.dispatchMouseEvent', { type: 'mouseMoved', x, y, button: 'none' }); + await send('Input.dispatchMouseEvent', { type: 'mousePressed', x, y, button: 'left', clickCount: 1 }); + for (let i = 1; i <= steps; i++) { + await send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: x + (dx * i) / steps, y: y + (dy * i) / steps, button: 'left', buttons: 1 }); + await delay(16); + } + await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: x + dx, y: y + dy, button: 'left', clickCount: 1 }); +} // The engine hands timings over in batches; two late frames flush them. async function settle() { await delay(1500); @@ -115,10 +173,11 @@ const results = {}; try { await send('Page.enable'); await send('Runtime.enable'); - await send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false }); await send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: 'light' }] }); const only = opts.only?.split(','); for (const s of SCENARIOS.filter((s) => !only || only.includes(s.name))) { + const [w, h] = (s.size ?? opts.size).split('x').map(Number); + await send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: false }); const reps = []; for (let rep = 0; rep < Number(opts.repeat); rep++) { const url = new URL('/', server.origin); @@ -167,7 +226,7 @@ try { console.log(s.name.padEnd(36), JSON.stringify(results[s.name])); } if (errors.length) console.log('page errors (first 5):', [...new Set(errors)].slice(0, 5)); - await writeFile(join(opts.out, 'interaction-bench.json'), JSON.stringify({ build: opts.build, size: opts.size, results }, null, 2)); + await writeFile(join(opts.out, 'interaction-bench.json'), JSON.stringify({ build: opts.build, size: opts.size, gpu: Boolean(opts.gpu), results }, null, 2)); } finally { await browser.close().catch(() => {}); await server.close();