import 'package:flutter_test/flutter_test.dart'; 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 'layout_fixtures.dart'; /// Invalid and boundary input for the pure layout engine. void main() { test('an empty definition yields empty padded bounds', () { final layout = layoutGraphNodes( nodes: const [], edges: const [], extents: const {}, config: layoutConfig(columnGap: 30, rowGap: 10, padding: 6), ); expect(layout.isEmpty, isTrue); expect(layout.rankCount, 0); expect(layout.width, 12); expect(layout.height, 12); expect(layout.ranks, isEmpty); }); test('missing measurements are reported rather than invented', () { final graph = linearGraphFixture(); final nodes = graphNodes(graph); final extents = uniformExtents(nodes)..remove('build'); expect( () => layoutGraphNodes( nodes: nodes, edges: graphEdges(graph), extents: extents, config: layoutConfig(), ), throwsArgumentError, ); }); test('extra measurements are ignored because they cannot become nodes', () { final graph = linearGraphFixture(); final nodes = graphNodes(graph); final extents = uniformExtents(nodes) ..['ghost'] = NodeExtent(width: 20, height: 20); final layout = layoutGraphNodes( nodes: nodes, edges: graphEdges(graph), extents: extents, config: layoutConfig(), ); expect(layout.nodeFor('ghost'), isNull); expect(layout.nodes.length, nodes.length); }); test('duplicate or empty node keys are rejected', () { const stageNode = GraphNode(key: 'a', terminal: false, stageIndex: 0); expect( () => layoutGraphNodes( nodes: const [stageNode, stageNode], edges: const [], extents: {'a': NodeExtent(width: 10, height: 10)}, config: layoutConfig(), ), throwsArgumentError, ); expect( () => layoutGraphNodes( nodes: const [ GraphNode(key: '', terminal: false, stageIndex: 0), ], edges: const [], extents: const {}, config: layoutConfig(), ), throwsArgumentError, ); }); test('invalid gaps and extents are rejected', () { expect( () => GraphLayoutConfig(columnGap: -1, rowGap: 8), throwsArgumentError, ); expect( () => GraphLayoutConfig(columnGap: 8, rowGap: double.nan), throwsArgumentError, ); expect( () => NodeExtent(width: double.infinity, height: 10), throwsArgumentError, ); }); }