Merge commit 'b29bd5830cba1485f365cd6f06a29d0e0f0468b4' into pipelines/run-20261111-0115-cupertino-out-servers-and-settings-secur-c6ad

This commit is contained in:
2026-11-11 01:40:09 +00:00
24 changed files with 920 additions and 1406 deletions
@@ -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<AttentionEntry> onDismiss;
final ValueChanged<List<AttentionEntry>> 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<NeedsYouBell> {
@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<NeedsYouBell> {
);
}
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);
}
@@ -6,13 +6,13 @@ const attentionBellKey = ValueKey<String>('attention-bell');
/// The visible count badge. Absent when nothing needs the operator.
const attentionBadgeKey = ValueKey<String>('attention-badge');
/// The open sheet itself, whichever native host draws it.
/// The open sheet itself.
const attentionSheetKey = ValueKey<String>('attention-sheet');
/// The honest empty line shown when the open snapshot has no entries.
const attentionEmptyKey = ValueKey<String>('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<String>('attention-done');
/// The bulk dismissal action, present only while the snapshot has entries.
@@ -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
@@ -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<void> showNeedsYouSheet({
required BuildContext context,
required ValueListenable<List<AttentionEntry>> entries,
@@ -28,19 +25,6 @@ Future<void> showNeedsYouSheet({
bool? cupertino,
}) {
final snapshot = attentionDismissalSnapshot(entries.value);
final native = cupertino ?? usesCupertinoHost(context);
if (native) {
return showCupertinoModalPopup<void>(
context: context,
builder: (_) => CupertinoNeedsYouSheet(
entries: entries,
snapshot: snapshot,
onOpen: onOpen,
onDismiss: onDismiss,
onClearAll: onClearAll,
),
);
}
return showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
@@ -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<List<AttentionEntry>> entries;
/// The identities captured when the sheet opened, all Clear all may remove.
final List<AttentionEntry> snapshot;
final ValueChanged<AttentionEntry> onOpen;
final ValueChanged<AttentionEntry> onDismiss;
final ValueChanged<List<AttentionEntry>> 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<List<AttentionEntry>>(
valueListenable: entries,
builder: (context, rows, _) => _sheet(context, rows),
);
}
Widget _sheet(BuildContext context, List<AttentionEntry> 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),
),
],
),
);
}
}
@@ -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<String>('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,
@@ -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<bool> _confirm(
required String body,
required String action,
}) async {
final confirmed = chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? await showCupertinoDialog<bool>(
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<bool>(
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<bool>(
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;
}
+11 -21
View File
@@ -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<FileDownloadButton> {
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!)),
],
+15 -32
View File
@@ -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',
+52 -67
View File
@@ -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<FilesPanel> {
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.'),
),
],
),
),
);
@@ -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<String?> showRenameEntryDialog(
DirectoryEntry entry,
) {
final dialog = _RenameEntryDialog(entry: entry);
return chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? showCupertinoDialog<String>(context: context, builder: (_) => dialog)
: showDialog<String>(context: context, builder: (_) => dialog);
return showDialog<String>(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),
@@ -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'))],
);
}
+8 -18
View File
@@ -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<void>(
usesCupertinoHost(context)
? CupertinoPageRoute<void>(builder: (_) => page)
: MaterialPageRoute<void>(builder: (_) => page),
);
Navigator.of(
context,
).push<void>(MaterialPageRoute<void>(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'),
),
],
),
);
@@ -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();
});
}
@@ -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<void> mountAttentionRuns(
WidgetTester tester,
AttentionRunsGateway gateway, {
required bool cupertino,
required AttentionStore store,
required List<JsonMap> runs,
int request = 0,
@@ -107,7 +97,6 @@ Future<void> mountAttentionRuns(
await tester.pumpWidget(
attentionRunsApp(
gateway,
cupertino: cupertino,
store: store,
textScale: textScale,
key: key,
@@ -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();
});
}
@@ -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<IconButton>());
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);
});
}
@@ -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<RenderParagraph>(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<RenderParagraph>(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);
});
}
@@ -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<List<AttentionEntry>>([before]);
addTearDown(source.dispose);
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: <AttentionEntry>[],
dismissed: <AttentionEntry>[],
cleared: <List<AttentionEntry>>[],
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<List<AttentionEntry>>([before]);
addTearDown(source.dispose);
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: <AttentionEntry>[],
dismissed: <AttentionEntry>[],
cleared: <List<AttentionEntry>>[],
),
),
);
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<List<AttentionEntry>>([a]);
addTearDown(source.dispose);
final cleared = <List<AttentionEntry>>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: <AttentionEntry>[],
dismissed: <AttentionEntry>[],
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<List<AttentionEntry>>([a]);
addTearDown(source.dispose);
final cleared = <List<AttentionEntry>>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: <AttentionEntry>[],
dismissed: <AttentionEntry>[],
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);
});
}
@@ -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<RunStatusIcon>(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<List<AttentionEntry>>([a, b]);
addTearDown(source.dispose);
final opened = <AttentionEntry>[];
final dismissed = <AttentionEntry>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: opened,
dismissed: dismissed,
cleared: <List<AttentionEntry>>[],
),
);
),
);
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<RunStatusIcon>(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<List<AttentionEntry>>([failed, decision]);
addTearDown(source.dispose);
final opened = <AttentionEntry>[];
final dismissed = <AttentionEntry>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: opened,
dismissed: dismissed,
cleared: <List<AttentionEntry>>[],
),
);
),
);
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<List<AttentionEntry>>([a, b]);
addTearDown(source.dispose);
final opened = <AttentionEntry>[];
final dismissed = <AttentionEntry>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: opened,
dismissed: dismissed,
cleared: <List<AttentionEntry>>[],
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<List<AttentionEntry>>([failed, decision]);
addTearDown(source.dispose);
final opened = <AttentionEntry>[];
final dismissed = <AttentionEntry>[];
await tester.pumpWidget(
attentionApp(
AttentionHarness(
source: source,
opened: opened,
dismissed: dismissed,
cleared: <List<AttentionEntry>>[],
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);
});
}
@@ -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<AttentionEntry> entries;
final bool cupertino;
final ValueChanged<AttentionEntry>? onOpen;
final ValueChanged<AttentionEntry>? onDismiss;
final ValueChanged<List<AttentionEntry>>? 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<List<AttentionEntry>> source;
final List<AttentionEntry> opened;
final List<AttentionEntry> dismissed;
final List<List<AttentionEntry>> 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<Icon>(xmark).semanticLabel ?? '';
}
return tester.widget<IconButton>(find.byKey(key)).tooltip ?? '';
}
@@ -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, String>{
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, String>{
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<RenderParagraph>(
find.text(view.helper),
);
expect(
helper.size.width,
greaterThan(100),
reason: 'the action must not squeeze the row copy',
);
final body = tester.renderObject<RenderParagraph>(
find.text(view.headline),
);
expect(body.didExceedMaxLines, isFalse);
expect(find.byKey(notificationEnableKey), findsOneWidget);
expect(
tester.widget(find.byKey(notificationEnableKey)),
isA<FilledButton>(),
);
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<RenderParagraph>(find.text(view.helper));
expect(
helper.size.width,
greaterThan(100),
reason: 'the action must not squeeze the row copy',
);
final body = tester.renderObject<RenderParagraph>(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);
});
}
@@ -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<TextField>(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 {
@@ -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<void> mount(
WidgetTester tester, {
required bool cupertino,
ValueChanged<num>? onSelected,
}) async {
gateway.reply = {
@@ -60,29 +58,23 @@ 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(
'uses native search and filters runs in CupertinoApp',
'filters runs from the filter sheet',
(tester) async {
num? selectedRun;
await mount(
tester,
cupertino: true,
onSelected: (id) => selectedRun = id,
);
await mount(tester, onSelected: (id) => selectedRun = id);
// The text filter lives in the filter sheet.
expect(find.byType(CupertinoSearchTextField), findsNothing);
expect(find.text('Alpha'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('runs.filter')));
await tester.pumpAndSettle();
await tester.enterText(find.byType(CupertinoSearchTextField), '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();
@@ -90,7 +82,7 @@ void main() {
await tester.tap(find.byKey(const ValueKey('run-row-2')));
expect(selectedRun, 2);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
testWidgets(
@@ -147,9 +139,9 @@ void main() {
gateway.gate = Completer<void>();
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 +150,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 +165,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<RunStatusIcon>(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<RunStatusIcon>(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),
);
});
}