Show running and failed run counts independently
Give the Runs tab separate activity and failure indicators so neither suppresses the other. Reuse known summaries and pushed updates, keep failed states separate from decisions and dismissal counts, and update across tabs even when total attention is unchanged.
This commit is contained in:
@@ -3,6 +3,7 @@ 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 'package:pipelines_app/shell/attention_badge.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import 'pipelines_app_test.dart' show pumpApp, replyList;
|
||||
@@ -17,77 +18,74 @@ void main() {
|
||||
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);
|
||||
testWidgets('waiting is announced without being labelled as a failed run', (
|
||||
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 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.byKey(const ValueKey('shell.destination.pipelines')),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/pipelines');
|
||||
await waitForRequest(tester, channel, 'list_pipelines');
|
||||
// The Runs page may still be fading out, but it is no longer the
|
||||
// active page: nothing on it takes a tap.
|
||||
expect(find.text('Nightly build').hitTestable(), findsNothing);
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/pipelines');
|
||||
await waitForRequest(tester, channel, 'list_pipelines');
|
||||
// The Runs page may still be fading out, but it is no longer the
|
||||
// active page: nothing on it takes a tap.
|
||||
expect(find.text('Nightly build').hitTestable(), findsNothing);
|
||||
|
||||
channel.incoming.add(
|
||||
jsonEncode({'type': 'run_event', 'run_id': 1, 'status': 'waiting'}),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
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,
|
||||
);
|
||||
expect(provider.value.uri.path, '/pipelines');
|
||||
expect(tester.widget<Badge>(find.byType(Badge)).isLabelVisible, isFalse);
|
||||
expect(
|
||||
tester
|
||||
.widget<RunsDestinationIcon>(find.byType(RunsDestinationIcon))
|
||||
.failed,
|
||||
0,
|
||||
);
|
||||
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();
|
||||
},
|
||||
);
|
||||
// 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,
|
||||
@@ -117,6 +115,12 @@ void main() {
|
||||
await tester.pump();
|
||||
|
||||
expect(provider.value.uri.path, '/settings');
|
||||
expect(badgeCount('1'), findsOneWidget);
|
||||
expect(badgeCount('1'), findsNothing);
|
||||
expect(
|
||||
tester
|
||||
.widget<RunsDestinationIcon>(find.byType(RunsDestinationIcon))
|
||||
.failed,
|
||||
0,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
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 'package:pipelines_app/shell/attention_badge.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import 'pipelines_app_test.dart' show pumpApp, replyList;
|
||||
|
||||
void main() {
|
||||
testWidgets('both run counts update while another destination is visible', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
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);
|
||||
final now = DateTime.now().toIso8601String();
|
||||
await replyList(
|
||||
tester,
|
||||
channel,
|
||||
runs: [
|
||||
{
|
||||
'id': 1,
|
||||
'pipeline_id': 1,
|
||||
'name': 'fixture',
|
||||
'title': 'Running job',
|
||||
'status': 'running',
|
||||
'executing': true,
|
||||
'created_at': now,
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'pipeline_id': 1,
|
||||
'name': 'fixture',
|
||||
'title': 'Failed job',
|
||||
'status': 'failed',
|
||||
'executing': false,
|
||||
'created_at': now,
|
||||
},
|
||||
{
|
||||
'id': 3,
|
||||
'pipeline_id': 1,
|
||||
'name': 'fixture',
|
||||
'title': 'Decision job',
|
||||
'status': 'waiting',
|
||||
'executing': false,
|
||||
'created_at': now,
|
||||
},
|
||||
],
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
RunsDestinationIcon counts() =>
|
||||
tester.widget<RunsDestinationIcon>(find.byType(RunsDestinationIcon));
|
||||
expect(counts().running, 1);
|
||||
expect(counts().failed, 1);
|
||||
expect(counts().attention, 2);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.pipelines')));
|
||||
await tester.pumpAndSettle();
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'type': 'run_event',
|
||||
'run_id': 3,
|
||||
'status': 'failed',
|
||||
'executing': false,
|
||||
}),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/pipelines');
|
||||
expect(counts().running, 1);
|
||||
expect(counts().failed, 2);
|
||||
// Waiting -> failed must repaint even though total attention is unchanged.
|
||||
expect(counts().attention, 2);
|
||||
|
||||
channel.incoming.add(
|
||||
jsonEncode({
|
||||
'type': 'run_event',
|
||||
'run_id': 1,
|
||||
'status': 'succeeded',
|
||||
'executing': false,
|
||||
}),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(counts().running, 0);
|
||||
expect(counts().failed, 2);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_tab_counts.dart';
|
||||
|
||||
void main() {
|
||||
test('running and failed statuses are counted independently', () {
|
||||
expect(
|
||||
runTabCounts([
|
||||
{'status': 'running', 'executing': true},
|
||||
{'status': 'queued', 'executing': true},
|
||||
{'status': 'failed', 'executing': false},
|
||||
{'status': 'waiting', 'executing': false},
|
||||
{'status': 'canceled'},
|
||||
{'status': 'interrupted'},
|
||||
]),
|
||||
(running: 2, failed: 1),
|
||||
);
|
||||
});
|
||||
|
||||
test('terminal statuses override stale execution flags', () {
|
||||
expect(
|
||||
runTabCounts([
|
||||
{'status': 'failed', 'executing': true},
|
||||
{'status': 'succeeded', 'executing': true},
|
||||
]),
|
||||
(running: 0, failed: 1),
|
||||
);
|
||||
});
|
||||
|
||||
test('older running summaries work without inventing other live states', () {
|
||||
expect(
|
||||
runTabCounts([
|
||||
{'status': 'running'},
|
||||
{'status': 'running', 'executing': false},
|
||||
{'status': 'queued'},
|
||||
{'status': 'waiting'},
|
||||
]),
|
||||
(running: 1, failed: 0),
|
||||
);
|
||||
expect(runTabCounts([]), (running: 0, failed: 0));
|
||||
});
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||
/// bar at full width on a phone and right-aligned on a wide window. 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');
|
||||
final needingAttention = RegExp('3 failed runs');
|
||||
final anyAttention = RegExp('failed runs');
|
||||
|
||||
Future<void> pumpShell(
|
||||
WidgetTester tester, {
|
||||
@@ -19,7 +19,7 @@ void main() {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final shell = AdaptiveShell(attentionCount: count);
|
||||
final shell = AdaptiveShell(failedRunCount: count);
|
||||
await tester.pumpWidget(MaterialApp(home: shell));
|
||||
}
|
||||
|
||||
|
||||
@@ -66,9 +66,10 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
Widget shell({int attention = 0}) {
|
||||
Widget shell({int attention = 0, int failed = 0}) {
|
||||
final app = AdaptiveShell(
|
||||
attentionCount: attention,
|
||||
failedRunCount: failed,
|
||||
destinationBodies: {
|
||||
AppDestination.runs: (_) => ShellBadge(
|
||||
kind: ShellBadgeKind.running,
|
||||
@@ -218,15 +219,15 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the Runs tab shows one indicator: attention outranks running', (
|
||||
testWidgets('the Runs tab shows running and failed indicators together', (
|
||||
tester,
|
||||
) async {
|
||||
await setSize(tester, const Size(1200, 800));
|
||||
await tester.pumpWidget(shell(attention: 2));
|
||||
await tester.pumpWidget(shell(attention: 2, failed: 2));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text('2'), findsOneWidget);
|
||||
expect(find.text('4'), findsNothing);
|
||||
expect(find.text('4'), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(shell());
|
||||
await tester.pump();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
|
||||
void main() {
|
||||
for (final width in [390.0, 1000.0]) {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('running and failed are distinct at $width $brightness', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = Size(width, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final semantics = tester.ensureSemantics();
|
||||
final theme = ThemeData(brightness: brightness);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: const AdaptiveShell(runningRunCount: 2, failedRunCount: 3),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final failed = find.byKey(const ValueKey('shell.badge.runs.failed'));
|
||||
final running = find.byKey(const ValueKey('shell.badge.runs.running'));
|
||||
expect(
|
||||
find.descendant(of: failed, matching: find.text('3')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(of: running, matching: find.text('2')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
tester.widget<Badge>(failed).backgroundColor,
|
||||
theme.colorScheme.error,
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.text('3')).bottom,
|
||||
lessThan(tester.getRect(find.text('2')).top),
|
||||
);
|
||||
expect(
|
||||
find.bySemanticsLabel(RegExp('2 runs in progress, 3 failed runs')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
semantics.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user