Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Avoid repeated tree searches in pane layout tests (#676)

Deed79827f3de0d
diff --git a/desktop/test/pane_preset_test.dart b/desktop/test/pane_preset_test.dart
index 93c291323..a9bbdd191 100644
--- a/desktop/test/pane_preset_test.dart
+++ b/desktop/test/pane_preset_test.dart
@@ -43,8 +43,20 @@ Future<List<Rect>> _layout(
);
await tester.pump();
final grid = tester.getRect(find.byType(PaneGrid));
+ // Find every cell in one tree walk instead of scanning the whole tree twice
+ // per pane. Preserve the finder's offstage filtering and require each key
+ // exactly once before measuring the same rendered corners as getRect.
+ final cellKeys = {for (final pane in notifier.panes) pane.cellKey};
+ final cells = find
+ .byWidgetPredicate((widget) => cellKeys.contains(widget.key))
+ .evaluate()
+ .toList();
+ expect(cells.map((cell) => cell.widget.key), unorderedEquals(cellKeys));
+ final rectanglesByKey = {
+ for (final cell in cells) cell.widget.key: _cellRect(cell),
+ };
final rectangles = [
- for (final pane in notifier.panes) tester.getRect(find.byKey(pane.cellKey)),
+ for (final pane in notifier.panes) rectanglesByKey[pane.cellKey]!,
];
final height = rectangles.fold<double>(
grid.height,
@@ -63,6 +75,14 @@ Future<List<Rect>> _layout(
];
}
+Rect _cellRect(Element cell) {
+ final box = cell.renderObject! as RenderBox;
+ return Rect.fromPoints(
+ box.localToGlobal(Offset.zero),
+ box.localToGlobal(box.size.bottomRight(Offset.zero)),
+ );
+}
+
/// Dividers eat a few pixels, so an edge lands near its fraction, not on it.
/// 0.02 of 1600px is 32px — wide enough for any divider, far too narrow to let
/// a half pass as a third.