import 'package:pipelines_app/features/graph/domain/graph_definition.dart'; import 'package:pipelines_app/features/graph/domain/graph_protocol.dart'; import 'package:pipelines_app/features/graph/layout/layout_models.dart'; import '../domain/graph_fixtures.dart' as domain; /// Small definitions and measured extents shared by the layout tests. GraphLayoutConfig layoutConfig({ double columnGap = 24, double rowGap = 12, double padding = 4, }) { return GraphLayoutConfig( columnGap: columnGap, rowGap: rowGap, padding: padding, ); } /// One measured size for every node, optionally scaled to simulate text growth. Map uniformExtents( Iterable nodes, { double width = 120, double height = 60, double scale = 1, }) { return { for (final node in nodes) node.key: NodeExtent(width: width * scale, height: height * scale), }; } Map scaledExtents( Map base, double scale, ) { return { for (final entry in base.entries) entry.key: NodeExtent( width: entry.value.width * scale, height: entry.value.height * scale, ), }; } /// Deliberately uneven measured boxes for the diamond definition. Map heterogeneousExtents() { return { 'a': NodeExtent(width: 210, height: 84), 'b': NodeExtent(width: 92, height: 44), 'c': NodeExtent(width: 148, height: 126), 'd': NodeExtent(width: 104, height: 58), failureEnd: NodeExtent(width: 72, height: 34), successEnd: NodeExtent(width: 228, height: 96), }; } /// Two stages in a cycle; both terminals are reached from inside the cycle. Map cycleGraph() => { 'stages': [ domain.stage( 'a', edges: {'success': 'b', 'error': '#'}, fallbackError: true, ), domain.stage( 'b', edges: {'success': 'a', 'error': '#success'}, ), ], }; /// Two independent routes and a stage with no edges at all. Map disconnectedGraph() => { 'stages': [ domain.stage('a', edges: {'success': '#success'}), domain.stage('b', edges: {'success': '#failure'}), domain.stage('c'), ], }; Map linearGraphFixture() => domain.linearGraph(); Map diamondGraphFixture() => domain.diamondGraph(); Map selfLoopGraphFixture() => domain.selfLoopGraph(); Map incompleteGraphFixture() => domain.incompleteGraph(); /// A long chain, used to prove the iterative rank walk cannot overflow. Map chainGraph(int length) => { 'stages': [ for (var index = 0; index < length; index += 1) domain.stage( 's$index', edges: { 'success': index + 1 < length ? 's${index + 1}' : '#success', }, ), ], };