Files
alan 407551b8bb 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.
2026-10-22 17:17:39 +01:00

186 lines
5.4 KiB
Dart

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);
});
}