Skip to content

Commit

Permalink
[dynamic_layouts] relax layout test to fix tree (#4677)
Browse files Browse the repository at this point in the history
A current roll from the engine to flutter/flutter to packages has broken this test value by a small amount. 

I wrote a small function to manage tolerances.

Let me know if this is a reasonable way to manage this for now.
  • Loading branch information
tarrinneal authored Aug 10, 2023
1 parent 8248ef2 commit 9b15c2e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .ci/flutter_master.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f4c25bbb351cc59ffdefe980c0c993196a8a6d47
685141bf3b5ff4a90589fd77784776e011dd5fcc
56 changes: 35 additions & 21 deletions packages/dynamic_layouts/example/test/wrap_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,33 @@
// found in the LICENSE file.

import 'package:example/wrap_layout_example.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
void withinTolerance(Offset actual, Offset expected, double tolerance) {
expect(
actual.dx,
(double actual) => actual <= expected.dx + tolerance,
reason: '${actual.dx} <= ${expected.dx + tolerance}',
);
expect(
actual.dx,
(double actual) => actual >= expected.dx - tolerance,
reason: '${actual.dx} >= ${expected.dx - tolerance}',
);
expect(
actual.dy,
(double actual) => actual <= expected.dy + tolerance,
reason: '${actual.dy} <= ${expected.dy + tolerance}',
);
expect(
actual.dy,
(double actual) => actual >= expected.dy - tolerance,
reason: '${actual.dy} >= ${expected.dy - tolerance}',
);
}

testWidgets('Check that the children are layed out.',
(WidgetTester tester) async {
const MaterialApp app = MaterialApp(
Expand All @@ -25,27 +47,19 @@ void main() {

// Material 3 changes the expected layout positioning.
final bool usesMaterial3 = (app.theme ?? ThemeData.light()).useMaterial3;
final Offset offset0 = usesMaterial3
? Offset(0.0, _getExpectedYOffset(91.0))
: const Offset(0.0, 103.0);
final Offset offset1 = usesMaterial3
? Offset(65.0, _getExpectedYOffset(121.0))
: const Offset(66.0, 124.0);
final Offset offset3 = usesMaterial3
? Offset(270.0, _getExpectedYOffset(171.0))
: const Offset(271.0, 174.0);
final Offset offset4 = usesMaterial3
? Offset(380.0, _getExpectedYOffset(221.0))
: const Offset(381.0, 224.0);
final Offset offset0 =
usesMaterial3 ? const Offset(0.0, 91.0) : const Offset(0.0, 103.0);
final Offset offset1 =
usesMaterial3 ? const Offset(65.0, 121.0) : const Offset(66.0, 124.0);
final Offset offset3 =
usesMaterial3 ? const Offset(270.0, 171.0) : const Offset(271.0, 174.0);
final Offset offset4 =
usesMaterial3 ? const Offset(380.0, 221.0) : const Offset(381.0, 224.0);

// See if they are in expected position.
expect(tester.getTopLeft(find.text('Index 0')), offset0);
expect(tester.getTopLeft(find.text('Index 1')), offset1);
expect(tester.getTopLeft(find.text('Index 3')), offset3);
expect(tester.getTopLeft(find.text('Index 4')), offset4);
withinTolerance(tester.getTopLeft(find.text('Index 0')), offset0, 0.2);
withinTolerance(tester.getTopLeft(find.text('Index 1')), offset1, 0.2);
withinTolerance(tester.getTopLeft(find.text('Index 3')), offset3, 0.2);
withinTolerance(tester.getTopLeft(find.text('Index 4')), offset4, 0.2);
});
}

double _getExpectedYOffset(double nonWeb) {
return kIsWeb ? nonWeb - 0.5 : nonWeb;
}

0 comments on commit 9b15c2e

Please sign in to comment.