import 'package:pipelines_app/features/graph/domain/graph_definition.dart'; import 'package:pipelines_app/features/graph/layout/graph_node_layout.dart'; import 'package:pipelines_app/features/graph/layout/layout_models.dart'; import 'package:pipelines_app/features/graph/routing/graph_edge_routing.dart'; import 'package:pipelines_app/features/graph/routing/route_models.dart'; import '../layout/layout_fixtures.dart' as layout; import '../domain/graph_fixtures.dart' as domain; /// Definitions, measured extents and configs shared by the routing tests. GraphLayoutConfig routingLayoutConfig({ double columnGap = 80, double rowGap = 16, double padding = 8, }) { return GraphLayoutConfig( columnGap: columnGap, rowGap: rowGap, padding: padding, ); } RoutingConfig routingConfig({ double nodeClearance = 8, double laneSpacing = 28, double corridorSpacing = 20, double portSpacing = 12, double labelGap = 4, double boundsPadding = 4, }) { return RoutingConfig( nodeClearance: nodeClearance, laneSpacing: laneSpacing, corridorSpacing: corridorSpacing, portSpacing: portSpacing, labelGap: labelGap, boundsPadding: boundsPadding, ); } GraphLayout layoutFor( Map graph, { Map? extents, GraphLayoutConfig? config, }) { final nodes = graphNodes(graph); return layoutGraphNodes( nodes: nodes, edges: graphEdges(graph), extents: extents ?? layout.uniformExtents(nodes), config: config ?? routingLayoutConfig(), ); } /// Measured label boxes sized from their text, as a renderer would supply them. Map labelsFor( Iterable edges, { double charWidth = 7, double padding = 12, double height = 18, }) { return { for (final edge in edges) edge.id: LabelExtent( width: edge.label.length * charWidth + padding, height: height, ), }; } /// One box per edge at an explicit size, used for wide-label checks. Map fixedLabels( Iterable edges, { double width = 52, double height = 18, }) { return { for (final edge in edges) edge.id: LabelExtent(width: width, height: height), }; } GraphRouting routeFor( Map graph, { Map? extents, Map? labels, GraphLayoutConfig? layoutConfig, RoutingConfig? config, }) { final layout = layoutFor(graph, extents: extents, config: layoutConfig); final edges = graphEdges(graph); return routeGraphEdges( layout: layout, edges: edges, labelExtents: labels ?? labelsFor(edges), config: config ?? routingConfig(), ); } /// Three outcomes from `a` to the same target `b`, then `b` to Success. Map parallelOutcomesGraph() => { 'stages': [ domain.stage( 'a', edges: { 'success': 'b', 'approved': 'b', 'rejected': 'b', }, ), domain.stage('b', edges: {'success': '#success'}), ], }; /// A single stage that retries itself and has no terminal pair. Map selfLoopOnlyGraph() => { 'stages': [ domain.stage('a', edges: {'retry': 'a'}), ], }; Map chainGraphFixture() => layout.chainGraph(4); Map diamondGraphFixture() => layout.diamondGraphFixture(); Map cycleGraphFixture() => layout.cycleGraph(); Map selfLoopGraphFixture() => layout.selfLoopGraphFixture(); Map disconnectedGraphFixture() => layout.disconnectedGraph(); Map incompleteGraphFixture() => layout.incompleteGraphFixture(); /// Three stages in one strongly connected component with no terminals. Map cycleThreeGraph() => { 'stages': [ domain.stage('a', edges: {'success': 'b'}), domain.stage('b', edges: {'success': 'c'}), domain.stage('c', edges: {'success': 'a'}), ], };