feat(app): pulse the run graph's recorded current stage

Mark the run's recorded current stage on the run graph while it executes. The
halo is a foreground painter outside the node box, so it adds no size, hit
target or semantics, and it is derived only from RunGraphState.activeStage,
which is non-null only while the run reports executing. Reduced motion keeps a
still ring instead of animating.

Widget tests cover the sole active node, a finished run with no halo or ticker,
reduced motion, toggling it at runtime and unchanged node extents.
This commit is contained in:
2026-10-22 17:17:39 +01:00
parent cf6da4acaa
commit 407551b8bb
6 changed files with 379 additions and 21 deletions
@@ -0,0 +1,185 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
import '../domain/graph_fixtures.dart';
Map<String, dynamic> _run({required bool executing}) => <String, dynamic>{
'id': 42,
'steps': <dynamic>[
step(
sequence: 1,
stage: 'plan',
status: 'completed',
outcome: 'success',
target: 'build',
),
if (executing)
step(
sequence: 2,
stage: 'build',
status: 'running',
startedAt: '2026-10-21T10:00:00Z',
)
else
step(
sequence: 2,
stage: 'build',
status: 'completed',
outcome: 'success',
target: 'ship',
),
],
'current_stage': executing ? 'build' : '',
'executing': executing,
};
Widget _host(Map<String, dynamic> run, {bool disableAnimations = false}) =>
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(disableAnimations: disableAnimations),
child: child!,
),
home: Scaffold(
body: SizedBox(
width: 900,
height: 700,
child: RunGraphView(
graph: linearGraph(),
run: run,
onStageSelected: (_) {},
),
),
),
);
Finder _node(String key) => find.byWidgetPredicate(
(widget) => widget is GraphStageNode && widget.node.key == key,
);
Finder _haloPainter() => find.byWidgetPredicate(
(widget) =>
widget is CustomPaint &&
widget.foregroundPainter is StageActivityHaloPainter,
);
StageActivityHaloPainter _painter(WidgetTester tester) =>
tester.widget<CustomPaint>(_haloPainter()).foregroundPainter!
as StageActivityHaloPainter;
void main() {
testWidgets('only the recorded current stage pulses while executing', (
tester,
) async {
await tester.pumpWidget(_host(_run(executing: true)));
await tester.pump();
await tester.pump();
await tester.pump();
expect(tester.widget<GraphStageNode>(_node('build')).active, isTrue);
for (final other in ['plan', 'ship', '#success', '#failure']) {
expect(
tester.widget<GraphStageNode>(_node(other)).active,
isFalse,
reason: '$other is not the run current stage',
);
}
expect(find.byType(StageActivityHalo), findsOneWidget);
expect(
find.descendant(
of: _node('build'),
matching: find.byType(StageActivityHalo),
),
findsOneWidget,
);
expect(tester.hasRunningAnimations, isTrue);
final before = _painter(tester).progress;
await tester.pump(const Duration(milliseconds: 400));
expect(_painter(tester).progress, isNot(closeTo(before, 0.01)));
expect(tester.hasRunningAnimations, isTrue);
expect(tester.takeException(), isNull);
});
testWidgets('a finished run shows no live activity', (tester) async {
await tester.pumpWidget(_host(_run(executing: false)));
await tester.pump();
await tester.pump();
await tester.pump();
for (final key in ['plan', 'build', 'ship']) {
expect(tester.widget<GraphStageNode>(_node(key)).active, isFalse);
}
expect(find.byType(StageActivityHalo), findsNothing);
expect(tester.hasRunningAnimations, isFalse);
expect(tester.takeException(), isNull);
});
testWidgets('reduced motion keeps a still ring on the current stage', (
tester,
) async {
await tester.pumpWidget(
_host(_run(executing: true), disableAnimations: true),
);
await tester.pump();
await tester.pump();
await tester.pump();
expect(tester.widget<GraphStageNode>(_node('build')).active, isTrue);
expect(find.byType(StageActivityHalo), findsOneWidget);
expect(tester.hasRunningAnimations, isFalse);
final still = _painter(tester).progress;
await tester.pump(const Duration(milliseconds: 800));
expect(_painter(tester).progress, still);
expect(tester.takeException(), isNull);
});
testWidgets('turning reduced motion on stops an existing pulse', (
tester,
) async {
await tester.pumpWidget(_host(_run(executing: true)));
await tester.pump();
await tester.pump();
await tester.pump();
expect(tester.hasRunningAnimations, isTrue);
await tester.pumpWidget(
_host(_run(executing: true), disableAnimations: true),
);
await tester.pump();
expect(tester.hasRunningAnimations, isFalse);
expect(find.byType(StageActivityHalo), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('the halo never changes the node box the layout measured', (
tester,
) async {
const node = GraphNode(key: 'build', terminal: false, stageIndex: 1);
final sizes = <Size>[];
for (final active in [false, true]) {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: GraphStageNode(
node: node,
active: active,
onSelected: (_) {},
),
),
),
),
);
await tester.pump();
sizes.add(tester.getSize(find.byType(GraphStageNode)));
}
expect(sizes[0], sizes[1]);
expect(tester.takeException(), isNull);
});
}
@@ -87,25 +87,26 @@ Widget _materialHost(
double scale = 1,
Size size = const Size(900, 700),
DateTime Function()? now,
bool disableAnimations = false,
}) {
return MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: TextScaler.linear(scale),
disableAnimations: disableAnimations,
),
child: child!,
),
home: Scaffold(
body: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: SizedBox(
width: size.width,
height: size.height,
child: RunGraphView(
graph: graph,
run: run,
selectedStage: selected,
onStageSelected: onSelected ?? (_) {},
now: now,
),
),
body: SizedBox(
width: size.width,
height: size.height,
child: RunGraphView(
graph: graph,
run: run,
selectedStage: selected,
onStageSelected: onSelected ?? (_) {},
now: now,
),
),
),
@@ -205,7 +206,9 @@ void main() {
});
testWidgets('the expanded run graph keeps the route legend', (tester) async {
await tester.pumpWidget(_materialHost(linearGraph(), _runningRun()));
await tester.pumpWidget(
_materialHost(linearGraph(), _runningRun(), disableAnimations: true),
);
await _settle(tester);
await tester.tap(find.byKey(const Key('graph-expand')));
await tester.pumpAndSettle();