Skip to content

Commit

Permalink
Add tests for curve2_d.0.dart (#150984)
Browse files Browse the repository at this point in the history
Contributes to flutter/flutter#130459

It adds a test for
- `examples/api/lib/animation/curves/curve2_d.0.dart`
  • Loading branch information
ValentinVignal authored Jul 16, 2024
1 parent fde0418 commit f84139b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
1 change: 0 additions & 1 deletion dev/bots/check_code_samples.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,5 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/widgets/actions/focusable_action_detector.0_test.dart',
'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart',
'examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart',
'examples/api/test/animation/curves/curve2_d.0_test.dart',
'examples/api/test/gestures/pointer_signal_resolver/pointer_signal_resolver.0_test.dart',
};
10 changes: 0 additions & 10 deletions dev/bots/test/check_code_samples_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ void main() {
final File barExample = examplesLib.childFile('bar_example.0.dart')
..createSync(recursive: true)
..writeAsStringSync('// Example for bar');
final File curvesExample =
examples.childDirectory('lib').childDirectory('animation').childDirectory('curves').childFile('curve2_d.0.dart')
..createSync(recursive: true)
..writeAsStringSync('// Missing a test, but OK');
if (missingLinks) {
examplesLib.childFile('missing_example.0.dart')
..createSync(recursive: true)
Expand All @@ -77,11 +73,9 @@ void main() {
if (malformedLinks) {
writeLink(source: flutterPackage.childDirectory('layer').childFile('foo.dart'), example: fooExample, alternateLink: '*See Code *');
writeLink(source: flutterPackage.childDirectory('layer').childFile('bar.dart'), example: barExample, alternateLink: ' ** See code examples/api/lib/layer/bar_example.0.dart **');
writeLink(source: flutterPackage.childDirectory('animation').childFile('curves.dart'), example: curvesExample, alternateLink: '* see code in examples/api/lib/animation/curves/curve2_d.0.dart *');
} else {
writeLink(source: flutterPackage.childDirectory('layer').childFile('foo.dart'), example: fooExample);
writeLink(source: flutterPackage.childDirectory('layer').childFile('bar.dart'), example: barExample);
writeLink(source: flutterPackage.childDirectory('animation').childFile('curves.dart'), example: curvesExample);
}
}

Expand Down Expand Up @@ -144,20 +138,16 @@ void main() {
final String lines = <String>[
'╔═╡ERROR #1╞════════════════════════════════════════════════════════════════════',
'║ The following examples are not linked from any source file API doc comments:',
if (!isWindows) '║ examples/api/lib/animation/curves/curve2_d.0.dart',
if (!isWindows) '║ examples/api/lib/layer/foo_example.0.dart',
if (!isWindows) '║ examples/api/lib/layer/bar_example.0.dart',
if (isWindows) r'║ examples\api\lib\animation\curves\curve2_d.0.dart',
if (isWindows) r'║ examples\api\lib\layer\foo_example.0.dart',
if (isWindows) r'║ examples\api\lib\layer\bar_example.0.dart',
'║ Either link them to a source file API doc comment, or remove them.',
'╚═══════════════════════════════════════════════════════════════════════════════',
'╔═╡ERROR #2╞════════════════════════════════════════════════════════════════════',
'║ The following malformed links were found in API doc comments:',
if (!isWindows) '║ /flutter sdk/packages/flutter/lib/src/animation/curves.dart:6: ///* see code in examples/api/lib/animation/curves/curve2_d.0.dart *',
if (!isWindows) '║ /flutter sdk/packages/flutter/lib/src/layer/foo.dart:6: ///*See Code *',
if (!isWindows) '║ /flutter sdk/packages/flutter/lib/src/layer/bar.dart:6: /// ** See code examples/api/lib/layer/bar_example.0.dart **',
if (isWindows) r'║ C:\flutter sdk\packages\flutter\lib\src\animation\curves.dart:6: ///* see code in examples/api/lib/animation/curves/curve2_d.0.dart *',
if (isWindows) r'║ C:\flutter sdk\packages\flutter\lib\src\layer\foo.dart:6: ///*See Code *',
if (isWindows) r'║ C:\flutter sdk\packages\flutter\lib\src\layer\bar.dart:6: /// ** See code examples/api/lib/layer/bar_example.0.dart **',
'║ Correct the formatting of these links so that they match the exact pattern:',
Expand Down
40 changes: 40 additions & 0 deletions examples/api/test/animation/curves/curve2_d.0_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter_api_samples/animation/curves/curve2_d.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('The buzz widget should move around', (WidgetTester tester) async {
await tester.pumpWidget(
const example.Curve2DExampleApp(),
);

final Finder textFinder = find.widgetWithText(CircleAvatar, 'B');
expect(tester.getCenter(textFinder), const Offset(58, 440));

const List<Offset> expectedOffsets= <Offset>[
Offset(43, 407),
Offset(81, 272),
Offset(185, 103),
Offset(378, 92),
Offset(463, 392),
Offset(479, 124),
Offset(745, 389),
Offset(450, 555),
Offset(111, 475),
Offset(58, 440),
Offset(43, 407),
];

const int steps = 10;
for (int i = 0; i <= steps; i++) {
await tester.pump(const Duration(seconds: 3) * (1 / steps));
final Offset center = tester.getCenter(textFinder);
expect(center.dx, moreOrLessEquals(expectedOffsets[i].dx, epsilon: 1));
expect(center.dy, moreOrLessEquals(expectedOffsets[i].dy, epsilon: 1));
}
});
}

0 comments on commit f84139b

Please sign in to comment.