-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test for animated_fractionally_sized_box.0.dart API example. #146721
Merged
auto-submit
merged 2 commits into
flutter:master
from
ksokolovskyi:add-animated-fractionally-sized-box-example-tests
May 1, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
examples/api/test/widgets/implicit_animations/animated_fractionally_sized_box.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// 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 'dart:ui'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/implicit_animations/animated_fractionally_sized_box.0.dart' | ||
as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets( | ||
'AnimatedFractionallySizedBox animates on tap', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.AnimatedFractionallySizedBoxExampleApp(), | ||
); | ||
|
||
final Finder fractionallySizedBoxFinder = find.descendant( | ||
of: find.byType(AnimatedFractionallySizedBox), | ||
matching: find.byType(FractionallySizedBox), | ||
); | ||
|
||
const double beginWidthFactor = 0.75; | ||
const double endWidthFactor = 0.25; | ||
const double beginHeightFactor = 0.25; | ||
const double endHeightFactor = 0.75; | ||
const Alignment beginAlignment = Alignment.bottomRight; | ||
const Alignment endAlignment = Alignment.topLeft; | ||
|
||
FractionallySizedBox fractionallySizedBox = tester.widget( | ||
fractionallySizedBoxFinder, | ||
); | ||
expect(fractionallySizedBox.widthFactor, beginWidthFactor); | ||
expect(fractionallySizedBox.heightFactor, beginHeightFactor); | ||
expect(fractionallySizedBox.alignment, beginAlignment); | ||
|
||
// Tap on the AnimatedFractionallySizedBoxExample to start the forward | ||
// animation. | ||
await tester.tap( | ||
find.byType(example.AnimatedFractionallySizedBoxExample), | ||
); | ||
await tester.pump(); | ||
|
||
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder); | ||
expect(fractionallySizedBox.widthFactor, beginWidthFactor); | ||
expect(fractionallySizedBox.heightFactor, beginHeightFactor); | ||
expect(fractionallySizedBox.alignment, beginAlignment); | ||
|
||
// Advance animation to the middle. | ||
await tester.pump( | ||
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2, | ||
); | ||
|
||
final double t = | ||
example.AnimatedFractionallySizedBoxExampleApp.curve.transform(0.5); | ||
|
||
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder); | ||
expect( | ||
fractionallySizedBox.widthFactor, | ||
lerpDouble(beginWidthFactor, endWidthFactor, t), | ||
); | ||
expect( | ||
fractionallySizedBox.heightFactor, | ||
lerpDouble(beginHeightFactor, endHeightFactor, t), | ||
); | ||
expect( | ||
fractionallySizedBox.alignment, | ||
Alignment.lerp(beginAlignment, endAlignment, t), | ||
); | ||
|
||
// Advance animation to the end. | ||
await tester.pump( | ||
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2, | ||
); | ||
|
||
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder); | ||
expect(fractionallySizedBox.widthFactor, endWidthFactor); | ||
expect(fractionallySizedBox.heightFactor, endHeightFactor); | ||
expect(fractionallySizedBox.alignment, endAlignment); | ||
|
||
// Tap on the AnimatedFractionallySizedBoxExample again to start the | ||
// reverse animation. | ||
await tester.tap( | ||
find.byType(example.AnimatedFractionallySizedBoxExample), | ||
); | ||
await tester.pump(); | ||
|
||
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder); | ||
expect(fractionallySizedBox.widthFactor, endWidthFactor); | ||
expect(fractionallySizedBox.heightFactor, endHeightFactor); | ||
expect(fractionallySizedBox.alignment, endAlignment); | ||
|
||
// Advance animation to the middle. | ||
await tester.pump( | ||
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2, | ||
); | ||
|
||
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder); | ||
expect( | ||
fractionallySizedBox.widthFactor, | ||
lerpDouble(endWidthFactor, beginWidthFactor, t), | ||
); | ||
expect( | ||
fractionallySizedBox.heightFactor, | ||
lerpDouble(endHeightFactor, beginHeightFactor, t), | ||
); | ||
expect( | ||
fractionallySizedBox.alignment, | ||
Alignment.lerp(endAlignment, beginAlignment, t), | ||
); | ||
|
||
// Advance animation to the end. | ||
await tester.pump( | ||
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2, | ||
); | ||
|
||
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder); | ||
expect(fractionallySizedBox.widthFactor, beginWidthFactor); | ||
expect(fractionallySizedBox.heightFactor, beginHeightFactor); | ||
expect(fractionallySizedBox.alignment, beginAlignment); | ||
}, | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Mayyybe give this a more explicit name. It took me awhile to track down what
t
was when I saw it used below, though admittedly that's only here in the GitHub UI that it's a problem since I would have used jump to definition in my editor. MaybecurveHalf
or something?It could be argued that this styleguide rule applies or does not apply here: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-abbreviations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t is a variable typically used to represent the animation value in calls to
lerp
. Since the animation in this case isn't using any particularly confusing arithmetic, I think it would fine to just leave it as is.