407551b8bb
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.
489 lines
14 KiB
Dart
489 lines
14 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/semantics.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/graph/domain/graph_protocol.dart';
|
|
import 'package:pipelines_app/features/graph/viewport/graph_expanded_view.dart';
|
|
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
|
|
import 'package:pipelines_app/features/graph/widgets/run_graph_canvas.dart';
|
|
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
|
|
|
import '../domain/graph_fixtures.dart';
|
|
|
|
JsonMap _runningRun() => <String, dynamic>{
|
|
'id': 42,
|
|
'steps': <dynamic>[
|
|
step(
|
|
sequence: 1,
|
|
stage: 'plan',
|
|
status: 'completed',
|
|
outcome: 'success',
|
|
target: 'build',
|
|
),
|
|
step(
|
|
sequence: 2,
|
|
stage: 'build',
|
|
status: 'running',
|
|
startedAt: '2026-10-21T10:00:00Z',
|
|
),
|
|
],
|
|
'current_stage': 'build',
|
|
'executing': true,
|
|
};
|
|
|
|
JsonMap _finishedRun({String outcome = 'success', String target = '#'}) =>
|
|
<String, dynamic>{
|
|
'id': 43,
|
|
'steps': <dynamic>[
|
|
step(
|
|
sequence: 1,
|
|
stage: 'plan',
|
|
status: 'completed',
|
|
outcome: outcome,
|
|
target: target,
|
|
),
|
|
],
|
|
'current_stage': '',
|
|
'executing': false,
|
|
};
|
|
|
|
/// plan -> build -> ship, with the last recorded outcome resolving a terminal.
|
|
JsonMap _completedPath({bool failure = false}) => <String, dynamic>{
|
|
'id': 45,
|
|
'steps': <dynamic>[
|
|
step(
|
|
sequence: 1,
|
|
stage: 'plan',
|
|
status: 'completed',
|
|
outcome: 'success',
|
|
target: 'build',
|
|
),
|
|
step(
|
|
sequence: 2,
|
|
stage: 'build',
|
|
status: 'completed',
|
|
outcome: 'success',
|
|
target: 'ship',
|
|
),
|
|
step(
|
|
sequence: 3,
|
|
stage: 'ship',
|
|
status: 'completed',
|
|
outcome: failure ? 'error' : 'success',
|
|
target: '#',
|
|
),
|
|
],
|
|
'current_stage': '',
|
|
'executing': false,
|
|
};
|
|
|
|
Widget _materialHost(
|
|
JsonMap? graph,
|
|
JsonMap run, {
|
|
ValueChanged<String>? onSelected,
|
|
String? selected,
|
|
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: SizedBox(
|
|
width: size.width,
|
|
height: size.height,
|
|
child: RunGraphView(
|
|
graph: graph,
|
|
run: run,
|
|
selectedStage: selected,
|
|
onStageSelected: onSelected ?? (_) {},
|
|
now: now,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _cupertinoHost(
|
|
JsonMap graph,
|
|
JsonMap run, {
|
|
ValueChanged<String>? onSelected,
|
|
double scale = 1,
|
|
}) {
|
|
return CupertinoApp(
|
|
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
|
home: CupertinoPageScaffold(
|
|
child: Builder(
|
|
builder: (context) => MediaQuery(
|
|
data: MediaQuery.of(
|
|
context,
|
|
).copyWith(textScaler: TextScaler.linear(scale)),
|
|
child: SizedBox(
|
|
width: 320,
|
|
height: 700,
|
|
child: RunGraphView(
|
|
graph: graph,
|
|
run: run,
|
|
onStageSelected: onSelected ?? (_) {},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _settle(WidgetTester tester) async {
|
|
await tester.pump();
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
Finder _node(String key) => find.byWidgetPredicate(
|
|
(widget) => widget is GraphStageNode && widget.node.key == key,
|
|
);
|
|
|
|
void _expectNoOverlaps(WidgetTester tester) {
|
|
final rects = <Rect>[
|
|
for (final element in find.byType(GraphStageNode).evaluate())
|
|
tester.getRect(find.byWidget(element.widget)),
|
|
];
|
|
for (var a = 0; a < rects.length; a += 1) {
|
|
for (var b = a + 1; b < rects.length; b += 1) {
|
|
expect(
|
|
rects[a].overlaps(rects[b]),
|
|
isFalse,
|
|
reason: 'nodes $a and $b overlap: ${rects[a]} and ${rects[b]}',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('visited stages show recorded status and the legend', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_runningRun(),
|
|
now: () => DateTime.utc(2026, 10, 21, 10, 2, 5),
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
|
|
expect(find.text(runGraphExecuted), findsOneWidget);
|
|
expect(find.text(runGraphNotExecuted), findsOneWidget);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('plan')).recordedStatus,
|
|
'completed',
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
|
|
'running',
|
|
);
|
|
expect(tester.widget<GraphStageNode>(_node('ship')).recordedStatus, isNull);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(failureEnd)).recordedStatus,
|
|
isNull,
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(successEnd)).recordedStatus,
|
|
isNull,
|
|
);
|
|
// The elapsed line exists only because this run is still executing.
|
|
expect(find.text('Current stage build · elapsed 2m 5s'), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('the expanded run graph keeps the route legend', (tester) async {
|
|
await tester.pumpWidget(
|
|
_materialHost(linearGraph(), _runningRun(), disableAnimations: true),
|
|
);
|
|
await _settle(tester);
|
|
await tester.tap(find.byKey(const Key('graph-expand')));
|
|
await tester.pumpAndSettle();
|
|
|
|
final expanded = find.byType(GraphExpandedView);
|
|
expect(expanded, findsOneWidget);
|
|
for (final label in [runGraphExecuted, runGraphNotExecuted]) {
|
|
expect(
|
|
find.descendant(of: expanded, matching: find.text(label)),
|
|
findsOneWidget,
|
|
reason: 'the full-screen canvas must explain its routes: $label',
|
|
);
|
|
}
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('only routes the run took are executed and labelled', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_runningRun(),
|
|
now: () => DateTime.utc(2026, 10, 21, 10, 2, 5),
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
|
|
final layer = tester.widget<RunGraphEdgeLayer>(
|
|
find.byType(RunGraphEdgeLayer),
|
|
);
|
|
expect(
|
|
layer.executedRoutes.map((route) => '${route.source}/${route.target}'),
|
|
['plan/build'],
|
|
);
|
|
expect(layer.untakenRoutes, isNotEmpty);
|
|
expect(
|
|
layer.executedRoutes.every(
|
|
(route) => route.source == 'plan' && route.target == 'build',
|
|
),
|
|
isTrue,
|
|
);
|
|
// A run labels only what happened: the untaken success/error routes on
|
|
// build/ship carry no chips, including the implicit fallback `error*`.
|
|
expect(find.text('success'), findsOneWidget);
|
|
expect(find.text('error*'), findsNothing);
|
|
expect(find.text('error'), findsNothing);
|
|
});
|
|
|
|
testWidgets('a terminal is executed only when a visit resolved there', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_materialHost(linearGraph(), _completedPath()));
|
|
await _settle(tester);
|
|
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(successEnd)).recordedStatus,
|
|
'success',
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(failureEnd)).recordedStatus,
|
|
isNull,
|
|
);
|
|
// A finished run has no active-stage line even with a current_stage value.
|
|
expect(find.textContaining('Current stage'), findsNothing);
|
|
|
|
await tester.pumpWidget(
|
|
_materialHost(linearGraph(), _completedPath(failure: true)),
|
|
);
|
|
await _settle(tester);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(failureEnd)).recordedStatus,
|
|
'error',
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(successEnd)).recordedStatus,
|
|
isNull,
|
|
);
|
|
});
|
|
|
|
testWidgets(
|
|
'a visited stage reports its key and an unvisited node does not',
|
|
(tester) async {
|
|
final picked = <String>[];
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_finishedRun(),
|
|
onSelected: picked.add,
|
|
selected: 'plan',
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
|
|
final handle = tester.ensureSemantics();
|
|
expect(tester.widget<GraphStageNode>(_node('plan')).selected, isTrue);
|
|
final visited = tester.getSemantics(_node('plan')).getSemanticsData();
|
|
expect(visited.flagsCollection.isButton, isTrue);
|
|
expect(visited.hasAction(SemanticsAction.tap), isTrue);
|
|
final unvisited = tester.getSemantics(_node('build')).getSemanticsData();
|
|
expect(unvisited.flagsCollection.isButton, isFalse);
|
|
expect(unvisited.hasAction(SemanticsAction.tap), isFalse);
|
|
expect(unvisited.label, 'build');
|
|
await tester.tap(_node('plan'));
|
|
await tester.pump();
|
|
expect(picked, ['plan']);
|
|
|
|
// `build` was never recorded in this run: it is a plain label, not a
|
|
// button, and tapping it reports nothing (never a fabricated visit).
|
|
await tester.tap(_node('build'), warnIfMissed: false);
|
|
await tester.pump();
|
|
expect(picked, ['plan']);
|
|
expect(
|
|
find.ancestor(
|
|
of: _node('build'),
|
|
matching: find.byWidgetPredicate(
|
|
(widget) => widget is IgnorePointer && widget.ignoring,
|
|
),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
handle.dispose();
|
|
},
|
|
);
|
|
|
|
testWidgets('a changed recorded status remeasures instead of keeping a box', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_materialHost(linearGraph(), _runningRun()));
|
|
await _settle(tester);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
|
|
'running',
|
|
);
|
|
|
|
final changed = _runningRun();
|
|
(changed['steps'] as List)[1] = step(
|
|
sequence: 2,
|
|
stage: 'build',
|
|
status: 'blocked',
|
|
);
|
|
await tester.pumpWidget(_materialHost(linearGraph(), changed));
|
|
await _settle(tester);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
|
|
'blocked',
|
|
);
|
|
expect(find.byType(GraphStageNode), findsNWidgets(5));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('a missing or stage-less graph states the server wording', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_materialHost(null, _finishedRun()));
|
|
await tester.pump();
|
|
expect(find.text(runGraphMissing), findsOneWidget);
|
|
expect(find.byType(InteractiveViewer), findsNothing);
|
|
|
|
await tester.pumpWidget(
|
|
_materialHost(<String, dynamic>{'stages': <dynamic>[]}, _finishedRun()),
|
|
);
|
|
await tester.pump();
|
|
expect(find.text(runGraphMissing), findsOneWidget);
|
|
expect(find.byType(InteractiveViewer), findsNothing);
|
|
});
|
|
|
|
testWidgets('executed routes keep success-first, error-last order', (
|
|
tester,
|
|
) async {
|
|
final graph = <String, dynamic>{
|
|
'stages': <dynamic>[
|
|
stage('a', edges: <String, String?>{'error': 'b', 'success': 'c'}),
|
|
stage('b', edges: <String, String?>{'success': '#failure'}),
|
|
stage('c', edges: <String, String?>{'success': '#success'}),
|
|
],
|
|
};
|
|
final run = <String, dynamic>{
|
|
'id': 44,
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'a', outcome: 'error', target: 'b'),
|
|
step(sequence: 2, stage: 'a', outcome: 'success', target: 'c'),
|
|
],
|
|
'current_stage': 'a',
|
|
'executing': false,
|
|
};
|
|
await tester.pumpWidget(_materialHost(graph, run));
|
|
await _settle(tester);
|
|
|
|
final layer = tester.widget<RunGraphEdgeLayer>(
|
|
find.byType(RunGraphEdgeLayer),
|
|
);
|
|
expect(layer.executedRoutes.map((route) => route.outcome), [
|
|
'success',
|
|
'error',
|
|
]);
|
|
});
|
|
|
|
testWidgets('320px at 2x text re-measures and keeps a deterministic layout', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(320, 700);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_runningRun(),
|
|
scale: 2,
|
|
size: const Size(320, 700),
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
final first = {
|
|
for (final element in find.byType(GraphStageNode).evaluate())
|
|
(element.widget as GraphStageNode).node.key: tester.getRect(
|
|
find.byWidget(element.widget),
|
|
),
|
|
};
|
|
_expectNoOverlaps(tester);
|
|
expect(first.values.every((rect) => rect.width <= 320), isTrue);
|
|
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_runningRun(),
|
|
scale: 2,
|
|
size: const Size(320, 700),
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
final second = {
|
|
for (final element in find.byType(GraphStageNode).evaluate())
|
|
(element.widget as GraphStageNode).node.key: tester.getRect(
|
|
find.byWidget(element.widget),
|
|
),
|
|
};
|
|
expect(second, first);
|
|
_expectNoOverlaps(tester);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('dark Cupertino host keeps native nodes and evidence', (
|
|
tester,
|
|
) async {
|
|
final picked = <String>[];
|
|
await tester.pumpWidget(
|
|
_cupertinoHost(linearGraph(), _runningRun(), onSelected: picked.add),
|
|
);
|
|
await _settle(tester);
|
|
|
|
expect(find.byType(Card), findsNothing);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(GraphStageNode),
|
|
matching: find.byType(CupertinoButton),
|
|
),
|
|
findsNWidgets(5),
|
|
);
|
|
expect(find.text(runGraphExecuted), findsOneWidget);
|
|
expect(find.text(runGraphNotExecuted), findsOneWidget);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('plan')).recordedStatus,
|
|
'completed',
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
|
|
'running',
|
|
);
|
|
_expectNoOverlaps(tester);
|
|
|
|
await tester.tap(_node('plan'));
|
|
await tester.pump();
|
|
expect(picked, ['plan']);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|