feat(app): mirror the attention count on the Runs tab

This commit is contained in:
2026-10-22 18:40:55 +01:00
parent 1bcc26a4fd
commit eb80092860
9 changed files with 454 additions and 15 deletions
@@ -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<Badge>(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<Badge>(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<Badge>(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<Badge>(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);
});
}
+106
View File
@@ -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<void> 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>(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>(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',
);
}
});
}