feat(app): graph pan, zoom and expanded view

This commit is contained in:
2026-10-22 02:05:20 +01:00
parent d5f24b8259
commit cc7eba59b6
19 changed files with 2622 additions and 200 deletions
@@ -82,6 +82,22 @@ Finder _node(String key) => find.byWidgetPredicate(
(widget) => widget is GraphStageNode && widget.node.key == key,
);
/// The graph-space extent of a placed node.
///
/// The viewport fits the measured graph into the available box, so an onstage
/// node's rectangle is its measured extent times the current scale. Dividing
/// the rectangle by that scale keeps these assertions about measurement rather
/// than about the viewport transform.
Size _measuredNodeSize(WidgetTester tester, String key) {
final scale = tester
.widget<InteractiveViewer>(find.byType(InteractiveViewer))
.transformationController!
.value
.getMaxScaleOnAxis();
final rect = _nodeRect(tester, key);
return Size(rect.width / scale, rect.height / scale);
}
Rect _nodeRect(WidgetTester tester, String key) => tester.getRect(_node(key));
Future<void> _tapNode(WidgetTester tester, String key) async {
@@ -123,11 +139,11 @@ void main() {
addTearDown(tester.view.reset);
await tester.pumpWidget(_materialHost(_longKeyGraph()));
await _settle(tester);
final wide = _nodeRect(tester, _longKey);
final wide = _measuredNodeSize(tester, _longKey);
tester.view.physicalSize = const Size(320, 700);
await tester.pump();
await _settle(tester);
final narrow = _nodeRect(tester, _longKey);
final narrow = _measuredNodeSize(tester, _longKey);
expect(narrow.width, lessThan(wide.width));
expect(narrow.width, lessThanOrEqualTo(320));
expect(narrow.height, greaterThan(wide.height));
@@ -156,6 +172,42 @@ void main() {
expect(picked, ['plan', '#success']);
});
testWidgets('a tap after zoom selects the node under the pointer', (
tester,
) async {
final picked = <String>[];
await tester.pumpWidget(
_materialHost(linearGraph(), onSelected: picked.add),
);
await _settle(tester);
final controller = tester
.widget<InteractiveViewer>(find.byType(InteractiveViewer))
.transformationController!;
final fitted = controller.value.getMaxScaleOnAxis();
// Scale about the node's own on-screen point, as a pinch there would.
final viewportRect = tester.getRect(find.byType(InteractiveViewer));
final anchor = _nodeRect(tester, 'build').center - viewportRect.topLeft;
final zoom = Matrix4.identity()
..translateByDouble(anchor.dx, anchor.dy, 0, 1)
..scaleByDouble(1.6, 1.6, 1.6, 1)
..translateByDouble(-anchor.dx, -anchor.dy, 0, 1);
controller.value = zoom * controller.value;
await tester.pump();
expect(controller.value.getMaxScaleOnAxis(), greaterThan(fitted));
// The node's on-screen rectangle already carries the transform, so this
// tap lands where the node is drawn rather than at its graph coordinate.
final build = _nodeRect(tester, 'build');
expect(
tester.getRect(find.byType(InteractiveViewer)).contains(build.center),
isTrue,
);
await tester.tapAt(build.center);
await tester.pump();
expect(picked, ['build']);
});
testWidgets('nodes use measured native sizes and never overlap', (
tester,
) async {
@@ -194,13 +246,13 @@ void main() {
final graph = linearGraph();
await tester.pumpWidget(_materialHost(graph));
await _settle(tester);
final oneX = _nodeRect(tester, 'plan');
final oneX = _measuredNodeSize(tester, 'plan');
final oneXLabel = tester.getRect(find.text('error*'));
await tester.pumpWidget(_materialHost(graph, scale: 2));
await _settle(tester);
final twoX = _nodeRect(tester, 'plan');
final twoX = _measuredNodeSize(tester, 'plan');
expect(twoX.height, greaterThan(oneX.height));
expect(twoX.width, greaterThan(oneX.width));
expect(
@@ -248,7 +300,13 @@ void main() {
);
await _settle(tester);
expect(find.byType(CupertinoButton), findsNWidgets(5));
expect(
find.descendant(
of: find.byType(GraphStageNode),
matching: find.byType(CupertinoButton),
),
findsNWidgets(5),
);
expect(find.byType(Card), findsNothing);
_expectNoOverlaps(tester);
@@ -5,6 +5,7 @@ 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';
@@ -203,6 +204,24 @@ void main() {
expect(tester.takeException(), isNull);
});
testWidgets('the expanded run graph keeps the route legend', (tester) async {
await tester.pumpWidget(_materialHost(linearGraph(), _runningRun()));
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 {
@@ -439,7 +458,13 @@ void main() {
await _settle(tester);
expect(find.byType(Card), findsNothing);
expect(find.byType(CupertinoButton), findsNWidgets(5));
expect(
find.descendant(
of: find.byType(GraphStageNode),
matching: find.byType(CupertinoButton),
),
findsNWidgets(5),
);
expect(find.text(runGraphExecuted), findsOneWidget);
expect(find.text(runGraphNotExecuted), findsOneWidget);
expect(