merge(app): land run-mode graph evidence component
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/features/graph/routing/route_models.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/run_graph_canvas.dart';
|
||||
|
||||
import '../painting/edge_layer_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
const executedColor = Colors.blue;
|
||||
const untakenColor = Colors.grey;
|
||||
final executed = edgeRoute(
|
||||
points: const [RoutePoint(10, 20), RoutePoint(90, 20)],
|
||||
);
|
||||
final untaken = edgeRoute(
|
||||
points: const [
|
||||
RoutePoint(10, 40),
|
||||
RoutePoint(40, 40),
|
||||
RoutePoint(40, 70),
|
||||
RoutePoint(90, 70),
|
||||
],
|
||||
);
|
||||
|
||||
test(
|
||||
'draws solid arrowed taken routes and dashed arrowless untaken routes',
|
||||
() {
|
||||
final canvas = TestRecordingCanvas();
|
||||
RunGraphEdgePainter(
|
||||
executedRoutes: [executed],
|
||||
untakenRoutes: [untaken],
|
||||
executedColor: executedColor,
|
||||
untakenColor: untakenColor,
|
||||
strokeWidth: 1,
|
||||
).paint(canvas, const Size(120, 90));
|
||||
|
||||
final draws = canvas.invocations
|
||||
.where((call) => call.invocation.memberName == #drawPath)
|
||||
.toList();
|
||||
final paints = [
|
||||
for (final call in draws)
|
||||
call.invocation.positionalArguments.last as Paint,
|
||||
];
|
||||
// One dashed path behind, then one solid line and one filled arrow.
|
||||
expect(draws, hasLength(3));
|
||||
expect(paints[0].style, PaintingStyle.stroke);
|
||||
expect(paints[0].color.toARGB32(), untakenColor.toARGB32());
|
||||
expect(paints[1].style, PaintingStyle.stroke);
|
||||
expect(paints[1].color.toARGB32(), executedColor.toARGB32());
|
||||
expect(paints[2].style, PaintingStyle.fill);
|
||||
expect(paints[2].color.toARGB32(), executedColor.toARGB32());
|
||||
|
||||
final clip = canvas.invocations.singleWhere(
|
||||
(call) => call.invocation.memberName == #clipRect,
|
||||
);
|
||||
expect(
|
||||
clip.invocation.positionalArguments.first,
|
||||
const Rect.fromLTWH(0, 0, 120, 90),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('an untaken route is broken into dashes and never an arrow', () {
|
||||
final canvas = TestRecordingCanvas();
|
||||
final painter = RunGraphEdgePainter(
|
||||
executedRoutes: const [],
|
||||
untakenRoutes: [untaken],
|
||||
executedColor: executedColor,
|
||||
untakenColor: untakenColor,
|
||||
strokeWidth: 1,
|
||||
);
|
||||
painter.paint(canvas, const Size(120, 90));
|
||||
|
||||
final paints = canvas.invocations
|
||||
.where((call) => call.invocation.memberName == #drawPath)
|
||||
.map((call) => call.invocation.positionalArguments.last as Paint);
|
||||
expect(paints, hasLength(1));
|
||||
expect(paints.single.style, PaintingStyle.stroke);
|
||||
expect(painter.dashedPath(untaken).computeMetrics().length, greaterThan(1));
|
||||
});
|
||||
|
||||
test('is passive and repaints only for a real change', () {
|
||||
final painter = RunGraphEdgePainter(
|
||||
executedRoutes: [executed],
|
||||
untakenRoutes: [untaken],
|
||||
executedColor: executedColor,
|
||||
untakenColor: untakenColor,
|
||||
strokeWidth: 1,
|
||||
);
|
||||
expect(painter.hitTest(const Offset(50, 20)), isFalse);
|
||||
expect(painter.hitTest(const Offset(500, 500)), isFalse);
|
||||
expect(
|
||||
painter.shouldRepaint(
|
||||
RunGraphEdgePainter(
|
||||
executedRoutes: [executed],
|
||||
untakenRoutes: [untaken],
|
||||
executedColor: executedColor,
|
||||
untakenColor: untakenColor,
|
||||
strokeWidth: 1,
|
||||
),
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
painter.shouldRepaint(
|
||||
RunGraphEdgePainter(
|
||||
executedRoutes: [executed],
|
||||
untakenRoutes: const [],
|
||||
executedColor: executedColor,
|
||||
untakenColor: untakenColor,
|
||||
strokeWidth: 1,
|
||||
),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
painter.shouldRepaint(
|
||||
RunGraphEdgePainter(
|
||||
executedRoutes: [executed],
|
||||
untakenRoutes: [untaken],
|
||||
executedColor: Colors.green,
|
||||
untakenColor: untakenColor,
|
||||
strokeWidth: 1,
|
||||
),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('sizes itself from the supplied graph canvas', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Center(
|
||||
child: RunGraphEdgeLayer(
|
||||
executedRoutes: [executed],
|
||||
untakenRoutes: [untaken],
|
||||
canvasSize: const Size(120, 90),
|
||||
executedColor: executedColor,
|
||||
untakenColor: untakenColor,
|
||||
strokeWidth: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.getSize(find.byType(RunGraphEdgeLayer)), const Size(120, 90));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
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/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,
|
||||
}) {
|
||||
return MaterialApp(
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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('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.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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user