From f84139b665fbcb144c9c60ef284db3055e49a54f Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Tue, 16 Jul 2024 18:44:22 +0800 Subject: [PATCH] Add tests for curve2_d.0.dart (#150984) Contributes to https://github.com/flutter/flutter/issues/130459 It adds a test for - `examples/api/lib/animation/curves/curve2_d.0.dart` --- dev/bots/check_code_samples.dart | 1 - dev/bots/test/check_code_samples_test.dart | 10 ----- .../animation/curves/curve2_d.0_test.dart | 40 +++++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 examples/api/test/animation/curves/curve2_d.0_test.dart diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 37263348dc..ad86ad037e 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -378,6 +378,5 @@ final Set _knownMissingTests = { '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', }; diff --git a/dev/bots/test/check_code_samples_test.dart b/dev/bots/test/check_code_samples_test.dart index c72c39010d..262db907a4 100644 --- a/dev/bots/test/check_code_samples_test.dart +++ b/dev/bots/test/check_code_samples_test.dart @@ -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) @@ -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); } } @@ -144,20 +138,16 @@ void main() { final String lines = [ '╔═╡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:', diff --git a/examples/api/test/animation/curves/curve2_d.0_test.dart b/examples/api/test/animation/curves/curve2_d.0_test.dart new file mode 100644 index 0000000000..e0bc505455 --- /dev/null +++ b/examples/api/test/animation/curves/curve2_d.0_test.dart @@ -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 expectedOffsets= [ + 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)); + } + }); +}