diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 14ecb4f6..dbbcfcf3 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; +import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -10,6 +11,8 @@ import '../shell/adaptive_shell.dart'; import '../shell/destination.dart'; import '../features/attention/notify/notification_controller.dart'; import '../features/attention/notify/notification_store.dart'; +import '../features/attention/runtime/attention_controller.dart'; +import '../features/attention/runtime/attention_store.dart'; import '../features/runs/ui/run_search_selection.dart'; import '../features/search/domain/search_target.dart'; import '../features/settings/settings_screen.dart'; @@ -89,6 +92,20 @@ class _PipelinesAppState extends State store: const SharedPreferencesNotificationStore(), ); + /// One attention surface for the app: the Runs heading's bell draws from it + /// and the shell mirrors its count on the Runs tab, so the badge is visible + /// from every destination. The Runs list seeds the rows when it loads; pushed + /// `run_event` frames are folded here so the count moves while another + /// destination is shown, and a replaced socket drops the status baseline. + late final AttentionController _attention = AttentionController( + store: const SharedPreferencesAttentionStore(), + ); + StreamSubscription? _attentionFrames; + int _attentionEpoch = 0; + + /// The count the shell's Runs tab shows; only a changed count rebuilds it. + final ValueNotifier _attentionCount = ValueNotifier(0); + @override void initState() { super.initState(); @@ -115,6 +132,12 @@ class _PipelinesAppState extends State _cupertino = widget.cupertino ?? _platformIsCupertino; _notifications.onOpenRun = (id) => _delegate.goTo(AppRoute.run(id)); unawaited(_notifications.load()); + unawaited(_attention.load()); + _attentionFrames = _session.gateway.frames + .where((frame) => frame['type'] == 'run_event') + .listen(_attention.observeFrame); + _session.addListener(_attentionSessionChanged); + _attention.addListener(_attentionChanged); _delegate = AppRouterDelegate( initial: initial, cupertino: _cupertino, @@ -137,6 +160,11 @@ class _PipelinesAppState extends State @override void dispose() { WidgetsBinding.instance.removeObserver(this); + _session.removeListener(_attentionSessionChanged); + unawaited(_attentionFrames?.cancel()); + _attention.removeListener(_attentionChanged); + _attention.dispose(); + _attentionCount.dispose(); _notifications.dispose(); _delegate.removeListener(_routeChanged); _delegate.dispose(); @@ -161,6 +189,33 @@ class _PipelinesAppState extends State unawaited(_session.retry()); } + /// A replaced socket drops the attention status baseline so the gap cannot + /// replay a transition; the Runs list's next read reseeds the rows. + void _attentionSessionChanged() { + final epoch = _session.connectionEpoch; + if (epoch == _attentionEpoch) return; + _attentionEpoch = epoch; + _attention.resetForReconnect(); + } + + /// Mirrors the controller's entry count for the shell. The Runs list seeds + /// the rows from inside its own build, and the shell sits above that layout + /// scope, so a count that changes mid-build lands after the frame; a pushed + /// frame arrives outside any build and applies at once. + void _attentionChanged() { + if (!mounted) return; + final count = _attention.entries.length; + if (count == _attentionCount.value) return; + if (SchedulerBinding.instance.schedulerPhase == + SchedulerPhase.persistentCallbacks) { + SchedulerBinding.instance.addPostFrameCallback( + (_) => _attentionChanged(), + ); + return; + } + _attentionCount.value = count; + } + @override Widget build(BuildContext context) => MyApp.router(cupertino: _cupertino, routerConfig: _config); @@ -277,7 +332,16 @@ class _PipelinesAppState extends State _delegate.goTo(AppRoute.run(id)); } - Widget _buildShell(BuildContext context, AppRoute route) => AdaptiveShell( + /// The shell rebuilds its Runs tab badge from the attention count alone; the + /// destination bodies keep their state through it. + Widget _buildShell(BuildContext context, AppRoute route) => + ValueListenableBuilder( + valueListenable: _attentionCount, + builder: (context, count, _) => _shellFor(route, count), + ); + + Widget _shellFor(AppRoute route, int attentionCount) => AdaptiveShell( + attentionCount: attentionCount, cupertino: _cupertino, destination: _destinationOf(route.kind), onDestinationSelected: (destination) => @@ -307,6 +371,7 @@ class _PipelinesAppState extends State initialDecide: route.decide, listRefreshToken: _runsRefresh, notifications: _notifications, + attention: _attention, onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)), onBack: () => _delegate.goTo(AppRoute.runs), ), diff --git a/app/lib/application/runs_destination.dart b/app/lib/application/runs_destination.dart index 978faad1..a987b086 100644 --- a/app/lib/application/runs_destination.dart +++ b/app/lib/application/runs_destination.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import '../features/attention/notify/notification_controller.dart'; +import '../features/attention/runtime/attention_controller.dart'; import '../features/runs/screen.dart'; import '../ui/adaptive/host.dart'; import 'app_session.dart'; @@ -26,6 +27,7 @@ class RunsDestination extends StatelessWidget { this.onBack, this.listRefreshToken = 0, this.notifications, + this.attention, }); final AppSession session; @@ -52,6 +54,9 @@ class RunsDestination extends StatelessWidget { /// The app-level notification capability shared with Settings. final NotificationController? notifications; + /// The app-level attention controller the shell's Runs tab badge reads. + final AttentionController? attention; + @override Widget build(BuildContext context) => AnimatedBuilder( animation: session, @@ -93,6 +98,7 @@ class RunsDestination extends StatelessWidget { syncToken: session.connectionEpoch, listRefreshToken: listRefreshToken, notifications: notifications, + attention: attention, onRunSelected: onRunSelected, onBack: onBack, ); 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 ddd9966b..7e856574 100644 --- a/app/lib/features/attention/ui/needs_you_runs_heading.dart +++ b/app/lib/features/attention/ui/needs_you_runs_heading.dart @@ -28,6 +28,7 @@ class NeedsYouRunsHeading extends StatefulWidget { this.now, this.cupertino, this.notifications, + this.attention, }); /// The run summaries the Runs destination already holds. @@ -55,23 +56,36 @@ class NeedsYouRunsHeading extends StatefulWidget { /// the bell, so no store or platform bridge is touched there. final NotificationController? notifications; + /// The app's shared attention controller, so the shell can mirror the same + /// count on the Runs tab. The heading seeds it with [rows]; its owner folds + /// [frames] and resets it on reconnect. Absent, the heading owns a private + /// controller fed from [frames], which fixtures and the list tests rely on. + final AttentionController? attention; + @override State createState() => _NeedsYouRunsHeadingState(); } class _NeedsYouRunsHeadingState extends State { - late final AttentionController _attention = AttentionController( - store: widget.store, - now: widget.now, - ); + late final AttentionController _attention = + widget.attention ?? + AttentionController(store: widget.store, now: widget.now); StreamSubscription? _frames; + bool get _ownsController => widget.attention == null; + @override void initState() { super.initState(); _attention.seedRows(widget.rows); - unawaited(_attention.load()); - _listen(); + if (_ownsController) { + unawaited(_attention.load()); + _listen(); + } else { + // The owner folds frames; publishing after every change it makes is the + // same idempotent call the private path makes after each frame. + _attention.addListener(_publish); + } final notifications = widget.notifications; if (notifications != null) { notifications.onOpenRun = _openRunById; @@ -115,7 +129,7 @@ class _NeedsYouRunsHeadingState extends State { @override void didUpdateWidget(covariant NeedsYouRunsHeading oldWidget) { super.didUpdateWidget(oldWidget); - if (!identical(oldWidget.frames, widget.frames)) { + if (_ownsController && !identical(oldWidget.frames, widget.frames)) { unawaited(_frames?.cancel()); _frames = null; _listen(); @@ -135,7 +149,11 @@ class _NeedsYouRunsHeadingState extends State { @override void dispose() { unawaited(_frames?.cancel()); - _attention.dispose(); + if (_ownsController) { + _attention.dispose(); + } else { + _attention.removeListener(_publish); + } super.dispose(); } diff --git a/app/lib/features/runs/screen.dart b/app/lib/features/runs/screen.dart index 3e8403e2..444aad3e 100644 --- a/app/lib/features/runs/screen.dart +++ b/app/lib/features/runs/screen.dart @@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart'; import '../../core/api_gateway.dart'; import '../../ui/adaptive/host.dart'; import '../attention/notify/notification_controller.dart'; +import '../attention/runtime/attention_controller.dart'; import '../attention/runtime/attention_store.dart'; import 'actions/decision_action.dart'; import 'data/runs_repository.dart'; @@ -34,6 +35,7 @@ class RunsScreen extends StatefulWidget { this.attentionStore = const SharedPreferencesAttentionStore(), this.attentionNow, this.notifications, + this.attention, }); final ApiGateway gateway; @@ -70,6 +72,9 @@ class RunsScreen extends StatefulWidget { /// App-level notification delivery for live attention transitions. final NotificationController? notifications; + /// The app's shared attention controller, mirrored on the shell's Runs tab. + final AttentionController? attention; + @override State createState() => _RunsScreenState(); } @@ -193,6 +198,7 @@ class _RunsScreenState extends State { attentionStore: widget.attentionStore, attentionNow: widget.attentionNow, notifications: widget.notifications, + attention: widget.attention, ), ), ), diff --git a/app/lib/features/runs/ui/runs_list.dart b/app/lib/features/runs/ui/runs_list.dart index 4c9bd7c1..1679c14a 100644 --- a/app/lib/features/runs/ui/runs_list.dart +++ b/app/lib/features/runs/ui/runs_list.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../../ui/adaptive/host.dart'; import '../../attention/notify/notification_controller.dart'; +import '../../attention/runtime/attention_controller.dart'; import '../../attention/runtime/attention_store.dart'; import '../../attention/ui/needs_you_runs_heading.dart'; import '../domain/run_models.dart'; @@ -19,6 +20,7 @@ class RunsList extends StatelessWidget { this.attentionStore = const SharedPreferencesAttentionStore(), this.attentionNow, this.notifications, + this.attention, }); final RunsController controller; @@ -37,6 +39,9 @@ class RunsList extends StatelessWidget { /// App-level notification delivery; absent in list-only fixtures. final NotificationController? notifications; + /// The app's shared attention controller; absent in list-only fixtures. + final AttentionController? attention; + @override Widget build(BuildContext context) { if (controller.loading && controller.runs.isEmpty) { @@ -108,6 +113,7 @@ class RunsList extends StatelessWidget { store: attentionStore, now: attentionNow, notifications: notifications, + attention: attention, ), ], ), diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index 007c6b9c..48c38b42 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -1,6 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'attention_badge.dart'; import 'destination.dart'; class AdaptiveShell extends StatefulWidget { @@ -11,6 +12,7 @@ class AdaptiveShell extends StatefulWidget { this.destination, this.onDestinationSelected, this.onSearch, + this.attentionCount = 0, }); final Map destinationBodies; @@ -25,6 +27,10 @@ class AdaptiveShell extends StatefulWidget { /// shell tests and compositions without routing keep their tab set only. final VoidCallback? onSearch; + /// Runs needing the operator today, mirrored on the Runs tab in every mount + /// so it stays visible from any destination. Zero shows no badge. + final int attentionCount; + @override State createState() => _AdaptiveShellState(); } @@ -65,6 +71,17 @@ class _AdaptiveShellState extends State { List _items(T Function(AppDestination) build) => AppDestination.values.map(build).toList(); + /// The destination's icon; only Runs carries the attention count. + Widget _icon(AppDestination destination, IconData data) { + final icon = Icon(data); + if (destination != AppDestination.runs) return icon; + return AttentionDestinationIcon( + count: widget.attentionCount, + cupertino: widget.cupertino, + child: icon, + ); + } + @override Widget build(BuildContext context) { final index = AppDestination.values.indexOf(_selected); @@ -108,6 +125,7 @@ class _AdaptiveShellState extends State { _CupertinoSidebar( selected: _selected, onSelected: _select, + attentionCount: widget.attentionCount, ), Expanded(child: _destinationStack(contents, index)), ], @@ -117,11 +135,12 @@ class _AdaptiveShellState extends State { Expanded(child: _destinationStack(contents, index)), CupertinoTabBar( currentIndex: index, - onTap: (value) => _select(AppDestination.values[value]), + onTap: (value) => + _select(AppDestination.values[value]), items: _items((destination) { final item = destinationDetails(destination); return BottomNavigationBarItem( - icon: Icon(item.cupertinoIcon), + icon: _icon(destination, item.cupertinoIcon), label: item.label, ); }), @@ -155,7 +174,7 @@ class _AdaptiveShellState extends State { destinations: _items((destination) { final item = destinationDetails(destination); return NavigationRailDestination( - icon: Icon(item.icon), + icon: _icon(destination, item.icon), label: Text(item.label), ); }), @@ -172,7 +191,7 @@ class _AdaptiveShellState extends State { destinations: _items((destination) { final item = destinationDetails(destination); return NavigationDestination( - icon: Icon(item.icon), + icon: _icon(destination, item.icon), label: item.label, ); }), @@ -189,10 +208,15 @@ class _AdaptiveShellState extends State { /// The wide-window Cupertino destination list: the web's 200px rail with the /// host's own grouped list controls. class _CupertinoSidebar extends StatelessWidget { - const _CupertinoSidebar({required this.selected, required this.onSelected}); + const _CupertinoSidebar({ + required this.selected, + required this.onSelected, + this.attentionCount = 0, + }); final AppDestination selected; final ValueChanged onSelected; + final int attentionCount; @override Widget build(BuildContext context) { @@ -215,7 +239,15 @@ class _CupertinoSidebar extends StatelessWidget { for (final destination in AppDestination.values) CupertinoListTile( key: ValueKey('shell.destination.${destination.name}'), - leading: Icon(destinationDetails(destination).cupertinoIcon), + leading: destination == AppDestination.runs + ? AttentionDestinationIcon( + count: attentionCount, + cupertino: true, + child: Icon( + destinationDetails(destination).cupertinoIcon, + ), + ) + : Icon(destinationDetails(destination).cupertinoIcon), title: Text(destinationDetails(destination).label), trailing: destination == selected ? Icon( diff --git a/app/lib/shell/attention_badge.dart b/app/lib/shell/attention_badge.dart new file mode 100644 index 00000000..6cf21f45 --- /dev/null +++ b/app/lib/shell/attention_badge.dart @@ -0,0 +1,82 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../features/attention/domain/attention_models.dart'; + +/// Mirrors the Runs-heading bell count onto the Runs destination icon. +/// +/// The bell itself lives in the Runs heading, so without this the count would +/// be visible only on that destination; the web mirrors it on the rail and +/// dock tab. Material hosts use the framework [Badge]; Cupertino has no badge +/// control, so its tab bar and sidebar get the host's red count overlay. Zero +/// draws the bare icon, and a count labels the item exactly like the bell: +/// `Notifications, {n} needing attention`. +class AttentionDestinationIcon extends StatelessWidget { + const AttentionDestinationIcon({ + super.key, + required this.count, + required this.cupertino, + required this.child, + }); + + final int count; + final bool cupertino; + final Widget child; + + @override + Widget build(BuildContext context) { + final visible = count > 0; + final Widget icon = cupertino + ? _CupertinoCountOverlay(count: count, visible: visible, child: child) + : Badge(label: Text('$count'), isLabelVisible: visible, child: child); + if (!visible) return icon; + // The number alone would read as a stray "3"; the item carries the bell's + // full label instead. + return Semantics( + label: attentionBadgeLabel(count), + child: ExcludeSemantics(child: icon), + ); + } +} + +/// The iOS tab-badge idiom: a red stadium with the count over the icon's +/// trailing corner. Content-driven size; only the overlap offset is fixed. +class _CupertinoCountOverlay extends StatelessWidget { + const _CupertinoCountOverlay({ + required this.count, + required this.visible, + required this.child, + }); + + final int count; + final bool visible; + final Widget child; + + @override + Widget build(BuildContext context) { + if (!visible) return child; + final style = CupertinoTheme.of( + context, + ).textTheme.tabLabelTextStyle.copyWith(color: CupertinoColors.white); + return Stack( + clipBehavior: Clip.none, + children: [ + child, + PositionedDirectional( + top: -6, + end: -10, + child: DecoratedBox( + decoration: ShapeDecoration( + color: CupertinoColors.systemRed.resolveFrom(context), + shape: const StadiumBorder(), + ), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1), + child: Text('$count', style: style), + ), + ), + ), + ], + ); + } +} diff --git a/app/test/application/attention_badge_wiring_test.dart b/app/test/application/attention_badge_wiring_test.dart new file mode 100644 index 00000000..ba4fd01c --- /dev/null +++ b/app/test/application/attention_badge_wiring_test.dart @@ -0,0 +1,118 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/transport/pipelines_client.dart'; + +import '../core/transport/pipelines_client_test.dart' show FakeChannel; +import 'pipelines_app_test.dart' show pumpApp, replyList; +import 'pipelines_replies.dart'; + +/// The app lifts one attention controller above the destinations: the Runs +/// list seeds it when it loads and the app folds pushed `run_event` frames, so +/// the shell's Runs tab badge moves while another destination is shown. +void main() { + final needingAttention = RegExp('needing attention'); + + Finder badgeCount(String count) => + find.descendant(of: find.byType(Badge), matching: find.text(count)); + + testWidgets( + 'a run_event folded to waiting raises the Runs tab badge from Pipelines', + (tester) async { + final semantics = tester.ensureSemantics(); + final channel = FakeChannel()..readyCompleter.complete(); + final client = PipelinesClient(channelFactory: (_) => channel); + final provider = PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')), + ); + addTearDown(provider.dispose); + + await pumpApp( + tester, + channel: channel, + client: client, + provider: provider, + ); + await replyList( + tester, + channel, + runs: [ + { + 'id': 1, + 'pipeline_id': 4, + 'name': 'nightly', + 'title': 'Nightly build', + 'status': 'running', + 'created_at': DateTime.now().toIso8601String(), + }, + ], + ); + expect(find.text('Nightly build'), findsWidgets); + expect(tester.widget(find.byType(Badge)).isLabelVisible, isFalse); + expect(find.bySemanticsLabel(needingAttention), findsNothing); + + await tester.tap(find.text('Pipelines').last); + await tester.pump(); + expect(provider.value.uri.path, '/pipelines'); + await waitForRequest(tester, channel, 'list_pipelines'); + expect(find.text('Nightly build'), findsNothing); + + channel.incoming.add( + jsonEncode({'type': 'run_event', 'run_id': 1, 'status': 'waiting'}), + ); + await tester.pump(); + await tester.pump(); + + expect(provider.value.uri.path, '/pipelines'); + expect(tester.widget(find.byType(Badge)).isLabelVisible, isTrue); + expect(badgeCount('1'), findsOneWidget); + expect( + find.bySemanticsLabel(RegExp('Notifications, 1 needing attention')), + findsOneWidget, + ); + + // The decision taken elsewhere clears the badge the same way. + channel.incoming.add( + jsonEncode({'type': 'run_event', 'run_id': 1, 'status': 'succeeded'}), + ); + await tester.pump(); + await tester.pump(); + expect(tester.widget(find.byType(Badge)).isLabelVisible, isFalse); + expect(badgeCount('1'), findsNothing); + expect(find.bySemanticsLabel(needingAttention), findsNothing); + semantics.dispose(); + }, + ); + + testWidgets('a new waiting run pushed before any list read is counted', ( + tester, + ) async { + final channel = FakeChannel()..readyCompleter.complete(); + final client = PipelinesClient(channelFactory: (_) => channel); + final provider = PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation(uri: Uri.parse('/settings')), + ); + addTearDown(provider.dispose); + + await pumpApp(tester, channel: channel, client: client, provider: provider); + expect(tester.widget(find.byType(Badge)).isLabelVisible, isFalse); + + channel.incoming.add( + jsonEncode({ + 'type': 'run_event', + 'run_id': 9, + 'pipeline_id': 4, + 'name': 'nightly', + 'title': 'Arrived while away', + 'status': 'waiting', + 'created_at': DateTime.now().toIso8601String(), + }), + ); + await tester.pump(); + await tester.pump(); + + expect(provider.value.uri.path, '/settings'); + expect(badgeCount('1'), findsOneWidget); + }); +} diff --git a/app/test/shell/attention_badge_test.dart b/app/test/shell/attention_badge_test.dart new file mode 100644 index 00000000..a11e2e71 --- /dev/null +++ b/app/test/shell/attention_badge_test.dart @@ -0,0 +1,106 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/shell/adaptive_shell.dart'; + +/// The Runs tab mirrors the attention count in every mount of both hosts: +/// Material rail and bottom bar, Cupertino sidebar and tab bar. Zero draws the +/// bare icon with no count and no attention semantics. +void main() { + final needingAttention = RegExp('Notifications, 3 needing attention'); + final anyAttention = RegExp('needing attention'); + + Future pumpShell( + WidgetTester tester, { + required double width, + required bool cupertino, + required int count, + }) async { + tester.view.physicalSize = Size(width, 900); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + final shell = AdaptiveShell(cupertino: cupertino, attentionCount: count); + await tester.pumpWidget( + cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell), + ); + } + + for (final width in [390.0, 1000.0]) { + final mount = width < 600 ? 'bottom bar' : 'rail'; + + testWidgets('Material $mount shows the count on the Runs tab', ( + tester, + ) async { + final semantics = tester.ensureSemantics(); + await pumpShell(tester, width: width, cupertino: false, count: 3); + expect( + find.byType(width < 600 ? NavigationBar : NavigationRail), + findsOneWidget, + ); + final badge = find.byType(Badge); + expect(badge, findsOneWidget); + expect(tester.widget(badge).isLabelVisible, isTrue); + expect( + find.descendant(of: badge, matching: find.text('3')), + findsOneWidget, + ); + expect(find.bySemanticsLabel(needingAttention), findsOneWidget); + semantics.dispose(); + }); + + testWidgets('Material $mount hides the badge at zero', (tester) async { + final semantics = tester.ensureSemantics(); + await pumpShell(tester, width: width, cupertino: false, count: 0); + final badge = find.byType(Badge); + expect(badge, findsOneWidget); + expect(tester.widget(badge).isLabelVisible, isFalse); + expect( + find.descendant(of: badge, matching: find.byType(Text)), + findsNothing, + ); + expect(find.bySemanticsLabel(anyAttention), findsNothing); + semantics.dispose(); + }); + } + + for (final width in [390.0, 1280.0]) { + final mount = width < 600 ? 'tab bar' : 'sidebar'; + + testWidgets('Cupertino $mount shows the count on the Runs item', ( + tester, + ) async { + final semantics = tester.ensureSemantics(); + await pumpShell(tester, width: width, cupertino: true, count: 3); + expect( + find.byType(CupertinoTabBar), + width < 600 ? findsOneWidget : findsNothing, + ); + expect(find.byType(Badge), findsNothing, reason: 'no Material badge'); + expect(find.text('3'), findsOneWidget); + expect(find.bySemanticsLabel(needingAttention), findsOneWidget); + semantics.dispose(); + }); + + testWidgets('Cupertino $mount hides the count at zero', (tester) async { + final semantics = tester.ensureSemantics(); + await pumpShell(tester, width: width, cupertino: true, count: 0); + expect(find.text('0'), findsNothing); + expect(find.bySemanticsLabel(anyAttention), findsNothing); + semantics.dispose(); + }); + } + + testWidgets('the badge stays visible from every destination', (tester) async { + await pumpShell(tester, width: 1000, cupertino: false, count: 2); + for (final label in ['Runs', 'Chat', 'Settings']) { + await tester.tap(find.text(label).last); + await tester.pumpAndSettle(); + expect( + find.descendant(of: find.byType(Badge), matching: find.text('2')), + findsOneWidget, + reason: 'badge missing on $label', + ); + } + }); +}