Files
pipelines/app/test/features/graph/layout/graph_layout_validation_test.dart
alan c1f140bc78 feat(app): add deterministic content-sized graph node layout
Pure-Dart SCC ranking and column placement over the landed graph
identities. Every extent and gap is caller supplied; missing
measurements are rejected rather than defaulted.

Focused tests cover linear, diamond, cycle, self-loop, disconnected,
terminal, expanded-text and invalid-input cases.
2026-10-21 16:25:17 +01:00

97 lines
2.8 KiB
Dart

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 <GraphNode>[],
edges: const <GraphEdge>[],
extents: const <String, NodeExtent>{},
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 <GraphNode>[stageNode, stageNode],
edges: const <GraphEdge>[],
extents: <String, NodeExtent>{'a': NodeExtent(width: 10, height: 10)},
config: layoutConfig(),
),
throwsArgumentError,
);
expect(
() => layoutGraphNodes(
nodes: const <GraphNode>[
GraphNode(key: '', terminal: false, stageIndex: 0),
],
edges: const <GraphEdge>[],
extents: const <String, NodeExtent>{},
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,
);
});
}